Preparing for GDB Debugging
Once your toolchain is ready, you can consider all the tools prepared.
Now let’s make the actual target you need to debug ready for debugging.
Adjusting Compiler Options
Ref: Linux Foundation 2020 Conference
First, when compiling C or C++ source code, add the -g option or -gN option as shown in the diagram above to include various information like source code debugging information in the ELF file.
Using -ggdbN will create an ELF using the gdb format instead of the standard DWARF format.
Generally, just adding -g will give the ELF a level equivalent to -g2.
Ref: Linux Foundation 2020 Conference
Next, you need to adjust the Optimization Options.
When optimization is enabled, the compiler analyzes the code logic and might generate different execution code that produces the same results, so you should remove optimization options during debugging.
Use the -O0 option or give -Og for GDB-compatible optimization options.
Reference
Share this article
Found this helpful? Share it with your network
관련 글
Join the Discussion
Share your thoughts and connect with other readers
댓글
GitHub 계정으로 로그인하여 댓글을 남겨보세요. 건설적인 의견과 질문을 환영합니다!
댓글을 불러오는 중...
댓글을 불러올 수 없습니다.