Unix Programming Tools Operating Systems. man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating.

Slides:



Advertisements
Similar presentations
Utilizing the GDB debugger to analyze programs Background and application.
Advertisements

Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Preparation for working in the CSIL Basic LINUX operations.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
1 Chapter 4 The Fundamentals of VBA, Macros, and Command Bars.
Chapter 5 Editing Text Files
CS Lecture 11 Outline Compiling C programs using gcc Archiving modules Using Makefiles Debugging using gdb Assignment 3 discussion Lecture 111CS.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 Using Editors Editors let you create and edit ASCII files UNIX normally includes two editors: vi and Emacs Vi and Emacs are screen editors: they display.
Guide To UNIX Using Linux Third Edition
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
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.
1 Unix Editors (ee, ed, ex, vi, vim) and Compilers (g77, gcc) Speaker: Li-Wen Chen Date:
1 Lab 2: The Unix environment, Using vi, C programming SITE, uOttawa.
Memory & Storage Architecture Seoul National University GDB commands Hyeon-gyu School of Computer Science and Engineering.
Copyright © 2009 Techtronics'09 by GCECT 1 Presents, De Code C De Code C is a C Programming competition, which challenges the participants to solve problems.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
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.
Creating your first C++ program
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
A Tutorial on Introduction to gdb By Sasanka Madiraju Graduate Assistant Center for Computation and Technology.
VI EDITOR University of Mississippi. Vi Editor What is Vi ? ▫Vi is a screen based editor. ▫The screen of your terminal will act as a window into the file.
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.
Lesson 4-Mastering the Visual Editor. Overview Introducing the visual editor. Working in an existing file with vi. Understanding the visual editor. Navigating.
Isecur1ty training center Presented by : Eng. Mohammad Khreesha.
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.
Data Display Debugger (DDD)
Oct 2001ANSI C Under Unix (v1.0)1 UNIX C Programming under Unix written and presented by M.T.Stanhope.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
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.
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?
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
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.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
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.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
 Wind River Systems, Inc Chapter - 4 CrossWind.
Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.
Using the GNU Debugger (GDB)‏ Techzemplary Pvt.Ltd February 24 th 2008 Pranav Peshwe.
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.
CSCI 4061 Recitation 2 1.
DEBUG.
Lecture 3 Translation.
Introduction to C Topics Compilation Using the gcc Compiler
Gnu Debugger (gdb) Debuggers are used to: Find semantic errors
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Debugging with gdb gdb is the GNU debugger on our CS machines.
Editor, Compiler, Linker, Debugger, Makefiles
Vi Editor.
Introduction to C Topics Compilation Using the gcc Compiler
gdb gdb is the GNU debugger on our CS machines.
Operating System Discussion Section.
Debuggers.
Getting Started: Developing Code with Cloud9
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
Appendix F C Programming Environment on UNIX Systems
Debugging.
Makefiles, GDB, Valgrind
SPL – PS1 Introduction to C++.
Presentation transcript:

Unix Programming Tools Operating Systems

man- on-line unix manual vi - a command line text editor make- runs make files gcc- compiler gdb- debugger Operating Systems

man pages Operating Systems

Most unix systems have a set of on-line documentation called the man pages. These are typically organized into several sections. The first three are of most interest to us: 1user commands 2system calls 3C library functions Operating Systems

Each man page covers a specific command, utility, or system call. Individual man pages commonly are divided into the following sections: HEADERthe title of this man page NAMEone line summary SYNOPSISbrief description DESCRIPTIONdetailed description ERRORSconditions for errors FILESfiles used BUGSknown bugs Operating Systems

vi Operating Systems

Why learn a command line editor? * it’s lean and fast * always available - even from a terminal Operating Systems

$ vi [ filename ] if no filename is provided, vi creates a new unnamed file Starting vi Operating Systems

ESC - to get into command more :q to quit :q! to force a quit without saving the file :wq to save the file and then quit Leaving vi Operating Systems

Command mode and Insert Mode Command mode Insert Mode:press i or a Insert Mode Command Mode:press Esc key The two modes of vi Operating Systems

vi commands are usually of the foem [count] command [where] for example. 23x deletes 23 characters vi Commands Operating Systems

aenter insert mode, the characters typed will be after the current cursor position. ienter insert mode, the character types will be before the current cursor position Some simple vi commands Operating Systems

[n]jmove the cursor down n lines [n]kmove the cursor up n lines [n]hmove the cursor left n characters [n]lmove the cursor right n characters Some simple vi commands Operating Systems

ctrl-Bscroll back one page ctrl-Fscroll forward one page Some simple vi commands Operating Systems

g0move to the first character on the line g$move to the last character on the line [n]Ggo to line n [n]gggo to line n Some simple vi commands Operating Systems

[n]wmove forward n words [n]bmove backwards n words Some simple vi commands Operating Systems

[n]xdelete n characters [n]dddelete n ines Some simple vi commands Operating Systems

