Nan*_*iao 0 c debugging assembly gdb solaris
我在Solaris中编写了一个简单的C程序,并希望检查以下的汇编代码dup:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int pdes[2];
if(-1 != (pipe(pdes)))
{
//printf("%d\n", dup(pdes[0]));
dup(pdes[0]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
(1)我使用gdb,并gdb输出汇编代码:
(gdb) disassemble dup
Dump of assembler code for function dup:
0xff2cda44 <+0>: mov 0x29, %g1 ! 0x29
0xff2cda48 <+4>: ta 8
0xff2cda4c <+8>: bcs 0xff223be0 <_cerror>
0xff2cda50 <+12>: nop
0xff2cda54 <+16>: retl
0xff2cda58 <+20>: nop
End of assembler dump.
Run Code Online (Sandbox Code Playgroud)
(2)我使用mdb,并mdb输出汇编代码:
> dup::dis
PLT:dup: sethi %hi(0x21000), %g1
PLT:dup: ba,a -0x88 <0x20a14>
PLT:dup: nop
0x20aa4: nop
0x20aa8: unimp 0x1
0x20aac: unimp 0xe0
0x20ab0: unimp 0xc
0x20ab4: unimp 0x109b8
0x20ab8: unimp 0xd
0x20abc: unimp 0x109d4
0x20ac0: unimp 0x1d
Run Code Online (Sandbox Code Playgroud)
(3)我使用命令:echo "dup::dis" | mdb -k和汇编代码:
dup: sra %o0, 0x0, %o0
dup+4: mov %o7, %g1
dup+8: clr %o2
dup+0xc: clr %o1
dup+0x10: call -0xeec <fcntl>
dup+0x14: mov %g1, %o7
Run Code Online (Sandbox Code Playgroud)
为什么这三种方法为同一个函数输出不同的汇编代码?
情况(1)显示了实际功能的反汇编.
情况(2)显示了该函数的PLT(过程链接表)条目.PLT用于解析从共享库导入的函数.主程序在调用函数时使用它.当然,代码流最终将通过运行时链接程序的最终功能结束.
案例(3):我不知道这是什么.