Gdb: "The left assignment operand is not an lvalue value."

I am debugging an ARM microcontroller remotely and trying to change a variable using gdb in the following code block:

for (int i = 0; i < 100; i++) {
    __asm__("nop");
}

When I execute print i, I can see the value of the variable

(gdb) print i
$1 = 0

Execution whatis ireturns this

whatis i
~"type = int\n"

But when I try to change the variable, I get the following error:

(gdb) set variable i=99
Left operand of assignment is not an lvalue.

What am I doing wrong here?

UPDATE: here is the assembler code

!        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    
+4
source share
4 answers

I had the same problem and the variable helped me volatile.

+4
source

The team will just set i = 99

+1
source

:

(gdb) print i
$1 = 3
(gdb) set var i=6
(gdb) print i
$2 = 6
0

There are two problems here, changing the variable name from ito var_ias there are some set commands, starting with itherefore set i=6will produce an ambiguous set of command error.

"The left assignment operand is not an lvalue." can be fixed with code changes as shown below.

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       do375       {                                                                                                        │
      >│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
0
source

Source: https://habr.com/ru/post/1531030/


All Articles