为什么GDB在寄存器信息期间用5s填充内存地址的0s? [英] Why is GDB filling the 0s of a memory address with 5s during a register info?

查看:131
本文介绍了为什么GDB在寄存器信息期间用5s填充内存地址的0s?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在x64 CPU上使用GDB。如您所见,我正在尝试访问 rip 寄存器的值,由于某种原因,该寄存器指向的指令的地址显示为5s而不是0s。 / p>

I am using GDB on a x64 CPU. As you can see, I am trying to access the value of the rip register and for some reason the address of the instruction the register is pointing to is displayed using 5s instead of 0s as it should be.

   Dump of assembler code for function main:
   0x0000000000001139 <+0>:     push   rbp
   0x000000000000113a <+1>:     mov    rbp,rsp
   0x000000000000113d <+4>:     sub    rsp,0x10
   0x0000000000001141 <+8>:     mov    DWORD PTR [rbp-0x4],0x0
   0x0000000000001148 <+15>:    mov    DWORD PTR [rbp-0x4],0x0
   0x000000000000114f <+22>:    jmp    0x1161 <main+40>
   0x0000000000001151 <+24>:    lea    rdi,[rip+0xeac]        # 0x2004
   0x0000000000001158 <+31>:    call   0x1030 <puts@plt>
   0x000000000000115d <+36>:    add    DWORD PTR [rbp-0x4],0x1
   0x0000000000001161 <+40>:    cmp    DWORD PTR [rbp-0x4],0x9
   0x0000000000001165 <+44>:    jle    0x1151 <main+24>
   0x0000000000001167 <+46>:    mov    eax,0x0
   0x000000000000116c <+51>:    leave  
   0x000000000000116d <+52>:    ret    
End of assembler dump.
(gdb) break main
Breakpoint 1 at 0x1141: file Desktop/myprogram.c, line 6.
(gdb) run
Starting program: /home/william/Desktop/a.out 

Breakpoint 1, main () at Desktop/myprogram.c:6
6         int i = 0;
(gdb) info register rip
rip            0x555555555141   0x555555555141 <main+8>

如您所见, rip 寄存器包含<上面列出的code> mov 指令,但由于某种原因已将所有0替换为5s。知道为什么吗?

As you can see, the rip register contains the address of the mov instruction listed above but for some reason has replaced all the 0s for 5s. Any idea why?

推荐答案

在运行与位置无关的可执行文件之前,没有基地址,因此gcc假定 0 。这与您从 objdump -drwC -Mintel / bin / ls 或其他内容中看到的内容匹配。

Before running a position-independent executable, there is no base address so gcc assumes 0. This matches what you'll see from objdump -drwC -Mintel /bin/ls or whatever.

正在运行可执行文件创建一个进程,操作系统的程序加载器将其映射到一个地址。当GDB禁用ASLR时,x86-64 Linux选择以 0x0000555555555 ... 开头的页面地址。

On running the executable to create a process, the OS's program-loader maps it to an address. x86-64 Linux chooses a page address that starts with 0x0000555555555... when GDB disables ASLR.

在GDB外部运行它,或将disable-randomization设置为 ,则该地址仍将以 0x000055555 开头,但会在一定范围内随机分配。

If you run it outside GDB, or with set disable-randomization off, then the address will still start with 0x000055555, but be randomized in some range.

这篇关于为什么GDB在寄存器信息期间用5s填充内存地址的0s?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