Getting started with UDB¶
UDB is Undo’s time travel debugger. It records the execution history of a program, so that the program can be executed forward and backward and its state examined at any time in its history. This makes it possible to diagnose the cause of defects by executing backwards from incorrect results to the code that created the results.
UDB can also load recordings of your software created by LiveRecorder.
Try the online tutorial: Getting started with UDB.
Launching a program in UDB¶
Start udb, naming the program to be debugged on the command line:
$ udb examples/hashtable
Reading symbols from examples/hashtable...
Then use the run command in UDB to run the program with command-line arguments:
not running> run 12345
Starting program: examples/hashtable 12345
hashtable: hashtable.c:131: main: Assertion `table_contains(table, element)' failed.
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
Alternatively, start udb with the --args
command-line option to specify the program and its command-line arguments:
$ udb --args examples/hashtable 12345
Reading symbols from examples/hashtable...
Then use the run command in UDB to run the program with the arguments already given:
not running> run
Starting program: examples/hashtable 12345
hashtable: hashtable.c:131: main: Assertion `table_contains(table, element)' failed.
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
See Invoking UDB for more details.
Attaching to an existing process¶
Attach UDB to a running process using the udb --pid PID
command-line option. For example:
$ examples/deadlock &
Running as pid 629622
$ udb --pid 629622
Reading symbols from /lib/x86_64-linux-gnu/libpthread.so.0...
Reading symbols from /usr/lib/debug/.build-id/f0/983025f0e0f327a6da752ff4ffa675e0be393f.debug...
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...
Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.31.so...
Reading symbols from /lib64/ld-linux-x86-64.so.2...
(No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
Have reached start of recorded history.
0x00007fcc233afcd5 in __pthread_clockjoin_ex (threadid=140514739029760, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145
145 pthread_join_common.c: No such file or directory.
recording 1> info threads
Id Target Id Frame
* 1 Thread 629622.629622 0x00007fcc233afcd5 in __pthread_clockjoin_ex (threadid=140514739029760, thread_return=0x0, clockid=<optimized out>, abstime=<optimized out>, block=<optimized out>) at pthread_join_common.c:145
2 Thread 629622.629623 __lll_lock_wait (futex=futex@entry=0x563ebc50e078 <g_lists+56>, private=0) at lowlevellock.c:52
3 Thread 629622.629624 __lll_lock_wait (futex=futex@entry=0x563ebc50e040 <g_lists>, private=0) at lowlevellock.c:52
Forward and reverse execution¶
To execute the program forward, use the execution commands. For example, the step command executes the program forward to the next source line, and the continue command continues execution of the program until a breakpoint is hit or the program stops on a signal.
To execute the program backward, use the reverse-execution commands. For example, the reverse-step command executes the program backward to the previous source line, and the reverse-continue command executes the program backward until a breakpoint is hit, or the program stops on a signal, or it reaches the start of execution history.