* [PATCH 1/4] sim: trace: add support for disassembling
2015-12-31 4:32 [PATCH 0/4] sim: unify disassmebly tracing logic Mike Frysinger
@ 2015-12-31 4:32 ` Mike Frysinger
2015-12-31 4:32 ` [PATCH 2/4] sim: msp430: switch to common disassembler tracing Mike Frysinger
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2015-12-31 4:32 UTC (permalink / raw)
To: gdb-patches; +Cc: nickc
Some targets have started to add support for calling the disassembler
automatically when executing code. Add support for that directly into
the trace core.
---
sim/common/sim-trace.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
sim/common/sim-trace.h | 40 +++++++++++++++++++++++++++++++-
2 files changed, 101 insertions(+), 1 deletion(-)
diff --git a/sim/common/sim-trace.c b/sim/common/sim-trace.c
index e69c62d..66ff4ac 100644
--- a/sim/common/sim-trace.c
+++ b/sim/common/sim-trace.c
@@ -25,6 +25,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "bfd.h"
#include "libiberty.h"
+#include "dis-asm.h"
+
#include "sim-assert.h"
#ifdef HAVE_STRING_H
@@ -61,6 +63,7 @@ static DECLARE_OPTION_HANDLER (trace_option_handler);
enum {
OPTION_TRACE_INSN = OPTION_START,
+ OPTION_TRACE_DISASM,
OPTION_TRACE_DECODE,
OPTION_TRACE_EXTRACT,
OPTION_TRACE_LINENUM,
@@ -90,6 +93,9 @@ static const OPTION trace_options[] =
{ {"trace-insn", optional_argument, NULL, OPTION_TRACE_INSN},
'\0', "on|off", "Perform instruction tracing",
trace_option_handler, NULL },
+ { {"trace-disasm", optional_argument, NULL, OPTION_TRACE_DISASM},
+ '\0', "on|off", "Disassemble instructions (slower, but more accurate)",
+ trace_option_handler, NULL },
{ {"trace-decode", optional_argument, NULL, OPTION_TRACE_DECODE},
'\0', "on|off", "Trace instruction decoding",
trace_option_handler, NULL },
@@ -249,6 +255,13 @@ trace_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
sim_io_eprintf (sd, "Instruction tracing not compiled in, `--trace-insn' ignored\n");
break;
+ case OPTION_TRACE_DISASM :
+ if (WITH_TRACE_DISASM_P)
+ return set_trace_option (sd, "-disasm", TRACE_DISASM_IDX, arg);
+ else
+ sim_io_eprintf (sd, "Instruction tracing not compiled in, `--trace-disasm' ignored\n");
+ break;
+
case OPTION_TRACE_DECODE :
if (WITH_TRACE_DECODE_P)
return set_trace_option (sd, "-decode", TRACE_DECODE_IDX, arg);
@@ -616,6 +629,7 @@ trace_idx_to_str (int trace_idx)
{
case TRACE_ALU_IDX: return "alu: ";
case TRACE_INSN_IDX: return "insn: ";
+ case TRACE_DISASM_IDX: return "disasm: ";
case TRACE_DECODE_IDX: return "decode: ";
case TRACE_EXTRACT_IDX: return "extract: ";
case TRACE_MEMORY_IDX: return "memory: ";
@@ -837,6 +851,54 @@ trace_generic (SIM_DESC sd,
trace_printf (sd, cpu, "\n");
}
+static int
+dis_read (bfd_vma memaddr, bfd_byte *myaddr, unsigned int length,
+ struct disassemble_info *dinfo)
+{
+ SIM_CPU *cpu = dinfo->application_data;
+ sim_core_read_buffer (CPU_STATE (cpu), cpu, NULL_CIA, myaddr, memaddr, length);
+ return 0;
+}
+
+static int
+dis_printf (SIM_CPU *cpu, const char *fmt, ...)
+{
+ SIM_DESC sd = CPU_STATE (cpu);
+ va_list ap;
+ va_start (ap, fmt);
+ trace_vprintf (sd, cpu, fmt, ap);
+ va_end (ap);
+ return 0;
+}
+
+void
+trace_disasm (SIM_DESC sd, sim_cpu *cpu, address_word addr)
+{
+ struct bfd *bfd = STATE_PROG_BFD (sd);
+ TRACE_DATA *trace_data = CPU_TRACE_DATA (cpu);
+ disassemble_info *info = &trace_data->dis_info;
+
+ /* See if we need to set up the disassembly func. */
+ if (trace_data->dis_bfd != bfd)
+ {
+ trace_data->dis_bfd = bfd;
+ trace_data->disassembler = disassembler (trace_data->dis_bfd);
+ INIT_DISASSEMBLE_INFO (*info, cpu, dis_printf);
+ info->read_memory_func = dis_read;
+ info->arch = bfd_get_arch (bfd);
+ info->mach = bfd_get_mach (bfd);
+ disassemble_init_for_target (info);
+ }
+
+ info->application_data = cpu;
+
+ trace_printf (sd, cpu, "%s %s",
+ trace_idx_to_str (TRACE_DISASM_IDX),
+ TRACE_PREFIX (trace_data));
+ trace_data->disassembler (addr, info);
+ trace_printf (sd, cpu, "\n");
+}
+
void
trace_input0 (SIM_DESC sd,
sim_cpu *cpu,
diff --git a/sim/common/sim-trace.h b/sim/common/sim-trace.h
index 28fc351..87e0478 100644
--- a/sim/common/sim-trace.h
+++ b/sim/common/sim-trace.h
@@ -22,12 +22,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef SIM_TRACE_H
#define SIM_TRACE_H
+#include "dis-asm.h"
+
/* Standard traceable entities. */
enum {
- /* Trace insn execution. */
+ /* Trace insn execution. The port itself is responsible for displaying what
+ it thinks it is decoding. */
TRACE_INSN_IDX = 1,
+ /* Disassemble code addresses. Like insn tracing, but relies on the opcode
+ framework for displaying code. Can be slower, more accurate as to what
+ the binary code actually is, but not how the sim is decoding it. */
+ TRACE_DISASM_IDX,
+
/* Trace insn decoding.
??? This is more of a simulator debugging operation and might best be
moved to --debug-decode. */
@@ -97,6 +105,7 @@ enum {
The case choice here is on purpose. The lowercase parts are args to
--with-trace. */
#define TRACE_insn (1 << TRACE_INSN_IDX)
+#define TRACE_disasm (1 << TRACE_DISASM_IDX)
#define TRACE_decode (1 << TRACE_DECODE_IDX)
#define TRACE_extract (1 << TRACE_EXTRACT_IDX)
#define TRACE_linenum (1 << TRACE_LINENUM_IDX)
@@ -118,6 +127,7 @@ enum {
/* Preprocessor macros to simplify tests of WITH_TRACE. */
#define WITH_TRACE_ANY_P (WITH_TRACE)
#define WITH_TRACE_INSN_P WITH_TRACE_P (TRACE_INSN_IDX)
+#define WITH_TRACE_DISASM_P WITH_TRACE_P (TRACE_DISASM_IDX)
#define WITH_TRACE_DECODE_P WITH_TRACE_P (TRACE_DECODE_IDX)
#define WITH_TRACE_EXTRACT_P WITH_TRACE_P (TRACE_EXTRACT_IDX)
#define WITH_TRACE_LINENUM_P WITH_TRACE_P (TRACE_LINENUM_IDX)
@@ -190,6 +200,19 @@ typedef struct _trace_data {
??? Not all cpu's support this. */
ADDR_RANGE range;
#define TRACE_RANGE(t) (& (t)->range)
+
+ /* The bfd used to disassemble code. Should compare against STATE_PROG_BFD
+ before using the disassembler helper.
+ Meant for use by the internal trace module only. */
+ struct bfd *dis_bfd;
+
+ /* The function used to actually disassemble code.
+ Meant for use by the internal trace module only. */
+ disassembler_ftype disassembler;
+
+ /* State used with the disassemble function.
+ Meant for use by the internal trace module only. */
+ disassemble_info dis_info;
} TRACE_DATA;
\f
/* System tracing support. */
@@ -204,6 +227,7 @@ typedef struct _trace_data {
/* Non-zero if --trace-<xxxx> was specified for SD. */
#define STRACE_ANY_P(sd) (WITH_TRACE_ANY_P && (STATE_TRACE_DATA (sd)->trace_any_p))
#define STRACE_INSN_P(sd) STRACE_P (sd, TRACE_INSN_IDX)
+#define STRACE_DISASM_P(sd) STRACE_P (sd, TRACE_DISASM_IDX)
#define STRACE_DECODE_P(sd) STRACE_P (sd, TRACE_DECODE_IDX)
#define STRACE_EXTRACT_P(sd) STRACE_P (sd, TRACE_EXTRACT_IDX)
#define STRACE_LINENUM_P(sd) STRACE_P (sd, TRACE_LINENUM_IDX)
@@ -226,6 +250,7 @@ typedef struct _trace_data {
trace_generic (sd, NULL, idx, fmt, ## args); \
} while (0)
#define STRACE_INSN(sd, fmt, args...) STRACE (sd, TRACE_INSN_IDX, fmt, ## args)
+#define STRACE_DISASM(sd, fmt, args...) STRACE (sd, TRACE_DISASM_IDX, fmt, ## args)
#define STRACE_DECODE(sd, fmt, args...) STRACE (sd, TRACE_DECODE_IDX, fmt, ## args)
#define STRACE_EXTRACT(sd, fmt, args...) STRACE (sd, TRACE_EXTRACT_IDX, fmt, ## args)
#define STRACE_LINENUM(sd, fmt, args...) STRACE (sd, TRACE_LINENUM_IDX, fmt, ## args)
@@ -252,6 +277,7 @@ typedef struct _trace_data {
/* Non-zero if --trace-<xxxx> was specified for CPU. */
#define TRACE_ANY_P(cpu) (WITH_TRACE_ANY_P && (CPU_TRACE_DATA (cpu)->trace_any_p))
#define TRACE_INSN_P(cpu) TRACE_P (cpu, TRACE_INSN_IDX)
+#define TRACE_DISASM_P(cpu) TRACE_P (cpu, TRACE_DISASM_IDX)
#define TRACE_DECODE_P(cpu) TRACE_P (cpu, TRACE_DECODE_IDX)
#define TRACE_EXTRACT_P(cpu) TRACE_P (cpu, TRACE_EXTRACT_IDX)
#define TRACE_LINENUM_P(cpu) TRACE_P (cpu, TRACE_LINENUM_IDX)
@@ -266,6 +292,7 @@ typedef struct _trace_data {
#define TRACE_SYSCALL_P(cpu) TRACE_P (cpu, TRACE_SYSCALL_IDX)
#define TRACE_REGISTER_P(cpu) TRACE_P (cpu, TRACE_REGISTER_IDX)
#define TRACE_DEBUG_P(cpu) TRACE_P (cpu, TRACE_DEBUG_IDX)
+#define TRACE_DISASM_P(cpu) TRACE_P (cpu, TRACE_DISASM_IDX)
/* Helper functions for printing messages. */
#define TRACE(cpu, idx, fmt, args...) \
@@ -288,6 +315,11 @@ typedef struct _trace_data {
#define TRACE_SYSCALL(cpu, fmt, args...) TRACE (cpu, TRACE_SYSCALL_IDX, fmt, ## args)
#define TRACE_REGISTER(cpu, fmt, args...) TRACE (cpu, TRACE_REGISTER_IDX, fmt, ## args)
#define TRACE_DEBUG(cpu, fmt, args...) TRACE (cpu, TRACE_DEBUG_IDX, fmt, ## args)
+#define TRACE_DISASM(cpu, addr) \
+ do { \
+ if (TRACE_DISASM_P (cpu)) \
+ trace_disasm (CPU_STATE (cpu), cpu, addr); \
+ } while (0)
\f
/* Tracing functions. */
@@ -313,6 +345,12 @@ extern void trace_generic (SIM_DESC sd,
...)
__attribute__((format (printf, 4, 5)));
+/* Disassemble the specified address. */
+
+extern void trace_disasm (SIM_DESC sd,
+ sim_cpu *cpu,
+ address_word addr);
+
typedef enum {
trace_fmt_invalid,
trace_fmt_word,
--
2.6.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/4] sim: msp430: switch to common disassembler tracing
2015-12-31 4:32 [PATCH 0/4] sim: unify disassmebly tracing logic Mike Frysinger
2015-12-31 4:32 ` [PATCH 1/4] sim: trace: add support for disassembling Mike Frysinger
@ 2015-12-31 4:32 ` Mike Frysinger
2015-12-31 4:32 ` [PATCH 3/4] sim: bfin: add support disasm tracing Mike Frysinger
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2015-12-31 4:32 UTC (permalink / raw)
To: gdb-patches; +Cc: nickc
The output format is a bit different, but the new form matches all the
other trace lines. Otherwise, it should be functionally equivalent.
---
sim/msp430/Makefile.in | 1 -
sim/msp430/msp430-sim.c | 40 +-----
sim/msp430/trace.c | 320 ------------------------------------------------
sim/msp430/trace.h | 28 -----
4 files changed, 2 insertions(+), 387 deletions(-)
delete mode 100644 sim/msp430/trace.c
delete mode 100644 sim/msp430/trace.h
diff --git a/sim/msp430/Makefile.in b/sim/msp430/Makefile.in
index 91473af..651f1a2 100644
--- a/sim/msp430/Makefile.in
+++ b/sim/msp430/Makefile.in
@@ -27,7 +27,6 @@
SIM_OBJS = \
$(SIM_NEW_COMMON_OBJS) \
msp430-sim.o \
- trace.o \
sim-resume.o
# List of extra dependencies.
diff --git a/sim/msp430/msp430-sim.c b/sim/msp430/msp430-sim.c
index ce29fb1..97c532c 100644
--- a/sim/msp430/msp430-sim.c
+++ b/sim/msp430/msp430-sim.c
@@ -32,7 +32,6 @@
#include "sim-syscall.h"
#include "dis-asm.h"
#include "targ-vals.h"
-#include "trace.h"
static int
loader_write_mem (SIM_DESC sd,
@@ -225,8 +224,6 @@ sim_open (SIM_OPEN_KIND kind,
assert (MAX_NR_PROCESSORS == 1);
msp430_initialize_cpu (sd, MSP430_CPU (sd));
- msp430_trace_init (STATE_PROG_BFD (sd));
-
if (prog_bfd != NULL)
{
MSP430_CPU (sd)->state.cio_breakpoint = lookup_symbol (sd, "C$$IO$$");
@@ -876,17 +873,6 @@ msp430_cio (SIM_DESC sd)
#define DSRC get_op (sd, opcode, 0)
#define DEST(V) put_op (sd, opcode, 0, (V))
-static int
-msp430_dis_read (bfd_vma memaddr,
- bfd_byte *myaddr,
- unsigned int length,
- struct disassemble_info *dinfo)
-{
- SIM_DESC sd = dinfo->application_data;
- sim_core_read_buffer (sd, MSP430_CPU (sd), 0, myaddr, memaddr, length);
- return 0;
-}
-
#define DO_ALU(OP,SOP,MORE) \
{ \
int s1 = DSRC; \
@@ -1144,34 +1130,12 @@ msp430_step_once (SIM_DESC sd)
break;
}
- if (TRACE_INSN_P (MSP430_CPU (sd)))
- {
- disassemble_info info;
- unsigned char b[10];
-
- msp430_trace_one (opcode_pc);
-
- sim_core_read_buffer (sd, MSP430_CPU (sd), 0, b, opcode_pc, opsize);
-
- init_disassemble_info (&info, stderr, (fprintf_ftype) fprintf);
- info.application_data = sd;
- info.read_memory_func = msp430_dis_read;
-
- fprintf (stderr, "%#8x ", opcode_pc);
- for (i = 0; i < opsize; i += 2)
- fprintf (stderr, " %02x%02x", b[i+1], b[i]);
- for (; i < 6; i += 2)
- fprintf (stderr, " ");
- fprintf (stderr, " ");
- print_insn_msp430 (opcode_pc, &info);
- fprintf (stderr, "\n");
- fflush (stdout);
- }
-
if (TRACE_ANY_P (MSP430_CPU (sd)))
trace_prefix (sd, MSP430_CPU (sd), NULL_CIA, opcode_pc,
TRACE_LINENUM_P (MSP430_CPU (sd)), NULL, 0, "");
+ TRACE_DISASM (MSP430_CPU (sd), opcode_pc);
+
carry_to_use = 0;
switch (opcode->id)
{
diff --git a/sim/msp430/trace.c b/sim/msp430/trace.c
deleted file mode 100644
index b6c7b02..0000000
--- a/sim/msp430/trace.c
+++ /dev/null
@@ -1,320 +0,0 @@
-/* trace.c --- tracing output for the MSP430 simulator.
-
- Copyright (C) 2005-2015 Free Software Foundation, Inc.
- Contributed by Red Hat, Inc.
-
- This file is part of the GNU simulators.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-#include "config.h"
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
-
-#include "libiberty.h"
-#include "bfd.h"
-#include "dis-asm.h"
-#include "trace.h"
-
-static int
-sim_dis_read (bfd_vma memaddr, bfd_byte * ptr, unsigned int length,
- struct disassemble_info *info)
-{
- return 0;
-}
-
-/* Filter out (in place) symbols that are useless for disassembly.
- COUNT is the number of elements in SYMBOLS.
- Return the number of useful symbols. */
-
-static long
-remove_useless_symbols (asymbol ** symbols, long count)
-{
- asymbol **in_ptr = symbols, **out_ptr = symbols;
-
- while (-- count >= 0)
- {
- asymbol *sym = *in_ptr ++;
-
- if (strstr (sym->name, "gcc2_compiled"))
- continue;
- if (sym->name == NULL || sym->name[0] == '\0')
- continue;
- if (sym->flags & (BSF_DEBUGGING))
- continue;
- if (bfd_is_und_section (sym->section)
- || bfd_is_com_section (sym->section))
- continue;
-
- if (sym->name[0] == '.' && sym->name[1] == 'L')
- continue;
-
- /* If the symbol ends in ^A or ^B it is
- an assembler generated local label. */
- if (sym->name[strlen (sym->name) - 1] < 32)
- continue;
-
- *out_ptr++ = sym;
- }
- return out_ptr - symbols;
-}
-
-static int
-compare_symbols (const PTR ap, const PTR bp)
-{
- const asymbol *a = *(const asymbol **) ap;
- const asymbol *b = *(const asymbol **) bp;
-
- if (bfd_asymbol_value (a) > bfd_asymbol_value (b))
- return 1;
- else if (bfd_asymbol_value (a) < bfd_asymbol_value (b))
- return -1;
- return 0;
-}
-
-static char opbuf[1000];
-
-static int
-op_printf (char *buf, char *fmt, ...)
-{
- int ret;
- va_list ap;
-
- va_start (ap, fmt);
- ret = vsprintf (opbuf + strlen (opbuf), fmt, ap);
- va_end (ap);
- return ret;
-}
-
-static bfd * current_bfd = NULL;
-static asymbol ** symtab = NULL;
-static int symcount = 0;
-static asection * code_section = NULL;
-static bfd_vma code_base = 0;
-static struct disassemble_info info;
-
-void
-msp430_trace_init (bfd *prog)
-{
- current_bfd = prog;
-}
-
-typedef struct Files
-{
- struct Files *next;
- char *filename;
- int nlines;
- char **lines;
- char *data;
-} Files;
-Files *files = 0;
-
-static char *
-load_file_and_line (const char *filename, int lineno)
-{
- Files *f;
- for (f = files; f; f = f->next)
- if (strcmp (f->filename, filename) == 0)
- break;
- if (!f)
- {
- int i;
- struct stat s;
- const char *found_filename, *slash;
- FILE *file;
-
- found_filename = filename;
- while (1)
- {
- if (stat (found_filename, &s) == 0)
- break;
- slash = strchr (found_filename, '/');
- if (!slash)
- return "";
- found_filename = slash + 1;
- }
-
- f = (Files *) xmalloc (sizeof (Files));
- f->next = files;
- files = f;
- f->filename = xstrdup (filename);
- f->data = (char *) xmalloc (s.st_size + 2);
- file = fopen (found_filename, "rb");
- fread (f->data, 1, s.st_size, file);
- f->data[s.st_size] = 0;
- fclose (file);
-
- f->nlines = 1;
- for (i = 0; i < s.st_size; i ++)
- if (f->data[i] == '\n')
- f->nlines ++;
- f->lines = (char **) xmalloc (f->nlines * sizeof (char *));
- f->lines[0] = f->data;
- f->nlines = 1;
- for (i = 0; i < s.st_size; i ++)
- if (f->data[i] == '\n')
- {
- f->lines[f->nlines] = f->data + i + 1;
- while (*f->lines[f->nlines] == ' '
- || *f->lines[f->nlines] == '\t')
- f->lines[f->nlines] ++;
- f->nlines ++;
- f->data[i] = 0;
- }
- }
- if (lineno < 1 || lineno > f->nlines)
- return "";
- return f->lines[lineno - 1];
-}
-
-int
-msp430_get_current_source_location (int mypc,
- const char ** pfilename,
- const char ** pfunctionname,
- unsigned int * plineno)
-{
- static int initted = 0;
-
- if (current_bfd == NULL)
- {
- printf("no bfd\n");
- return 0;
- }
-
- if (!initted)
- {
- int storage;
- asection * s;
-
- initted = 1;
- memset (& info, 0, sizeof (info));
- INIT_DISASSEMBLE_INFO (info, stdout, op_printf);
- info.read_memory_func = sim_dis_read;
- info.arch = bfd_get_arch (current_bfd);
- info.mach = bfd_get_mach (current_bfd);
- if (info.mach == 0)
- info.arch = bfd_arch_msp430;
-
- disassemble_init_for_target (& info);
-
- storage = bfd_get_symtab_upper_bound (current_bfd);
- if (storage > 0)
- {
- symtab = (asymbol **) xmalloc (storage);
- symcount = bfd_canonicalize_symtab (current_bfd, symtab);
- symcount = remove_useless_symbols (symtab, symcount);
- qsort (symtab, symcount, sizeof (asymbol *), compare_symbols);
- }
-
- for (s = current_bfd->sections; s; s = s->next)
- {
- if (s->flags & SEC_CODE || code_section == 0)
- {
- code_section = s;
- code_base = bfd_section_lma (current_bfd, s);
- break;
- }
- }
- }
-
- *pfilename = *pfunctionname = NULL;
- *plineno = 0;
-
- bfd_find_nearest_line
- (current_bfd, code_section, symtab, mypc - code_base,
- pfilename, pfunctionname, plineno);
-
- return 1;
-}
-
-void
-msp430_trace_one (int mypc)
-{
- static int last_sym = -1;
- static const char * prev_filename = "";
- static int prev_lineno = 0;
- const char * filename;
- const char * functionname;
- unsigned int lineno;
- int sym, bestaddr;
- int min, max, i;
-
- if (! msp430_get_current_source_location (mypc, & filename, & functionname, & lineno))
- return;
-
- if (filename && functionname && lineno)
- {
- if (lineno != prev_lineno || strcmp (prev_filename, filename))
- {
- char * the_line = load_file_and_line (filename, lineno);
- const char * slash = strrchr (filename, '/');
-
- if (!slash)
- slash = filename;
- else
- slash ++;
- fprintf
- (stderr, "========================================"
- "=====================================\n");
- fprintf (stderr, "\033[37;41m %s:%d: \033[33;40m %s\033[K\033[0m\n",
- slash, lineno, the_line);
- }
- prev_lineno = lineno;
- prev_filename = filename;
- }
-
- min = -1;
- max = symcount;
- while (min < max - 1)
- {
- bfd_vma sa;
-
- sym = (min + max) / 2;
- sa = bfd_asymbol_value (symtab[sym]);
- /*printf ("checking %4d %08x %s\n",
- sym, sa, bfd_asymbol_name (symtab[sym])); */
- if (sa > mypc)
- max = sym;
- else if (sa < mypc)
- min = sym;
- else
- {
- min = sym;
- break;
- }
- }
-
- if (min != -1 && min != last_sym)
- {
- bestaddr = bfd_asymbol_value (symtab[min]);
- fprintf (stderr, "\033[43;30m%s", bfd_asymbol_name (symtab[min]));
- if (bestaddr != mypc)
- fprintf (stderr, "+%d", mypc - bestaddr);
- fprintf (stderr, ":\t\t\t\033[0m\n");
- last_sym = min;
-#if 0
- if (trace == 1)
- if (strcmp (bfd_asymbol_name (symtab[min]), "abort") == 0
- || strcmp (bfd_asymbol_name (symtab[min]), "exit") == 0)
- trace = 0;
-#endif
- }
-}
diff --git a/sim/msp430/trace.h b/sim/msp430/trace.h
deleted file mode 100644
index 0085c3c..0000000
--- a/sim/msp430/trace.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* trace.h --- interface to tracing output for the MSP430 simulator.
-
- Copyright (C) 2005-2015 Free Software Foundation, Inc.
- Contributed by Red Hat, Inc.
-
- This file is part of the GNU simulators.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#ifndef SIM_MSP430_TRACE_H_
-#define SIM_MSP430_TRACE_H_
-
-extern void msp430_trace_init (bfd *);
-extern void msp430_trace_one (int pc);
-extern int msp430_get_current_source_location (int, const char **, const char **, unsigned int *);
-
-#endif
--
2.6.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/4] sim: bfin: add support disasm tracing
2015-12-31 4:32 [PATCH 0/4] sim: unify disassmebly tracing logic Mike Frysinger
2015-12-31 4:32 ` [PATCH 1/4] sim: trace: add support for disassembling Mike Frysinger
2015-12-31 4:32 ` [PATCH 2/4] sim: msp430: switch to common disassembler tracing Mike Frysinger
@ 2015-12-31 4:32 ` Mike Frysinger
2015-12-31 4:40 ` [PATCH 4/4] sim: aarch64: switch to common disassembler tracing Mike Frysinger
2016-01-05 16:54 ` [PATCH 0/4] sim: unify disassmebly tracing logic Nick Clifton
4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2015-12-31 4:32 UTC (permalink / raw)
To: gdb-patches; +Cc: nickc
---
sim/bfin/interp.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c
index 2da70b5..c71b0a2 100644
--- a/sim/bfin/interp.c
+++ b/sim/bfin/interp.c
@@ -620,6 +620,8 @@ step_once (SIM_CPU *cpu)
trace_prefix (sd, cpu, NULL_CIA, oldpc, TRACE_LINENUM_P (cpu),
NULL, 0, " "); /* Use a space for gcc warnings. */
+ TRACE_DISASM (cpu, oldpc);
+
/* Handle hardware single stepping when lower than EVT3, and when SYSCFG
has already had the SSSTEP bit enabled. */
ssstep = false;
--
2.6.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/4] sim: aarch64: switch to common disassembler tracing
2015-12-31 4:32 [PATCH 0/4] sim: unify disassmebly tracing logic Mike Frysinger
` (2 preceding siblings ...)
2015-12-31 4:32 ` [PATCH 3/4] sim: bfin: add support disasm tracing Mike Frysinger
@ 2015-12-31 4:40 ` Mike Frysinger
2016-01-05 16:54 ` [PATCH 0/4] sim: unify disassmebly tracing logic Nick Clifton
4 siblings, 0 replies; 6+ messages in thread
From: Mike Frysinger @ 2015-12-31 4:40 UTC (permalink / raw)
To: gdb-patches; +Cc: nickc
The output should largely be the same.
---
sim/aarch64/interp.c | 96 -------------------------------------------------
sim/aarch64/memory.c | 2 --
sim/aarch64/simulator.c | 49 +++++++------------------
sim/aarch64/simulator.h | 3 --
4 files changed, 13 insertions(+), 137 deletions(-)
diff --git a/sim/aarch64/interp.c b/sim/aarch64/interp.c
index b297460..8dc8cb3 100644
--- a/sim/aarch64/interp.c
+++ b/sim/aarch64/interp.c
@@ -38,58 +38,9 @@
#include "memory.h"
#include "simulator.h"
-#include "dis-asm.h"
-
-static struct disassemble_info info;
static unsigned long symcount = 0;
static asymbol ** symtab = NULL;
-/* FIXME: 1000 characters should be enough to hold the disassembled
- instruction plus any comments that come after it. But maybe with
- C++ programs this might not be enough. Not sure if it is worth
- adding logic to dynamically grow the buffer though. */
-static char opbuf[1000];
-
-static int op_printf (void *, const char *, ...) ATTRIBUTE_FPTR_PRINTF_2;
-
-static int
-op_printf (void *stream ATTRIBUTE_UNUSED, const char *fmt, ...)
-{
- size_t space_remaining;
- int ret;
- va_list ap;
-
- space_remaining = sizeof (opbuf) - strlen (opbuf);
- va_start (ap, fmt);
- /* Instead of printing to stream we store the text in opbuf.
- This allows us to use the sim_io_eprintf routine to output
- the text in aarch64_print_insn. */
- ret = vsnprintf (opbuf + strlen (opbuf), space_remaining, fmt, ap);
- va_end (ap);
- return ret;
-}
-
-void
-aarch64_print_insn (SIM_DESC sd, uint64_t addr)
-{
- int size;
-
- opbuf[0] = 0;
- size = print_insn_aarch64 (addr, & info);
- sim_io_eprintf (sd, " %*s\n", size, opbuf);
-}
-
-static int
-sim_dis_read (bfd_vma memaddr,
- bfd_byte * ptr,
- unsigned int length,
- struct disassemble_info * info)
-{
- aarch64_get_mem_blk (info->application_data, memaddr, (char *) ptr, length);
-
- return 0;
-}
-
/* Filter out (in place) symbols that are useless for disassembly.
COUNT is the number of elements in SYMBOLS.
Return the number of useful symbols. */
@@ -202,16 +153,6 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd, char **argv, char **env)
STATE_PROG_ARGV (sd) = dupargv (argv);
}
- memset (& info, 0, sizeof (info));
- init_disassemble_info (& info, NULL, op_printf);
- info.read_memory_func = sim_dis_read;
- info.arch = bfd_get_arch (abfd);
- info.mach = bfd_get_mach (abfd);
- info.application_data = cpu;
- if (info.mach == 0)
- info.arch = bfd_arch_aarch64;
- disassemble_init_for_target (& info);
-
storage = bfd_get_symtab_upper_bound (abfd);
if (storage > 0)
{
@@ -384,41 +325,6 @@ free_state (SIM_DESC sd)
sim_state_free (sd);
}
-enum
-{
- OPTION_DISAS = OPTION_START,
-};
-
-static SIM_RC
-aarch64_option_handler (SIM_DESC sd ATTRIBUTE_UNUSED,
- sim_cpu * current_cpu ATTRIBUTE_UNUSED,
- int opt,
- char * arg ATTRIBUTE_UNUSED,
- int is_command ATTRIBUTE_UNUSED)
-{
- switch (opt)
- {
- case OPTION_DISAS:
- disas = TRUE;
- return SIM_RC_OK;
-
- default:
- sim_io_eprintf (sd, "Unknown AArch64 option %d\n", opt);
- return SIM_RC_FAIL;
- }
-}
-
-static DECLARE_OPTION_HANDLER (aarch64_option_handler);
-
-const OPTION aarch64_options[] =
-{
- { {"disas", no_argument, NULL, OPTION_DISAS },
- '\0', NULL, "Enable instruction disassembly",
- aarch64_option_handler, NULL },
-
- { {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL, NULL }
-};
-
SIM_DESC
sim_open (SIM_OPEN_KIND kind,
struct host_callback_struct * callback,
@@ -434,8 +340,6 @@ sim_open (SIM_OPEN_KIND kind,
SIM_ASSERT (STATE_MAGIC (sd) == SIM_MAGIC_NUMBER);
- sim_add_option_table (sd, NULL, aarch64_options);
-
/* Perform the initialization steps one by one. */
if (sim_cpu_alloc_all (sd, 1, 0) != SIM_RC_OK
|| sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK
diff --git a/sim/aarch64/memory.c b/sim/aarch64/memory.c
index 4df9360..c3762cd 100644
--- a/sim/aarch64/memory.c
+++ b/sim/aarch64/memory.c
@@ -39,8 +39,6 @@
static inline void
mem_error (sim_cpu *cpu, const char *message, uint64_t addr)
{
- if (disas)
- sim_io_eprintf (CPU_STATE (cpu), "\n");
TRACE_MEMORY (cpu, "ERROR: %s: %" PRIx64, message, addr);
}
diff --git a/sim/aarch64/simulator.c b/sim/aarch64/simulator.c
index 5957946..93dd3d5 100644
--- a/sim/aarch64/simulator.c
+++ b/sim/aarch64/simulator.c
@@ -29,8 +29,6 @@
#include <time.h>
#include <limits.h>
-#include "dis-asm.h"
-
#include "simulator.h"
#include "cpustate.h"
#include "memory.h"
@@ -38,8 +36,6 @@
#define NO_SP 0
#define SP_OK 1
-bfd_boolean disas = FALSE;
-
#define TST(_flag) (aarch64_test_CPSR_bit (cpu, _flag))
#define IS_SET(_X) ( TST (( _X )))
#define IS_CLEAR(_X) (!TST (( _X )))
@@ -47,14 +43,11 @@ bfd_boolean disas = FALSE;
#define HALT_UNALLOC \
do \
{ \
- if (TRACE_INSN_P (cpu)) \
- { \
- aarch64_print_insn (CPU_STATE (cpu), aarch64_get_PC (cpu)); \
- TRACE_INSN (cpu, \
- "Unallocated instruction detected at sim line %d,"\
- " exe addr %" PRIx64, \
- __LINE__, aarch64_get_PC (cpu)); \
- } \
+ TRACE_DISASM (cpu, aarch64_get_PC (cpu)); \
+ TRACE_INSN (cpu, \
+ "Unallocated instruction detected at sim line %d," \
+ " exe addr %" PRIx64, \
+ __LINE__, aarch64_get_PC (cpu)); \
sim_engine_halt (CPU_STATE (cpu), cpu, NULL, aarch64_get_PC (cpu),\
sim_stopped, SIM_SIGILL); \
} \
@@ -63,14 +56,11 @@ bfd_boolean disas = FALSE;
#define HALT_NYI \
do \
{ \
- if (TRACE_INSN_P (cpu)) \
- { \
- aarch64_print_insn (CPU_STATE (cpu), aarch64_get_PC (cpu)); \
- TRACE_INSN (cpu, \
- "Unimplemented instruction detected at sim line %d,"\
- " exe addr %" PRIx64, \
- __LINE__, aarch64_get_PC (cpu)); \
- } \
+ TRACE_DISASM (cpu, aarch64_get_PC (cpu)); \
+ TRACE_INSN (cpu, \
+ "Unimplemented instruction detected at sim line %d," \
+ " exe addr %" PRIx64, \
+ __LINE__, aarch64_get_PC (cpu)); \
sim_engine_halt (CPU_STATE (cpu), cpu, NULL, aarch64_get_PC (cpu),\
sim_stopped, SIM_SIGABRT); \
} \
@@ -12682,9 +12672,6 @@ handle_halt (sim_cpu *cpu, uint32_t val)
else if (fd == 1)
{
printf ("%.*s", (int) len, aarch64_get_mem_ptr (cpu, buf));
- if (disas)
- /* So that the output stays in sync with trace output. */
- fflush (stdout);
}
else if (fd == 2)
{
@@ -13036,19 +13023,9 @@ aarch64_step (sim_cpu *cpu)
aarch64_set_next_PC (cpu, pc + 4);
aarch64_get_instr (cpu) = aarch64_get_mem_u32 (cpu, pc);
- if (TRACE_INSN_P (cpu))
- {
- if (disas)
- TRACE_INSN (cpu, " pc = %" PRIx64 " ", pc);
- else
- TRACE_INSN (cpu, " pc = %" PRIx64 " instr = %x", pc,
- aarch64_get_instr (cpu));
- }
- else if (disas)
- sim_io_eprintf (CPU_STATE (cpu), " %" PRIx64 " ", pc);
-
- if (disas)
- aarch64_print_insn (CPU_STATE (cpu), pc);
+ TRACE_INSN (cpu, " pc = %" PRIx64 " instr = %x", pc,
+ aarch64_get_instr (cpu));
+ TRACE_DISASM (cpu, pc);
aarch64_decode_and_execute (cpu, pc);
diff --git a/sim/aarch64/simulator.h b/sim/aarch64/simulator.h
index 1f22448..e074644 100644
--- a/sim/aarch64/simulator.h
+++ b/sim/aarch64/simulator.h
@@ -29,8 +29,6 @@
#include "sim-main.h"
#include "decode.h"
-extern bfd_boolean disas;
-
#define TOP_LEVEL_RETURN_PC 0xffffffffffffffecULL
/* Call this to set the start stack pointer, frame pointer and pc
@@ -50,7 +48,6 @@ extern void aarch64_init (sim_cpu *, uint64_t);
extern void aarch64_run (SIM_DESC);
extern const char * aarch64_get_func (uint64_t);
-extern void aarch64_print_insn (SIM_DESC, uint64_t);
extern uint64_t aarch64_get_sym_value (const char *);
extern void aarch64_init_LIT_table (void);
--
2.6.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/4] sim: unify disassmebly tracing logic
2015-12-31 4:32 [PATCH 0/4] sim: unify disassmebly tracing logic Mike Frysinger
` (3 preceding siblings ...)
2015-12-31 4:40 ` [PATCH 4/4] sim: aarch64: switch to common disassembler tracing Mike Frysinger
@ 2016-01-05 16:54 ` Nick Clifton
4 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2016-01-05 16:54 UTC (permalink / raw)
To: Mike Frysinger, gdb-patches
Hi Mike,
> Nick: could you give the msp430/aarch64 changes a glance before i push ?
They look good to me.
Thanks for unifying the code in this way.
Cheers
Nick
^ permalink raw reply [flat|nested] 6+ messages in thread