This procedure shows the basic steps needed to work on a
programming homework assignment. Use this for a quick start.
- Follow instructions for setting up the class account.
- Check out the homework assignment. The command below is
for Homework 1 in Spring 2008, modify as necessary.
Makefile
coord.h
frame_buffer.h
hw1
hw1-debug
hw1.cc
hw1.s
The files should be copied to directory ~/hw1 (or whatever
the last component of the svn URI was).
- Locate and read the homework instructions, for 2008 hw1 they are in
file hw1.cc. The recommended way is to use Emacs to load the file and
then read within Emacs.
- Edit the file to solve one of the problems, but intentionally
make a syntax error by declaring a variable "integer".
- Compile by pressing [f9] and then [Enter].
Compilation started at Mon Feb 11 18:47:48
g++ -Wall -g hw1.cc -o hw1-debug -lX11 -lXi -lglut -lGL -lGLU -lm -lpthread -lrt
hw1.cc: In function ‘void render_hw1(pFrame_Buffer&)’:
hw1.cc:233: error: ‘integer’ was not declared in this scope
hw1.cc:233: error: expected `;' before ‘i’
gmake: *** [hw1] Error 1
The output above appears in a pane below the one showing the program.
- Middle-click over the error to jump to the line with the error
or, press [f5] and enter the line number to jump to. Then correct
the mistake, and repeat until compilation is successful.
- Run the code under the debugger within Emacs by selecting the
"Tools | Debugger (gdb)", then if necessary changing the gdb command
in the minibuffer to "hw1-debug" and pressing [Enter].
Current directory is /home/faculty/koppel/teach/gpcom/gp/hw/2008/hw1/
GNU gdb Red Hat Linux (6.5-25.el5_1.1rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb)
The homework makefiles build two versions of the homework program,
one for debugging and one for regular use. The only difference between
the two is that the debug version is not optimized.
- Run
(gdb) run
Starting program: /home/faculty/koppel/teach/gpcom/gp/hw/2008/hw1/hw1-debug
[Thread debugging using libthread_db enabled]
[New Thread -1208965392 (LWP 4349)]
S GL_VENDOR - "NVIDIA Corporation"
S GL_RENDERER - "GeForce 8800 GT/PCI/SSE2"
S GL_VERSION - "2.1.2 NVIDIA 169.07"
Program exited normally.
(gdb)
The output before "Program exited normally" is displayed while
the program is running.
- Set a breakpoint to examine variable values: Position
the cursor over the line at which you want to break and enter
C-x SPC (Control-x then space).
Breakpoint 1 at 0x804b99f: file hw1.cc, line 452.
(gdb)
If this didn't work take the time to figure it out or ask
someone.
- Re-run, print out some variables, and continue. The
transcript below shows the use of a variety of commands. The
text starting with "<-" are comments inserted into the transcript.
Note that
user input and gdb output are intermixed in the text below.
Breakpoint 1, render_hw1 (frame_buffer=@0xbfc9e17c) at hw1.cc:452
(gdb) print scale <- print value of variable 'scale'
$1 = 0.0623286702
(gdb) p length <- p is equivalent to print
$2 = 2.00249839
(gdb) print length * length
$3 = 4.0099997951056707
(gdb) print v.red
$4 = 249
(gdb) next <- Single-step execution.
(gdb) print v.red
$5 = 15.5198393
(gdb) info break <- List active breakpoints.
Num Type Disp Enb Address What
1 breakpoint keep y 0x0804b99f in render_hw1(pFrame_Buffer&)
at hw1.cc:452
breakpoint already hit 1 time
(gdb) print v.z
$6 = -4
(gdb) cond 1 v.z < -5 <- Set a condition for breakpoint 1.
(gdb) continue
Continuing.
Breakpoint 1, render_hw1 (frame_buffer=@0xbfc9e17c) at hw1.cc:452
(gdb) print v.z
$7 = -5.25
(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep y 0x0804b99f in render_hw1(pFrame_Buffer&)
at hw1.cc:452
stop only if v.z < -5
breakpoint already hit 2 times
(gdb) disable 1 <- Temporarily turn off breakpoint 1.
(gdb) c
Continuing.
Use gdb's help command to find out more about each command.
- Re-compile, run, and debug until code is working.
Emacs, at its core, is a text editor, however surrounding that core
are many commands and modes to help with programming tasks of all
kinds and other activities from the practical, such as editing files
on remote computers (look for Remote Files in the documentation), to
the amusing, such as inserting keywords designed to attract the
attention of counterespionage agents (M-x spook). Emacs
has commands for
practically anything.
These steps show how
to use Emacs to edit a file.
- Type emacs & in a command shell
or start using the "Applications | Accessories | Emacs Text Editor"
menu item.
A window should pop up, the frame will be labeled Emacs.
- Load a file by selecting "Open File..." from the Files menu.
- Enter a file name. Note that text may appear in the bottom
of the main window in an area called the minibuffer,
or in a dialog box.
(Once loaded, the file name will appear in the mode line near the
bottom of the window.)
- Enter text in the buffer to try out the editor.
- Select "Save Buffer" from the Files menu to save.
- When done with editing for the day
select "Exit Emacs" from Files to exit.
Many users prefer to leave Emacs open with multiple files
rather than exiting and re-starting Emacs for each file edited.
Special features for editing C code. (Some
work with other languages.)
- Load a C file into a buffer.
Enter C code (any C code).
Code should be
syntax highlighted (different colors should be used for C keywords,
comments, etc.), alerting you to some syntax errors
and giving you something pretty to look at.
- Pressing tab will automatically indent the line the cursor
is over. This is useful for catching syntax errors and keeping the
description properly indented.
- Pressing F9 will build the program (using the Makefile
that is in the directory). A window will open
showing the compiler output. Clicking on an error message with
the center mouse button will move the cursor to the line with the error.
(The tutorial is an introduction for first-time users.)
(Info provides detailed documentation for Emacs and other programs.)
- Start Emacs
- Select "Browse Manuals" from "Help" menu.
- Following instructions, select the Emacs manual.