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

Similar documents
Laboratory 1 Semester 1 11/12

M2 Instruction Set Architecture

Problem Set 1: Unix Commands 1

Reviewing gcc, make, gdb, and Linux Editors 1

Introduction to Supercomputing

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

Exercise 1: Basic Tools

DAY 4. CS3600, Northeastern University. Alan Mislove

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

CS480. Compilers Eclipse, SVN, Makefile examples

Compilation, Disassembly, and Profiling (in Linux)

Using Subversion for Source Code Control

CS 261 Recitation 1 Compiling C on UNIX

CS631 - Advanced Programming in the UNIX Environment

UNIX Makefile. C Project Library Distribution and Installation.

Department of Computer Science College of Engineering Boise State University

CSE 374 Programming Concepts & Tools. Hal Perkins Winter 2012 Lecture 16 Version control and svn

Construction: version control and system building

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

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

Chapter 3. Revision Control

CS 107 Lecture 18: GCC and Make

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

{C} Tools of the Trade

The Linux Programming Environment. Computer Science Department Texas State University

Compila(on, Disassembly, and Profiling

Makefiles SE 2XA3. Term I, 2018/19

Section 1: Tools. Contents CS162. January 19, Make More details about Make Git Commands to know... 3


CSE 15L Winter Midterm :) Review

Unix and C Program Development SEEM

Subversion FOUR. 4.1 What is Version Control? 4.2 What is Subversion? Types of Version Control SESSION

Make. Dependency Graphs

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

Introduction to Supercomputing

Debugging for production systems

2012 LLVM Euro - Michael Spencer. lld. Friday, April 13, The LLVM Linker

Debugging (Part 1) The material for this lecture is drawn, in part, from The Practice of Programming (Kernighan & Pike) Chapter 5

Computer Systems Organization

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

How Compiling and Compilers Work

CptS 360 (System Programming) Unit 3: Development Tools

Revision Control. An Introduction Using Git 1/15

ECE/ME/EMA/CS 759 High Performance Computing for Engineering Applications

CS 270 Systems Programming. Debugging Tools. CS 270: Systems Programming. Instructor: Raphael Finkel

2 Compiling a C program

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

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

CSCI 2132: Software Development. Norbert Zeh. Faculty of Computer Science Dalhousie University. Subversion (and Git) Winter 2019

Source Code Management

Unit 10. Linux Operating System

Learning Objectives. A Meta Comment. Exercise 1. Contents. From CS61Wiki

Exercise Session 6 Computer Architecture and Systems Programming

Introduction to the UNIX command line

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

CMPSC 311- Introduction to Systems Programming Module: Build Processing

COS 318: Operating Systems

Using the Debugger. Michael Jantz Dr. Prasad Kulkarni

CSCI Operating Systems, Winter 2019 Lab 1 : Introduction to the BLITZ Tools, git, kpl, makefile, etc. Due Date: 21 January 2019

Common Configuration Management Tasks: How to Do Them with Subversion

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

Home Page. Title Page. Contents. Page 1 of 17. Version Control. Go Back. Ken Bloom. Full Screen. Linux User Group of Davis March 1, Close.

Unit 13. Linux Operating System Debugging Programs

Versioning. Jurriaan Hage homepage: Slides stolen from Eelco Dolstra.

Building oorexx 4.00 on MacOSX

Hg Tutorial. For : COP Object oriented Programming (Using C++) Biswas Parajuli

VSO. Configuration Management

Introduction to Version Control

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Source Control. Comp-206 : Introduction to Software Systems Lecture 21. Alexandre Denault Computer Science McGill University Fall 2006

Version Control. Contents. Steven J Zeil. February 19, Version Control 3

Download, Install and Setup the Linux Development Workload Create a New Linux Project Configure a Linux Project Configure a Linux CMake Project

CS Basics 15) Compiling a C prog.

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

Announcements. Reading. Today: 5.6 Tuesday: z Project proposal drafts due March 14,1997 z. CMSC S97 (lect 12)

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Using the Unix system. UNIX Introduction

TNM093 Practical Data Visualization and Virtual Reality Laboratory Platform

Follow us on Twitter for important news and Compiling Programs

CSCI 2467, Fall 2017 Lab 0: Introductions to C and Unix Due: Thursday August. 24, 11:59PM

Program Design: Using the Debugger

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

Managing Source Code With Subversion

2/9/2013 LAB OUTLINE INTRODUCTION TO VCS WHY VERSION CONTROL SYSTEM(VCS)? II SENG 371 SOFTWARE EVOLUTION VERSION CONTROL SYSTEMS

Version Control. Version Control

Construction: version control and system building

Revision Control II. - svn

Intro to Segmentation Fault Handling in Linux. By Khanh Ngo-Duy

