.ELF file created by PlatformIO does not contain degub symbol

I am creating .elf using Platform IO(using with VS code). When i load this elf file into Proteus simulation for debugging, it does not show a source code. I have tried same thing with arduino official IDE, here it works just fine. i have tried following build flags “build_flags = -g3 -ggdb”.

Does setting build_type = debug in the platformio.ini make any difference (as opposed to the default setting of release)?

1 Like

thank you @pfeerick.
Now i can see some of the files while debugging. But i can only see file where are from arduino library. Files where my implementation is, i still not see those files.

When you say it worked with the Arduino IDE, did you have to do anything (set any options there?) And what board (or platform) is this for?

I have such a problem. Have you found a solution?

Solution is already above.

Otherwise please state exactly what info is still missing in there.

Here are the files that were included in the debug:

There is no file from the project:

The project files were not included in debugging. The build script for kernel files works in a special way. Platformio users would like this path to be available for all other project files.

I don’t have this problem when working with GDB. Just using the ELF file, GDB can display the code.

C:\Users\Max>C:\Users\Max\.platformio\packages\toolchain-atmelavr@1.70300.191015\bin\avr-gdb.exe C:\Users\Max\Documents\PlatformIO\Projects\esp8266_airfilter\.pio\build\nanoatmega328\firmware.elf
GNU gdb (GDB) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-w64-mingw32 --target=avr".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from C:\Users\Max\Documents\PlatformIO\Projects\esp8266_airfilter\.pio\build\nanoatmega328\firmware.elf...done.
(gdb) list src/main.cpp:5
1       #include "Arduino.h"
2
3       void setup()
4       {
5         pinMode(LED_BUILTIN, OUTPUT);
6       }
7
8       void loop()
9       {
10        digitalWrite(LED_BUILTIN, HIGH);
(gdb)
11        delay(1000);
12        digitalWrite(LED_BUILTIN, LOW);
13        delay(1000);
14      }(gdb)
(gdb)
Source files for which symbols have been read in:

C:\Users\Max\Documents\PlatformIO\Projects\esp8266_airfilter/<artificial>,
c:\users\max\.platformio\packages\framework-arduino-avr\variants\standard\pins_arduino.h,
c:\users\max\.platformio\packages\toolchain-atmelavr@1.50400.190710\avr\include\stdint.h,
C:\Users\Max\Documents\PlatformIO\Projects\esp8266_airfilter\src\main.cpp,
C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\main.cpp,
C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\wiring.c,
C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\wiring_digital.c,
C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\hooks.c

Source files for which symbols will be read in on demand:

C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\main.cpp,
C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\wiring.c,
C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\wiring_digital.c,
C:\Users\Max\.platformio\packages\framework-arduino-avr\cores\arduino\hooks.c,

And that’s from a project with a stanard

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
build_type = debug

How do you view the source code of the ELF file within Proteus?

1 Like

How can I use the GDB utility to list all the files?
In Proteus:

GNU gdb (GDB) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type “show copying”
and “show warranty” for details.
This GDB was configured as “–host=i686-w64-mingw32 --target=avr”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type “help”.
Type “apropos word” to search for commands related to “word”…
Reading symbols from C:\Users\Pavel\Documents\PlatformIO\Projects\TestDebugInfo.pio\build\nanoatmega328new\firmware.elf…done.
(gdb) list src/main.cpp:5
warning: Source file is more recent than executable.
1
2 #include “Arduino.h”
3
4 void setup()
5 {
6 pinMode(LED_BUILTIN, OUTPUT);
7 }
8
9 void loop()
10 {
(gdb)
11 digitalWrite(LED_BUILTIN, HIGH);
12
13 delay(1000);
14
15 digitalWrite(LED_BUILTIN, LOW);
16
17 delay(1000);
18 }
(gdb)
Line number 19 out of range; src/main.cpp has 18 lines.
(gdb)
Line number 19 out of range; src/main.cpp has 18 lines.
(gdb)
Line number 19 out of range; src/main.cpp has 18 lines.
(gdb)

You can write info sources in the GDB console.

Seems like the source file was changed and the ELF has an older version.

How do you get to this screen? I have the Proteus Demo version (as I don’t have ~800€ for the Pro version) and I can start a new project for the Nano 3 and load the ELF file via ‘Edit properties’ → Program file of the microcontroller, but I don’t see how I can get to the AVR Source Code UI.




Ah thanks, now I get to that Window, too.

Seems like Proteus has problems with the src/main.cpp, confusing it with arduino/main.cpp

I start in main() and when I go into the function call to setup(), I just land at the start of some header file.

grafik

Let me rename some files…

Be sure to try it. It didn’t work out for me.
And he jumps to the line where the pins should be pulled in the kernel code. The user code simply does not see it. There is either something with the paths or with the build options.

GNU gdb (GDB) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type “show copying”
and “show warranty” for details.
This GDB was configured as “–host=i686-w64-mingw32 --target=avr”.
Type “show configuration” for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type “help”.
Type “apropos word” to search for commands related to “word”…
Reading symbols from C:\Users\Pavel\Documents\PlatformIO\Projects\TestDebugInfo.pio\build\nanoatmega328new\firmware.elf…done.
(gdb) info sources
Source files for which symbols have been read in:

C:\Users\Pavel\Documents\PlatformIO\Projects\TestDebugInfo/<<‘artificial’>>,
c:\users\pavel.platformio\packages\framework-arduino-avr\variants\standard\pins_arduino.h,
c:\users\pavel.platformio\packages\toolchain-atmelavr\avr\include\stdint.h,
C:\Users\Pavel\Documents\PlatformIO\Projects\TestDebugInfo\src\main.cpp,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\main.cpp,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\wiring.c,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\wiring_digital.c,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\hooks.c

Source files for which symbols will be read in on demand:

/home/jenkins-mingw32/workspace/avr-gcc-staging/label/Ubuntu14.04x64-mingw32/gcc-build/avr/avr5/libgcc/…/…/…/…/gcc/libgcc/config/avr/lib1funcs.S, C:\Users\Pavel\Documents\PlatformIO\Projects\TestDebugInfo\src\main.cpp,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\main.cpp,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\wiring.c,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\wiring_digital.c,
C:\Users\Pavel.platformio\packages\framework-arduino-avr\cores\arduino\hooks.c,
(gdb)

There is the file, I don’t know why Proteus doesn’t see it.

If I load only the firmware.elf file into other binary analysis programs like IDA, I can also see that it sees my project’s main source file.

(There I’ve named it src/user_main.cpp).

I’ll check with whether a Arduino-IDE generated ELF file works. If it does, is must be something in the build process.

What is it:

artificial???

Good question, no idea.

However, it works with .elf files built from the Arduino IDE.

Not sure why though.

Please analyze the elf file from the Arduino IDE in the GDB utility. Use the “info sources” command.