src/gb/debugger/symbols.c (view raw)
1/* Copyright (c) 2013-2016 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include <mgba/internal/gb/debugger/symbols.h>
7
8#include <mgba/internal/debugger/symbols.h>
9#include <mgba-util/string.h>
10#include <mgba-util/vfs.h>
11
12void GBLoadSymbols(struct mDebuggerSymbols* st, struct VFile* vf) {
13 char line[512];
14
15 while (true) {
16 ssize_t bytesRead = vf->readline(vf, line, sizeof(line));
17 if (bytesRead <= 0) {
18 break;
19 }
20 if (line[bytesRead - 1] == '\n') {
21 line[bytesRead - 1] = '\0';
22 }
23 int segment = -1;
24 uint32_t address = 0;
25
26 uint8_t byte;
27 const char* buf = line;
28 while (buf && bytesRead >= 2) {
29 buf = hex8(buf, &byte);
30 if (!buf) {
31 break;
32 }
33 address <<= 8;
34 address += byte;
35 bytesRead -= 2;
36
37 if (buf[0] == ':') {
38 segment = address;
39 address = 0;
40 ++buf;
41 }
42 if (isspace((int) buf[0])) {
43 break;
44 }
45 }
46 if (!buf || bytesRead < 1) {
47 continue;
48 }
49
50 while (isspace((int) buf[0]) && bytesRead > 0) {
51 --bytesRead;
52 ++buf;
53 }
54
55 if (!bytesRead) {
56 continue;
57 }
58
59 mDebuggerSymbolAdd(st, buf, address, segment);
60 }
61}