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.

Slides:



Advertisements
Similar presentations
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Advertisements

Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
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,
CS201 - Repetition loops.
Declaring Arrays Declare an array of 10 elements: int nums[10]; Best practice: #define SIZE 10 int nums[SIZE]; // cannot be int[SIZE] nums; C99: int nums[someVariable]
Guidelines for working with Microsoft Visual Studio.Net.
CSSE 332 Explicit Memory Allocation, Parameter passing, and GDB.
Guidelines for working with Microsoft Visual Studio 6.
. Memory Management. Memory Organization u During run time, variables can be stored in one of three “pools”  Stack  Static heap  Dynamic heap.
C Slides and captured lecture (video and sound) are available at:
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
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
C Course Lecture 4 This lecture we'll talk about: Multi-dimensional arrays. Pointer arithmetic. Pointers to structures. Multi-file programming. What is.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
Outline Midterm results Static variables Memory model
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.
Practical Session 4. Labels Definition - advanced label: (pseudo) instruction operands ; comment valid characters in labels are: letters, numbers, _,
Our Environment We will exercise on Microsoft Visual C++ v.6 We will exercise on Microsoft Visual C++ v.6 because that is what we have in the univ. because.
CS 241 Section Week #2 9/9/10. 2 Topics This Section MP1 issues MP2 overview Process creation using fork()‏ Debugging tools: valgrind, gdb.
1 C Programming Week 2 Variables, flow control and the Debugger.
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.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
C By Example 1 The assumption is that you know Java and need to extend that knowledge so you can program in C. 1. Hello world 2. declarations 3. pass by.
(language, compilation and debugging) David 09/16/2011.
C/C++ Basics. Basic Concepts Basic functions of each language: Input, output, math, decision, repetition Types of errors: Syntax errors, logic errors,
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 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.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
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.
CMSC 104, Version 8/061L14AssignmentOps.ppt Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips Reading Section.
Functions and Pointers Dr. Sajib Datta Oct 6, 2014.
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
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.
CSCI 4061 Recitation 2 1.
DEBUG.
Memory-Related Perils and Pitfalls in C
The First Real Bug.
Static Code Analysis What it is and does. Copyright © 2016 Curt Hill.
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Debugging with Clion and GDB
Debugger Ritu Chaturvedi
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.
COMP 2710 Software Construction Introduction to GDB
Lab: ssh, scp, gdb, valgrind
Debuggers.
Tonga Institute of Higher Education
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Chapter 15 Debugging.
Our Environment We will exercise on Microsoft Visual C++ v.6
Programming in C Pointer Basics.
CSE 303 Concepts and Tools for Software Development
Chapter 15 Debugging.
Debugging.
Makefiles, GDB, Valgrind
The First Real Bug.
Chapter 15 Debugging.
Introduction to C CS 3410.
Presentation transcript:

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.

Common Bugs Bugs with pointers and memory –Memory leaks The allocated memory is not freed subsequently. –Free the already freed resource int main(){ char* str = ( char* ) malloc( sizeof(char) * 10 ); if ( global == 0 ) free( str ); /* Doing Something here … */ free ( str ); return 0; }

Common Bugs Bugs with pointers and memory –Memory leaks The allocated memory is not freed subsequently. –Free the already freed resource –NULL-pointer dereferencing Improper initialization int main(){ char* str = NULL; strcpy( str, “def” ); printf( “%s”, str ); return 0; } int main(){ char* str = “abc”; strcpy( str, “def” ); printf( “%s”, str ); return 0; }

Common Bugs Error of scanf() int main(){ int num; char* str = (char*)malloc(sizeof(char) * SIZE); scanf("%d", &num);// require to pass address to scanf() scanf("%s", &str);// Not need & here, str points to variable itself printf("%d %s\n", num, str); return 0; }

Common Bugs Using ‘=’ instead of ‘==’ int main(){ int i; int a = 0; for(i = 0; i < 10; i++) a += i; if(a = 0) a = 1000; printf("%d", a); return 0; } Output: 0

Common Bugs Loop error int x = 5; while(x > 0); x--; Infinite loop int main() { int a = 0; while(a < 10){ printf("%d\n", a); if (a = 5) printf("a equals 5!\n"); a++; } return 0; } Infinite loop

Debugger A debugger is a computer program used to test and debug other programs. The code to be examined might alternatively be running on an instruction set simulator (ISS), a technique that allows great power in its ability to halt when specific conditions are encountered.

Debugger (GDB) GDB – GNU Debugger Compiler your program with ‘-g’ for debugging –gcc -g [your program] -o [executable file]

Debugger (GDB) Start GDB –gdb –gdb [executable file] GDB window

Debugger (GDB) Load your program on GDB –file [executable file] Run your program –start ( 開始執行程式,並停留在 main 入口處 ) –run ( 開始執行程式,直到遭遇 break point) Stop at the beginning of ‘main’

Debugger (GDB) Set breakpoints –break [location] –break [function] Stop at the line 43 The command “list” is used to list part of the code of your program.

Debugger (GDB) Set breakpoints –break [function / location] if [condition] Stop at the function ‘InsertSorted’ if (head->data data)

Debugger (GDB) Print the value of some variables –print [variable] Continue executing your program –continue (c) Continue executing Print the value of variable ‘new->data’, and the value is 10.

Debugger (GDB) Set watchpoints –watch [variable] The value of variable ‘head’ has been changed.

Debugger (GDB) Set value of variable –set [variable] = [value] Set the value of new->data as 1.

Debugger (GDB) List breakpoints and watchpoints –list break Delete breakpoint or watchpoint –delete [point number] The list of all breakpoints and watchpoints. Delete the watchpoint which Num is 4.

Debugger (Code Blocks) Settings → Compiler and debugger…

Debugger (Code Blocks) Add breakpoint

Debugger (Code Blocks) Open debugging window

Debugger (Code Blocks) Start debugging Watching window (the state of all variables) Press to start debugging

References GDB manual – Code::Blocks Debugger manual – tutorials/206-codeblocks-debuggerhttp://ez2learn.com/index.php/c-tutorials/codeblocks- tutorials/206-codeblocks-debugger Dev C++ Debugger manual – dev-cdebuggerhttp://ez2learn.com/index.php/c-tutorials/dev-c-/203- dev-cdebugger