Presentation is loading. Please wait.

Presentation is loading. Please wait.

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?

Similar presentations


Presentation on theme: "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?"— Presentation transcript:

1 COP 3530 Spring 12 Discussion Session 1

2 Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?

3 Introduction Ravi Jampani Ph.D. student rjampani@cise.ufl.edu www.cise.ufl.edu/~rjampani/ Office hour for this week: Thursday 9 th period Location: E309

4 Remote Programming: Remote programming 1) putty/terminal Editing files: pico, emacs, vim, kate 2) winscp, filrezilla, cyberduckwinscpfilrezillacyberduck Transfer files to E114. remote machines list: link, any machine starts with "lin"link host: lin114-01.cise.ufl.edu Tutorial: http://www.cise.ufl.edu/help/access/remote/ http://www.cise.ufl.edu/help/access/remote/ Off-campus: http://web.uflib.ufl.edu/login/vpn.html http://web.uflib.ufl.edu/login/vpn.html Submitting a hw in sakai: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

5 Separate code header file #ifndef ADD_H #define ADD_H int 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.cppStack.cppmain.cppStack.hStack.cpp

6 Compilation 1.Compiling, in which C++ code is translated into assembly; 2.Assembling, in which assembly is translated into machine language; and 3.Linking, in which calls to functions outside the main file are linked to their definitions. //////////////////////////////////////////////// g++ -c stack.cppstack.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

7 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 instructions example Note: Build several independent targets in order, below is sample makefile ========================================================== all: target1 target2 target3 target1: dependencies instructions target2:...

8 Run./program_name For ex:./stack

9 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. 1.Enable symbol table 2.Debug the program g++ -g -o stack stack.cpp gdb stack

10 Use gdb Quitting gdb (gdb) quit (or q or Ctrl-D) Starting Execution of Program (gdb) run (or r) Resuming Execution at a Breakpoint Once 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.

11 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.

12 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

13 Displaying Values print expression (or p expression)Displays the value of the expression (usually a variable) once → at the current point of execution. display expression Displays 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 num Stop displaying expression number num.


Download ppt "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?"

Similar presentations


Ads by Google