Section 2: Developer tools and you. Alex Mariakakis (staff-wide)

COSC345 Software Engineering. Version Control

ENCE Computer Organization and Architecture. Chapter 1. Software Perspective

Debugging! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 5!

Introduction to Linux

Revision Control and GIT

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

git the SCM system Jan-Simon Möller training.linuxfoundation.org

CPSC 491. Lecture 19 & 20: Source Code Version Control. VCS = Version Control Software SCM = Source Code Management

Systems Programming Advanced Software Development

Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

Chapter 2. Basics of Program Writing

Transcription:

CS631 - Advanced Programming in the UNIX Environment Slide 1 CS631 - Advanced Programming in the UNIX Environment UNIX development tools Department of Computer Science Stevens Institute of Technology Jan Schaumann jschauma@stevens.edu http://www.cs.stevens.edu/~jschauma/631/

Software Development Tools CS631 - Advanced Programming in the UNIX Environment Slide 2

Software Development Tools CS631 - Advanced Programming in the UNIX Environment Slide 3

Software Development Tools CS631 - Advanced Programming in the UNIX Environment Slide 4 UNIX Userland is an IDE essential tools that follow the paradigm of Do one thing, and do it right can be combined. The most important tools are: $EDITOR the compiler toolchain gdb(1) debugging your code make(1) project build management, maintain program dependencies diff(1) and patch(1) report and apply differences between files cvs(1), svn(1), git(1) etc. distributed project management, version control

Compilers CS631 - Advanced Programming in the UNIX Environment Slide 5 A compiler translates source code from a high-level programming language into machine code for a given architecture by performing a number of steps: lexical analysis preprocessing parsing semantic analysis code optimization code generation assembly linking

Compilers CS631 - Advanced Programming in the UNIX Environment Slide 6

Compilers CS631 - Advanced Programming in the UNIX Environment Slide 7 There are many different closed- and open-source compiler chains: Intel C/C++ Compiler (or icc) Turbo C / Turbo C++ / C++Builder (Borland) Microsoft Visual C++... Clang (a frontend to LLVM) GNU Compiler Collection (or gcc) Portable C Compiler (or pcc)...

The compiler toolchain CS631 - Advanced Programming in the UNIX Environment Slide 8 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)).

Preprocessing CS631 - Advanced Programming in the UNIX Environment Slide 9 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). $ cd compilechain $ cat hello.c $ man cpp $ cpp hello.c hello.i $ file hello.i $ man cc $ cc -v -E hello.c > hello.i $ more hello.i $ cc -v -DFOOD=\"Avocado\" -E hello.c > hello.i.2 $ diff -bu hello.i hello.i.2

Compilation CS631 - Advanced Programming in the UNIX Environment Slide 10 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). $ more hello.i $ cc -v -S hello.i > hello.s $ file hello.s $ more hello.s

Assembly CS631 - Advanced Programming in the UNIX Environment Slide 11 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). $ as -o hello.o hello.s $ file hello.o $ cc -v -c hello.s $ objdump -d hello.o [...]

Linking CS631 - Advanced Programming in the UNIX Environment Slide 12 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). $ ld hello.o [...] $ ld hello.o -lc [...] $ cc -v hello.o [...] $ ld -dynamic-linker /usr/libexec/ld.elf_so \ /usr/lib/crt0.o /usr/lib/crti.o /usr/lib/crtbegin.o \ hello.o -lc /usr/lib/crtend.o /usr/lib/crtn.o $ file a.out $./a.out

Linking CS631 - Advanced Programming in the UNIX Environment Slide 13 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). $ cc -v -DFOOD=\"Avocado\" hello.c 2>&1 more

cc(1) and ld(1) CS631 - Advanced Programming in the UNIX Environment Slide 14 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). Different flags can be passed to cc(1) to be passed through to each tool as well as to affect all tools. $ cc -v -O2 -g hello.c 2>&1 more

cc(1) and ld(1) CS631 - Advanced Programming in the UNIX Environment Slide 15 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). Different flags can be passed to cc(1) to be passed through to each tool as well as to affect all tools. The order of the command line flags may play a role! Directories searched for libraries via -L and the resolving of undefined symbols via -l are examples of position sensitive flags. $ cc -v main.c -L./lib2 -L./lib -lldtest 2>&1 more $ cc -v main.c -L./lib -L./lib2 -lldtest 2>&1 more