the un-named register (“”) numbered registers (0-9) 0 used by most recent yank command 1 used by most recent delete command named registers (a-z and A-Z) :regshow contents of all registers vi registers Operating Systems

[“x][n]yy yank n lines into register x [“x][n]dd delete n lines into register x [“x][n]p put register x after the cursor, n times Some simple vi commands Operating Systems

[n]r charreplace n characters with char Some simple vi commands Operating Systems

:set cindent shiftwidth=4sets auto indent for C Some simple vi commands Operating Systems

vi Manual Operating Systems

gcc Operating Systems

gcc Operating Systems gcc is the gnu C compiler. It processes input file in four distinct phases: pre-processor compiler assembler linker

gcc flags Operating Systems the following are common compiler flags. See the man pages for more information.

gcc flags Operating Systems -ansienforce full ansi compliance -ccompile and assemble, but do not link -gcreate a symbol table for debugging -Estop after running the pre-processor. do not compile

gcc flags Operating Systems -Idiradd the directory dir to the list of directories searched for include files -llibrary link in the name library

gcc flags Operating Systems -Ooptimize. There are 3 levels of optimization, O1, O2, and O3 -o filename stores the resulting output in filename, most often used for linker output - Wallissue compiler warnings

gcc examples Operating Systems compile a single source code file, and link gcc test1.c output will be a.out

gcc examples Operating Systems compile a single source code file, don’t link gcc -c test1.c output will be test1.o

gcc examples Operating Systems compile multiple source code files, and link gcc -c test1.c gcc -c test2.c gcc -o test.exe test1.o test2.o output from the first line will be test1.o

gcc examples Operating Systems compile a single source code file, link math library gcc -o power power.c -lm output will be power (no extension)

make Operating Systems

make Operating Systems The unix make utility allows programmers to create “recipes” for compiling and linking multiple files in a project. These “recipes” called make files, allow for incremental re-compilation... only changed files are recompiled.

make Operating Systems Make files are located in the same directory as the source code files they are meant to work with. A make file is made up of a set of dependencies and rules. a dependency - defines a target file and the files required to build that target a rule - tells the system what it must do to build a target

make example Operating Systems Consider a project that contains the following source code files: main.c studentinfo.c studentinfo.h

make example Operating Systems Step One: Compile the studentinfo file studentinfo.o:studentinfo.c studentinfo.h this is the name of the target in order to build this target, we need these source code files the first line lists the dependecies

make example Operating Systems Step One: Compile the studentinfo file studentinfo.o:studentinfo.c studentinfo.h gcc -c studentinfo.c the second line tells the rule to build studentinfo.o the rule line must start with a tab character

make example Operating Systems Step Two: Compile main.c main.o:main.c studentinfo.h gcc -c main.c

make example Operating Systems Step Three: Link demo.exe: main.o studentinfo.o gcc -o demo.exe main.o studentinfo.o

make example Operating Systems The complete makefile demo.exe: main.o studentinfo.o gcc -o demo.exe main.o studentinfo.o main.o:main.c studentinfo.h gcc -c main.c studentinfo.o:studentinfo.c studentinfo.h gcc -c studentinfo.c

make example Operating Systems To execute the makefile, type make on the command line. This makefile should produce the following output: gcc -c studentinfo.c gcc -c main.c gcc -o demo.exe main.o studentinfo.o

gdb Operating Systems

Starting GDB At the command prompt type gdb program_name program_name is an executable, compiled with –g option the –g option creates a symbol table used by gdb the current source file is set to the file containing main and the current source line is set to the first executable statement in main( )

Program Execution runrun (or rerun) the program from the beginning stepexecute the next source instruction and return to gdb. Follow subroutine calls. step countexecute count source lines nextsame as step, but does not step into functions finishrun until the current function returns returnreturn to calling function jump addressjump to specified source line

BreakpointsBreakpoints info breaklist all breakpoints break functionset breakpoint at beginning of function break linenumberset breakpoint at this line number break filename:lineset breakpoint at specified line in file break fn if exprstop at breakpoint fn if expr is true disable breaknumdisable or enable breakpoint breaknum enable breaknum delete breaknumdelete breakpoint breaknum command breaknumexecute the commands when breaknum is reached contcontinue execution

The Stack Frame A stack frame is the portion of the run-time stack allocated to the currently executing function. gdb assigns numbers to stack frames, counting from zero for the currently executing function. Variable names are all relative to the current stack frame.

Examining the Stack backtraceshow stackframes useful for looking at calling sequence frame framenumberlook at stack frame framenumber downlook at stack frame called by this one uplook at stack frame calling this one info argsshow argument variables in the current stack frame info localsshow local variables in the current stack frame

Source Code list linenumprint 10 lines of source code, centered around linenum list functionprint 10 lines of source code, centered around the beginning of function listprint 10 more lines of source code

Examining Data print expressionprint value of expression, evaluated within the current stack frame set variable = expression assign result of expression to variable display expressionprint value of expression every time program stops ( a watch) undisplaycancels previous display requests