1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
~/work/stack # gcc float.c -o float -g
root@127.0.0.1::[08:30:35]::[Exit Code: 0] ->
~/work/stack # gdb float
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-100.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/work/stack/float...done.
(gdb) l
8 long zz = c + 4 + h;
9 long ww = i + j;
10 double vv = d + g;
11 long sum = xx + yy + zz + ww + vv;
12
13 return xx * yy * zz + sum;
14 }
15
16 int main(int argc, char **argv) {
17 myfunc(1,2,3,4.0,5,6,7.0,8, 9, 10);
(gdb) l
18
19 return 0;
20 }
(gdb) b myfunc
Breakpoint 1 at 0x400513: file float.c, line 6.
(gdb) r
Starting program: /root/work/stack/float
Breakpoint 1, myfunc (a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10) at float.c:6
6 long xx = a + 2 + e;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-196.el7.x86_64
可以看出rdi、rsi、rdx、rcx、r8、r9分别传递了前8个非浮点类型的参数。
(gdb) info reg
rax 0x4010000000000000 4616189618054758400
rbx 0x0 0
rcx 0x5 5
rdx 0x3 3
rsi 0x2 2
rdi 0x1 1
rbp 0x7fffffffe2f8 0x7fffffffe2f8
rsp 0x7fffffffe2f8 0x7fffffffe2f8
r8 0x6 6
r9 0x8 8
r10 0x7fffffffe110 140737488347408
r11 0x7ffff7a39b10 140737348082448
r12 0x400400 4195328
r13 0x7fffffffe410 140737488348176
r14 0x0 0
r15 0x0 0
rip 0x400513 0x400513 <myfunc+38>
eflags 0x212 [ AF IF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
//而第四个参数和第七个参数为浮点数类型,他们分别通过寄存器xmm0和xmm1来传递。
(gdb) p /x $xmm0
$2 = {v4_float = {0x0, 0x2, 0x0, 0x0}, v2_double = {0x4, 0x0}, v16_int8 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0}, v8_int16 = {0x0, 0x0, 0x0, 0x4010, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x40100000, 0x0, 0x0}, v2_int64 = {
0x4010000000000000, 0x0}, uint128 = 0x00000000000000004010000000000000}
(gdb) p /x $xmm1
$3 = {v4_float = {0x0, 0x2, 0x0, 0x0}, v2_double = {0x7, 0x0}, v16_int8 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0}, v8_int16 = {0x0, 0x0, 0x0, 0x401c, 0x0, 0x0, 0x0, 0x0}, v4_int32 = {0x0, 0x401c0000, 0x0, 0x0}, v2_int64 = {
0x401c000000000000, 0x0}, uint128 = 0x0000000000000000401c000000000000}
(gdb) p /x $xmm2
$4 = {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x0}, v16_int8 = {0x0 <repeats 16 times>}, v8_int16 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0}, v4_int32 = {0x0, 0x0, 0x0, 0x0}, v2_int64 = {0x0, 0x0}, uint128 = 0x00000000000000000000000000000000}
(gdb) p /x $xmm3
$5 = {v4_float = {0x0, 0x0, 0x0, 0x0}, v2_double = {0x0, 0x8000000000000000}, v16_int8 = {0x0 <repeats 15 times>, 0xff}, v8_int16 = {0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff00}, v4_int32 = {0x0, 0x0, 0x0, 0xff000000}, v2_int64 = {0x0, 0xff00000000000000},
uint128 = 0xff000000000000000000000000000000}
(gdb) disas myfunc
Dump of assembler code for function myfunc:
0x00000000004004ed <+0>: push %rbp
0x00000000004004ee <+1>: mov %rsp,%rbp
0x00000000004004f1 <+4>: mov %rdi,-0x38(%rbp)
0x00000000004004f5 <+8>: mov %rsi,-0x40(%rbp)
0x00000000004004f9 <+12>: mov %rdx,-0x48(%rbp)
0x00000000004004fd <+16>: movsd %xmm0,-0x50(%rbp)
0x0000000000400502 <+21>: mov %rcx,-0x58(%rbp)
0x0000000000400506 <+25>: mov %r8,-0x60(%rbp)
0x000000000040050a <+29>: movsd %xmm1,-0x68(%rbp)
0x000000000040050f <+34>: mov %r9,-0x70(%rbp)
=> 0x0000000000400513 <+38>: mov -0x38(%rbp),%rax
0x0000000000400517 <+42>: lea 0x2(%rax),%rdx
0x000000000040051b <+46>: mov -0x58(%rbp),%rax
0x000000000040051f <+50>: add %rdx,%rax
0x0000000000400522 <+53>: mov %rax,-0x8(%rbp)
0x0000000000400526 <+57>: mov -0x40(%rbp),%rax
0x000000000040052a <+61>: lea 0x3(%rax),%rdx
0x000000000040052e <+65>: mov -0x60(%rbp),%rax
0x0000000000400532 <+69>: add %rdx,%rax
0x0000000000400535 <+72>: mov %rax,-0x10(%rbp)
0x0000000000400539 <+76>: mov -0x48(%rbp),%rax
0x000000000040053d <+80>: lea 0x4(%rax),%rdx
0x0000000000400541 <+84>: mov -0x70(%rbp),%rax
0x0000000000400545 <+88>: add %rdx,%rax
0x0000000000400548 <+91>: mov %rax,-0x18(%rbp)
0x000000000040054c <+95>: mov 0x18(%rbp),%rax
0x0000000000400550 <+99>: mov 0x10(%rbp),%rdx
0x0000000000400554 <+103>: add %rdx,%rax
0x0000000000400557 <+106>: mov %rax,-0x20(%rbp)
0x000000000040055b <+110>: movsd -0x50(%rbp),%xmm0
0x0000000000400560 <+115>: addsd -0x68(%rbp),%xmm0
0x0000000000400565 <+120>: movsd %xmm0,-0x28(%rbp)
0x000000000040056a <+125>: mov -0x10(%rbp),%rax
0x000000000040056e <+129>: mov -0x8(%rbp),%rdx
0x0000000000400572 <+133>: add %rax,%rdx
0x0000000000400575 <+136>: mov -0x18(%rbp),%rax
0x0000000000400579 <+140>: add %rax,%rdx
0x000000000040057c <+143>: mov -0x20(%rbp),%rax
0x0000000000400580 <+147>: add %rdx,%rax
0x0000000000400583 <+150>: cvtsi2sd %rax,%xmm0
0x0000000000400588 <+155>: addsd -0x28(%rbp),%xmm0
0x000000000040058d <+160>: cvttsd2si %xmm0,%rax
0x0000000000400592 <+165>: mov %rax,-0x30(%rbp)
0x0000000000400596 <+169>: mov -0x8(%rbp),%rax
0x000000000040059a <+173>: imul -0x10(%rbp),%rax
0x000000000040059f <+178>: imul -0x18(%rbp),%rax
0x00000000004005a4 <+183>: mov %rax,%rdx
0x00000000004005a7 <+186>: mov -0x30(%rbp),%rax
0x00000000004005ab <+190>: add %rdx,%rax
0x00000000004005ae <+193>: pop %rbp
0x00000000004005af <+194>: retq
End of assembler dump.
|