C_lecture_6 - CS 11 C track: lecture 6 Last week: pointer...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 11 C track: lecture 6 ± Last week: pointer arithmetic ± This week: ± The gdb program ± struct ± typedef ± linked lists
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
gdb for debugging (1) ± gdb : the G nu D e B ugger ± http://www.cs.caltech.edu/courses/cs11/ material/c/mike/misc/gdb.html ± Use when program core dumps ± or when want to walk through execution of program line-by-line
Background image of page 2
gdb for debugging (2) ± Before using gdb : ± Must compile C code with additional flag: -g ± This puts all the source code into the binary executable ± Then can execute as: gdb myprogram ± Brings up an interpreted environment
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
gdb for debugging (3) gdb> run ± Program runs. .. ± If all is well, program exits successfully, returning you to prompt ± If there is (e.g.) a core dump, gdb will tell you and abort the program
Background image of page 4
gdb – basic commands (1) ± Stack backtrace (" where ") ± Your program core dumps ± Where was the last line in the program that was executed before the core dump? ± That's what the where command tells you
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
gdb – basic commands (2) gdb> where #0 0x4006cb26 in free () from /lib/libc.so.6 #1 0x4006ca0d in free () from /lib/libc.so.6 #2 0x8048951 in board_updater (array=0x8049bd0, ncells=2) at 1dCA2.c:148 #3 0x80486be in main (argc=3, argv=0xbffff7b4) at 1dCA2.c:44 #4 0x40035a52 in __libc_start_main () from /lib/libc.so.6 stack backtrace last call in your code last call
Background image of page 6
gdb – basic commands (3) ± Look for topmost location in stack backtrace that corresponds to your code ± Watch out for ± freeing memory you didn't allocate ± accessing arrays beyond their maximum elements ± dereferencing pointers that don't point to part of a malloc() ed block
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
gdb – basic commands (4) ± break , continue , next , step
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/30/2008 for the course C CMPE 150 taught by Professor Tuna during the Spring '08 term at Boğaziçi University.

Page1 / 35

C_lecture_6 - CS 11 C track: lecture 6 Last week: pointer...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online