Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.

Slides:



Advertisements
Similar presentations
The make Utility Programming Tools and Environments Winter 2006.
Advertisements

Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.
CS Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS.
CS465 - Unix C Programming (cc/make and configuration control)
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
1 uClinux course Day 3 of 5 The uclinux toolchain, elf format and ripping a “hello world”
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.
Spring 2014 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Introduction to Embedded Systems Dr. Jerry Shiao, Silicon Valley University.
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, Build and Version Control Rudra Dutta CSC Spring 2007, Section 001.
BioPSE NCRR SCIRun: Getting Started Installation and Configuration J. Davison de St. Germain (801)
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
CIS*2450 Seminar I Makefiles Debugging/Design Approaches Exception Handling Library Revision Control Designed by: Terry Moreland Updated by: Tom Crabtree.
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.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
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.
Developing C/C++ applications with the Eclipse CDT David Gallardo.
Lecture 5 Software Development. Types of Development Tools Archiving: tar, cpio, pax, RPM Configuration: autoconf Compilation and building: make Managing.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
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.
Active-HDL Interfaces Debugging C Code Course 10.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
1 SEEM3460 Tutorial Compiling and Debugging C programs.
Data Display Debugger (DDD)
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.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
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?
Multiple File Compilation and linking By Bhumik Sapara.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Wed Mar Michael Imamura / The GNU Autotools Your very own./configure.
Lecture 6 UNIX Development Tools. Software Development Tools.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
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)
Institute of Radio Physics and Electronics ILug-Cal Introduction to GDB Institute of Radio Physics and Electronics and Indian GNU/Linux Users Group Kolkata.
Multiple file project management & Makefile
CSCI 4061 Recitation 2 1.
Makefiles CSSE 332 Operating Systems
Lecture 3 Translation.
The make utility (original presentation courtesy of Alark Joshi)
Computer System Laboratory
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
Debugging with gdb gdb is the GNU debugger on our CS machines.
Editor, Compiler, Linker, Debugger, Makefiles
Compiling from source code
gdb gdb is the GNU debugger on our CS machines.
Operating System Discussion Section.
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Makefiles and the make utility
GNU DEBUGGER TOOL. What is the GDB ? GNU Debugger It Works for several languages – including C/C++ [Assembly, Fortran,Go,Objective-C,Pascal]
CMPSC 60: Week 4 Discussion
Makefiles and the make utility
Debugging.
Makefiles, GDB, Valgrind
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Presentation transcript:

Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools

GCC gcc – compile and link Compile options -o outfile -c -Dname -Idir -Ldir -lname -Wall -On -Os -g

Make Utility “easy” compilation of complex programs Requires creation of a makefile Usage: make [target] Looks for Makefile or makefile or GNUMakefile. Use –f to specify a makefile filename If no target given when running make, it will use the first one.

Using Make Macros Can define macros using macro=val pairs. Commonly defined macros CC OBJS CFLAGS LDLIBS

Special Macros - The target of this rule $< - The first dependency of this rule

Suffix Rules Make has built in rules for compiling certain things based on the suffix of the file.c.o: $(CC) –c $(CFLAGS) –o $< Adding custom suffixes.SUFFIXES:.dat

Pattern Rules More powerful than suffix rules Can have dependencies Matches patterns provided %.o : %.c $(CC) –c $(CFLAGS) –o $<

Commonly Expected Targets all install uninstall clean

Phony Targets Sometimes we need to specify a rule has no corresponding file Use the.PHONY directive.PHONY: target

Open Source Code GNU Build System Autoconf Automake Libtool

Installing Open Source Software Download the tarball tar ztvf bash.tar.gz tar zxvf bash.tar.gz tar jxvf bash.tar.bz2 Compile and install./configure make – compile only make install – compile and install

Libraries Static Libraries (lib*.a files) Collection of object (*.o) files Maintains a table of what symbols are defined by what object files Created using archiver utility ar rcs libfoo.a obj1.o obj2.o obj3.o

Compiling Against Static Libraries Functions copied from library into binary during linking gcc –c –o hello.o hello.c ar rcs libhello.a hello.o gcc –Wall –c main.c –o main.o gcc –o hello main.o –L. –lhello./hello

Shared Libraries One copy of code in library that multiple programs can use Smaller programs Easier to make updates Portability issues Backward compatibility

Creating Shared Libraries Position Independent Code –fPIC Don’t use –fomit-frame-pointer gcc –fPIC –c hello.c –o hello.o gcc –shared –Wl,-soname,libfoo.so.1 –o libfoo.so.1.5 hello.o

Compiling Against The Shared Library System must know where to find the library. /usr/lib /lib Otherwise, add to LD_LIBRARY_PATH Define during program execution with LD_LIBRARY_PATH = /path/to/lib./progname Compile against the library gcc main.c –o main –L. -lhello

GNU Debugger (gdb) Command Line Debugger Compile program with –g flag Run program through debugger gdb progname gdb can examine core files gdb progname corefile

gdb commands list / l Lists lines of source code. Default is 10 lines around current address. Can specify range: l 5,10 break / b Sets a breakpoint on a given line clear / delete Remove breakpoint(s)

gdb commands (cont) run / r Starts the program to be debugged running from the begging until the first breakpoint next / n Executes the next instruction. Does not step into functions! step / s Executes the next instruction. Does step into functions!

gdb commands (cont) command breakpointnum Allows a list of commands to be run when the breakpoint is encountered display Displays some value at every breakpoint undisplay Cancels the display command

gdb commands (cont) print / p Displays the value of an expression “p option” will print the value of the variable “option” set Sets the value of a variable set option=10 where / w Prints a backtrace. continue / c Continues executing the program

GLIBC Memory Debugging Common Problems Memory Leaks Buffer Over/Under flow Tools env variable MALLOC_CHECK_ mcheck library

GLIBC Memory Debugging MALLOC_CHECK_ MALLOC_CHECK_=1./badmem prints any warning to stderr MALLOC_CHECK_=2./badmem prints warning to stderr and calls abort()

GLIBC Memory Debugging mcheck Link against mcheck library gcc –g badmem.c –o badmem –lmcheck Through gdb Set breakpoint for main Add a command for that breakpoint “call mcheck(0)” “continue” In all cases, mcheck must be called before any calls to malloc!

Memory Debugging Preventing overflows with “electric fence” Link with –lefence Provides new form of malloc that allocates additional space after requested space Any attempt to write to that space will cause the Kernel to kill the process with SIGSEGV

Memory Debugging Tracing Memory Leaks Set env MALLOC_TRACE to a logfile Call mtrace from gdb

Memory Debugging Other tools mpr – Memory allocation profiler gcov – Coverate test tool strace – Trace system calls during execution ltrace – Trace library calls during execution mtrace – Trace memory allocation valgrind – debugging suite of tools