Download presentation
Presentation is loading. Please wait.
Published bySuzanna Armstrong Modified over 9 years ago
1
Memory & Storage Architecture Lab. @ Seoul National University GDB commands Hyeon-gyu Lee(hglee@archi.snu.ac.kr) School of Computer Science and Engineering Seoul National University
2
Memory & Storage Architecture Lab. @ Seoul National University To Use GDB in Your Program Additional compile option gcc –g –o prog prog.c Execute gdb gdb prog 2
3
Memory & Storage Architecture Lab. @ Seoul National University Looking the Program Source List instruction (gdb) list Abbreviated to the letter ‘l’ Shows your code of your program 3
4
Memory & Storage Architecture Lab. @ Seoul National University Looking the Program Source List instruction options (gdb) list Shows the code of (gdb) list : Shows the code of in the (gdb) list Shows the code from (gdb) list : Shows the code from in the (gdb) list - Shows the code right before your current position Current unit lines of printing: 10 (gdb) set listsize 20 Set the unit lines of printing to 20 4
5
Memory & Storage Architecture Lab. @ Seoul National University Running the program Run the program (gdb) run Abbreviated to the letter ‘r’ Run your code continuously -If confronts breakpoint, gdb stops there. -If there are no breakpoints, gdb runs until the program terminates. Useful when your program has errors (gdb) run arg1 arg2 … Run your code continuously with arguments 5
6
Memory & Storage Architecture Lab. @ Seoul National University Breakpoints Make points to stop (gdb) break Abbreviated to the letter ‘b’ Without any option, breakpoint is made at your current position 6
7
Memory & Storage Architecture Lab. @ Seoul National University Making Breakpoints Breakpoint options (gdb) break Breakpoint at the start of the function (gdb) break : Breakpoint at the start of the function in the file (gdb) break Breakpoint at the designated line (gdb) break Breakpoint at the current-position-relatively designated line (gdb) break Breakpoint at the instruction that pointed by the memory address Used at assembly debugging Above all options can be done with conditions e.g. (gdb) break 10 if var==0 7
8
Memory & Storage Architecture Lab. @ Seoul National University Manipulating Breakpoints Breakpoint information (gdb) info break Shows the information about your breakpoints Valid until the gdb terminates Deleting breakpoint (gdb) clear Abbreviated to ‘cl’ Clear breakpoints that you made Should be used with options (gdb) clear Delete breakpoint at that line number 8
9
Memory & Storage Architecture Lab. @ Seoul National University Manipulating Breakpoints Deleting breakpoint options (gdb) clear Delete breakpoint at that line number (gdb) clear Delete breakpoint at the start of the function (gdb) clear : Delete breakpoint at the start of the function in the file (gdb) d Delete all breakpoints (gdb) disable/enable br Disable/enable all breakpoints (gdb) disable/enable br 1 3 Disable/enable breakpoints with number 1, 3. 9
10
Memory & Storage Architecture Lab. @ Seoul National University Single-stepping Single stepping (gdb) step Abbreviated to the letter ‘s’ When a function is called at the point, it goes into the function (gdb) step Repeat ‘step’ with times of the number. (gdb) next Abbreviated to the letter ‘n’ When a function is called at the point, it executes the whole function continuously (gdb) next Repeat ‘next’ with times of the number. 10
11
Memory & Storage Architecture Lab. @ Seoul National University Single-stepping Other instructions (gdb) continue Abbreviated to the letter ‘c’ Continuously execute from your current position (gdb) advance Continuously execute from your current position to the line number (gdb) until Continuously execute until current repetition finish point When the current position is not in a repetition, it operates like ‘next’ 11
12
Memory & Storage Architecture Lab. @ Seoul National University Single-stepping Other instructions (gdb) finish Continuously execute from your current position until current function finish point (gdb) return Return without executing the remaining part of the function When needed, you can manually designate a return value (gdb) set var = Change the content of the variable to the given value 12
13
Memory & Storage Architecture Lab. @ Seoul National University Watchpoints Stop when a variable is set to a specific value (gdb) watch Break when a value is written in the variable (gdb) rwatch Break when the value is read in the variable (gdb) awatch Break when a value is read/written in the variable 13
14
Memory & Storage Architecture Lab. @ Seoul National University Displaying Values See values in your program (gdb) info locals Shows values of local variables that you can access from your current position (gdb) info variables Shows values of global variables that you can access from your current position (gdb) print Shows value of the variable When the variable is a pointer, dereferencing is possible with an asterisk. (gdb) print Shows address of the function 14
15
Memory & Storage Architecture Lab. @ Seoul National University Displaying Values See values in your program (gdb) print $ Shows value of the register. (gdb) print ‘ ’:: Shows value of the variable in the file. (gdb) print :: Shows value of the variable in the function (gdb) whatis Shows type of the variable (gdb) display Shows value of the variable automatically with progress of the program Enabling/disabling is possible (gdb) undisplay Delete display 15
16
Memory & Storage Architecture Lab. @ Seoul National University Examining the Stack Backtracing the stack (gdb) backtrace Abbreviated to the ‘bt’ Shows stack trace of your current position 16
17
Memory & Storage Architecture Lab. @ Seoul National University Killing the Executing Program in the GDB Kill instruction (gdb) kill Kill the executing program forcefully 17
18
Memory & Storage Architecture Lab. @ Seoul National University Quitting the GDB Quit and exit to the Linux (gdb) quit Abbreviated to the letter ‘q’ 18
19
Memory & Storage Architecture Lab. @ Seoul National University References References http://kwanseob.blogspot.kr/2012/03/gdb.html, retrieved on May 20, 2015. http://kwanseob.blogspot.kr/2012/03/gdb.html http://darkdust.net/files/GDB%20Cheat%20Sheet.pdf, retrieved on May 20, 2015. http://darkdust.net/files/GDB%20Cheat%20Sheet.pdf https://kldp.org/node/71806, retrieved on May 20, 2015. https://kldp.org/node/71806 19
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.