C: release & debug differences (might apply to all programming languages)

Sometimes we build a program as release and when debugging, some variables cannot be printed out, and displayed as optimized out. That is because the debugger(gdb) always prints a variable which locates on the stack, or resides in memory. But in release programs, variables might be optimized to only reside in register (or sometimes not exist and be pre-calculated into other variables when compiling). So print a variable which does not exist (in memory) always get you nothing. So this time we need to learn some asm and print the related register. Also, specify a variable as 'volatile' should prevent the compiler from optimizing the specified variable out from the memory, thus resulting that we can print the 'volatile' variable in the debugger(gdb).

When talking about release & debug version of programs, both symbols and debug-info can reside in every object-file/executable, there is no difference between debug & release when talking about symbols or debuginfos. Play around with stacks, abi & asm are very important when debugging release programs. But keep in mind symbols and debug-infos are different. Symbols in object files/executables tells us which memory has the name of "a"; Debuginfos give sources. So in CentOS, installing a debuginfo of a certain package means we can then debug into the package functions (obtained the sourced version of the package libraries).

posted on 2017-12-21 20:12  三叁  阅读(160)  评论(0编辑  收藏  举报

导航