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) {
29 buf = hex8(buf, &byte);
30 if (!buf) {
31 break;
32 }
33 address <<= 8;
34 address += byte;
35
36 if (buf[0] == ':') {
37 segment = address;
38 address = 0;
39 ++buf;
40 }
41 if (isspace((int) buf[0])) {
42 break;
43 }
44 }
45 if (!buf) {
46 continue;
47 }
48
49 while (isspace((int) buf[0])) {
50 ++buf;
51 }
52
53 mDebuggerSymbolAdd(st, buf, address, segment);
54 }
55}