summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret2013-03-06 11:21:05 (EST)
committerEugene Tarassov2013-03-17 14:39:48 (EDT)
commit3f6ae612da9e4e14b32084df8d9fccce8e4126fb (patch)
tree78ba0f537bdcb7ab8b833eed9fce2a192d57ba83
parentdf1de4ff35d7999062a2139a591ed2ed5fca2c4f (diff)
downloadorg.eclipse.tcf.agent-3f6ae612da9e4e14b32084df8d9fccce8e4126fb.zip
org.eclipse.tcf.agent-3f6ae612da9e4e14b32084df8d9fccce8e4126fb.tar.gz
org.eclipse.tcf.agent-3f6ae612da9e4e14b32084df8d9fccce8e4126fb.tar.bz2
add_disassembler: overwrite disassembler entry if existing
-rw-r--r--agent/tcf/services/disassembly.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/agent/tcf/services/disassembly.c b/agent/tcf/services/disassembly.c
index 1764853..2a78ca5 100644
--- a/agent/tcf/services/disassembly.c
+++ b/agent/tcf/services/disassembly.c
@@ -62,33 +62,42 @@ static size_t context_extension_offset = 0;
#define EXT(ctx) (ctx ? ((ContextExtensionDS *)((char *)(ctx) + context_extension_offset)) : NULL)
-void add_disassembler(Context * ctx, const char * isa, Disassembler disassembler) {
- DisassemblerInfo * i = NULL;
- ContextExtensionDS * ext = EXT(ctx);
- assert(ctx == context_get_group(ctx, CONTEXT_GROUP_CPU));
- if (ext->disassemblers_cnt >= ext->disassemblers_max) {
- ext->disassemblers_max += 8;
- ext->disassemblers = (DisassemblerInfo *)loc_realloc(ext->disassemblers,
- sizeof(DisassemblerInfo) * ext->disassemblers_max);
- }
- i = ext->disassemblers + ext->disassemblers_cnt++;
- i->isa = loc_strdup(isa);
- i->disassembler = disassembler;
-}
-
-static Disassembler * find_disassembler(Context * ctx, const char * isa) {
+static DisassemblerInfo * find_disassembler_info(Context * ctx, const char * isa) {
if (isa != NULL) {
unsigned i = 0;
ContextExtensionDS * ext = EXT(ctx);
while (i < ext->disassemblers_cnt) {
if (strcmp(ext->disassemblers[i].isa, isa) == 0)
- return ext->disassemblers[i].disassembler;
+ return &ext->disassemblers[i];
i++;
}
}
return NULL;
}
+static Disassembler * find_disassembler(Context * ctx, const char * isa) {
+ DisassemblerInfo * i = find_disassembler_info(ctx, isa);
+ return i ? i->disassembler : NULL;
+}
+
+void add_disassembler(Context * ctx, const char * isa, Disassembler disassembler) {
+ DisassemblerInfo * i = NULL;
+ ContextExtensionDS * ext = EXT(ctx);
+ assert(ctx == context_get_group(ctx, CONTEXT_GROUP_CPU));
+ if ((i = find_disassembler_info(ctx, isa)) == NULL) {
+ if (ext->disassemblers_cnt >= ext->disassemblers_max) {
+ ext->disassemblers_max += 8;
+ ext->disassemblers = (DisassemblerInfo *)loc_realloc(ext->disassemblers,
+ sizeof(DisassemblerInfo) * ext->disassemblers_max);
+ }
+ i = ext->disassemblers + ext->disassemblers_cnt++;
+ } else {
+ if (i->isa) loc_free(i->isa);
+ }
+ i->isa = loc_strdup(isa);
+ i->disassembler = disassembler;
+}
+
static void command_get_capabilities(char * token, Channel * c) {
int error = 0;
char id[256];