GDB skips over code

dschnabel
Posts: 2
Joined: Thu Jun 27, 2019 6:45 pm

GDB skips over code

Postby dschnabel » Thu Jun 27, 2019 7:06 pm

I am fairly new using gdb on ESP32 and I am not sure if what I'm seeing is expected. I got debugging working fine using a JTAG and OpenOCD but when I step through the code, some lines are getting skipped. First I thought the problem is that my ELF file is not debug optimized but looking at the compiler flags it tells me that the ELF is debug optimized (-Og -ggdb):

Code: Select all

xtensa-esp32-elf-gcc -std=gnu99 -Og -ggdb -Wno-frame-address -ffunction-sections \
-fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wall -Werror=all \
-Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable \
-Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare \
-Wno-old-style-declaration -DESP_PLATFORM -D IDF_VER=\"v4.0-dev-837-g58df1d93b-dirty\" \
-MMD -MP   -D_GNU_SOURCE -DGCC_NOT_5_2_0=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' \
-DHAVE_CONFIG_H -DUNITY_INCLUDE_CONFIG_H [a bunch of -I includes] \
-c /home/daniel/esp32/projects/hello_world/main/hello_world_main.c -o hello_world_main.o
My simple program has these lines:

Code: Select all

int a = 1;
a = 3;
printf("%d\n", a);
a = 4;
printf("%d\n", a);
I expect to be able to step through each line, but GDB only stops at the two 'printf()' commands. It does not stop at 'a = 3;' or 'a = 4;'.

Running 'disassemble' in gdb gives me this assembly:

Code: Select all

(gdb) disassemble /m app_main
Dump of assembler code for function app_main:
4	{
   0x400d29e4 <+0>:	entry	a1, 32

5		int a = 1;

6		a = 3;

7		printf("%d\n", a);
   0x400d29e7 <+3>:	l32r	a2, 0x400d0348 <_stext+816>
   0x400d29ea <+6>:	movi	a11, 3
   0x400d29ed <+9>:	or	a10, a2, a2
   0x400d29f0 <+12>:	call8	0x400d3290 <printf>

8		a = 4;

9		printf("%d\n", a);
   0x400d29f3 <+15>:	movi.n	a11, 4
   0x400d29f5 <+17>:	mov.n	a10, a2
   0x400d29f7 <+19>:	call8	0x400d3290 <printf>
   0x400d29fa <+22>:	retw.n

End of assembler dump.
Any idea what's going on?

dschnabel
Posts: 2
Joined: Thu Jun 27, 2019 6:45 pm

[Solved] GDB skips over code

Postby dschnabel » Fri Jun 28, 2019 4:36 am

Turns out I had to use the gcc build flag '-O0' instead of '-Og' in order to disable any sort of optimization. Using '-O0' allows me to step through each line of the code.

See the issue I had opened and the solution from igrr: https://github.com/espressif/openocd-esp32/issues/79

Who is online

Users browsing this forum: No registered users and 132 guests