1 SEEM3460 Tutorial Compiling and Debugging C programs.

Slides:



Advertisements
Similar presentations
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Advertisements

CS 202 Computer Science II Lab Fall 2009 September 24.
DEBUGGING IN THE REAL WORLD : Recitation 4.
Environment & tools Assistant Anssi Jääskeläinen Visiting hours: Tuesdays Room: 6606
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
1 Lab Session-2 CSIT 121 Spring 2005 Debugging Tips NiMo’s Varying Rates Lab-2 Exercise.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
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 Tips for Programmers. Outline Script debugging Script debugging –C shell –BASH/Bourne/Korn shell tips Compiled language debugging Compiled language.
Homework Reading Programming Assignments
Debugging Cluster Programs using symbolic debuggers.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction Unix-like system is everywhere Linux Android for smartphones Google Chrome OS for Chromebook Web.
August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004.
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.
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.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Active-HDL Interfaces Debugging C Code Course 10.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
ENEE150 – 0102 ANDREW GOFFIN Testing and Debugging.
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.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Georgia Institute of Technology Creating Classes part 2 Barb Ericson Georgia Institute of Technology June 2006.
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.
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.
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?
CMSC 202 Lesson 15 Debugging. Warmup  What is the bug in the following code? int* foo(int a) { return &a; }
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.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
CMSC 104, Version 8/061L14AssignmentOps.ppt Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips Reading Section.
CPT: Debug/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to talk about the various approaches to testing.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
HP-SEE Debugging with GDB Vladimir Slavnic Research Assistant SCL, Institute of Physics Belgrade The HP-SEE initiative.
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.
SEEM3460 Tutorial Unix Introduction.
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Editor, Compiler, Linker, Debugger, Makefiles
gdb gdb is the GNU debugger on our CS machines.
Operating System Discussion Section.
Debuggers.
Common C Programming Errors, GDB Debugging
SEEM3460 Tutorial Unix Introduction Xinshi Lin & Zihao Fu
Getting Started: Developing Code with Cloud9
Debugging at Scale.
Using a Debugger 1-Jan-19.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
Our Environment We will exercise on Microsoft Visual C++ v.6
Video Notes.
CSE 303 Concepts and Tools for Software Development
Debugging.
Makefiles, GDB, Valgrind
Presentation transcript:

1 SEEM3460 Tutorial Compiling and Debugging C programs

2 Compiling C programs in Unix Compiler: cc – the native C compiler under Unix gcc – C compiler under GNU project Usage is the same, gcc is more popular To compile a C source code file, say example.c, type in: cc example.c gcc example.c The output of both compilers (i.e. the executable) would be “a.out” by default To override the default executable name, use “-o” flag cc example.c –o example gcc example.c –o example You can name the executable as.exe or.bin file to remind yourself the nature of the file One more tip, use “-Wall” to get some warning messages Warning message usually indicate hidden bugs Try to understand the error messages and warning messages. For other flags, “man cc” or “man gcc”

3 Compiling C programs in Unix If there are so many compilation errors that it cannot fit into one screen. One way is to compile by the following command: cc example.c |& more It means that the compilation errors will be displayed screen by screen. That is, it will display the first screen of errors and wait. After the user examines the errors, he/she can choose to display the next screen of errors by hitting RETURN or quit by hitting Control-C. Then, the user can go back to modify the source code.

4 Debugging C programs in Unix Mainly 2 ways: Add printf to trace the bug Use debugger to find out the bug Debugger lets you to know: What statement or expression did the program crash on? If an error occurs while executing a function, what line of the program contains the call to that function, and what are the parameters? What are the values of program variables at a particular point during execution of the program? What is the result of a particular expression in a program? Reference:

5 Debugging C programs (2) Debuggers available on your Unix workstations: dbx – work for cc gdb – work for gcc To use debugger, add “-g” flag when compiling the program cc –g example.c –o example gcc –g example.c –o example And then start the debugger by loading the executable: dbx example(for cc) gdb example(for gcc) Demo on how to use a debugger (using dbx on Lab asg 1) The demo covers only a few important commands in dbx. For detail tutorial on using dbx and gdb, google for “gdb tutorial” and “dbx tutorial” respectively.

6 Demo commands on dbx (details see pdf tutorial notes) help run rerun trace step trace change function`variable trace in function stop step print whatis whereis quit