Differences between version 8 and previous revision of DeBugging.
Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History
Newer page: | version 8 | Last edited on Tuesday, October 28, 2003 11:22:58 am | by JohnMcPherson | Revert |
Older page: | version 7 | Last edited on Friday, October 17, 2003 9:30:52 am | by JohnMcPherson | Revert |
@@ -21,9 +21,9 @@
!strace
strace(1) lets you see what a program is doing in a coarse kind of way, if you think strace(1) is too quiet, perhaps ltrace(1) is for you. for the bsdites amongst us, I believe these are called struss(1) and sotrace(1). The command for this is:
strace ''programname''
if the program is already running:
- strace ''pid''
+ strace -p
''pid''
will also work.
!signals
If your program hangs, you can press Alt-\ to send it a SIGQUIT and force it to dump core. You can also force them to dump core with the command:
@@ -37,8 +37,20 @@
gdb(1) can also do postmortem analysis on core files like so:
gdb ./''program'' ./''corefile''
If you run gdb(1) on your program and it displays the names of the functions but doesn't display their types (eg: what arguments they have or line number information) you probably didn't compile them with -g
+
+! modifying a running process
+You can use gdb to attach to a currently running process. For example, to change where its stderr is going:
+
+ $ gdb <executable> <process_id>
+ (gdb) call close(2)
+ $1 = 0
+ (gdb) call open("/tmp/prog-debug", 0101)
+ $2 = 2
+ (gdb) cont
+
+Note that the octal 0101 stands for O_CREAT|O_WRONLY, since gdb will complain about no debugging symbols for resolving those words otherwise. Check with your /usr/include files... the c library with debian testing at least has these definitions in /usr/include/bits/fcntl.h. (0100 + 01).
!ddd
ddd(1) appears to be a reasonable [GUI] interface to gdb(1) for those that are afraid of CommandLine's.