Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly - How to see the value in a particular variable with gdb

Here is my assembly code

section .data

msg: db "hello"

section .text
global _start
_start:
nop
mov rax,23
nop

can i access the data located in 'msg' with gdb

like image 590
Bhanu Manthry Avatar asked Dec 21 '25 18:12

Bhanu Manthry


1 Answers

The command x/5cb &msg should dump five bytes at the correct address, in both decimal and character notation.

Alternatively, you should be able to use printf "%5.5s\n", &msg as well, substituting in whatever format string you need for other data (a null terminated string, for example, would need only "%s").

This was all tested under CygWin with the following program:

section .data

msg:    db    "hello"

section .text
global _start

_start: mov   eax, 42
        ret

When you compile and run that, you get the expected 42 as a return code:

pax> nasm -f elf -o prog.o prog.asm
pax> ld -o prog.exe prog.o
pax> ./prog.exe ; echo $?
42

Starting it in the debugger, you can see the commands needed to get at msg:

pax> gdb prog.exe
GNU gdb (GDB) 7.8
Copyright (C) 2014 Free Software Foundation, Inc.
<blah blah blah>
Reading symbols from prog.exe...(no debugging symbols found)...done.

(gdb) b start
Breakpoint 1 at 0x401000

(gdb) r
Starting program: /cygdrive/c/pax/prog.exe
[New Thread 7416.0x20c0]
Breakpoint 1, 0x00401000 in start ()

(gdb) x/5cb &msg
0x402000 <msg>: 104 'h' 101 'e' 108 'l' 108 'l' 111 'o'

(gdb) printf "%5.5s\n", &msg
hello
like image 129
paxdiablo Avatar answered Dec 24 '25 00:12

paxdiablo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!