home *** CD-ROM | disk | FTP | other *** search
- p @"This session is under the control of a command file"
- p @"that is being read in. At the appropriate time, you will"
- p @"be prompted to <Hit Any Key to Continue>."
- p @"The command file may be aborted by entering a Ctrl-C or Cmd-C"
- p @"at the prompt."
- &
- p @n
- p @"Welcome to a demonstration walk-through of the Aztec C Source"
- p @"Level Debugger. We will take a look at some of the functions"
- p @"and features by debugging a sample program."
- &
- p @n
- p @"At this point, the debugger has been started by double clicking"
- p @"on the bc.dbg icon. If you were running under the Aztec or"
- p @"MPW Shell, you would enter the command line:"
- p @n
- p @" sdb bc"
- p @n
- p @"Before getting into the debugging itself, let's look at SDB's"
- p @"display and how it can be manipulated. The first thing you notice"
- p @"is that the window is split into three sub-windows. The top window"
- p @"is the source window which is a scrollable window used to examine"
- p @"the source of the program being debugged. Notice that one line in"
- p @"the window is highlighted to indicate the current location of the"
- p @"program counter. That is, this is the line about to be executed."
- p @"The source can be scrolled by using the scroll bar to the right"
- p @"of the window or by using the SHIFT UP and SHIFT DOWN arrow keys."
- p @"Finally notice that the lines are numbered so that they can be"
- p @"referenced by the debugger commands."
- &
- p @n
- p @"The second window is a one line window which is the command window."
- p @"This window is used to input commands to the debugger. The command"
- p @"window supports the standard types of cursor editing and also"
- p @"supports a history mechanism using the up and down arrow keys."
- p @"There is also a small gadget at the end of the window which can be"
- p @"used to move the command line up or down and thereby increasing or"
- p @"decreasing the sizes of the source and data windows. The command"
- p @"window may also be moved by using the SHIFT-CMD-UP and"
- p @"SHIFT-CMD-DOWN arrow keys."
- &
- p @n
- p @"The third and final window is the data window which displays the"
- p @"output of the various commands given to the debugger. This window"
- p @"is also a scrollable window with approximately 4000 characters"
- p @"saved in a circular buffer making it possible to look back at"
- p @"previous output. This window may be scrolled from the keyboard"
- p @"by using the CMD-UP and CMD-DOWN arrow keys."
- &
- p @n
- p @"There are just two more notes on the display before we get to the"
- p @"program itself. First, note that the window size can be changed"
- p @"and the number of lines in the source and data areas will be"
- p @"adjusted appropriately. Second, when the debugger is active, the"
- p @"debugger window can be toggled between the back of all other"
- p @"windows and the front by using the <esc> or ` key. For this demo, we"
- p @"will do that for you. For example,"
- &
- &2
- p @n
- p @"Well, that's it for the display, let's get to some debugging."
- &
- p @n
- p @"The first thing you notice when SDB is started is that it has"
- p @"loaded the program to be debugged into memory, set a breakpoint"
- p @"on the 'main()' function, started the program and stopped at the"
- p @"beginning of main(). The second thing you notice is that SDB has"
- p @"automatically found the correct file and line number"
- p @"corresponding to the beginning of main(). This is important"
- p @"since this particular program consists of several source files"
- p @"all located in a subdirectory."
- &
- p @n
- p @"Let's get started by using the 's' command. This command will"
- p @"single step the program source line by source line. Doing it once"
- p @n
- p @"sdb?s"
- p @n
- p @"moves us past the function entry code to the first statement"
- p @"which calls InitGraf()."
- s
- &
- p @n
- p @"A second"
- p @n
- p @"sdb?s"
- p @n
- p @"actually executes the statement."
- s
- &
- p @n
- p @"Let's do two single steps by giving a count"
- p @n
- oe
- 2s
- oe
- p @n
- p @"which brings us to a function call to setupmenus()."
- p @n
- p @"Since an s would actually step into the function,"
- p @"we'll use a t to treat the function as a single instruction."
- p @n
- &
- p @"sdb?t"
- p @n
- t
- p @"We'll now let the rest of the initialization take place and stop"
- p @"at line 24 by using the g command with a temporary breakpoint."
- p @n
- &
- oe
- g .24
- oe
- p @n
- p @"At this point we are about to open the window for the program"
- p @"output, which is a good time to discuss some commands for"
- p @"displaying memory. We knew above that the OpenLibrary() calls"
- p @"returned non-zero by watching where control went at the 'if'"
- p @"statements. Now we want to see the exact value of the myWindow"
- p @"variable before assigning a new value to it. One way is to use the"
- p @"'dw' command to display words of memory as in:"
- p @n
- oe
- dw myWindow
- oe
- &
- p @n
- p @"Since myWindow is a pointer, it consists of the first two words"
- p @"displayed which are zero. We could also have displayed it as bytes"
- p @"or long words by using the 'db' or 'dl' commands respectively."
- &
- p @n
- p @"While the 'd' commands are useful for looking at raw memory, there"
- p @"is a much more elegant command which can be used to look at"
- p @"program variables and data. This is the 'p' command which is"
- p @"extremely flexible and powerful, but in its simplest form can be"
- p @"used as:"
- p @n
- oe
- p myWindow
- oe
- &
- p @n
- p @"Note that the 'p' command not only knows where the myWindow variable"
- p @"is in memory, but also knows the type of the variable and displays"
- p @"the type as part of it's output. Since it knows the type, it also"
- p @"knows exactly how many bytes to use when getting the value of the"
- p @"variable."
- &
- p @n
- p @"Now let's open the window by using"
- p @n
- p @"sdb?s"
- p @n
- p @"again."
- s
- &
- p @n
- p @"When the line was executed, the window was opened and appeared"
- p @"momentarily before disappearing. This is because when the"
- p @"debugger gets control because of a breakpoint or the end of a"
- p @"single step it automatically makes its window the front window"
- p @"and activates it."
- &
- p @n
- p @"Let's look again at the value of myWindow."
- p @n
- oe
- p myWindow
- oe
- &
- p @n
- p @"We know the NewWindow() succeeded because we saw the window"
- p @"appear, and now we have the address of the GrafPort structure"
- p @"pointed to by the myWindow variable. Now, when we said 'p myWindow' we"
- p @"were printing a pointer to a GrafPort structure and got a hex value"
- p @"for the address. If we want to look at the contents of the"
- p @"structure we could try several things."
- &
- p @n
- p @"First, we could use the 'dw' command with the hex value displayed"
- p @"above to look at the structure contents. Or more simply, we could"
- p @"look at what myWindow points at by using:"
- p @n
- oe
- dw *myWindow
- oe
- &
- p @n
- p @"This saves us from having to deal with hex numbers, but is still"
- p @"going to be a lot of work to get any useful information. So, as a"
- p @"last resort, why not try the 'p' command again, but this time on"
- p @"*myWindow instead of just Window."
- &
- p @n
- oe
- p *myWindow
- oe
- p @n
- p @"Voila! Since myWindow was a pointer to a structure, *myWindow is an"
- p @"instance of a structure and the 'p' command proceeded to dump the"
- p @"entire contents of the structure. There are two important things"
- p @"to notice here. First, SDB was able to display the type and name"
- p @"of each structure element. Second, with both the 'dw' and the 'p'"
- p @"command we were able to use a C expression as a parameter of the"
- p @"command. In fact, we can use any arbitrary C expression as a"
- p @"parameter."
- &
- p @n
- p @"For example, to see just the value of the portRect, we could say:"
- p @n
- oe
- p myWindow->portRect
- oe
- &
- p @n
- p @"or to see the visible region:"
- p @n
- oe
- p **myWindow->visRgn
- oe
- &
- p @n
- p @"This is extremely powerful and can be summarized by saying that"
- p @"you can debug most programs without actually knowing the physical"
- p @"hex address of any variable. We'll expand on this a little later."
- &
- p @n
- p @"Let's move on now by looking at the next few lines of source,"
- p @"which aren't too threatening looking, and skipping over them by"
- p @"going to line 29 using the 'g' command."
- &
- p @n
- oe
- g .29
- oe
- p @n
- p @"Unlike the 's' command, the 'g' command let's the processor run"
- p @"the program at full speed until a breakpoint is reached. If no"
- p @"breakpoints have been set, the program will run until it exits."
- p @"In this case, we have set a temporary breakpoint at line 29 by"
- p @"following the 'g' command with the '.29'."
- &
- p @n
- p @"In general, source lines are specified by an optional file name"
- p @"followed by a '.' and the line number. Thus we could also have said:"
- p @n
- p @" g main.c.29"
- p @n
- p @"to achieve the same effect. If no file name is present, the file"
- p @"currently displayed in the source window is assumed."
- &
- p @n
- p @"Let's continue by single stepping the call to the redraw() function."
- &
- p @n
- p @"sdb?s"
- s
- p @n
- p @"Unlike previous function calls, this time single stepping has"
- p @"brought us to the beginning of the function being called. This is"
- p @"because the previous calls were to functions for which there was"
- p @"no source available. In this event, the function is called"
- p @"directly without 'stepping into' the function itself. However, if"
- p @"the source is present, the function is 'stepped into' at the"
- p @"beginning of the function. As we did with setupmenus(), it would"
- p @"have been possible to treat the redraw() function as though there"
- p @"were no source by using the 't' command which single steps without"
- p @"ever 'stepping into' functions."
- &
- p @n
- p @"It is possible to see how we got here by looking at a stack"
- p @"backtrace."
- p @n
- oe
- ds
- oe
- &
- p @n
- p @"This shows the redraw() function was called from main() which was"
- p @"called from _main() with two arguments which was called from ...."
- &
- p @n
- p @"The same backtrace can be shown with local variable values by"
- p @"using 'dS' instead of 'ds'."
- p @n
- p @"Now that we're here, let's look at what redraw() is going to do."
- p @"First it draws the axes and then labels them and then draws the"
- p @"bars for the chart. Another feature of SDB is that it knows the"
- p @"location of the source to every function. Let's use that to look"
- p @"at the drawaxes() function."
- &
- p @n
- oe
- df drawaxes
- oe
- p @n
- p @"SDB has automatically changed source files and moved to the"
- p @"beginning of the drawaxes() function. This function resets the Pen"
- p @"values and then draws the axes based on the variables passed into"
- p @"the function. Then starting at line 12, it saves the values for"
- p @"the axes in the 'xyb' structure. So, lets set a permanent"
- p @"breakpoint at line 12."
- p @n
- oe
- bs .12
- oe
- &
- p @n
- p @"Lets just check it to make sure it got the right file."
- p @n
- oe
- bd
- oe
- &
- p @n
- p @"Okay, now let's just recheck where the program counter is by using"
- p @"the context command."
- &
- p @n
- oe
- c
- oe
- p @n
- p @"Good enough, now we want to run till we hit that breakpoint."
- &
- p @n
- oe
- g
- oe
- p @n
- p @"Let's flip the window to the back for a couple of seconds to"
- p @"examine the axes we've drawn."
- &
- &2
- p @n
- p @"Now we can examine some more of SDB's commands. First, although"
- p @"SDB is a source level debugger, it still retains many assembly"
- p @"level abilities. For example, to look at the assembly language"
- p @"that corresponds to the next few statements, we use the unassemble"
- p @"command."
- &
- p @n
- oe
- u pc,2
- oe
- &
- p @n
- p @"Note that the source and assembly language are intermixed. Using"
- p @"the 'z' command we can switch from source to assembly mode and"
- p @"back. When in assembly mode, single stepping is done by assembly"
- p @"language statement."
- &
- p @n
- p @"The values of the local variables in a function can be displayed:"
- p @n
- oe
- da
- oe
- &
- p @n
- p @"The complement to the 'da' command is the 'dg' command which"
- p @"displays the values of all global variables."
- p @n
- p @"Note that the structure Myxyb is pointed to by the pointer xyb as"
- p @"passed in to the current function. Let's look at the contents."
- p @n
- oe
- p *xyb
- oe
- &
- p @n
- p @"All zero to start. Let's execute a line."
- &
- p @n
- p @"sdb?s"
- s
- p @n
- p @"And check the contents now."
- p @n
- oe
- p *xyb
- oe
- &
- p @n
- p @"This brings us to another VERY powerful feature of SDB. Suppose"
- p @"that at this point we realize that we really meant to place the"
- p @"value of 'xaxis+1' into the xyb structure. Again we have several"
- p @"ways to do this. The assembly language debugger approach is to"
- p @"find the address of the structure."
- p @n
- oe
- p xyb
- oe
- &
- p @n
- p @"Then we could look at the value stored there."
- p @n
- oe
- dw *xyb
- oe
- &
- p @n
- p @"Finally we could modify it using an instruction like"
- p @n
- p @" mw *xyb = 36"
- &
- p @n
- p @"On the other hand, the SDB approach is to use the evaluate"
- p @"command. This command evaluates an arbitrary C expression. For"
- p @"this case we could use:"
- p @n
- oe
- e ++xyb->xaxis
- oe
- &
- p @n
- p @"which would increment the value. We could also say"
- p @n
- oe
- e xyb->xaxis = xaxis + 1
- oe
- &
- p @n
- p @"With this capability, it is also possible to modify local"
- p @"variables on the stack without knowing their exact address."
- &
- p @n
- p @"The 'e' command is even more powerful since when we say an"
- p @"arbitrary C expression we pretty much mean it. For example, let's"
- p @"try:"
- p @n
- oe
- e DrawString("hello world!")
- oe
- p @n
- p @"Now we'll flip the windows to look at the output."
- &
- &2
- p @n
- p @"Since DrawString() was linked with the program it can be called as"
- p @"part of the expression evaluation."
- &
- p @n
- p @"Okay, let's show one more feature and then we'll give you a chance"
- p @"to play. First, let's go back to the function that called this one"
- p @"by using the convenient shorthand symbol '@'."
- &
- p @n
- oe
- g @
- oe
- p @n
- p @"Now, lets label the axes by calling single stepping the next two"
- p @"lines using the 't' command."
- &
- p @n
- p @"sdb?t"
- t
- &
- p @n
- p @"sdb?t"
- t
- p @n
- p @"Let's flip the window to the back for a couple of seconds to"
- p @"look at the result."
- &
- &2
- p @n
- p @"Next, the program will draw the actual bars for the chart and then"
- p @"will return. So let's set a breakpoint at the return of the"
- p @"current function."
- p @n
- oe
- bs @
- oe
- &
- p @n
- p @"Let's check the breakpoint table."
- p @n
- oe
- bd
- oe
- &
- p @n
- p @"Hmmm, we might as well get rid of the old one."
- p @n
- oe
- bc drawaxes.c.12
- oe
- &
- p @n
- p @"And now we turn on single step trace mode."
- p @n
- oe
- bT
- oe
- &
- p @n
- p @"This will force single stepping until a breakpoint is reached. Now"
- p @"we type 'g' and watch the program run."
- &
- p @n
- oe
- g
- oe
- p @n
- p @"Back at the main() function, we disable line tracing."
- p @n
- oe
- bT
- oe
- &
- p @n
- p @"And now we let the program run to completion. You will have to"
- p @"click in the close box to get the program to quit."
- &
- p @n
- oe
- g
- oe
- p @n
- p @"At this point, the program has exited and is gone so most commands"
- p @"won't work anymore. For example:"
- &
- p @n
- oe
- 2s
- oe
- p @n
- p @"To reload the program, the 'lp' command is used."
- &
- p @n
- oe
- lp
- oe
- p @n
- p @"And we're ready to go again."
- &
- p @n
- p @"In summary, SDB through its support of arbitrary C expressions and"
- p @"in particular the 'e' and 'p' commands allows the programmer to"
- p @"debug his program without ever having to:"
- p @n
- p @" LOOK AT ANY ASSEMBLY LANGUAGE!"
- p @n
- p @" LOOK AT ANY HEX ADDRESSES!"
- p @n
- p @" CALCUALATE THE OFFSET OF A STRUCTURE ELEMENT!"
- &
- p @n
- p @"Instead, the programmer tests and debugs with the same syntax used"
- p @"to write the program in the first place."
- &
- p @n
- p @"When you've finished working with the program, you can exit sdb by"
- p @"using the q for quit command. The only other command that you'll need"
- p @"to remember is the ? for help. With that you should be able to figure"
- p @"the rest out by yourself."
- &
- p @n
- p @n"The command file has now terminated, and you're in control."
-