{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
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
Image of page 7

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

View Full Document Right Arrow Icon
gdb
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern