GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Similar documents
Makefiles SE 2XA3. Term I, 2018/19

[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France

CMPT 300. Operating Systems. Brief Intro to UNIX and C

UNIX Makefile. C Project Library Distribution and Installation.

CS Basics 15) Compiling a C prog.

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Intermediate Programming, Spring 2017*

2 Compiling a C program

Reviewing gcc, make, gdb, and Linux Editors 1

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

HPC User Environment

Introduction to Linux

Introduction to System Programming : makefile

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Make. Dependency Graphs

COSC345 Software Engineering. Make

GNU Make 1. 1 material adapted from GNU Make by Richard Stallman

CSC 2500: Unix Lab Fall 2016

CSCI 2132 Software Development. Lecture 29: Dynamic Memory Allocation

CS11 Advanced C++ Fall Lecture 4

Software Development With Emacs: The Edit-Compile-Debug Cycle

Introduction to Supercomputing

Exercise 1: Basic Tools

CS240: Programming in C

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

independent compilation and Make

Section 1: Tools. Kaifei Chen, Luca Zuccarini. January 23, Make Motivation How... 2

PRINCIPLES OF OPERATING SYSTEMS

Projects and Make Files

CS2141 Software Development using C/C++ Compiling a C++ Program

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

Lab 1: Introduction to C Programming. (Creating a program using the Microsoft developer Studio, Compiling and Linking)

Make! CSC230: C and Software Tools. N.C. State Department of Computer Science. Some examples adapted from

CS240: Programming in C. Lecture 2: Overview

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

The make utility. Alark Joshi COMPSCI 253

The Linux Programming Environment. Computer Science Department Texas State University

CS 261 Recitation 1 Compiling C on UNIX

{C} Tools of the Trade

DAY 4. CS3600, Northeastern University. Alan Mislove

Data and File Structures Laboratory

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

Systems Programming. laboratory. Compilation automation. make ceedling

CS631 - Advanced Programming in the UNIX Environment. UNIX development tools

Kurt Schmidt. May 23, 2018

#include <stdio.h> int main() { printf ("hello class\n"); return 0; }

Dalhousie University CSCI 2132 Software Development Winter 2018 Lab 8, March 22

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS

The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

Makefile Tutorial. Eric S. Missimer. December 6, 2013

GDB 1 GDB 2 GDB. Fortran Pascal GDB 4. hoge.c. Fig. 1. calc.c. Fig GDB. GDB Debian. # apt-get install gdb

JTSK Programming in C II C-Lab II. Lecture 3 & 4

Maemo Diablo GNU Make and makefiles Training Material

CSE 124 Discussion (10/3) C/C++ Basics

CMPSC 311- Introduction to Systems Programming Module: Build Processing

The Makefile utility. (Extract from the slides by Terrance E. Boult

Laboratory Assignment #3 Eclipse CDT

Problem Set 1: Unix Commands 1

Reliable C++ development - session 1: From C to C++ (and some C++ features)

Program Development Tools

C / C++ Coding Rules

We first learn one useful option of gcc. Copy the following C source file to your

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems

EE516: Embedded Software Project 1. Setting Up Environment for Projects


Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

Debugging. ICS312 Machine-Level and Systems Programming. Henri Casanova

The CS-220 Development Environment

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Embedded Software TI2726 B. 3. C tools. Koen Langendoen. Embedded Software Group

Build automation. CSE260, Computer Science B: Honors Stony Brook University

EL2310 Scientific Programming

Software project Gnome Graphics

Itron Riva Kernel Module Building

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic Compilation Control with Make

Programming in C week 1 meeting Tiina Niklander

MPATE-GE 2618: C Programming for Music Technology. Unit 4.1

CSCi 4061: Intro to Operating Systems Spring 2017 Instructor: Jon Weissman Assignment 1: Simple Make Due: Feb. 15, 11:55 pm

Introduction to Supercomputing

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

Using the Unix system. UNIX Introduction

Using GNU make C HAPTER 4

CS 107 Lecture 18: GCC and Make

CSCI 2132 Final Exam Solutions

Programming in C First meeting

And You Thought There Couldn t be More C++ Fundamentals of Computer Science

Laboratory 1 Semester 1 11/12

Lab 2: More Advanced C

Software Building (Sestavování aplikací)

EL2310 Scientific Programming

CAAM 420 Fall 2012 Lecture 15. Roman Schutski

CS201 - Lecture 1 The C Programming Language

AN 834: Developing for the Intel HLS Compiler with an IDE

CSE 15L Winter Midterm :) Review