cc(1) and ld(1) CS631 - Advanced Programming in the UNIX Environment Slide 16 The compiler chain or driver usually performs preprocessing (e.g. via cpp(1)), compilation (cc(1)), assembly (as(1)) and linking (ld(1)). Different flags can be passed to cc(1) to be passed through to each tool as well as to affect all tools. The order of the command line flags may play a role! Directories searched for libraries via -L and the resolving of undefined symbols via -l are examples of position sensitive flags. The behavior of the compiler toolchain may be influenced by environment variables (eg TMPDIR, SGI ABI) and/or the compilers default configuration file (MIPSPro s /etc/compiler.defaults or gcc s specs). $ cc -v hello.c $ TMPDIR=/var/tmp cc -v hello.c $ cc -dumpspec

A Debugger CS631 - Advanced Programming in the UNIX Environment Slide 17

gdb(1) CS631 - Advanced Programming in the UNIX Environment Slide 18 The purpose of a debugger such as gdb(1) is to allow you to see what is going on inside another program while it executes or what another program was doing at the moment it crashed. gdb allows you to make your program stop on specified conditions (for example by setting breakpoints) examine what has happened, when your program has stopped (by looking at the backtrace, inspecting the value of certain variables) inspect control flow (for example by stepping through the program) Other interesting things you can do: examine stack frames: info frame, info locals, info args examine memory: x examine assembly: disassemble func

gdb(1) CS631 - Advanced Programming in the UNIX Environment Slide 19 $ cd gdb-examples/ls $./a.out ~/tmp Memory fault (core dumped) $ gdb./a.out (gdb) run ~/tmp Program received signal SIGSEGV, Segmentation fault. 0x0000000000401a6d in record_stat (statp=0x7f7fffffdaf0, path_name=0x7f7ff7b09175 "noown") at ls.c:497 497 strcpy(new_node->owner_name, password->pw_name); (gdb) bt [...] (gdb) frame 0 [...] (gdb) li

CS631 - Advanced Programming in the UNIX Environment Slide 20 [...] (gdb) print password

gdb(1) CS631 - Advanced Programming in the UNIX Environment Slide 21 (gdb) start -l [...] (gdb) watch blocksize [...] (gdb) c [...] (gdb) li [...] (gdb) show environment BLOCKSIZE [...] (gdb) call strtoll(blocksize_str, 0, 0) [...]

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 22

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 23 make(1) is a command generator and build utility. Using a description file (usually Makefile) it creates a sequence of commands for execution by the shell. used to sort out dependency relations among files

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 24 make(1) is a command generator and build utility. Using a description file (usually Makefile) it creates a sequence of commands for execution by the shell. used to sort out dependency relations among files avoids having to rebuild the entire project after modification of a single source file

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 25 make(1) is a command generator and build utility. Using a description file (usually Makefile) it creates a sequence of commands for execution by the shell. used to sort out dependency relations among files avoids having to rebuild the entire project after modification of a single source file performs selective rebuilds following a dependency graph

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 26 make(1) is a command generator and build utility. Using a description file (usually Makefile) it creates a sequence of commands for execution by the shell. used to sort out dependency relations among files avoids having to rebuild the entire project after modification of a single source file performs selective rebuilds following a dependency graph allows simplification of rules through use of macros and suffixes, some of which are internally defined

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 27 make(1) is a command generator and build utility. Using a description file (usually Makefile) it creates a sequence of commands for execution by the shell. used to sort out dependency relations among files avoids having to rebuild the entire project after modification of a single source file performs selective rebuilds following a dependency graph allows simplification of rules through use of macros and suffixes, some of which are internally defined different versions of make(1) (BSD make, GNU make, Sys V make,...) may differ (among other things) in variable assignment and expansion/substitution including other files flow control (for-loops, conditionals etc.)

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 28 $ cd make-examples $ ls *.[ch] cmp.c ls.c main.c stat_flags.c util.c extern.h ls.h print.c stat_flags.h

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 29 $ cd make-examples $ ls *.[ch] cmp.c ls.c main.c stat_flags.c util.c extern.h ls.h print.c stat_flags.h

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 30 $ cd make-examples $ ls *.[ch] cmp.c ls.c main.c stat_flags.c util.c extern.h ls.h print.c stat_flags.h

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 31 $ cd make-examples $ ls *.[ch] cmp.c ls.c main.c stat_flags.c util.c extern.h ls.h print.c stat_flags.h

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 32 $ cd make-examples $ ls *.[ch] cmp.c ls.c main.c stat_flags.c util.c extern.h ls.h print.c stat_flags.h

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 33 $ ln -s Makefile.1 Makefile $ make # or: make -f Makefile.1 [...] $ make

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 34 $ ln -sf Makefile.2 Makefile $ make # or: make -f Makefile.2 [...] $ make clean $ export CFLAGS="-Wall -Werror" $ make [...] $ make clean [...]

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 35 $ make -f Makefile.3 [...] $ make -f Makefile.3 ls.txt [...] $

