CSE 303 Lecture 13a Debugging C programs

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

Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 7, 2012 CSCE 212Honors Computer Organization.
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’
CS 202 Computer Science II Lab Fall 2009 September 24.
DEBUGGING IN THE REAL WORLD : Recitation 4.
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
David Notkin Autumn 2009 CSE303 Lecture 16 #preprocessor Debugging is twice as hard as writing the code in the first place. Therefore, if you write the.
Memory & Storage Architecture Seoul National University Computer Architecture “ Bomb Lab Hints” 2nd semester, 2014 Modified version : The original.
Embedded Systems Principle of Debugger. Reference Materials kl.de/avr_projects/arm_projects/#winarmhttp://
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.
Debugging Cluster Programs using symbolic debuggers.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
Instructor Notes GPU debugging is still immature, but being improved daily. You should definitely check to see the latest options available before giving.
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.
CSE 332: C++ debugging in Eclipse C++ Debugging in Eclipse We’ve now covered several key program features –Variable declarations, expressions and statements.
CS 241 Section Week #2 9/9/10. 2 Topics This Section MP1 issues MP2 overview Process creation using fork()‏ Debugging tools: valgrind, gdb.
Adv. UNIX: debug/141 Advanced UNIX v Objectives of these slides: –tools and techniques for debugging C code Special Topics in Comp. Eng.
CSE 232: C++ Programming in Visual Studio Graphical Development Environments for C++ Eclipse –Widely available open-source debugging environment Available.
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.
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.
Debugging. Outline Announcements: –HW II due Fridayl db.
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.
COP 3530 Spring2012 Data Structures & Algorithms Discussion Session Week 2.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
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.
1 Debugging (Part 2). “Programming in the Large” Steps Design & Implement Program & programming style (done) Common data structures and algorithms Modularity.
Lab 9 Department of Computer Science and Information Engineering National Taiwan University Lab9 - Debugging I 2014/11/4/ 28 1.
1 C Basics Monday, August 30, 2010 CS 241. Announcements MP1, a short machine problem, will be released today. Due: Tuesday, Sept. 7 th at 11:59pm via.
CMSC 104, Version 8/061L14AssignmentOps.ppt Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips Reading Section.
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.
CSE 333 – SECTION 2 Memory Management. Questions, Comments, Concerns Do you have any? Exercises going ok? Lectures make sense? Homework 1 – START EARLY!
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Gnu Debugger (GDB) Topics Overview Quick Reference Card Readings: Quick Reference Card February 4, 2010 CSCE 212Honors Computer Organization.
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.
Lab 2 main issues Point and line classes should NOT have their own protected “type” attributes these hide the parent (shape) classes attribute with the.
a.k.a how we test Your code
Instructions for test_function
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Valgrind Overview What is Valgrind?
CSE 374 Programming Concepts & Tools
Testing and Debugging.
Debugging with gdb gdb is the GNU debugger on our CS machines.
gdb gdb is the GNU debugger on our CS machines.
Recitation: C Review TA’s 19 Feb 2018.
Computer Architecture “Bomb Lab Hints”
Lab: ssh, scp, gdb, valgrind
ניפוי שגיאות - Debugging
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
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
a.k.a how we test Your code
CSE 303 Concepts and Tools for Software Development
Debugging.
Getting Started Download the tarball for this session. It will include the following files: driver 64-bit executable driver.c C driver source bomb.h declaration.
Valgrind Overview What is Valgrind?
Makefiles, GDB, Valgrind
Presentation transcript:

CSE 303 Lecture 13a Debugging C programs reading: Programming in C Ch. 13 slides created by Marty Stepp http://www.cs.washington.edu/303/

gdb gdb : GNU debugger. Helps you step through C programs. usage: absolutely essential for fixing crashes and bad pointer code your program must have been compiled with the -g flag usage: $ gdb program GNU gdb Fedora (6.8-23.fc9) Copyright (C) 2008 Free Software Foundation, Inc... (gdb) run parameters ... redirecting input: (gdb) run parameters < inputfile

gdb commands command description run or r parameters run the program break or b place sets a breakpoint at the given place: - a function's name - a line number - a source file : line number print or p expression prints the given value / variable step or s advances by one line of code ("step into") next or n ("step over") finish runs until end of function ("step out") continue or c resumes running program backtrace or bt display current function call stack quit or q exits gdb

A gdb session $ gdb intstack GNU gdb 5.2.1 Copyright 2002 Free Software Foundation, Inc. (gdb) b 34 Breakpoint 1 at 0x4010ea: file intstack.c, line 34. (gdb) r Starting program: /home/user/intstack Breakpoint 1, main () at intstack.c:34 34 Node* oldFront = stack; (gdb) p stack $1 = (Node *) 0x4619c0 (gdb) n 35 printf("%d\n", stack->data); 36 stack = stack->next; 37 free(oldFront); $4 = (Node *) 0x462856 (gdb) p oldFront $2 = (Node *) 0x4619c0 (gdb) p *oldFront $3 = {data = 10, next = 0x462856} (gdb) c Continuing.

ddd ddd (Data Display Debugger): Graphical front-end for gdb allows you to view the values of your variables, pointers, etc. $ ddd programName

nemiver nemiver : Another graphical debugger front-end design goal: Be usable even if you don't know gdb commands $ nemiver programName arguments

Other debuggers Eclipse CDT (C/C++ Development Toolkit) create a new Managed Make C Project right-click project name, choose Debug As, Local C/C++ Application

valgrind valgrind : A memory-leak detector and debugging tool. valgrind programName arguments (1) push, (2) pop, (3) clear, or (0) quit? 2 ==3888== Conditional jump or move depends on uninitialised value(s) ==3888== at 0x80484E7: main (intstack.c:28) ==3888== ==3888== Use of uninitialised value of size 4 ==3888== at 0x80484F2: main (intstack.c:30) -15156339 ==3888== at 0x8048507: main (intstack.c:31) ==3888== Invalid free() / delete / delete[] ==3888== at 0x4025DFA: free (vg_replace_malloc.c:323) ==3888== by 0x8048517: main (intstack.c:32) ==3888== Address 0x8048569 is in the Text segment of /home/stepp/intstack

more valgrind valgrind dumps stats about leaked memory on program exit (1) push, (2) pop, (3) clear, or (0) quit? 1 Number to push? 10 Number to push? 20 (1) push, (2) pop, (3) clear, or (0) quit? 2 20 10 (1) push, (2) pop, (3) clear, or (0) quit? 0 ==5162== LEAK SUMMARY: ==5162== definitely lost: 16 bytes in 2 blocks. ==5162== possibly lost: 0 bytes in 0 blocks. ==5162== still reachable: 0 bytes in 0 blocks. ==5162== suppressed: 0 bytes in 0 blocks.

lint / splint lint (or more recently, splint) checks code for possible errors famously picky (sometimes should be ignored) but good for helping you find potential sources of bugs/errors not installed on attu, but can install it on your Linux: $ sudo apt-get install splint $ splint *.c Splint 3.1.2 --- 07 May 2008 part2.c: (in function main) part2.c:8:2: Path with no return in function declared to return int There is a path through a function declared to return a value on which there is no return statement. This means the execution may fall through without returning a meaningful result to the caller. (Use -noret to inhibit warning) use_linkedlist.c:5:5: Function main defined more than once A function or variable is redefined. One of the declarations should use extern. (Use -redef to inhibit warning) part2.c:8:1: Previous definition of main