Overview of today s lecture. Quick recap of previous C lectures. Introduction to C programming, lecture 2. Abstract data type - Stack example

CSE 351. GDB Introduction

RVDS 4.0 Introductory Tutorial

Testing and Debugging C Programming and Software Tools. N.C. State Department of Computer Science

Transcription:

GDB and Makefile Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

GDB Debugging: An Example #include<stdio.h> void main() { int i; int result = 0; for (i=1;i<=100;i++) { result += i; } printf( result=%d\n, result); }

GDB Debugging: Main Steps 1. compile program gcc g test.c o test 2. start GDB gdb test 3. set breaking point break main 4. run program run 5. program execution continue to the next source line : next 6. resume program execution : continue

GDB Commands list(l):list source code break(b) function break(b) line break(b) file: line break (b) line if condition e.g., break 6 if i=10

GDB Commands Info break : check all possible breakpoints delete [breakpoint number]: delete # breakpoint Without arguments deletes all breakpoints run(r): run program next(n): program execution continue to the next source line, omitting function calls step(s): program execution continue to next source line, going into function calls continue(c): resume program execution

GDB Commands print(p) variable : check the value of a variable finish: forced return (from a function) watch variable: stops whenever the value of the variable changes quit(q):quit GDB

Makefile Provide a way for separate compilation Describe the dependencies among the project files make utility

Makefile (Cont ) The make utility in Unix is one of the original tools designed by S. I. Fieldman of AT&T Bell labs circa 1977. What is make?: The tool is designed to allow programmers to efficiently compile large complex programs with many components easily. You can place the commands to compile a program in a Unix script but this will cause ALL modules to be compiled every time. The make utility allows us to only compile those that have changed and the modules that depend upon them.

Example hello: main.o func1.o func2.o gcc main.o func1.o func2.o o hello main.o: main.c gcc c main.c func1.o: func1.c gcc c func1.c func2.o: func2.c gcc c func2.c.phony : clean clean: rm f hello main.o func1.o func2.o main.o main.c hello func1.o func1.c clean func2.o func2.c

Using Makefile Naming: makefile or Makefile are standard Other name can be also used Running make Make make f filename if the name of your file is not makefile or Makefile

Main Components Rules Variables (macros) # sign comments everything till the end of the line \ sign to separate one command line on two rows

Rules Makefiles main element is called a rule target : dependencies TAB commands # shell commands hello: main.o func1.o func2.o gcc main.o func1.o func2.o o hello main.o: main.c gcc c main.c func1.o: func1.c gcc c func1.c func2.o: func2.c gcc c func2.c.phony : clean clean: rm f hello main.o func1.o func2.o

Variables (macros) hello: main.o func1.o func2.o gcc main.o func1.o func2.o o hello Question: how do you add an additional dependency, say func3.o? Answer 1: hello: main.o func1.o func2.o func3.o gcc main.o func1.o func2.o func3.o o hello Answer 2: obj=main.o func1.o func2.o func3.o hello:$(obj) gcc $(obj) o hello

Automatic Variables hello: main.o func1.o func2.o gcc main.o func1.o func2.o o hello S@: The name of the target of the rule (hello) S<: The name of the first dependency (main.o) S^: The names of all the dependencies (main.o, func1.o, func2.o) hello: main.o func1.o func2.o gcc S^ -o S@

Phony Targets Targets that have no dependencies. Used only as names for commands that you want to execute. To invoke it: make clean hello: main.o func1.o func2.o gcc main.o func1.o func2.o o hello main.o: main.c gcc c main.c func1.o: func1.c gcc c func1.c func2.o: func2.c gcc c func2.c.phony : clean clean: rm f hello main.o func1.o func2.o

Inference Rules Inference rules are a method of generalizing the build process. In essence, it is a sort of wild card notation. The % is used to indicate a wild card. Example: %.obj : %.c $(CC) $(FLAGS) c $(SOURCE) All.obj files have dependencies of all %.c files of the same name.

An Example TARGET = myname_lab1assignment CROSS_COMPILE = arm-linux-gnueabihf- CFLAGS = -static -g -Wall -I $(HOME)/Documents/C_Projects/include -Dsoc_cv_av LDFLAGS = -g -Wall CC = $(CROSS_COMPILE)gcc ARCH= arm build: $(TARGET) $(TARGET): main.o fpga.o $(CC) $(LDFLAGS) $^ -o $@ -lpthread -lrt %.o : %.c $(CC) $(CFLAGS) -c $< -o $@.PHONY: clean clean: rm -f $(TARGET) *.a *.o *~

Misc hello: hello.c @gcc hello.c o hello @: cancel echo command