aboutsummaryrefslogtreecommitdiff
path: root/sim/common
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
parent31925464a80970e37c06192a0c49f8948a2f5da0 (diff)
downloadgdb-5357150c97899af2cc93072780a9c3a128c5b1ae.zip
gdb-5357150c97899af2cc93072780a9c3a128c5b1ae.tar.gz
gdb-5357150c97899af2cc93072780a9c3a128c5b1ae.tar.bz2
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')
-rw-r--r--sim/common/ChangeLog12
-rw-r--r--sim/common/sim-base.h4
-rw-r--r--sim/common/sim-trace.c89
-rw-r--r--sim/common/sim-trace.h4
4 files changed, 83 insertions, 26 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index e8da2b1..0d4ec46 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,15 @@
+2016-08-15 Mike Frysinger <vapier@gentoo.org>
+
+ * sim-base.h (sim_state_base): Add prog_syms_count.
+ (STATE_PROG_SYMS_COUNT): Define.
+ * sim-trace.c (trace_uninstall): Free STATE_PROG_SYMS memory.
+ (trace_load_symbols): New function.
+ (trace_sym_value): Likewise.
+ (trace_prefix): Change STATE_CPU(cpu) to sd. Replace symbol
+ loading logic with a call to trace_load_symbols.
+ * sim-trace.h (trace_load_symbols, trace_sym_value): New
+ prototypes.
+
2016-08-13 Mike Frysinger <vapier@gentoo.org>
* cgen-types.h (mode_names): Mark const.
diff --git a/sim/common/sim-base.h b/sim/common/sim-base.h
index 350b352..76167eb 100644
--- a/sim/common/sim-base.h
+++ b/sim/common/sim-base.h
@@ -160,6 +160,10 @@ typedef struct {
struct bfd_symbol **prog_syms;
#define STATE_PROG_SYMS(sd) ((sd)->base.prog_syms)
+ /* Number of prog_syms symbols. */
+ long prog_syms_count;
+#define STATE_PROG_SYMS_COUNT(sd) ((sd)->base.prog_syms_count)
+
/* The program's text section. */
struct bfd_section *text_section;
/* Starting and ending text section addresses from the bfd. */
diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c
index e299cf8..5e84e13 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;
diff --git a/sim/common/sim-trace.h b/sim/common/sim-trace.h
index 40de5bf..d3392ae 100644
--- a/sim/common/sim-trace.h
+++ b/sim/common/sim-trace.h
@@ -671,6 +671,10 @@ extern void trace_vprintf (SIM_DESC, sim_cpu *, const char *, va_list);
/* Non-zero if "--debug-insn" specified. */
#define DEBUG_INSN_P(cpu) DEBUG_P (cpu, DEBUG_INSN_IDX)
+/* Symbol related helpers. */
+int trace_load_symbols (SIM_DESC);
+bfd_vma trace_sym_value (SIM_DESC, const char *name);
+
extern void sim_debug_printf (sim_cpu *, const char *, ...)
__attribute__((format (printf, 2, 3)));