简体   繁体   English

<optimized out>在 gdb 在 ubuntu</optimized>

[英]<Optimized out > in gdb in ubuntu

While debugging using gdb in ubuntu, after a break point I tried to print some thing.在 ubuntu 中使用 gdb 进行调试时,在断点之后我尝试打印一些东西。 It showed <value optimized out > .它显示<value optimized out > In the make file I have changed -O2 to -O0 , even then the same error occurs.在制作文件中,我已将-O2更改为-O0 ,即使这样也会发生相同的错误。 How to get rid of this error and print the optimized out value?如何摆脱此错误并打印优化后的值?

The dreaded "optimized out" message means that the compiler decided that it can't tell the debugger where the variable lies.可怕的“优化”消息意味着编译器决定它不能告诉调试器变量所在的位置。 It could be totally gone, or it could just be too complicated to represent in some way (perhaps in the interests of sanity inside the compiler code).它可能完全消失了,或者它可能太复杂而无法以某种方式表示(也许是为了编译器代码内部的理智)。

There are a few techniques you can use to avoid this message.您可以使用一些技术来避免此消息。

First, make sure -fvar-tracking is enabled.首先,确保-fvar-tracking已启用。 It should be the default when optimizing if you are using DWARF (side note: never use stabs), but it doesn't hurt to make sure.如果您使用 DWARF,它应该是优化时的默认设置(旁注:永远不要使用 stabs),但确保它并没有什么坏处。 You may want -fvar-tracking-assignments as well.您可能还需要-fvar-tracking-assignments These flags tell GCC to try harder to generate debug info for variables.这些标志告诉 GCC 更加努力地为变量生成调试信息。

If that fails, and you still need a particular variable, you can try compiling with less optimization.如果失败了,并且您仍然需要一个特定的变量,您可以尝试使用较少的优化进行编译。 -O0 should work. -O0应该可以工作。 I see in the post that you say it does not work, but in my long experience working on gdb, this always turns out to be some kind of developer error -- you forgot to rebuild the correct file, you are using the wrong library, something like that.我在帖子中看到您说它不起作用,但是根据我在 gdb 上工作的长期经验,这总是被证明是某种开发人员错误——您忘记重建正确的文件,您使用了错误的库,类似的东西。 You could also try -Og , which tries to enable only optimizations that won't hurt debugging.您也可以尝试-Og ,它尝试仅启用不会影响调试的优化。

One final option is to try to make the variable in question live at the point at which you're interested in it.最后一种选择是尝试使有问题的变量在您对其感兴趣的位置生效。 For example you can take its address and pass it to some other function, being careful not to let the compiler optimize that function away.例如,您可以获取它的地址并将其传递给其他一些 function,注意不要让编译器优化 function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM