Question

Supposing I have a static variable declared in gps_anetenova_m10478.c as follows:

static app_timer_id_t m_gps_response_timeout_timer_id;

I have some sort of buffer overrun bug in my code and at some point a write to the variable right before m_gps_response_timeout_timer_id in memory is overwriting it.

I can find out where m_gps_response_timeout_timer_id is in memory using the 'Expressions' view in Eclipse's GDB client. Just enter &m_gps_response_timeout_timer_id. But how do I tell which variable is immediately before it in memory?

Is there a way to get this info into the .map file that ld produces? At the moment I only see source files:

 .bss           0x000000002000011c        0x0 _build/debug_leds.o
 .bss           0x000000002000011c     0x11f8 _build/gps_antenova_m10478.o
 .bss           0x0000000020001314     0x161c _build/gsm_ublox_sara.o
Was it helpful?

Solution

I'll be honest, I don't know enough about Eclipse to give an easy way within Eclipse to get this. The tool you're probably looking for is either objdump or nm. An example with objdump is to simply run objdump -x <myELF>. This will then return all symbols in the file, which section they're in, and their addresses. You'll then have to manually search for the variable in which you're interested based on the addresses.

objdump -x <ELFfile> will give output along the lines of the following:

000120d8 g     F .text  0000033c bit_string_copy
00015ea4 g     O .bss   00000004 overflow_bit
00015e24 g       .bss   00000000 __bss_start
00011ce4 g     F .text  0000003c main
00014b6c g     F .text  0000008c integer_and

The first column is the address, the fourth the section and the fifth the length of that field.

nm <ELFfile> gives the following:

00015ea8 B __bss_end
00015e24 B __bss_start
0000c000 T _start
00015e20 D zero_constant
00015e24 b zero_constant_itself

The first column is the address and the second the section. D/d is data, B/b is BSS and T/t is text. The rest can be found in the manpage. nm also accepts the -n flag to sort the lines by their numeric address.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top