# Getting started

This chapter is short introduction to the cross debugger or axd. The debugger is a special interpreter that is designed to help the developer to trace an application. The debugger is designed to operate in a stand-alone mode or with Emacs. If you plan to use the debugger with Emacs, you will have to install a `gud-mode` package.

## A sample debugger session

The cross debugger or axd is a special interpreter that gives the developer the opportunity to trace an application and examine the object contents during the execution. Operations normally available in a debugger are available with axd. Such operations include breakpoints, stepping, stack tracing, and many others. Because axd is built on top of the interpreter, all standard operations are supported by the debugger.

### Starting the debugger

The debugger is started with the command `axd`. Within Emacs, the command `Meta-x axd` will do the same. When the debugger is started, an axd prompt is displayed. At this stage, there is no difference with the standard interpreter, except that a new nameset called axd is defined with all debugger commands. The `axd:quit` or `axd:quit` commands will terminate the session.

zsh> axd (axd)axd:quit

### Debugger commands

All debugger commands are located in the axd nameset. For example, the command to set a breakpoint is `axd:break`. Since typing such command can be annoying, it is possible to rebind them at your convenience. For example, the form `const b axd:break` will define the symbol `b` as the breakpoint command, but care should be taken with this approach if your program uses the same symbol.

### Debugging session example

The first example that demonstrates the use of axd is located in the directory exp/ref, that is part of this distribution. The platform information example 0501.als will be used for illustration. A simple session and the original source code is given below.

zsh> axi 0501.als major version number : minor version number : patch version number : interpreter version : .. program name : afnix operating system name : linux operating system type : unix afnix official uri : http://www.afnix.org

The source code for this example is given below.

# many comments before println "major version number : " interp:major-version println "minor version number : " interp:minor-version println "patch version number : " interp:patch-version println "interpreter version : " interp:version println "program name : " interp:program-name println "operating system name : " interp:os-name println "operating system type : " interp:os-type println "afnix official url : " interp:afnix-uri

The debugger is started with the file to debug. The `axd:info` command can be used to print some information.

zsh> axd 0501.als (axd) axd:info debugger version : .. os name : linux os type : unix initial file : 0501.als form file name : 0501.als form line number : 17 verbose mode : true max line display : 10 defined breakpoints : 0 (axd)

Along with the version, initial file name and other information, is the form file name and the form line number that indicates where the debugger is position. Another way to get this information is with the `axd:list` command that display the file at its current break position.

(axd) axd:list 17 println "major version number : " interp:major-version 18 println "minor version number : " interp:minor-version 19 println "patch version number : " interp:patch-version 20 println "interpreter version : " interp:version 21 println "program name : " interp:program-name 22 println "operating system name : " interp:os-name 23 println "operating system type : " interp:os-type 24 println "afnix official uri : " interp:afnix-uri 25 26 (axd)

With this in place it is possible to run the program. The `axd:run` command will do the job, but will not give you the opportunity to do something since there is no breakpoint installed. So, installing a breakpoint is simply achieved by giving the file name and line number. To make life easier, the `axd:break` command takes also 0 or argument. Without argument, a breakpoint is set at the current position. With one integer argument, a breakpoint is set at the specified line in the current file. If the verbose mode is active (which is the default), a message is printed to indicate the breakpoint index.

(axd) axd:break 19 setting breakpoint 0 in file 0501.als at line 19 (axd)axd:run major version number : minor version number : breakpoint 0 in file 0501.als at line 19 (axd)

The `axd:run` command starts the program and immediately stops at the breakpoint. Note that the debugger prints a message to indicate the cause of such break. After this, stepping is achieved with the `axd:next` command. Resuming the execution is done with the `axd:continue` command. The `axd:exit` or `axd:quit` command terminates the session.

(axd)axd:next patch version number : (axd)axd:next interpreter version : -- (axd)axd:continue program name : axd operating system name : linux operating system type : unix afnix official uri : http://www.afnix.org (axd)axd:quit