CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

CSc 352 Programming Hygiene Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Utilizing the GDB debugger to analyze programs Background and application.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
CSc 352 Freeing Dynamically Allocated Memory Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
DEBUGGING IN THE REAL WORLD : Recitation 4.
Dr. Fabrizio Gala Dipartimento di Scienze di Base e Applicate Per l’Ingegneria – Sezione di Fisica Via Scarpa Rome, Italy 1.
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
Lecture Roger Sutton CO331 Visual programming 15: Debugging 1.
Inline Assembly Section 1: Recitation 7. In the early days of computing, most programs were written in assembly code. –Unmanageable because No type checking,
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
CSE 303 Lecture 13a Debugging C programs
CSc 352 Shell Scripts Saumya Debray Dept. of Computer Science
CS 225 Lab #2 - Pointers, Copy Constructors, Destructors, and DDD.
CSc 352 C : Arrays, Structs, Pointers
Debugger Presented by 李明璋 2012/05/08. The Definition of Bug –Part of the code which would result in an error, fault or malfunctioning of the program.
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.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
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.
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.
Python Functions.
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.
CSCI Rational Purify 1 Rational Purify Overview Michel Izygon - Jim Helm.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
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.
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.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Unit - V. Debugging GNU Debugger helps you in getting information about the following: 1.If a core dump happened, then what statement or expression did.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
17/02/2016S. Ponce / EP-LBC1 Debugging Under Linux Sebastien Ponce Friday, 8 March 2002.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
Announcements Partial Credit Due Date for Assignment 2 now due on Sat, Feb 27 I always seem to be behind and get tons of daily. If you me and.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Hank Childs, University of Oregon April 13 th, 2016 CIS 330: _ _ _ _ ______ _ _____ / / / /___ (_) __ ____ _____ ____/ / / ____/ _/_/ ____/__ __ / / /
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Using the GNU Debugger (GDB)‏ Techzemplary Pvt.Ltd February 24 th 2008 Pranav Peshwe.
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.
Computer System Laboratory
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Debugging and Handling Exceptions
CSE 374 Programming Concepts & Tools
Testing and Debugging.
Debugging with gdb gdb is the GNU debugger on our CS machines.
Checking Memory Management
gdb gdb is the GNU debugger on our CS machines.
Debugging with Eclipse
Chapter 15 Debugging.
DEBUGGING JAVA PROGRAMS USING ECLIPSE DEBUGGER
CSc 352: Testing and Code Coverage
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
Chapter 15 Debugging.
CSc 352: Elementary “make”
CSE 303 Concepts and Tools for Software Development
Understanding and Preventing Buffer Overflow Attacks in Unix
Chapter 15 Debugging.
Debugging.
Makefiles, GDB, Valgrind
Debugging with Eclipse
Topic 2b ISA Support for High-Level Languages
Chapter 15 Debugging.
Presentation transcript:

CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson debray@cs.arizona.edu

Uninitialized pointers str was never initialized to point to anything

Uninitialized pointers Suppose this was a program of realistic size. How would we identify the location and reason for the problem?

Locating the problem: gdb load the program into gdb run the program within gdb show where execution stopped show values of variables

Memory error diagnosis: valgrind invoking the tool: valgrind progName arg1 arg2 … indicates: there was a problem; what happened where it happened

Dangling pointers We looked at this code earlier: runtime stack main my_read read_string string a c b buf str dangling pointer!

Dangling pointers Minor variation on this code:

(on hedgehog.cs.arizona.edu) Dangling pointers the code seems to work!!! (on hedgehog.cs.arizona.edu)

(on lectura.cs.arizona.edu) Dangling pointers doesn’t work (on lectura.cs.arizona.edu)

What’s going on? runtime stack main my_read read_string the array padding[ ] “protects” buf[ ] from getting overwritten — so the code seems to work (on some machines) strlen a padding[ ] a c b buf[ ]

More diagnosis

Summary Just because a program produces the expected output doesn’t mean that it’s correct the observed behavior may be accidental the observed behavior may be system-dependent Use valgrind to check whether the execution was free of memory errors provides information only about one execution other executions may contain erroneous behaviors provides some help in identifying where the error occurred.

Another example

Example 2 out of bounds memory access

Example 2 where the invalid memory access occurred, (incl. stack trace) where this memory was allocated (incl. stack trace)

off-by-one problem fixed Example 3 off-by-one problem fixed

Example 3

gdb: basic functionality Interactive debugger allows the user to run a program and interactively examine its execution. Features include: breakpoints (“run until control reaches here, then prompt user”) stack backtrace (chain of calls leading to some point in the code) examination of program variables Usage: compile program using gcc –g … invoke the program as gdb prog (then supply arguments inside gdb)

Interactive debugging: gdb expected behavior buggy behavior

gdb: example usage invocation set a breakpoint start execution in this case: at entry to main() start execution specify command-line arguments here execution reaches breakpoint and returns control to user examine the program move to next statement

gdb: Looking at the program “list the program source around the line number specified”

gdb set a breakpoint here

gdb execution reaches breakpoint and returns control to user single-step through the execution

continue to next breakpoint gdb examine program state continue to next breakpoint

gdb

gdb: moving around the runtime stack where did the Seg Fault occur? move up the stack (i.e., to the caller) to examine variable values

gdb: other features Gdb provides many other debugging features, e.g.: conditional breakpoints “break execution at some point in the code and return control to the user if some condition holds” watchpoints “break execution and return control to user if a variable is read or written’ change the value of a variable in the program state See tutorials in the DOCS area of class website

gdb: reading commands from a file input to the program to be debugged script of commands to gdb invoking gdb to read commands from script file

ddd: a GUI front end for GDB common operations program source gdb interaction