CSE 374 Programming Concepts & Tools

Slides:



Advertisements
Similar presentations
Introduction to the Omega Server CSE Overview Intro to Omega Basic Unix Command Files Directories Printing C and C++ compilers GNU Debugger.
Advertisements

Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
CSE 303 Lecture 13a Debugging C programs
Gdb is the GNU debugger on our CS machines. gdb is most effective when it is debugging a program that has debugging symbols linked in to it. With gcc and.
Homework Reading Programming Assignments
Debugging Cluster Programs using symbolic debuggers.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
Compiling & Debugging Quick tutorial. What is gcc? Gcc is the GNU Project C compiler A command-line program Gcc takes C source files as input Outputs.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
Debugging and Profiling With some help from Software Carpentry resources.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
CSE 332: C++ debugging Why Debug a Program? When your program crashes –Finding out where it crashed –Examining program memory at that point When a bug.
Debugging Xin Tong. GDB GNU Project debugger Allows you to see what is going on `inside' another program while it executes or crashed. (Faster than printing.
CSE 351 GDB Introduction. Lab 1 Status? How is Lab 1 going? I’ll be available at the end of class to answer questions There are office hours later today.
Debugging Computer Networks Sep. 26, 2007 Seunghwan Hong.
C++ crash course Class 9 flight times program, using gdb.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Debugging 1/6/2016. Debugging 1/6/2016 Debugging  Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a program.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 10 – C: the heap and manual memory management.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
Debugging: Tips and Tools Also, Aloha Recitation Wednesday, February 7th, 2007.
Systems Dev. Tutorial IV: Debugging: Tips and Tools Recitation Wednesday, Sept 27th, 2006.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors Locate seg faults and bus errors Prepared by Dr. Spiegel.
DEBUG.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
14 Compilers, Interpreters and Debuggers
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
Testing and Debugging.
Debugging with gdb gdb is the GNU debugger on our CS machines.
CSE 374 Programming Concepts & Tools
CSE 351 Section 1: HW 0 + Intro to C
gdb gdb is the GNU debugger on our CS machines.
Lab: ssh, scp, gdb, valgrind
COMP 2710 Software Construction Introduction to GDB
Debugging Techniques.
Lab: ssh, scp, gdb, valgrind
CS/COE 0449 Jarrett Billingsley
Common C Programming Errors, GDB Debugging
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
Tonga Institute of Higher Education
Debugging at Scale.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
When your program crashes
CSE 303 Concepts and Tools for Software Development
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2015.
EECS150 Fall 2007 – Lab Lecture #4 Shah Bawany
Homework Any Questions?.
Debugging “Why you were up till 2AM”
Homework Reading Programming Assignments Finish K&R Chapter 1
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2016.
CSE 303 Concepts and Tools for Software Development
Debugging.
Makefiles, GDB, Valgrind
CAP6135: Malware and Software Vulnerability Analysis Buffer Overflow : Example of Using GDB to Check Stack Memory Cliff Zou Spring 2013.
CSE 303 Concepts and Tools for Software Development
Presentation transcript:

CSE 374 Programming Concepts & Tools Hal Perkins Winter 2017 Lecture 11 – gdb and Debugging UW CSE 374 Winter 2017

Administrivia HW4 due Thursday, 11 pm: C code and libraries. How’s it look? Some tools: gdb (debugger) and clint.py (style checker). gdb demo today. Due Thursday, 11 pm Midterm next Monday, in class Everything up to hw4/basic C Closed book – will provide reference summary info on test as needed Old exams on web now for studying Review Q&A Sunday, 1 pm, LOW 101 UW CSE 374 Winter 2017

Agenda Debuggers, particularly gdb Why? To learn general features of breakpoint-debugging To learn specifics of gdb To learn general debugging “survival skills” Skill #1: don’t panic! Skill #2: be systematic – have a plan UW CSE 374 Winter 2017

How to avoid debugging Don’t put bugs in the program!! Think before typing – design before coding Write down design (comments) as you go Functions: declaration+comments should be complete spec Significant data: declaration + comments should be complete spec If someone has to read the code to figure out how to use something or understand data structures, comments are bad Review/check comments and compare to code as you work Will catch errors before you run the program Turn on compiler warnings (-Wall); use assert; get the computer to find problems for you. But things can still go wrong… UW CSE 374 Winter 2017

An execution monitor? What would you like to “see inside” and “do to” a running program? Why might all that be helpful? What are reasonable ways to debug a program? A “debugger” is a tool that lets you stop running programs, inspect (sometimes set) values, etc. A “MRI” for observing executing code UW CSE 374 Winter 2017

Issues Source information for compiled code. (Get compiler help) Stopping your program too late to find the problem. (Art) Trying to “debug” the wrong algorithm Trying to “run the debugger” instead of understanding the program It’s an important tool Debugging C vs. Java Eliminating crashes does not make your C program correct Debugging Java is “easier” because (some) crashes and memory errors do not exist But programming Java is “easier” for the same reason! UW CSE 374 Winter 2017

gdb gdb (Gnu debugger) is part of the standard Linux toolchain. gdb supports several languages, including C compiled by gcc. Modern IDEs have fancy GUI interfaces, which help, but concepts are the same. Compile with debugging information: gcc -g Otherwise, gdb can tell you little more than the stack of function calls. Running gdb: gdb executable Source files should be in same directory (or use the -d flag). At prompt: run args Note: You can also inspect core files, which is why they got saved on older systems after every crash (Mostly useful for analyzing crashed programs after-the-fact, not for systematic debugging. The original use of db.) UW CSE 374 Winter 2017

Basic functions backtrace frame, up, down print expression, info args, info locals Often enough for “crash debugging” Also often enough for learning how “the compiler does things” (e.g., stack direction, malloc policy, ...) UW CSE 374 Winter 2017

Breakpoints break function (or line-number or ...) conditional breakpoints (break XXX if expr) to skip a bunch of iterations to do assertion checking going forward: continue, next, step, finish Some debuggers let you “go backwards” (typically an illusion) Often enough for “binary search debugging” Also useful for learning program structure (e.g., when is some function called) Skim the manual for other features. UW CSE 374 Winter 2017

A few tricks Everyone develops their own “debugging tricks”; here are a few: Always checking why a seg-fault happened (infinite stack and array-overflow very different) Printing pointer values to see how big objects were. “Staring at code” even if it does not crash Printing array contents (especially last elements) . . . UW CSE 374 Winter 2017

Advice Understand what the tool provides you Use it to accomplish a task, for example “I want to know the call-stack when I get the NULL-pointer dereference” Optimize your time developing software Think of debugging as a systematic experiment to discover what’s wrong — not a way to randomly poke around. Observation: the problem; hypothesis: I think the cause is …; experiment: use debugger to verify Use development environments that have debuggers? See also: jdb for Java Like any tool, takes extra time at first but designed to save you time in the long run Education is an investment UW CSE 374 Winter 2017

gdb summary – running programs Be sure to compile with gcc -g Open the program with: gdb <executable file> Start or restart the program: run <program args> Quit the program: kill Quit gdb: quit Reference information: help Most commands have short abbreviations <return> often repeats the last command Particularly useful when stepping through code UW CSE 374 Winter 2017

gdb summary – looking around bt – stack backtrace up, down – change current stack frame list – display source code (list n, list <function name>) print expression – evaluate and print expression display expression – (re-)evaluate and print expression every time execution pauses.  undisplay – remove an expression from this recurring list. info locals – print all locals (but not parameters) x (examine) – look at blocks of memory in various formats UW CSE 374 Winter 2017

gdb summary – breakpoints, stepping break – set breakpoint. (break <function name>, break <linenumber>, break <file>:<linenumber>) info break – print table of currently set breakpoints clear – remove breakpoints disable/enable – temporarily turn breakpoints off/on without removing them from the breakpoint table  continue – resume execution to next breakpoint or end of program step – execute next source line next – execute next source line, but treat function calls as a single statement and don't step into them finish – execute to the conclusion of the current function How to recover if you meant “next” instead of “step” UW CSE 374 Winter 2017