Currently the debugger only works on Linux. All the platform specific stuff is in `xdbg.cpp`.
## `(dbs)`
Print the status of the debugger and listener. The listener status is whether or not there is a socket connection open between the compiler and the target. The "debug context" is information that the runtime sends to the compiler so it can find the correct thread to debug. In order to debug, you need both.
## `(dbg)`
Attach the debugger. This will stop the target.
Example of connecting to the target for debugging:
```lisp
OpenGOAL Compiler 0.1
;; attach the listener over the network
g> (lt)
[Listener] Socket connected established! (took 0 tries). Waiting for version...
Got version 0.1 OK!
;; this message is sent from the target from kprint.cpp and contains the "debug context"
[OUTPUT] reset #x147d24#x2000000000 1062568
;; the debugger gets the message and remembers it so it can connect in the future.
[Debugger] Context: valid = true, s7 = 0x147d24, base = 0x2000000000, tid = 1062568
;; attach the debugger and halt
gc> (dbg)
[Debugger] PTRACE_ATTACHED! Waiting for process to stop...
Debugger connected.
;; print the debugger status
gc> (dbs)
Listener connected? true
Debugger context? true
Attached? true
Halted? true
Context: valid = true, s7 = 0x147d24, base = 0x2000000000, tid = 1062568
```
## `(:cont)`
Continue the target if it has been stopped.
## `(:break)`
Immediately stop the target if it is running. Will print some registers.
The file will be the exact size of `EE_MAIN_MEM_SIZE`, but the first `EE_LOW_MEM_PROTECT` bytes are zero, as these cannot be written or read.
## Address Spec
Anywhere an address can be used, you can also use an "address spec", which gives you easier ways to input addresses. For now, the address spec is pretty simple, but there will be more features in the future.
-`(sym-val <sym-name>)`. Get the address stored in the symbol with the given name. Currently there's no check to see if the symbol actually stores an address or not. This is like "evaluate `<sym-name>`, then treat the value as an address"
-`(sym <sym-name>)`. Get the address of the symbol object itself, including the basic offet.
The element size is the size of each word to print. It can be 1, 2, 4, 8 currently. The address is the GOAL Address to print at. The elt-count is the number of words to print. The print mode is option and defaults to `hex`. There is also an `unsigned-decimal`, a `signed-decimal`, and `float`. The `float` mode only works when `elt-size` is 4.
There are some useful macros inspired by the original PS2 TOOL debugger (`dsedb`) for the different sizes. They are `db`, `dh`, `dw`, and `dd` for 1, 2, 4, and 8 byte hex prints which follows the naming convention of MIPS load/stores. There is also a `df` for printing floats. See the example below.
```lisp
OpenGOAL Compiler 0.1
;; first connect the listener
g> (lt)
[Listener] Socket connected established! (took 0 tries). Waiting for version...
Got version 0.1 OK!
[OUTPUT] reset #x147d24#x2000000000 53371
[Debugger] Context: valid = true, s7 = 0x147d24, base = 0x2000000000, tid = 53371
;; define a new array of floats, and set a few values
gc> (define x (new 'global 'array 'float 12))
1452224
gc> (set! (-> x 0) 1.0)
1065353216
gc> (set! (-> x 2) 2.0)
1073741824
;; attach the debugger (halts the target)
gc> (dbg)
[Debugger] PTRACE_ATTACHED! Waiting for process to stop...