0

I'm running strace on my process to monitor performance and I see a lot of calls like so:

futex(0x3d89d68, FUTEX_WAKE_PRIVATE, 1) = 0
...

I'm trying to catch where this call is being done in gdb ( just like I do for other system calls ). However when I try to break on futex gdb doesnt recognize the symbol:

(gdb) b futex
Function "futex" not defined.
Make breakpoint pending on future shared library load? (y or [n])

Is there some special way to break on futex calls?

ByteMe95
  • 836
  • 1
  • 6
  • 18

1 Answers1

1

According to the futex syscall manual page:

glibc provides no wrapper for futex()

So instead of break, you’ll need to use the GDB command catch syscall futex to suspend the program when it starts that syscall.

Mark Plotnick
  • 9,598
  • 1
  • 24
  • 40
  • That's awesome, this works. Do you know if its also possible to set this break on a specific thread? – ByteMe95 Sep 10 '21 at 14:22
  • @ByteMe95 Unfortunately, the `catch` command doesn't take a `thread` argument (`break` does), but you can get close. You can use the `condition` command to tell GDB to evaluate an expression each time the catchpoint is hit; when it's true, the program will be suspended and you'll get a GDB prompt. For example, after setting a catchpoint whose number is 1, you can type `condition 1 $_thread == 3` to suspend the program only when the catchpoint is hit in thread ID 3. – Mark Plotnick Sep 10 '21 at 19:26
  • I just gave this a try, didnt seem to break at all when setting the condition like that. I tried providing the gdb thread id and the LWP thread id – ByteMe95 Sep 13 '21 at 13:35