37

I'm trying to use the reverse debugging features of gdb 7.3.1 on a multi-threaded project (using libevent), but I get the following error:

(gdb) reverse-step
Target multi-thread does not support this command.

From this question, I thought perhaps that it was an issue loading libthread_db but, when I run the program, gdb says:

Starting program: /home/robb/slug/slug 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/libthread_db.so.1".

How can I enable reverse debugging with gdb 7.3.1 on a multi-threaded project? Is it possible?

Community
  • 1
  • 1
rps
  • 1,263
  • 3
  • 13
  • 18
  • There exists a [link](http://stackoverflow.com/questions/6625486/reverse-step-multithread-error) to a similar question here. – Martin Sep 23 '11 at 07:25
  • Yes, I know, I linked to that question in my own. – rps Sep 23 '11 at 15:28

1 Answers1

34

To do this, you need to activate the instruction-recording target, by executing the command

record

from the point where you want to go forward and backward (remember that the recording will significantly slow down the execution, especially if you have several threads!)

I've just checked that it's working correctly:

(gdb) info threads 
  Id   Target Id         Frame 
  2    Thread 0x7ffff7860700 (LWP 5503) "a.out" hello (arg=0x601030) at test2.c:16
* 1    Thread 0x7ffff7fca700 (LWP 5502) "a.out" main (argc=2, argv=0x7fffffffe2e8) at test2.c:47

...

(gdb) next
49          p[i].id=i;
(gdb) reverse-next
47      for (i=0; i<n; i++)

...

17      printf("Hello from node %d\n", p->id);
(gdb) next
Hello from node 1
18      return (NULL);
(gdb) reverse-next
17      printf("Hello from node %d\n", p->id);
Kevin
  • 4,618
  • 3
  • 38
  • 61
  • When I do `record` I get an error: `Process record target can't debug inferior in non-stop mode (non-stop).` – Nordlöw Nov 14 '13 at 13:47
  • 6
    try `set non-stop off` and/or `set target-async off`, these options might true by default in GDB's latest versions – Kevin Nov 15 '13 at 10:12
  • 2
    The `record` feature does not support multithreading properly. See https://sourceware.org/bugzilla/show_bug.cgi?id=20456#c8. – parras Jan 03 '20 at 15:44
  • 1
    The accepted answer does not work for GDB 8.0. Nor the solutions proposed by @Kevin work. – foki Apr 23 '20 at 00:29