all repos — mgba @ 2c6715d78f84e5c85ce3b1ebfe81d291e5d49cf7

mGBA Game Boy Advance Emulator

src/debugger/symbols.c (view raw)

 1/* Copyright (c) 2013-2017 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/debugger/symbols.h>
 7
 8#include <mgba-util/table.h>
 9
10struct mDebuggerSymbol {
11	int32_t value;
12	int segment;
13};
14
15struct mDebuggerSymbols {
16	struct Table names;
17};
18
19struct mDebuggerSymbols* mDebuggerSymbolTableCreate(void) {
20	struct mDebuggerSymbols* st = malloc(sizeof(*st));
21	HashTableInit(&st->names, 0, free);
22	return st;
23}
24
25void mDebuggerSymbolTableDestroy(struct mDebuggerSymbols* st) {
26	HashTableDeinit(&st->names);
27	free(st);
28}
29
30bool mDebuggerSymbolLookup(const struct mDebuggerSymbols* st, const char* name, int32_t* value, int* segment) {
31	struct mDebuggerSymbol* sym = HashTableLookup(&st->names, name);
32	if (!sym) {
33		return false;
34	}
35	*value = sym->value;
36	*segment = sym->segment;
37	return true;
38}
39
40void mDebuggerSymbolAdd(struct mDebuggerSymbols* st, const char* name, int32_t value, int segment) {
41	struct mDebuggerSymbol* sym = malloc(sizeof(*sym));
42	sym->value = value;
43	sym->segment = segment;
44	HashTableInsert(&st->names, name, sym);
45}
46
47void mDebuggerSymbolRemove(struct mDebuggerSymbols* st, const char* name) {
48	HashTableRemove(&st->names, name);
49}