Skip to content

Commit cbf8162

Browse files
authored
Merge pull request buserror#512 from gatk555/dwarf
Use libwarf to show additional symbols and line numbers in tracing.
2 parents 53ae63c + 292a7bb commit cbf8162

File tree

10 files changed

+775
-148
lines changed

10 files changed

+775
-148
lines changed

Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PREFIX = ${DESTDIR}
1414

1515
all: build-simavr build-tests build-examples build-parts
1616

17-
build-simavr:
17+
build-simavr: Libs.mk
1818
$(MAKE) -C simavr RELEASE=$(RELEASE)
1919

2020
build-tests: build-simavr
@@ -34,6 +34,28 @@ install-simavr:
3434
install-parts:
3535
$(MAKE) -C examples/parts install RELEASE=$(RELEASE) DESTDIR=$(DESTDIR) PREFIX=$(PREFIX)
3636

37+
38+
# Find whether libelf and libdwarf are available.
39+
40+
Libs.mk:
41+
@echo CONF $@
42+
@echo "# Autogenerated: do not edit." > $@
43+
@if \
44+
echo "#include <libelf.h>" > testit.c && \
45+
$(CC) -E $(CFLAGS) ${AVR_CPPFLAGS} testit.c > /dev/null 2>&1 ; \
46+
then \
47+
echo CFLAGS += -DHAVE_LIBELF >> $@ ; \
48+
echo LDFLAGS += -lelf >> $@ ; \
49+
if \
50+
echo "#include <dwarf.h>" > testit.c && \
51+
$(CC) -E $(CFLAGS) ${AVR_CPPFLAGS} testit.c > /dev/null 2>&1 ; \
52+
then \
53+
echo CFLAGS += -DHAVE_LIBDWARF >> $@ ; \
54+
echo LDFLAGS += -ldwarf >> $@ ; \
55+
fi \
56+
fi
57+
@rm -f testit.c
58+
3759
doc:
3860
$(MAKE) -C doc RELEASE=$(RELEASE)
3961

@@ -43,4 +65,5 @@ clean:
4365
$(MAKE) -C examples clean
4466
$(MAKE) -C examples/parts clean
4567
$(MAKE) -C doc clean
68+
rm -f Libs.mk
4669

Makefile.common

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ OBJ := obj-${shell $(CC) -dumpmachine}
114114
LIBDIR := ${shell pwd}/${SIMAVR}/${OBJ}
115115
LDFLAGS += -L${LIBDIR} -lsimavr -lm
116116

117-
LDFLAGS += -lelf
117+
# Are libelf and/or libdwarf installed?
118+
# The included file is created when running "make" at the top level.
119+
120+
ifeq ($(shell test -f $(SIMAVR)/../Libs.mk || echo Exists), Exists)
121+
$(warning Missing library configuration file. Make from top level to create it.)
122+
endif
123+
-include $(SIMAVR)/../Libs.mk
118124

119125
ifeq (${WIN}, Msys)
120126
LDFLAGS += -lws2_32

simavr/sim/sim_avr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ avr_init(
105105
memset(avr->data, 0, avr->ramend + 1);
106106
#ifdef CONFIG_SIMAVR_TRACE
107107
avr->trace_data = calloc(1, sizeof(struct avr_trace_data_t));
108+
avr->trace_data->data_names_size = avr->ioend + 1;
108109
#endif
110+
avr->data_names = calloc(avr->ioend + 1, sizeof (char *));
109111

110112
AVR_LOG(avr, LOG_TRACE, "%s init\n", avr->mmcu);
111113

simavr/sim/sim_avr.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,17 @@ enum {
106106

107107
cpu_Sleeping, // we're now sleeping until an interrupt
108108

109-
cpu_Step, // run ONE instruction, then...
109+
cpu_Step, // run ONE instruction, then...
110110
cpu_StepDone, // tell gdb it's all OK, and give it registers
111111
cpu_Done, // avr software stopped gracefully
112112
cpu_Crashed, // avr software crashed (watchdog fired)
113113
};
114114

115115
// this is only ever used if CONFIG_SIMAVR_TRACE is defined
116116
struct avr_trace_data_t {
117-
struct avr_symbol_t ** codeline;
117+
const char ** codeline; // Text for each Flash address
118+
uint32_t codeline_size; // Size of codeline table.
119+
uint32_t data_names_size;// Size of data_names table.
118120

119121
/* DEBUG ONLY
120122
* this keeps track of "jumps" ie, call,jmp,ret,reti and so on
@@ -152,14 +154,12 @@ typedef void (*avr_run_t)(
152154
#define AVR_FUSE_HIGH 1
153155
#define AVR_FUSE_EXT 2
154156

155-
#define REG_NAME_COUNT (256 + 32) // Size of reg_names table.
156-
157157
/*
158158
* Main AVR instance. Some of these fields are set by the AVR "Core" definition files
159159
* the rest is runtime data (as little as possible)
160160
*/
161161
typedef struct avr_t {
162-
const char * mmcu; // name of the AVR
162+
const char * mmcu; // name of the AVR
163163
// these are filled by sim_core_declare from constants in /usr/lib/avr/include/avr/io*.h
164164
uint16_t ioend;
165165
uint16_t ramend;
@@ -348,6 +348,10 @@ typedef struct avr_t {
348348
uint32_t size;
349349
uint32_t len;
350350
} io_console_buffer;
351+
352+
// Table of register names used by gdb and tracing.
353+
354+
const char ** data_names;
351355
} avr_t;
352356

353357

0 commit comments

Comments
 (0)