GDB debugger manual

xiaoxiao2021-03-05  28

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 -o -g means that the executable of the original code debug symbol is generated. -o means specifying an executable file name. (GCC's command line parameters have a lot of piles, interested in seeing yourself.) Anyway, in Linux, the OS.c is compiled by the above method, generates executables available to GDB. I use GCC -G OS.c -o OS, generated executable document called OS. Then play GDB OS, you can enter GDB, screen tips: GDB IS free software and you are welcome to distributes of it Under Certain Conditions; TYPE "Show Copying" to see the conditions. there is absolutely no warranty for gdb; type "show warranty" for details. GDB 4.16, Copyright 1995 Free Software Foundation, Inc ... (GDB) (GDB) is a prompt, in This prompt can enter the command until you exit. (Exit Command is Q / Q) In order to match the order of the original document description, even if the command that is useless in this example I will also demonstrate. First we can set the GDB screen size. Type: (GDB) Set Width 70 is set to 70 columns of the standard screen. Then let us set the breakpoint. Setting method is simple: BREAK or simple play B. Bill number or function name, such as we can break on the main function: (GDB) BREAK Main or (GDB) b Main System Tips: Breakpoint 1 at 0x8049552: File OS. C, Line 455. Then we can run this program. When the program runs to the main function, the program will stop returning to the GDB prompt. The running command is Run or R (there are many alias in GDB, you can look at the help, hit HELP under GDB) RUN can be followed by parameters, which is to specify command line parameters for the program. For example, R ABCD, the program will be ABCD as a parameter. (Here to explain here, you can use SET ARGS to specify parameters). After entering R or Run, the program starts running until the entrance to Main is stopped, showing: Starting Program: / OSBreakpoint 1, Main () at Os.c: 455455 Initial (); here 455 initial (); The command or function to be executed. GDB provides two ways: 1. Single step entry, Step Into is tracking to the function. The command is STEP or S 2. Single step, Next, it is a simple single step and does not enter the function. The command is NEXT or N these two commands have other usage later.

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 444444 Let's find a variable to see. : -) (GDB) L 1 Remember the role of L? l or list shows the original code symbol, L or List adds the original code starting from .

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 You can also specify a core file for your execution file: $ gdb Core You can also specify the file you want to execute A process number: $ gdb , & gdb OS 1234 will enable GDB and process 1234 (Attach) unless you still have a file called 1234. GDB first checks a Core file. If you are using a remote terminal for remote debugging, then if your terminal is not supported, you will not be able to use the second parameter or even there is no core dump. If you feel that the prompt information starting is comparative, you can use GDB-Silent. You can also control the behavior of GDB with command line parameters. It can be prompted in this regard to gdb -help or -h. All parameters are passed in the order of arrangements to GDB unless you use the -X parameter. When GDB starts running, it uses any parameters that are prefixed as an executable or Core file (or process number). Just like the -SE or -C option in front. The GDB regards the parameters of the first previously described instructions as the previous-SE option, while the second (if any) is as follows, followed by the -c option. Many options have abbreviations and can be seen with GDB -H. In GDB, you can also call the option name to end, just ensure that the GDB can judge the unique parameter. Here we explain some of the most common parameter option -symbols (- S ) ------ Read the symbol from . -EXEC (- E ) ---- Perform in the right time to perform the correct data to compare with Core DUMP. -SE ------ Read symbols from and use it as an executable file.

转载请注明原文地址:https://www.9cbs.com/read-33735.html

New Post(0)