From 70d394483206f5afe911fa21c8456b852c12da74 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 30 Dec 2015 23:19:01 -0500 Subject: [PATCH] sim: msp430: switch to common disassembler tracing 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/ChangeLog | 10 ++ sim/msp430/Makefile.in | 1 - sim/msp430/msp430-sim.c | 41 +------ sim/msp430/trace.c | 320 ------------------------------------------------ sim/msp430/trace.h | 28 ----- 5 files changed, 12 insertions(+), 388 deletions(-) delete mode 100644 sim/msp430/trace.c delete mode 100644 sim/msp430/trace.h diff --git a/sim/msp430/ChangeLog b/sim/msp430/ChangeLog index fea5ce8..4f4b938 100644 --- a/sim/msp430/ChangeLog +++ b/sim/msp430/ChangeLog @@ -1,3 +1,13 @@ +2016-01-05 Mike Frysinger + + * Makefile.in (SIM_OBJS): Delete trace.o. + * msp430-sim.c: Delete dis-asm.h and trace.h includes. + (sim_open): Delete msp430_trace_init call. + (msp430_dis_read): Delete function. + (msp430_step_once): Replace disassembly logic with a call + to TRACE_DISASM. + * trace.c, trace.h: Delete files. + 2016-01-04 Mike Frysinger * configure: Regenerate. diff --git a/sim/msp430/Makefile.in b/sim/msp430/Makefile.in index 3746fc2..4194690 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 f701f81..a074587 100644 --- a/sim/msp430/msp430-sim.c +++ b/sim/msp430/msp430-sim.c @@ -30,9 +30,7 @@ #include "opcode/msp430-decode.h" #include "sim-main.h" #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 +223,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 +872,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 +1129,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 e7b26da..0000000 --- a/sim/msp430/trace.c +++ /dev/null @@ -1,320 +0,0 @@ -/* trace.c --- tracing output for the MSP430 simulator. - - Copyright (C) 2005-2016 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 . -*/ - - -#include "config.h" -#include -#include -#include -#include -#include -#include -#include - -#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 5fc1a01..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-2016 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 . */ - -#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.7.4