Please SUBSCRIBE to YouTube channel Embedkari for further discussion on Embedded Systems. I recommend to use laptop/PC with headphone or at least Tablet for watching related DWARF YouTube video.
If you find something missing, Please provide feedback in comment box so that I can take corrective action. I discussed about Motorola S record, ELF format in the last blog post. I strongly recommend you to read earlier blogs for better understanding .
Key Takeaway : Debug symbol generation and compiler optimization concepts.
How to generate debugging sybols by gcc ?
As per WiKi DWARF(Debugging With Attributed Record Format) . As per DWARF standard , DWARF stands for Debugging With Arbitrary Record Format.
One can generate DWARF symbols using -g option with gcc and print the same using -w option with readelf utility. We can also use nm(name managing) binary utility of linux to inspect generated ELF.
Verification of Debug symbol generation with x86-64
In this experiment , first hello.c is compiled without -g option and later with -g option. Both the outputs were read by nm -al and stored in text files. Then diff was used to find the difference. As expected, -g option output has information of source file path used.
Inspection of RISCV Release and Debug binaries
Here I am repeating the nm and diff commands as done above. The release binary has no debugging information.
If source level debugging is desired, Avoid any compiler optimization which can lead to mismatch of source code and executable binary.
For final release(without debug information) , You may use suitable optimization flag. There are different optimization options (-O0,-O1,-O2,-O3,-Os,-Ofast) available. One can choose as per requirement. e.g If small code size is required , You may use-Os. Please refer to this for detail.
Thanks for reading till end. I am trying to improve usability of my site. Did you find this discussion helpful ? If so, Please subscribe to YouTube channel Embedkari as well for additional embedded related stuff.