在gdb中运行后,"main"功能的运动? [英] Movement of `main` function after running in gdb?

查看:57
本文介绍了在gdb中运行后,"main"功能的运动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ret0.c 中具有以下C代码.

I have the following C code in ret0.c.

int main(){
  return 0;
}

编译并通过gdb运行,​​我有以下输出:

Compiling and running through gdb, I have the following output:

(gdb) disas main
Dump of assembler code for function main:
   0x0000000000001119 <+0>: push   %rbp
   0x000000000000111a <+1>: mov    %rsp,%rbp
   0x000000000000111d <+4>: mov    $0x0,%eax
   0x0000000000001122 <+9>: pop    %rbp
   0x0000000000001123 <+10>:    retq   
End of assembler dump.
(gdb) run
Starting program: /home/michael/core/mind/ob/thm/cs/lang/other/c/ret0 
[Inferior 1 (process 14766) exited normally]
(gdb) disas main
Dump of assembler code for function main:
   0x0000555555555119 <+0>: push   %rbp
   0x000055555555511a <+1>: mov    %rsp,%rbp
   0x000055555555511d <+4>: mov    $0x0,%eax
   0x0000555555555122 <+9>: pop    %rbp
   0x0000555555555123 <+10>:    retq   
End of assembler dump.

因此,执行一次后, main 在内存中的位置已更改?这是怎么回事?

So after executing once, the location of main in memory has changed? What's going on here?

推荐答案

在开始该过程之前,先打印了第一个输出.在这种情况下,gdb将偏移量打印在二进制文件中.

The first output was printed before the process was started. In this case gdb prints the offset in the binary file.

第二个输出是在进程终止之后,您会在进程的内存空间中看到实际地址.

The second output is after the process was terminated, and you see the actual address in the memory space of the process.

这篇关于在gdb中运行后,"main"功能的运动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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