COSC 340: Software Engineering Using the Debugger
Michael Jantz
COSC 340: Software Engineering 1
COSC 340: Software Engineering Using the Debugger Michael Jantz - - PowerPoint PPT Presentation
COSC 340: Software Engineering Using the Debugger Michael Jantz COSC 340: Software Engineering 1 Introduction What is it? A tool that supports examination of your program during execution How does it work? User attaches the
COSC 340: Software Engineering 1
COSC 340: Software Engineering 2
COSC 340: Software Engineering 3
COSC 340: Software Engineering 4
COSC 340: Software Engineering 5
COSC 340: Software Engineering 6
COSC 340: Software Engineering 7
COSC 340: Software Engineering 8
COSC 340: Software Engineering 9
find $1 -name '*'.[ch] | xargs grep -c $2 | sort -t : +1.0 -2.0 --numeric --reverse | head --lines=$3
‒ Find files with .c and .h extensions under the directory given by arg $1
‒ Search the set of files on standard input for the string given by arg $2. ‒ -c asks for the number of times $2 is used in each file
‒ Sort standard input and print the sorted order to standard output ‒ -t : +1.0 -2.0 says sort using the second column on each line ‒ --numeric says to sort numerically (as opposed to alphabetically) ‒ --reverse says sort in reverse order
‒ Print only the first n lines of input, with n specified as arg $3
COSC 340: Software Engineering 10
Breakpoint 1, execute_command (command=0x724088) at execute_cmd.c:376
COSC 340: Software Engineering 11
COSC 340: Software Engineering 12
‒ Continue until the next breakpoint is reached, the program terminates, or an error
‒ Execute one instruction, step over function calls
‒ Execute one instruction, step into function calls
‒ Continue to the end of the function you're currently in
‒ Kills the program being debugged (does not exit gdb – preserves everything else from the session, i.e., breakpoints.)
COSC 340: Software Engineering 13
COSC 340: Software Engineering 14
COSC 340: Software Engineering 15
(gdb) p command $14 = (COMMAND *) 0x724088 (gdb) ptype command type = struct command {
enum command_type type; int flags; int line; REDIRECT *redirects; union { struct for_com *For; ... struct coproc_com *Coproc; } value;
} *
COSC 340: Software Engineering 16
int ignore; COMMAND *first; COMMAND *second; int connector;
COSC 340: Software Engineering 17
(gdb) p ((struct connection *) command->value)->first $17 = (COMMAND *) 0x721108 (gdb) p ((struct connection *) command->value)->first->type $18 = cm_simple (gdb) ptype ((struct simple_com *) ((struct connection *) command->value)->first) type = struct simple_com {
int flags; int line; WORD_LIST *words; REDIRECT *redirects;
} *
COSC 340: Software Engineering 18
(gdb) p ((struct simple_com *) ((struct connection *) command->value)->first)->words $19 = (WORD_LIST *) 0xdfdfdfdfdfdfdfdf (gdb) ptype ((struct simple_com *) ((struct connection *) command->value)->first)->words type = struct word_list { struct word_list *next; WORD_DESC *word; } *
COSC 340: Software Engineering 19
(gdb) ptype ((struct simple_com *) ((struct connection *) command->value)->first)->words->word type = struct word_desc { char *word; int flags; } * (gdb) p ((struct simple_com *) ((struct connection *) command->value)->first)->words->word Cannot access memory at address 0xdfdfdfdfdfdfdfe7
COSC 340: Software Engineering 20
COSC 340: Software Engineering 21
(gdb) b execute_simple_command Breakpoint 2 at 0x4380a4: file execute_cmd.c, line 3650. (gdb) c Continuing. (gdb) p simple_command $28 = (SIMPLE_COM *) 0x721148 (gdb) p simple_command->words $29 = (WORD_LIST *) 0x721fe8 (gdb) call _print_word_list(simple_command->words, " ", printf) (gdb) call fflush(stdout) find $1 -name '*'.[ch]$30 = 0
COSC 340: Software Engineering 22
‒ Stops execution of your program whenever the value of EXPRESSION changes ‒ Can be useful if you find a variable or data has changed unexpectedly, but do not know what part of the code caused the change
‒ rwatch: stops whenever expression is read ‒ awatch: stops on read or write
‒ Watchpoints are very slow without hardware support ‒ x86 includes 4 debug registers (4 bytes each) for watchpoint support ‒ Watching structures larger than 32 bytes requires a software watchpoint, which is excruciatingly slow
COSC 340: Software Engineering 23
COSC 340: Software Engineering 24
> ctags -R
COSC 340: Software Engineering 25
COSC 340: Software Engineering 26
COSC 340: Software Engineering 27
COSC 340: Software Engineering 28