Break line number: Set breakpoint
Clean line number: Clear Breakpoint
Info break: Show breakpoints
Finish: Exit function
BT: Viewing the function stack
Break function name, setting a breakpoint at the position of the function
Delete breakpoint Remove all breakpoints
Disable/enable Breakpoint 1 Enable breakpoint
Debugging a multi-process first method:
The set Detach-on-fork off enables simultaneous debugging of two processes, one running a block at the fork
Set Follow-fork-mode Parent/child by setting whether to debug a parent or child process
After Setup, query the process that is being debugged info inferior
Switch to the process you are debugging inferior number (the preceding number is not a process)
When you switch past processes to set breakpoints, C executes
The second method: You can easily debug any kind of process
By attach process number
Through this debugging, it is generally necessary to set the start position of the process to sleep for a period of time convenient attach, this operation requires root authority. The process number can be obtained by Pstree-ap | Prep Pthread
Also set the breakpoint at the location of the process to toggle past C execution
Multithreaded debugging:
Setting set scheduler-locking on first
A breakpoint is set inside the entry function or the entry function of the thread.
The program executes downward until the thread is generated (the breakpoint cannot be set directly C).
Info thread
Jump to the specified thread via thread 2
C execution
Internal commissioning
Return to main thread after commissioning
#include <stdio.h> #include <pthread.h>void processa (); void Processb (); void * Processaworker (void *arg); int main (int argc, const char *argv[]) {int PID; PID = fork (); if (pid! = 0) Processa (); else{Sleep (20); PROCESSB (); }//PROCESSB (); void Processa () {pid_t pid = Getpid (); Char prefix[] = "Processa:"; Char tprefix[] = "thread"; int tstatus; pthread_t pt; printf ("%s%lu%s\n", prefix, PID, "Step1"); Tstatus = pthread_create (&pt, NULL, processaworker, NULL); if (tstatus! = 0) {printf ("Processa:can not create new thread."); }//Processaworker (NULL); Sleep (1); }void * Processaworker (void *arg) {pid_t pid = Getpid (); pthread_t tid = pthread_self (); Char prefix[] = "Processa:"; Char tprefix[] = "thread"; printf ("%s%lu%s%lu%s\n", prefix, PID, Tprefix, Tid, "Step2"); printf ("%s%lu%s%lu%s\n", prefix, PID, Tprefix, Tid, "step3"); return NULL; }void Processb () {pid_t pid = Getpid (); Char prefix[] = "PROCESSB:"; Printf("%s%lu%s\n", prefix, PID, "Step1"); printf ("%s%lu%s\n", prefix, PID, "Step2"); printf ("%s%lu%s\n", prefix, PID, "Step3"); }
Thread Debugging steps:
1.start
2.set scheduler-locking on
3.B 50 (internal to thread)
4.N until a new thread is generated
5.info thread
6.thread 2
7.c
8.n
9thread 1
There is one more command:
Thread apply ID1 ID 2 command
Debugging of the process:
1.start
2.set detach-on-fork off
3.b PROCESSB (This function can be set)
4.n
5.info inferior
6.inferior 2
7 C
If you want to change a process
Inferior other process numbers
Second: First set the wait time in front of the process you want to debug
1.sudo gdb Pthread
2.b 60 (to be set to internal)
3.fork after pstree-ap| grep pthread
Process number for 4.attach debugging
5. C
6. Internal commissioning
GDB debugging multi-process and multithreading