1. 程式人生 > >C: release & debug differences (might apply to all programming languages)

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

keep cau variable volatile pro symbol com centos exec

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.

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 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).

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