130 likes | 239 Views
COP 3530 Spring 12. Discussion Session 1. Agenda. Introduction Remote programming Separate code Compile -- g++,makefile Debug -- gdb Questions?. Introduction. Ravi Jampani Ph.D. student rjampani@cise.ufl.edu www.cise.ufl.edu/~rjampani/
E N D
COP 3530 Spring 12 Discussion Session 1
Agenda • Introduction • Remote programming • Separate code • Compile -- g++,makefile • Debug -- gdb • Questions?
Introduction Ravi Jampani Ph.D. student rjampani@cise.ufl.edu www.cise.ufl.edu/~rjampani/ Office hour for this week: Thursday 9th period Location: E309
Remote Programming: Remote programming 1) putty/terminal Editing files: pico, emacs, vim, kate 2) winscp, filrezilla, cyberduck Transfer files to E114. remote machines list: link , any machine starts with "lin" host: lin114-01.cise.ufl.edu Tutorial: http://www.cise.ufl.edu/help/access/remote/ Off-campus: http://web.uflib.ufl.edu/login/vpn.html Submitting a hw in sakai: To create a tar file: tar cvf (tar file name) (file 1) (file 2) (file 3)...tar cvf myhwassignment.tar readme makefile *.cpp *.h
Separate code header file #ifndef ADD_H#define ADD_Hint add(int x, int y); // function prototype for add.h #endif Header guards Because header files can include other header files, it is possible to end up in the situation where a header file gets included multiple times. For example, consider the following program: .cpp int add(int x, int y){return x + y;} Example: Stack.cpp into main.cpp, Stack.h, Stack.cpp
Compilation • Compiling, in which C++ code is translated into assembly; • Assembling, in which assembly is translated into machine language; and • Linking, in which calls to functions outside the main file are linked to their definitions. //////////////////////////////////////////////// g++ -c stack.cpp g++ -c main.cpp g++ -o stack main.o stack.o or //////////////////////////////////////////////// g++ -o stack main.cpp stack.cpp -o program_name // compiling and linking to generate program_name, default "a.out" -c // compiling but no linking-g // for debugging, but runs slow
make and makefile make is a system designed to create programs from large source code trees and to maximize the efficiency of doing so. To that effect, make uses a file in each directory called a Makefile. This file contains instructions for make on how to build your program and when. target: dependencies<tab>instructions<enter> example Note: Build several independent targets in order, below is sample makefile ========================================================== all: target1 target2 target3 target1: dependencies <tab>instructions<enter> target2: ...
Run ./program_name For ex: ./stack
GNU debugger -- gdb A symbolic debugger is a program that aids programmers in finding logical errors, by allowing them to execute their program in a controlled manner. • Enable symbol table • Debug the program g++ -g -o stack stack.cpp gdb stack
Use gdb Quitting gdb (gdb) quit (or q or Ctrl-D) Starting Execution of Program (gdb) run (or r) Resuming Execution at a BreakpointOnce you have suspended execution at a particular statement, you can resume execution in several ways: continue (or c) Resumes execution and continues until the next breakpoint or until execution is completed. next (or n) next will execute a function in the current statement in its entirety.step (or s) step command will execute the next statement, but will step into function calls.
Setting Breakpoints Setting a breakpoint permits you to mark a particular line in your program (called a breakpoint) so that when execution reaches that line, program execution will be suspended, allowing you to enter a gdb command. break function: Set a breakpoint at entry to function function. break filename:linenum :Set a breakpoint at line linenum in source file filename.
Removing Breakpoints and backtrace clear function clear filename:function ----- Delete any breakpoints set at entry to the function function. clear filename:linenum ---- Delete any breakpoints set at or within the code of the specified line. bt OR backtrace ---- Shows the functions in the execution path
Displaying Values print expression (or p expression)Displays the value of the expression (usually a variable) once → at the current point of execution. display expressionDisplays the value of the expression (usually a variable) each time execution is suspended info display Displays a numbered list of all expressions currently being displayed. undisplay numStop displaying expression number num.