1

been using gas assembler and here is code below that moves a data between register and memory

  3 .section .data
  4     constant:
  5         .int 10
  6 
  7 .section .text
  8     .globl _start
  9 
 10 _start:
 11     nop
 12 
 13 mov_immediate_data_between_reg_and_mem:
 14     movl $777, %eax
 15     movl %eax, constant
 16 
 17 exit:
 18     movl $1, %eax
 19     movl $0, %ebx
 20     int $0x80

then created executable file and linker and then i debug that code below, i want to to print a changed value of variable and then error appears:

Breakpoint 1, 0x08049000 in _start ()
(gdb) si
0x08049001 in mov_immediate_data_between_reg_and_mem ()
(gdb) si
0x08049006 in mov_immediate_data_between_reg_and_mem ()
(gdb) si
0x0804900b in exit ()
(gdb) print constant
'constant' has unknown type; cast it to its declared type

but when i cast it with its type it works perfect:

(gdb) print (int)constant
$1 = 777

and if i try to assign new value to a variable it push the same error and if i try to set a new value to variable with its type it push the error below:

(gdb) set (int)constant = 666
Left operand of assignment is not an lvalue.
4
  • 5
    set *(int *)&constant = ... Commented May 29 at 17:17
  • In short, gdb takes types from .debug_info section. See also this question Commented May 30 at 0:44
  • 1
    The syntax is C-like, and this behavior is consistent with C, where the result of a cast expression is never an lvalue and cannot be assigned to. So as mentioned, you have to cast a pointer and then dereference (which is usually a strict aliasing violation in C, but perfectly fine in the debugger). Commented May 30 at 3:50
  • Proper title would be "How to set assembler symbol's debug type information". Also pretty much a duplicate of stackoverflow.com/questions/56663591/… Commented May 30 at 7:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.