summaryrefslogtreecommitdiff
path: root/sim/common/sim-trace.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-01-21 22:17:59 -0500
committerMike Frysinger <vapier@gentoo.org>2016-08-15 07:00:11 -0700
commit5357150c97899af2cc93072780a9c3a128c5b1ae (patch)
treef61415d77e934b9f54994e92e7f00b30da499890 /sim/common/sim-trace.c
parent31925464a80970e37c06192a0c49f8948a2f5da0 (diff)
downloadbinutils-gdb-5357150c97899af2cc93072780a9c3a128c5b1ae.tar.gz
sim: unify symbol table handling
The common sim tracing code already handles loading and tracking of symbols from the target program so that it can show symbol info in trace/disassembly calls. Once we touch up the trace code and add a few API callbacks, ports don't need to do loading and searching of symbol tables themselves anymore.
Diffstat (limited to 'sim/common/sim-trace.c')
-rw-r--r--sim/common/sim-trace.c89
1 files changed, 63 insertions, 26 deletions
diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c
index e299cf857d0..5e84e13deca 100644
--- a/sim/common/sim-trace.c
+++ b/sim/common/sim-trace.c
@@ -510,6 +510,9 @@ trace_uninstall (SIM_DESC sd)
fclose (cfile);
}
}
+
+ if (STATE_PROG_SYMS (sd))
+ free (STATE_PROG_SYMS (sd));
}
/* compute the nr of trace data units consumed by data */
@@ -685,6 +688,57 @@ trace_results (SIM_DESC sd,
trace_printf (sd, cpu, "\n");
}
+int
+trace_load_symbols (SIM_DESC sd)
+{
+ bfd *abfd;
+ asymbol **asymbols;
+ long symsize;
+ long symbol_count;
+
+ /* Already loaded, so nothing to do. */
+ if (STATE_PROG_SYMS (sd))
+ return 1;
+
+ abfd = STATE_PROG_BFD (sd);
+ if (abfd == NULL)
+ return 0;
+
+ symsize = bfd_get_symtab_upper_bound (abfd);
+ if (symsize < 0)
+ return 0;
+
+ asymbols = xmalloc (symsize);
+ symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
+ if (symbol_count < 0)
+ {
+ free (asymbols);
+ return 0;
+ }
+
+ STATE_PROG_SYMS (sd) = asymbols;
+ STATE_PROG_SYMS_COUNT (sd) = symbol_count;
+ return 1;
+}
+
+bfd_vma
+trace_sym_value (SIM_DESC sd, const char *name)
+{
+ asymbol **asymbols;
+ long i;
+
+ if (!trace_load_symbols (sd))
+ return -1;
+
+ asymbols = STATE_PROG_SYMS (sd);
+
+ for (i = 0; i < STATE_PROG_SYMS_COUNT (sd); ++i)
+ if (strcmp (asymbols[i]->name, name) == 0)
+ return bfd_asymbol_value (asymbols[i]);
+
+ return -1;
+}
+
void
trace_prefix (SIM_DESC sd,
sim_cpu *cpu,
@@ -744,9 +798,9 @@ trace_prefix (SIM_DESC sd,
{
char buf[256];
buf[0] = 0;
- if (STATE_TEXT_SECTION (CPU_STATE (cpu))
- && pc >= STATE_TEXT_START (CPU_STATE (cpu))
- && pc < STATE_TEXT_END (CPU_STATE (cpu)))
+ if (STATE_TEXT_SECTION (sd)
+ && pc >= STATE_TEXT_START (sd)
+ && pc < STATE_TEXT_END (sd))
{
const char *pc_filename = (const char *)0;
const char *pc_function = (const char *)0;
@@ -754,31 +808,14 @@ trace_prefix (SIM_DESC sd,
bfd *abfd;
asymbol **asymbols;
- abfd = STATE_PROG_BFD (CPU_STATE (cpu));
- asymbols = STATE_PROG_SYMS (CPU_STATE (cpu));
- if (asymbols == NULL)
- {
- long symsize;
- long symbol_count;
+ if (!trace_load_symbols (sd))
+ sim_engine_abort (sd, cpu, cia, "could not load symbols");
- symsize = bfd_get_symtab_upper_bound (abfd);
- if (symsize < 0)
- {
- sim_engine_abort (sd, cpu, cia, "could not read symbols");
- }
- asymbols = (asymbol **) xmalloc (symsize);
- symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
- if (symbol_count < 0)
- {
- sim_engine_abort (sd, cpu, cia, "could not canonicalize symbols");
- }
- STATE_PROG_SYMS (CPU_STATE (cpu)) = asymbols;
- }
+ abfd = STATE_PROG_BFD (sd);
+ asymbols = STATE_PROG_SYMS (sd);
- if (bfd_find_nearest_line (abfd,
- STATE_TEXT_SECTION (CPU_STATE (cpu)),
- asymbols,
- pc - STATE_TEXT_START (CPU_STATE (cpu)),
+ if (bfd_find_nearest_line (abfd, STATE_TEXT_SECTION (sd), asymbols,
+ pc - STATE_TEXT_START (sd),
&pc_filename, &pc_function, &pc_linenum))
{
char *p = buf;