Post on 05-Jan-2016
description
CMSC212: Intro to Low-Level Programming Concepts
Section 0101: 9:00am – 9:50amSection 0102: 10:00am-10:50amMonday & WednesdaysRoom 3118
Announcements/Reminders
•Quiz #2: This Wednesday (12mins)•Reminder: Must submit versions of every
project that work on at least half the public tests to pass the course (Still can submit Project #1 up until 10:00 tonight)
•Today: First, the GNU Project Debugger (GDB) and its innards. Later, a worksheet (based on quiz questions from earlier semesters)
GNU Project Debugger (GDB)
•The main idea▫Lets your step through your code “line-by-
line” during execution▫Lets you look/modify variables and their
values during run-time▫Breakpoints!
Want your program to temporary halt execution on a particular line of code, set a breakpoint
•http://sourceware.org/gdb/current/onlinedocs/gdb_toc.html
GNU Project Debugger (GDB)
•Programs must be compiled with the option –g to be debugged with gdb
•Some common commands with console gdb▫r: run: runs the program from the beginning▫c: cont: continues execution after breakpoint▫n: next: executes next statement, steps over
function calls▫s: step: executes next statement, steeping into
function calls▫finish: completes the execution (returns from
current function)
GNU Project Debugger (GDB)
•Breakpoints▫b: break: sets a breakpoint on current line
or any line▫tb: tbreak: sets a temporary breakpoint on
indicated line▫d: delete: deletes one or all breakpoints▫i b: info breakpoints: lists all currently set
breakpoints
GNU Project Debugger (GDB)
•Looking at data▫p: print: prints a variable’s current value.,
print/x prints in hex▫info locals: prints values of current function’s
local variables▫display: followed by a variable name which is
visible at the current position, prints the value of that variable each time the program execution stops.
▫undisplay: Cancels the display of variables set in prior display commands
GNU Project Debugger (GDB)
•Execution history▫where: shows list of active functions, in
order from most recent-called back to main function
▫up: moves up the function which called the current one (to be able to examine its data)
▫down: move back after calling up•If program crashes during execution (e.g.
segfault, use ‘where’ to find out where it happened
GDB with emacs
•Hit escape-x▫Type ‘gdb’▫The following may appear, just hit enter to
launch: gdb –annotate=3 program.x
•Begin debugging, hit r▫Should see a split window of console and
code▫set breakpoints using cursor in the code
window
▫Other features: Look at menu ‘GuD’, “GDB-UI”, and “Display other Windows” Gdb interaction (console) window display of local variables in the main program Source code Runtime stack and current function call chain List o breakpoints set