CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.

Slides:



Advertisements
Similar presentations
{ Dominion - Test Plan Version 1 – 22 nd Apr Aravind Palanisami.
Advertisements

Carnegie Mellon 1 Debugging : Introduction to Computer Systems Recitation 12: Monday, Nov. 9 th, 2013 Yixun Xu Section K.
Creating a Program In today’s lesson we will look at: what programming is different types of programs how we create a program installing an IDE to get.
DEBUGGING IN THE REAL WORLD : Recitation 4.
18-213: Introduction to Computer Systems April 6, 2015
CS201 – Makefile Tutorial. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc.
Debugging Introduction to Computing Science and Programming I.
Debugging CPSC 315 – Programming Studio Fall 2008.
Makefiles, Unix, and Project 1 Q&A : Recitation 2 September 12, 2007.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Introduction to The Linaro Toolchain Embedded Processors Training Multicore Software Applications Literature Number: SPRPXXX 1.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
BioPSE NCRR SCIRun: Getting Started Installation and Configuration J. Davison de St. Germain (801)
Make: the good, the bad, and the ugly Dan Berger Titus Winters
© 2012 IBM Corporation Rational Insight | Back to Basis Series Chao Zhang Unit Testing.
Exceptions 1. Your computer takes exception Exceptions are errors in the logic of a program (run-time errors). Examples: Exception in thread “main” java.io.FileNotFoundException:
Intro to C++ And Some Tools Opening Discussion zHave any questions come up since last class? Have you had a chance to look over the project.
1 Software Development Configuration management. \ 2 Software Configuration  Items that comprise all information produced as part of the software development.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.
August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004.
Developing C/C++ applications with the Eclipse CDT David Gallardo.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
1 Software Construction and Evolution - CSSE 375 Exception Handling - Principles Steve Chenoweth, RHIT Above – Exception handling on the ENIAC. From
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
C Tutorial - Program Organization CS Introduction to Operating Systems.
CSE 232: C++ debugging in Visual Studio and emacs C++ Debugging (in Visual Studio and emacs) We’ve looked at programs from a text-based mode –Shell commands.
Debugging and Profiling With some help from Software Carpentry resources.
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 Computer Networks Sep. 26, 2007 Seunghwan Hong.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
HKOI Programming HKOI Training Team (Intermediate) Alan, Tam Siu Lung Unu, Tse Chi Yung.
Byoung-Jo CHOI Fall 2007 SW Project II Advanced Linux Programming.
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.
Threads. Readings r Silberschatz et al : Chapter 4.
CS12230 Introduction to Programming Lecture 6-2 –Errors and Exceptions 1.
Version Control and SVN ECE 297. Why Do We Need Version Control?
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
How to configure, build and install Trilinos November 2, :30-9:30 a.m. Jim Willenbring.
Debugging: Tips and Tools Also, Aloha Recitation Wednesday, February 7th, 2007.
Systems Dev. Tutorial IV: Debugging: Tips and Tools Recitation Wednesday, Sept 27th, 2006.
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.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
CSE 332: C++ expressions Expressions: Operators and Operands Operators obey arity, associativity, and precedence int result = 2 * 3 + 5; // assigns 11.
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Overview of OpenPegasus Debugging Hints and Tips Karl Schopmeyer Project Coordinator, Pegasus Open Source Project October 2013.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
CLHEP Infrastructure Improvements CHEP 2004 Lynn Garren, FNAL and Andreas Pfeiffer, CERN.
C Debugging Workshop using gdb Jürgen Weigert Documentation & Legal Team openSUSE.org
© 9/27/ What to Expect from GDB ? $ gdb program core List source code, see stack backtrace, inspect variables (Post Mortem Analysis)
Debugging with Clion and GDB
Debugging Memory Issues
CSE 374 Programming Concepts & Tools
Editor, Compiler, Linker, Debugger, Makefiles
Lab: ssh, scp, gdb, valgrind
Lab: ssh, scp, gdb, valgrind
Creating your first C program
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
CSCI 380: Operating Systems Lecture #11 Instructor: William Killian
CSE451 Fall 2008 Section 1 Roxana Geambasu
When your program crashes
CMPSC 60: Week 4 Discussion
CSCI 380: Operating Systems Instructor: William Killian
CS 240 – Advanced Programming Concepts
CSE 303 Concepts and Tools for Software Development
Makefiles, GDB, Valgrind
Presentation transcript:

CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree

Makefiles Makefile Variables Makefile Variables CC = gcc CFLAGS = -Wall –std=c99 -pedantic -g LIBS = -L. -lefence Using Makefile Variables Using Makefile Variables $(CC) $(CFLAGS) …. Targets Targets : :

Makefiles #A sample makefile (PARTIAL) CC = gcc CFLAGS = -Wall –std=c99 -pedantic -g LIBS = -L. -lefence all: client server client: client.o common.o $(CC) client.o common.o -o client $(LIBS) $(CC) client.o common.o -o client $(LIBS) server: server.o common.o $(CC) server.o common.o -o server $(LIBS) $(CC) server.o common.o -o server $(LIBS) common.o: common.c structs.h consts.h $(CC) $(CFLAGS) -c common.c

Design Approaches A good design approach can make debugging a program easier A good design approach can make debugging a program easier Write small functions, if a function is getting bigger than 50 or 100 lines try looking for repetition in the function. Any repetition can be moved to a smaller functions Write small functions, if a function is getting bigger than 50 or 100 lines try looking for repetition in the function. Any repetition can be moved to a smaller functions Write small utility functions first, functions that will be used by your other functions; then test the small functions to make sure they work before moving on Write small utility functions first, functions that will be used by your other functions; then test the small functions to make sure they work before moving on

Design Approaches Don’t be afraid to throw away code Don’t be afraid to throw away code –If something isn’t working it can be faster to re-write than trying to fix –If your spending more than an hour trying to fix a function then think about re-writing it, or at least moving some of its functionality to smaller functions

Debugging Approaches Debugging is easier with small functions Debugging is easier with small functions –Nobody likes debugging a 1000 line function, and generally it’s not done because nobody writes 1000 line functions Scientific Approach Scientific Approach –There are no magic tools that work in every case, in the end you have to think about your code. –Consider where the error could be happening, and narrow down the possible choices either by commenting out code or print statements

Debugging Approaches Scientific Approach continued… Scientific Approach continued… –Don’t believe in magic, a printf statement is not causing your program to work; your programs behaviour is just erratic –Think and reason about what your program is doing, your brain is the best debugging tool you have

Debugging Tools Note: these won’t always work, don’t depend on them as they aren’t always available Note: these won’t always work, don’t depend on them as they aren’t always available Electric Fence Electric Fence –A library designed to make your program more picky about memory usage –It sets up read only memory boundaries around all allocated memory so that as soon as a boundary has been breached a seg-fault occurs –Can be used with gdb to accurately determine where a seg-fault is occuring –Usage: gcc –Wall –std=c99 –o … -lefence

Debugging Tools Electric Fence continued… Electric Fence continued… –Disadvantages: Speed, may not be an issue for this course, but it will be later. Electric Fence severally slows down a program (eg; With Electric Fence 5.5 Hrs, without 2.5 minutes) Speed, may not be an issue for this course, but it will be later. Electric Fence severally slows down a program (eg; With Electric Fence 5.5 Hrs, without 2.5 minutes) Not always available. It’s not always installed, and you won’t always be able to get it installed Not always available. It’s not always installed, and you won’t always be able to get it installed Doesn’t always work. Won’t work in every situation. Doesn’t always work. Won’t work in every situation.

Debugging Tools GDB GDB –Best used with electric fence –Usage: Compile with –g flag; eg; gcc –Wall –std=c99 –g … –Usage: gdb program-name –c core_file –GDB can analyze a core file to determine where the segfault occurred, right down to the filename and line number –Can step through a running program command by command –Can look at variable values while the program is paused –BUT… isn’t always available and doesn’t always work

Debugging Tools Valgrind Valgrind –Debugger/profiler package –5 tools 2 memory error detectors 2 memory error detectors –Like a combination of electric fence and gdb Thread error detector Thread error detector Cache profiler Cache profiler Heap profiler Heap profiler –Not installed by default in labs –Tutorial on course web site – –

Debugging Tools Exception Handling Library Exception Handling Library –Written by Terry Moreland –Mimics Java’s try/catch design – ANSI C Compliant –Released as open source under GPL –Can catch signals such as SIGSEGV (seg fault) –available from course website

Revision Control Why use revision control Why use revision control –Backups of every change you ever made to a file –If you break your code you can get an earlier copy that worked –Each version has a log entry, in theory you can find out what you changed between versions –RCS Vs CVS

Final Notes More detailed descriptions of the commands listed in this seminar are available online and in the linux man pages More detailed descriptions of the commands listed in this seminar are available online and in the linux man pages DO NOT DEPEND ON DEBUGGING TOOLS, they are not always there, and don’t always work DO NOT DEPEND ON DEBUGGING TOOLS, they are not always there, and don’t always work Questions ??? Comments ??? Questions ??? Comments ???