Function 如何从bind()获取函数参数?

Function 如何从bind()获取函数参数?,function,parameters,gdb,Function,Parameters,Gdb,当使用gdb时,我通常会得到一个传递给函数的参数列表。但是,对于某些函数,如bind,我无法获得以下参数: (gdb) break bind Breakpoint 1 at 0x404b40 (gdb) r ... Breakpoint 1, bind () at ../sysdeps/unix/syscall-template.S:82 82 in ../sysdeps/unix/syscall-template.S (gdb) bt #0 bind () at ../sysdep

当使用
gdb
时,我通常会得到一个传递给函数的参数列表。但是,对于某些函数,如
bind
,我无法获得以下参数:

(gdb) break bind
Breakpoint 1 at 0x404b40
(gdb) r
...
Breakpoint 1, bind () at ../sysdeps/unix/syscall-template.S:82
82      in ../sysdeps/unix/syscall-template.S
(gdb) bt
#0  bind () at ../sysdeps/unix/syscall-template.S:82
...

如何仍能获得传递给这些函数的参数?

bind
是套接字系统调用之一。在gdb中有一种特殊的方法可以在系统调用上放置断点-
catch syscall
。在这种断点命中之后,您可以根据需要在寄存器中查看syscall参数。对于x86_64,参数通过%rdi、%rsi、%rdx、%r10、%r8和%r9寄存器传递。对于x86-32-通过%ebx、%ecx、%edx、%esi、%edi、%ebp寄存器

(gdb) catch syscall bind 
Catchpoint 3 (syscall 'bind' [49])
(gdb) r
Starting program: /usr/bin/nmap google.com

Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-16 01:09 PDT
Warning: Hostname google.com resolves to 6 IPs. Using 173.194.69.100.

Catchpoint 3 (call to syscall 'bind'), 0x00007ffff6520307 in bind ()
   from /lib/libc.so.6
(gdb) info registers 
rax            0xffffffffffffffda   -38
rbx            0xb35870 11753584
rcx            0xffffffffffffffff   -1
rdx            0x14 20
rsi            0x7fffffff7d90   140737488321936
rdi            0x8  8
rbp            0x8  0x8
rsp            0x7fffffff7d58   0x7fffffff7d58
r8             0xb  11
r9             0x8000   32768
r10            0x7fffffff7b00   140737488321280
r11            0x202    514
r12            0xb09630 11572784
r13            0xb359f0 11753968
r14            0x2  2
r15            0xc8 200
rip            0x7ffff6520307   0x7ffff6520307 <bind+7>
eflags         0x202    [ IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
---Type <return> to continue, or q <return> to quit---
gs             0x0  0
(gdb) 
(gdb)捕获系统调用绑定
要点3(系统调用“绑定”[49])
(gdb)r
启动程序:/usr/bin/nmap google.com
启动Nmap 5.00(http://nmap.org )美国东部时间2012-03-16 01:09
警告:主机名google.com解析为6个IP。使用173.194.69.100。
捕获点3(调用syscall'bind'),绑定中的0x00007ffff6520307()
from/lib/libc.so.6
(gdb)信息寄存器
rax 0xFFFFFFFFDA-38
rbx 0xb35870 11753584
rcx 0xFFFFFFFFFFFF-1
rdx 0x14 20
rsi 0x7FFFFF7D90 140737488321936
rdi 0x8
rbp 0x8 0x8
rsp 0x7FFFFF7D58 0x7fffffff7d58
r8 0xb 11
r9 0x8000 32768
r10 0x7FFFFFFF7B000 140737488321280
r11 0x202 514
r12 0xb09630 11572784
r13 0xb359f0 11753968
r14 0x2 2
r15 0xc8 200
rip 0x7ffff6520307 0x7ffff6520307
eflags 0x202[如果]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
---键入以继续,或键入q以退出---
gs 0x0 0
(gdb)
例如,此处%rdi包含第一个
bind
call参数-socket文件描述符


对于x86-32,由于socket系统调用是通过
socketcall
系统调用实现的,因此事情更加复杂。这就是为什么不可能将catchpoint直接放到
bind
。您可以找到有关它的更多信息。

bind
是套接字系统调用之一。在gdb中有一种特殊的方法可以在系统调用上放置断点-
catch syscall
。在这种断点命中之后,您可以根据需要在寄存器中查看syscall参数。对于x86_64,参数通过%rdi、%rsi、%rdx、%r10、%r8和%r9寄存器传递。对于x86-32-通过%ebx、%ecx、%edx、%esi、%edi、%ebp寄存器

(gdb) catch syscall bind 
Catchpoint 3 (syscall 'bind' [49])
(gdb) r
Starting program: /usr/bin/nmap google.com

Starting Nmap 5.00 ( http://nmap.org ) at 2012-03-16 01:09 PDT
Warning: Hostname google.com resolves to 6 IPs. Using 173.194.69.100.

Catchpoint 3 (call to syscall 'bind'), 0x00007ffff6520307 in bind ()
   from /lib/libc.so.6
(gdb) info registers 
rax            0xffffffffffffffda   -38
rbx            0xb35870 11753584
rcx            0xffffffffffffffff   -1
rdx            0x14 20
rsi            0x7fffffff7d90   140737488321936
rdi            0x8  8
rbp            0x8  0x8
rsp            0x7fffffff7d58   0x7fffffff7d58
r8             0xb  11
r9             0x8000   32768
r10            0x7fffffff7b00   140737488321280
r11            0x202    514
r12            0xb09630 11572784
r13            0xb359f0 11753968
r14            0x2  2
r15            0xc8 200
rip            0x7ffff6520307   0x7ffff6520307 <bind+7>
eflags         0x202    [ IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
---Type <return> to continue, or q <return> to quit---
gs             0x0  0
(gdb) 
(gdb)捕获系统调用绑定
要点3(系统调用“绑定”[49])
(gdb)r
启动程序:/usr/bin/nmap google.com
启动Nmap 5.00(http://nmap.org )美国东部时间2012-03-16 01:09
警告:主机名google.com解析为6个IP。使用173.194.69.100。
捕获点3(调用syscall'bind'),绑定中的0x00007ffff6520307()
from/lib/libc.so.6
(gdb)信息寄存器
rax 0xFFFFFFFFDA-38
rbx 0xb35870 11753584
rcx 0xFFFFFFFFFFFF-1
rdx 0x14 20
rsi 0x7FFFFF7D90 140737488321936
rdi 0x8
rbp 0x8 0x8
rsp 0x7FFFFF7D58 0x7fffffff7d58
r8 0xb 11
r9 0x8000 32768
r10 0x7FFFFFFF7B000 140737488321280
r11 0x202 514
r12 0xb09630 11572784
r13 0xb359f0 11753968
r14 0x2 2
r15 0xc8 200
rip 0x7ffff6520307 0x7ffff6520307
eflags 0x202[如果]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
---键入以继续,或键入q以退出---
gs 0x0 0
(gdb)
例如,此处%rdi包含第一个
bind
call参数-socket文件描述符


对于x86-32,由于socket系统调用是通过
socketcall
系统调用实现的,因此事情更加复杂。这就是为什么不可能将catchpoint直接放到
bind
。您可以找到有关它的更多信息。

您使用的是什么操作系统?x64还是x86?答案取决于architecture.x86_64,但我也对x86感兴趣。您使用的是什么操作系统?x64还是x86?答案取决于architecture.x86_64,但我也对x86感兴趣。