(gdb) n
134 a = b = c = 0xdeadbeef + ((uint32_t)length) + initval;
(gdb) n
(gdb) p a
$30 = <value optimized out>
(gdb) p b
$31 = <value optimized out>
(gdb) p c
$32 = 3735928563
Run Code Online (Sandbox Code Playgroud)
gdb如何优化我的价值?
我正在使用gdb来调试C++程序.
我有这个代码:
int x = floor(sqrt(3));
Run Code Online (Sandbox Code Playgroud)
我想查看x的值.但是,gdb声称x是"<optimized_out>".如何查看x的值?我应该更改编译器标志吗?
我希望能够在GDB中设置一个断点,让它运行到那一点 - 并在此过程中,打印出已经"逐步完成"的行.
这是一个例子,基于这个带有a main和a函数的简单文件,每个都有两个断点:
$ cat > test.c <<EOF
#include "stdio.h"
int count=0;
void doFunction(void) {
// two steps forward
count += 2;
// one step back
count--;
}
int main(void) {
// some pointless init commands;
count = 1;
count += 2;
count = 0;
//main loop
while(1) {
doFunction();
printf("%d\n", count);
}
}
EOF
$ gcc -g -Wall test.c -o test.exe
$ chmod +x test.exe
$ gdb -se test.exe
...
Reading symbols from /path/to/test.exe...done.
(gdb) b …Run Code Online (Sandbox Code Playgroud) 我试图让ZBar进入调试会话.我能够这样做,但我无法关闭优化器,因此我的调试会话意外跳转,许多变量都标记为optimized-outEclipse Indigo.我在Ubuntu中运行.
我尝试尽可能在Makefile中的任何gcc调用中添加-O0,因为最后一个-O是代理的.我使用-Q --help = optimizers来查找要查找的内容,但它的输出有点奇怪:
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -I./zbar -I./include -O0 -O0 -Q --help=optimizers -Wall -Wno-parentheses -O0 -g -O0 -Q --help=optimizers -MT zbar/zbar_libzbar_la-config.lo -MD -MP -MF zbar/.deps/zbar_libzbar_la-config.Tpo -c zbar/config.c -fPIC -DPIC -o zbar/.libs/zbar_libzbar_la-config.o
The following options control optimizations:
make[1]: *** [zbar/zbar_libzbar_la-config.lo] Error 1
-O<number>
make: *** [all] Error 2
-Ofast
-Os
-falign-functions [disabled]
-falign-jumps [disabled]
-falign-labels [disabled]
-falign-loops [disabled]
-fasynchronous-unwind-tables [enabled]
-fbranch-count-reg [enabled]
-fbranch-probabilities [disabled]
-fbranch-target-load-optimize [disabled]
-fbranch-target-load-optimize2 [disabled]
-fbtr-bb-exclusive [disabled]
-fcaller-saves …Run Code Online (Sandbox Code Playgroud) 我正在远程调试 ARM 微控制器,并尝试使用 gdb 在以下代码块中修改变量:
for (int i = 0; i < 100; i++) {
__asm__("nop");
}
Run Code Online (Sandbox Code Playgroud)
当我执行时print i我可以看到变量的值
(gdb) print i
$1 = 0
Run Code Online (Sandbox Code Playgroud)
执行whatis i返回这个
whatis i
~"type = int\n"
Run Code Online (Sandbox Code Playgroud)
但是当我尝试更改变量时出现以下错误
(gdb) set variable i=99
Left operand of assignment is not an lvalue.
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
更新:这是汇编代码
! for (int i = 0; i < 100; i++) {
main+38: subs\tr3, #1
main+40: bne.n\t0x80001d0 <main+36>
main+42: b.n\t0x80001c4 <main+24>
main+44: lsrs\tr0, r0, #16
main+46: ands\tr2, r0
! …Run Code Online (Sandbox Code Playgroud)