memory - Assembly - How to see the value in a particular variable with gdb -
here assembly code
section .data msg: db "hello" section .text global _start _start: nop mov rax,23 nop
can access data located in 'msg' gdb
the command x/5cb &msg
should dump 5 bytes @ correct address, in both decimal , character notation.
alternatively, should able use printf "%5.5s\n", &msg
well, substituting in whatever format string need other data (a null terminated string, example, need "%s"
).
this tested under cygwin following program:
section .data msg: db "hello" section .text global _start _start: mov eax, 42 ret
when compile , run that, expected 42
return code:
pax> nasm -f elf -o prog.o prog.asm pax> ld -o prog.exe prog.o pax> ./prog.exe ; echo $? 42
starting in debugger, can see commands needed @ msg
:
pax> gdb prog.exe gnu gdb (gdb) 7.8 copyright (c) 2014 free software foundation, inc. <blah blah blah> reading symbols prog.exe...(no debugging symbols found)...done. (gdb) b start breakpoint 1 @ 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
Comments
Post a Comment