When using gdb, I often get a nice list of parameters passed to functions. However, with certain functions like bind, I do not get the parameters:
(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
...
How can I still get the parameters passed to these functions?
bindis one of socket system calls. There is a special way to put breakpoints on system calls in gdb –catch syscall <syscall name>. After this kind of breakpoint hit, you can watch syscall parameters in registers according to kernel calling conventions. For x86_64, parameters are passed via %rdi, %rsi, %rdx, %r10, %r8 and %r9 registers. For x86-32 – via %ebx, %ecx, %edx, %esi, %edi, %ebp registers.For example here %rdi contains first
bindcall parameter – socket file descriptor.For x86-32 things are more complicated as socket system calls are implemented via
socketcallsystem call. Thats why it’s impossible to put catchpoint directly tobind. You can find more info about it here.