Use GDB: The original code debugger of GDB and GNU described herein. (This is a 4.12 version of 1994, GDB version 4.16) * Directory: * Summary: GDB Summary * Instance: A Using Instance * Getting Started: Enter and Exit GDB * Command: GDB Command * Run: In GDB Running program * Stop: Pause and continue execution * Stack: Check Stack * Original File: Check Original File * Data: Check Data * Language: Use GDB * Symbol: Check Symbol Table * Change: Change Perform * GDB File File * Object Specify debug object * Control GDB Control * Perform a sequence: Perform a sequence command * Emacs: Work together with Emacs * GDB bug: * Command line Editor: Row Editing * Using history interactions: * Format document : How to format and print GDB documents * Index: GDB introduction: ************* Debugger (such as gdb) allows you to observe another program in execution, or What happened when the program was wrong. GDB is mainly able to do four things for you (including feature to accomplish these things), help you find out the error in the program. * Run your program and set all things that can affect the program. * Ensure that your program stops under the specified conditions. * When you stop, let you check what happened. * Change your program. Such as a problem caused by a bug and then continues to find another bug. You can use GDB to debug C and C written programs. (Reference * C and C ) When debugging the Pascal program, there are some functions that cannot be used. GDB can also be used to debug the FORTRAN program, although the input, output variables, or class fortifications are not supported now. * GDB is "Free Software", everyone can copy free of charge. It is also possible to add new features for GDB, but you have to follow the license agreement of the GNU. Anyway, I think that GNU is quite good :-) on this sentence: Fundamentally, the General Public License is a license which saysthat you have these freedoms and that you can not take these freedomsaway from anyone else.GDB Author: Richard Stallman is GDB The starter, there are many members of many other GNUs. Many people have contributed to this.
(Both don't mention it foreigners, I hope they will not come to me :-)) This is an example of GDB: the original text is a program called M4. But unfortunately I can't find the original code of this program, so there is no way to follow the original text. However, it is an example, I will take an operating system to schedule the original code to explain that the original code I will attach it. First of all this program is OS.c is a primary program for analog process schedule (maybe it is an old antique :-)). Take a look at how to get an executable code including the original code symbol. If you have your heart, you can go to see the GCC's MAN file (MAN GCC under the shell). GCC -G
We use n command, type: (gdb) nSuccess forking process # 1, pid is 31474Success forking process # 2, pid is 31475Success forking process # 3, pid is 31476Success forking process # 5, pid is forking 31478Success process # 6, pid is 31479 Dispatch Algorithm: FIFO ****************************************************************** ********************************************* PCB # pid priority PC State 1 31474 24 0 WAITI 2 31475 19 0 Waiting 3 31476 16 0 WAITI 4 31477 23 0 WAITI 5 31478 22 0 WAITING 6 31479 20 0 waiting ****************************************** ***************************************************************************************** CPU : No processwaiting cpu !!! 31474 31475 31476 31477 31478 31479Waiting Io None456 State = Waiting; the final one is the next order to execute. We are now incorporated on another function. Note We can use the l / list command to display the original code.
Here we type (GDB) L451 Main () 452 {453 int Message; 454455 Initial (); 456 State = waiting; 457 Printf ("Use Control-C to Halt / N"; 458 Signal (SigalRM, AlarmMMessage); 459 Signal (SIGINT, InteruptMessage); 460 Signal (Sigusr2, Iomessage); (GDB) L461 Alarm (TimeSlot); 462 for (;;) 463 {464 Message = getMessage (); 465 Switch (Message) 466 {468 Break; 469 Case Child_io: waitingio (); 470 Break; showing the original code, now incorporate points on the alarmMessage. (GDB) B AlarmMessageBreakpoint 2 at 0x8048EE3: File Os.c, line 259. (GDB) Then we continue to run the program. (GDB) CC or Continue command let us continue to be interrupted. Display: Continuing.use control-c to haltbreakpoint 2, alarmmessage () at Os.c: 259259 clearsl (); note that we will follow the following statement is clearsal (); we use S / Step Tracking into this function to see what it is doing? . (GDB) Sclearsignal () at Os.c: 227227 Signal (SIGINT, SIG_IGN); List Original Code with the L Command: (GDB) L222} 223224225 Void ClearsR () / * Clear Other Signals * / 226 {227 Signal (Sigint , SIG_IGN); 228 Signal (SIGALRM, SIG_IGN); 229 Signal (SIGUSR2, SIG_IGN); 230} 231 (GDB) We can continue tracking with S commands. Let us now try the BT or BackTrace command. This command can display the contents in the stack. (GDB) BT # 0 clearsal () at Os.c: 227 # 1 0x8048ee8 in alarmMMessage () at Os.c: 259 # 2 0xBfffAec in ?? () # 3 0x80486ae in ___crt_dummy__ () (GDB) everyone can see I understand what it means. The top of the stack is ALARMMMESSAGE, the next function has no name - there is no original code symbol. This shows the nesting of the function call. Ok, we have tracked the value of the variable for a long time. Checking the value of the expression is a P or Print format is P
I found a content (GDB) p waitingQueue $ 1 = {1, 2, 3, 4, 5, 6, 0} (GDB) WaitingQueue, is a array, and the GDB also supports the display of the structure. GDB) P PCB $ 2 = {{PID = 0, State = 0, PIOR = 0, PC = 0}, {PID = 31474, State = 2, PIOR = 24, PC = 0}, {PID = 31475, State = 2, prior = 19, pc = 0}, {pid = 31476, state = 2, prior = 16, pc = 0}, {pid = 31477, state = 2, prior = 23, pc = 0}, {PID = 31478, State = 2, PRIOR = 22, PC = 0}, {PID = 31479, State = 2, prior = 20, PC = 0}} (GDB) This can be viewed for the original program. The original document is a debugging process, but I think I have already introduced the common function of GDB, basically it can be used to debug the program. :-) Run GDB (some detailed description): I have already mentioned how to run GDB, let us look at some more interesting things. You can specify a large number of parameters and options through many command line parameters while running GDB, and you can set up the environment run at the beginning. Here, the command line parameters to be described have covered most of the case, in fact, there is nothing to use in a certain environment. The most common command is to use a parameter: $ GDB