arm-elf-gdb is confused with source files.

Started by laur...@gmx.de March 8, 2014
Hello,

I am having a problem debugging my code on a LPC2387. The code works fine, but I can't debug.
Somehow arm-elf-gdb is confused by the source files. When for example I try to "list myfunc()", gdb shows the wrong file or doesn't show anything at all ("No source available").
The same with breakpoints. When I set a breakpoint in a function other that main(), the program stops, but gdb jumps to the wrong source file or doesn't jump at all.
Debugging main.c somehow works. Breakpoints are handled correct and a "list main" gives the correct result.

Here is my setup:
-I have multiple files, some in a subdirectory.
-arm-elf-gcc 4.1.1
-arm-elf-gdb 7.7
-newlib 1.14
-I debug the target using openOCD 1.0

My files get compiles like this:
LANG=en arm-elf-gcc -c -mcpu=arm7tdmi-s -I. -gdwarf-2 -g3 -DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2387__ -Wall -Wcast-align -Wimplicit -Wpointer-arith -Wswitch -ffunction-sections -fdata-sections -fpack-struct -Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wa,-adhlns=target.lst -I./inc/ -Wcast-qual -MD -MP -MF .dep/target.o.d -Wnested-externs -std=gnu99 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations target.c -o target.o

Linker:
LANG=en arm-elf-gcc -mcpu=arm7tdmi-s -I. -gdwarf-2 -g3 -DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2387__ -Wall -Wcast-align -Wimplicit -Wpointer-arith -Wswitch -ffunction-sections -fdata-sections -fpack-struct -Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wa,-adhlns=Startup.lst -I./trezor-crypto/ -Wcast-qual -MD -MP -MF .dep/main.elf.d [Bunch of .o files here] --output main.elf -nostartfiles -Wl,-Map=main.map,--cref,--gc-sections -lc -lgcc -T./LPC2387.ld

Any suggestions? I have tried to solve this for days now, but haven't found a solution.

Regards,

Laurenz

An Engineer's Guide to the LPC2100 Series

Using –g3 you are compiling with the optomizer turned on, in which case you enable a variety of optimizations that mean functions may for example get inlined, code may even be generated by the linker ( Not sure whether GCC supports this but many toolchains do ).

Try compiling with –g0, if not for the whole project then at least for the parts you want to debug.

Regards

Phil.

From: l... [mailto:l...] On Behalf Of l...@gmx.de
Sent: 07 March 2014 16:18
To: l...
Subject: [lpc2000] arm-elf-gdb is confused with source files.

Hello,

I am having a problem debugging my code on a LPC2387. The code works fine, but I can't debug.

Somehow arm-elf-gdb is confused by the source files. When for example I try to "list myfunc()", gdb shows the wrong file or doesn't show anything at all ("No source available").

The same with breakpoints. When I set a breakpoint in a function other that main(), the program stops, but gdb jumps to the wrong source file or doesn't jump at all.

Debugging main.c somehow works. Breakpoints are handled correct and a "list main" gives the correct result.

Here is my setup:

-I have multiple files, some in a subdirectory.

-arm-elf-gcc 4.1.1

-arm-elf-gdb 7.7

-newlib 1.14

-I debug the target using openOCD 1.0

My files get compiles like this:

LANG=en arm-elf-gcc -c -mcpu=arm7tdmi-s -I. -gdwarf-2 -g3 -DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2387__ -Wall -Wcast-align -Wimplicit -Wpointer-arith -Wswitch -ffunction-sections -fdata-sections -fpack-struct -Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wa,-adhlns=target.lst -I./inc/ -Wcast-qual -MD -MP -MF .dep/target.o.d -Wnested-externs -std=gnu99 -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations target.c -o target.o

Linker:

LANG=en arm-elf-gcc -mcpu=arm7tdmi-s -I. -gdwarf-2 -g3 -DROM_RUN -D__WinARM__ -D__WINARMSUBMDL_LPC2387__ -Wall -Wcast-align -Wimplicit -Wpointer-arith -Wswitch -ffunction-sections -fdata-sections -fpack-struct -Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wa,-adhlns=Startup.lst -I./trezor-crypto/ -Wcast-qual -MD -MP -MF .dep/main.elf.d [Bunch of .o files here] --output main.elf -nostartfiles -Wl,-Map=main.map,--cref,--gc-sections -lc -lgcc -T./LPC2387.ld

Any suggestions? I have tried to solve this for days now, but haven't found a solution.

Regards,

Laurenz
On 08/03/2014 08:21, Phil Young wrote:
>
>
> Using –g3 you are compiling with the optomizer turned on, in which
> case you enable a variety of optimizations that mean functions may for
> example get inlined, code may even be generated by the linker ( Not sure
> whether GCC supports this but many toolchains do ).
>
>
>
> Try compiling with –g0, if not for the whole project then at least for
> the parts you want to debug.
>

-g has nothing to do with optimisation, and everything to do with how
much debugging information is available. The existing setting of -g3
will provide maximum debugging information, so changing this to -g0
will, if anything, make the problem worse.

Optimisation is controlled by -O[level], which can be set to -O0 to -O3
(and -Os) where the higher the number the higher the optimisation level.
As far as I can see you do not specify a -O level at all, in which case
the default is 0, which is what you want for easy debugging. You may
want to add -O0 to your command line just to make sure. Otherwise the
problem lies elsewhere (are you sure the object being debugged is that
actually built? Are you sure the build was successful?).

Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for microcontrollers. More than 107000 downloads in 2013.

+ http://www.FreeRTOS.org/plus
IoT, Trace, Certification, FAT FS, TCP/IP, Training, and more...



You are using a very old version of gcc (4.1.1 - the latest is 4.8.3) and a very new version of gdb. Perhaps there is a conflict there.

Try getting the latest version of GCC/GDB etc from:
https://launchpad.net/gcc-arm-embedded https://launchpad.net/gcc-arm-embedded
Hey,

thank You all for your input. I've been playing around with all different kinds of settings for -g and -O, without success.
Today I installed a fresh and up to date version of gcc, binutils, gdb and newlib, this time with -target=arm-none-eabi instead of arm-elf and everything is running fine again. I now compile with -g3 and -Os.

Regards,

Laurenz