#include <stdlib.h>
static int func2(int i,int j)
{
int k;
k = i + j;
return k;
}
static int func(int fd,const char *ptr, int arg3, int arg4,int arg5,
int arg6, int arg7, int arg8)
{
int ret;
ret = arg7 + arg8;
func2(fd, arg3);
return ret;
}
int main(void)
{
func(12, "Hello,World!",3, 4, 5, 6, 7,8);
return 0;
}
Breakpoint 1 at 0x4004d4: file m.c, line26.
(gdb) b func
Breakpoint 2 at 0x4004ac: file m.c, line17.
(gdb) b func2
Breakpoint 3 at 0x40047e: file m.c, line8.
(gdb)
Dump of assembler code for function main:
25 {
0x00000000004004cc <+0>: push%rbp
0x00000000004004cd <+1>: mov%rsp,%rbp
0x00000000004004d0 <+4>: sub $0x10,%rsp
26 func(12,"Hello,World!", 3,4, 5, 6, 7, 8);
=> 0x00000000004004d4<+8>: movl $0x8,0x8(%rsp)
0x00000000004004dc <+16>: movl $0x7,(%rsp)
0x00000000004004e3 <+23>: mov $0x6,%r9d
0x00000000004004e9 <+29>: mov $0x5,%r8d
0x00000000004004ef <+35>: mov $0x4,%ecx
0x00000000004004f4 <+40>: mov $0x3,%edx
0x00000000004004f9 <+45>: mov $0x400608,%esi
0x00000000004004fe <+50>: mov $0xc,%edi
0x0000000000400503 <+55>: callq 0x40048f<func>
27
28 return 0;
0x0000000000400508 <+60>: mov $0x0,%eax
29 }
0x000000000040050d <+65>: leaveq
0x000000000040050e <+66>: retq
End of assembler dump.
(gdb)
rax 0x351658ff60 228008197984
rbx 0x0 0
rcx 0x0 0
rdx 0x7fffffffe4e8 140737488348392
rsi 0x7fffffffe4d8 140737488348376
rdi 0x1 1
rbp 0x7fffffffe3f0 0x7fffffffe3f0
rsp 0x7fffffffe3e0 0x7fffffffe3e0
r8 0x351658e300 228008190720
r9 0x3515a0e9d0 227996133840
r10 0x7fffffffe240 140737488347712
r11 0x351621ebe0 228004588512
r12 0x400390 4195216
r13 0x7fffffffe4d0 140737488348368
r14 0x0 0
r15 0x0 0
rip 0x4004d4 0x4004d4 <main+8>
eflags 0x202 [ IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
(gdb)
rax 0x351658ff60 228008197984
rbx 0x0 0
rcx 0x4 4
rdx 0x3 3
rsi 0x400608 4195848
rdi 0xc 12
rbp 0x7fffffffe3d0 0x7fffffffe3d0
rsp 0x7fffffffe3a0 0x7fffffffe3a0
r8 0x5 5
r9 0x6 6
r10 0x7fffffffe240 140737488347712
r11 0x351621ebe0 228004588512
r12 0x400390 4195216
r13 0x7fffffffe4d0 140737488348368
r14 0x0 0
r15 0x0 0
rip 0x4004ac 0x4004ac <func+29>
eflags 0x206 [ PF IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
(gdb)
Dump of assembler code for function func:
14 {
0x000000000040048f <+0>: push%rbp
0x0000000000400490 <+1>: mov%rsp,%rbp
0x0000000000400493 <+4>: sub $0x30,%rsp
0x0000000000400497 <+8>: mov%edi,-0x14(%rbp)
0x000000000040049a <+11>: mov%rsi,-0x20(%rbp)
0x000000000040049e <+15>: mov%edx,-0x24(%rbp)
0x00000000004004a1 <+18>: mov%ecx,-0x28(%rbp)
0x00000000004004a4 <+21>: mov%r8d,-0x2c(%rbp)
0x00000000004004a8 <+25>: mov%r9d,-0x30(%rbp)
15 int ret;
16
17 ret = arg7+ arg8;
=> 0x00000000004004ac<+29>: mov 0x18(%rbp),%eax
0x00000000004004af <+32>: mov 0x10(%rbp),%edx
0x00000000004004b2 <+35>: lea (%rdx,%rax,1),%eax
0x00000000004004b5 <+38>: mov%eax,-0x4(%rbp)
18
19 func2(fd, arg3);
0x00000000004004b8 <+41>: mov-0x24(%rbp),%edx
0x00000000004004bb <+44>: mov-0x14(%rbp),%eax
0x00000000004004be <+47>: mov%edx,%esi
0x00000000004004c0 <+49>: mov%eax,%edi
0x00000000004004c2 <+51>: callq 0x400474<func2>
20
21 return ret;
0x00000000004004c7 <+56>: mov-0x4(%rbp),%eax
22 }
0x00000000004004ca <+59>: leaveq
0x00000000004004cb <+60>: retq
$9 = 12
(gdb) p $rdi
$10 = 12
(gdb) set $rdi=15
(gdb) p fd
$11 = 12
(gdb) set *(int *)($rbp-0x14)=15
(gdb) p fd
$12 = 15
(gdb)
$6 = 0x400608"Hello,World!"
(gdb) p (char *)($rbp-0x20)
$7 = 0x7fffffffe3b0"\b\006@"
(gdb)
printf("func1: %s\n", $$vars);
$fd = 15;
}
probe process("a.out").statement("func2") {
printf("edi = %d\n", register("edi"));
}
func1: fd=0xc ptr=0x400608 arg3=0x3 arg4=0x4 arg5=0x5 arg6=0x6 arg7=0x7 arg8=0x8 ret=0x0
edi = 15
[root@CentOS_190 ~]#
printf("func1: %s\n", $$vars);
printf("func1: edi = %d\n", register("edi"));
}
probe process("a.out").statement("func2") {
printf("func2: %s\n", $$vars);
printf("func2: edi = %d\n", register("edi"));
}
func1: fd=0x0 ptr=0x7fffa0a4bff8 arg3=0x0 arg4=0x40036b arg5=0x0 arg6=0x0 arg7=0x7 arg8=0x8 ret=0x0
func1: edi =12
func2: i=0x0 j=0x1 k=0x35
func2: edi =12
[root@CentOS_190 ~]#
再次向大家強烈推薦SystemTap!