make(1) CS631 - Advanced Programming in the UNIX Environment Slide 36 $ ln -sf Makefile.4 Makefile $ make help [...] $ make showvars [...] $ make CFLAGS="${CFLAGS}" showvars [...]

CS631 - Advanced Programming in the UNIX Environment Slide 37 Priority of Macro Assignments for make(1) 1. Internal (default) definitions of make(1) 2. Current shell environment variables. This includes macros that you enter on the make command line itself. 3. Macro definitions in Makefile. 4. Macros entered on the make(1) command line, if they follow the make command itself.

Ed is the standard text editor. CS631 - Advanced Programming in the UNIX Environment Slide 38 $ ed? help? quit? exit? bye? eat flaming death? ^C? ^D?

Ed is the standard text editor. CS631 - Advanced Programming in the UNIX Environment Slide 39 $ ed a ed is the standard Unix text editor. This is line number two.. 2i. %l 3s/two/three/ w foo q $ cat foo

diff(1) and patch(1) CS631 - Advanced Programming in the UNIX Environment Slide 40 diff(1): compares files line by line output may be used to automatically edit a file can produce human readable output as well as diff entire directory structures output called a patch

diff(1) and patch(1) CS631 - Advanced Programming in the UNIX Environment Slide 41 patch(1): applies a diff(1) file (aka patch) to an original may back up original file may guess correct format ignores leading or trailing garbage allows for reversing the patch may even correct context line numbers

diff(1) and patch(1) CS631 - Advanced Programming in the UNIX Environment Slide 42 $ diff Makefile.2 Makefile.5 [...] $ cp Makefile.2 /tmp $ ( diff -e Makefile.2 Makefile.5; echo w; ) ed Makefile.2 $ diff Makefile.[25] $ mv /tmp/makefile.2. $ diff -c Makefile.[25] $ diff -u Makefile.[25] > /tmp/patch $ patch </tmp/patch $ diff Makefile.[25]

diff(1) and patch(1) CS631 - Advanced Programming in the UNIX Environment Slide 43 Difference in ls(1) between NetBSD and OpenBSD: $ diff -bur netbsd/src/bin/ls openbsd/src/bin/ls Difference in ls(1) between NetBSD and FreeBSD: $ diff -bur netbsd/src/bin/ls freebsd-ls/ls

Revision Control CS631 - Advanced Programming in the UNIX Environment Slide 44 Version control systems allow you to collaborate with others simultaneously work on a code base keep old versions of files keep a log of the who, when, what, and why of any changes perform release engineering by creating branches

Revision Control CS631 - Advanced Programming in the UNIX Environment Slide 45 Source Code Control System (SSCS) begat the Revision Control System (RCS). RCS operates on a single file; still in use for misc. OS config files the Concurrent Versions System (CVS) introduces a client-server architecture, control of hierarchies Subversion provides atomic commits, renaming, cheap branching etc. Git, Mercurial etc. implement a distributed approach (ie peer-to-peer versus client-server), adding other features (cryptographic authentication of history,...)

Revision Control CS631 - Advanced Programming in the UNIX Environment Slide 46 Examples: http://cvsweb.netbsd.org/bsdweb.cgi/src/bin/ls/ http://svnweb.freebsd.org/base/stable/9/bin/ls/ http://git.savannah.gnu.org/cgit/coreutils.git/log/ http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/bsd-family-tree?rev=head

Revision Control: Branching CS631 - Advanced Programming in the UNIX Environment Slide 47 Different strategies: trunk / master is fragile trunk is work in progress, may not even compile all work happens in trunk releases are tagged on trunk, then branched trunk / master is stable master is always stable all work is done in branches (feature or bugfix) feature branches are deleted after merge releases are made automatically from master You may combine these as release branching / feature branching / task branching.

Commit Messages CS631 - Advanced Programming in the UNIX Environment Slide 48 Commit messages are like comments: too often useless and misleading, but critical in understanding human thinking behind the code. Commit messages should be full sentences in correct and properly formatted English. Commit messages briefly summarize the what, but provide important historical context as to the how and, more importantly, why. Commit messages SHOULD reference and integrate with ticket tracking systems. See also: http://is.gd/wd1lha http://is.gd/cutwha http://is.gd/rpqj5e

Revision Control CS631 - Advanced Programming in the UNIX Environment Slide 49 $ cd freebsd/bin/ls $ git log cat

Links CS631 - Advanced Programming in the UNIX Environment Slide 50 Revision Control: http://cvsbook.red-bean.com/cvsbook.html http://svnbook.red-bean.com/ http://git-scm.com/ GDB: http://sources.redhat.com/gdb/current/onlinedocs/gdb toc.html http://heather.cs.ucdavis.edu/~matloff/unixandc/clanguage/debug.html http://www.unknownroad.com/rtfm/gdbtut/gdbtoc.html