0

I want to know what happens in the current instruction line. So, my code is simple hello world program which just prints hello world to the screen written in c. I was analyzing in gdb and found this line which pushes the value into $rdi register. But what I couldn't figure out is before I execute this statement the address of that string if $rip + 0xec4 = 0x555555555ffd right ? So when I add that and try to print there's no string there. But when I execute this line, the value also gets set there and also in $rdi. Am I missing something here?


Dump of assembler code for function main:
   0x0000555555555135 <+0>:     push   %rbp
   0x0000555555555136 <+1>:     mov    %rsp,%rbp
=> 0x0000555555555139 <+4>:     lea    0xec4(%rip),%rdi        # 0x555555556004
   0x0000555555555140 <+11>:    callq  0x555555555030 <puts@plt>
   0x0000555555555145 <+16>:    mov    $0x0,%eax
   0x000055555555514a <+21>:    pop    %rbp
   0x000055555555514b <+22>:    retq
rax            0x555555555135      93824992235829
rbx            0x0                 0
rcx            0x7ffff7fbb718      140737353856792
rdx            0x7fffffffe1b8      140737488347576
rsi            0x7fffffffe1a8      140737488347560
rdi            0x1                 1
rbp            0x7fffffffe0c0      0x7fffffffe0c0
rsp            0x7fffffffe0c0      0x7fffffffe0c0
r8             0x0                 0
r9             0x7ffff7fe3530      140737354020144
r10            0x3                 3
r11            0x2                 2
r12            0x555555555050      93824992235600
r13            0x7fffffffe1a0      140737488347552
r14            0x0                 0
r15            0x0                 0
rip            0x555555555139      0x555555555139 <main+4>
eflags         0x246               [ PF ZF IF ]
cs             0x33                51
ss             0x2b                43
ds             0x0                 0
es             0x0                 0
fs             0x0                 0
  • If it helps my machine is x64. – Mahesh C. Regmi Aug 09 '20 at 05:45
  • GDB's commented disassembly calculated the absolute address for you. Also, you could have single-stepped one instruction further to see what address it put in RDI. Also, don't post pictures of text; copy/paste into a code-formatting block. – Peter Cordes Aug 09 '20 at 05:47
  • Thanks for your comment. Surely, I would do that next time. But, How does gdb calculates that? – Mahesh C. Regmi Aug 09 '20 at 05:48
  • 1
    Don't wait for next time, [edit] to fix your current question. – Peter Cordes Aug 09 '20 at 05:49
  • 1
    RIP-relative addressing is relative to the *end* of the instruction (start of the next). I closed this as a duplicate of several Q&As that explain this. (Thanks for fixing your question, removed my downvote). – Peter Cordes Aug 09 '20 at 06:08

0 Answers0