我正在远程调试ARM微控制器并尝试在以下代码块中使用gdb修改变量:
for (int i = 0; i < 100; i++) {
__asm__("nop");
}
当我执行print i
时,我可以看到变量的值
(gdb) print i
$1 = 0
执行whatis i
会返回此
whatis i
~"type = int\n"
但是当我尝试更改变量时,我得到以下错误
(gdb) set variable i=99
Left operand of assignment is not an lvalue.
我在这里做错了什么?
更新:这里是汇编代码
! 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
! __asm__("nop");
main+36: nop
答案 0 :(得分:4)
我遇到了同样的问题,并使变量volatile
有所帮助。
答案 1 :(得分:1)
命令只是set i = 99
答案 2 :(得分:0)
以这种方式尝试:
(gdb) print i
$1 = 3
(gdb) set var i=6
(gdb) print i
$2 = 6
答案 3 :(得分:0)
这里有两个问题,将变量名从i
更改为var_i
,因为有一些以i
开头的set命令,因此set i=6
将给出模糊的命令集错误。
“赋值的左操作数不是左值。”可以通过如下所示的代码更改来解决。
volatile int var_i = 1;
TRACE((2255, 0, NORMAL, "Ravi I am sleeping here........."));
do
{
sleep(5);
var_i = 1;
}while(var_i);
(gdb)bt
#1 0x00007f67fd7b9404 in sleep () from /lib64/libc.so.6
#2 0x00000000004cd410 in pgWSNVBUHandleGetUser (warning: Source file is more recent than executable.
ptRequest=<optimized out>, oRequest=<optimized out>,
(gdb) finish
Run till exit from #0 0x00007f67fd7b9550 in __nanosleep_nocancel () from /lib64/libc.so.6
0x00007f67fd7b9404 in sleep () from /lib64/libc.so.6
(gdb) finish
Run till exit from #0 0x00007f67fd7b9404 in sleep () from /lib64/libc.so.6
0x00000000004cd410 in pgWSNVBUHandleGetUser (ptRequest=<optimized out>, oRequest=<optimized out>,
pptResponse=0x7fff839e8760) at /root/Checkouts/trunk/source/base/webservice/provnvbuuser.c:376
(gdb)
│372 volatile int var_i = 1; │
│373 TRACE((2255, 0, NORMAL, "Ravi I am sleeping here.........")); │
│374 do │
│375 { │
>│376 sleep(5); │
│377 var_i = 1; │
│378 }while(var_i);
(gdb) set var_i=0
(gdb) n
(gdb) p var_i
$1 = 1
(gdb) set var_i=0
(gdb) p var_i
$2 = 0
(gdb) n
(gdb) n