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

Posted 三叁

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.

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)的主要内容,如果未能解决你的问题,请参考以下文章

VS2008 如何将Release版本设置可以调试的DEBUG版本

c语言怎么从debug模式到release模式?

C语言dev c++,选项release,debug,profiling啥意思?

C语言dev c++,选项release,debug,profiling啥意思?

Android 判断是开发debug模式,还是发布release模式

为啥有些 C 程序在 debug 中可以工作,但在 release 中不行?