Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.

Similar presentations


Presentation on theme: "Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment."— Presentation transcript:

1 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment

2 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Command Line Mentality Old fashioned but… …surprisingly efficient… … except for editing.

3 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Operating System: UNIX Oldest “modern” operating system Base for Linux, HP/UX, Solaris, AIX, Android, etc. Most widely used Available on Lab accounts Free version available on Windows : CYGWIN (https://www.cygwin.com/)https://www.cygwin.com/ Assume basic knowledge of UNIX (http://www.ee.surrey.ac.uk/Teaching/Unix)http://www.ee.surrey.ac.uk/Teaching/Unix Large library of free software - GNU compilers, editors, debuggers, etc. (http://en.wikipedia.org/wiki/GNU)http://en.wikipedia.org/wiki/GNU

4 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Basic Commands Editor – gedit (not available everywhere) Compiler / Linker – gcc Build manager – make Debugger - gdb

5 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Editor - gedit Hybrid command line / Graphical User Interfacce (GUI) First invocation from command line starts GUI Suggest “gedit myfile.c &” first time – otherwise, hangs up command line until gedit is closed Once gedit is running, successive “gedit” commands send messages to existing GUI Hints: Turn off backup to avoid files names ~myfile.c Turn on line numbering so you can use line numbers in gdb

6 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The compile / link process myfile.c Translate to x86 Assembler myfile.s Translate machine object language myfile.o Pre- processor myfile.h stdlib.h libstdlib.so linker executable

7 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 GCC (Gnu C Compiler) gcc Basic options: -o -g [include debug information in output file] -I -L -l For example: gcc –g –o executable myfile.c For more detail, gcc –- help or man gcc Complete documentation: https://gcc.gnu.org/onlinedocs/https://gcc.gnu.org/onlinedocs/

8 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Make Concepts Build a product from components Keep track of what’s new Rebuild only components that have changed

9 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Example C style build hierarchy mycmdmymain.cmymain.hmycomp.hmycomp.cmycomp.h

10 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Change/Rebuild mycmdmymain.cmymain.hmycomp.hmycomp.cmycomp.h

11 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 File that tells “make” what to do and how to do it Composed of a list of “make rules” (and variables…) A rule has three parts: Target – the file that this rule produces Pre-requisite files – A list of file used to make the target Recipe – Unix command(s) to produce target from the pre-requisite files For example: mymain.o : mymain.c mymain.h mycomp.h gcc –o mymain.o mymain.c Makefile Required Tab

12 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Example Makefile mycmd : mymain.o mycomp.o gcc –o mycmd mymain.o mycomp.o mymain.o : mymain.c mymain.h mycomp.h gcc –o mymain.o mymain.c mycomp.o : mycomp.c mycomp.h gcc –o mycomp.o mycomp.c test : mycmd mycmd “test string” mycmd “test string 2” clean: -rm mycmd mymain.o mycomp.o

13 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Invoking make Command : make If not specified, look for target “all” If not specified and no “all” target, make first target in the make file

14 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Make processing Find rule for target Make all dependencies for that rule If target file does not exist, or if any dependencies are newer than target file, invoke recipe

15 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Phony Targets Targets for which recipe does not actually create the target file For example: clean & test Recipe invoked each time target is specified, independent of dependencies For example “make test” invokes “mycmd” every time it is called.

16 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Typical Targets all - all executables required clean - remove all built files test – test all executables built install - any commands required to make executables generally available

17 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Debugging – GDB (Gnu DeBugger) gdb Starts debugger Loads executable Prompts for gdb commands Basic GDB commands: h[elp] – help on gdb commands b[reak] – set a breakpoint at the specified location Location can be either a line number in a file or a function name run - invoke command and run to next breakpoint c[ontinue] – continue to next breakpoint s[tep] – run next program instruction, stepping into function invocations n[ext] – run next program instruction, skipping over function invocations p[rint] - print the current value of variable x - print (examine) memory at locations q[uit] – exit out of gdb

18 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 GDB hints gdb –x gdbcmds.txt mycommand Runs command from gdbcmds.txt before prompting Useful when you have lots of breakpoints and/or complicated parameters Null gdb command same as “repeat previous” E.g. “step” to step 3 instructions If you see a prompt like: Breakpoint 1, 0x00000001004010d8 in main () You forgot to compile with –g Prompt shows the line of C code ABOUT to execute Documentation: http://www.gnu.org/software/gdb/documentation/ http://www.gnu.org/software/gdb/documentation/


Download ppt "Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment."

Similar presentations


Ads by Google