-
Run
make
-
After successfully building, there are two files to copy into your project:
gdbstub.bin
andgdbstub.h
.
The GDB stub has the following constraints:
-
The binary must reside in read/writable memory.
-
The
sp
(r15
) register must be properly set.
Depending on how your project is structured, there's a few ways to include gdbstub.bin
:
- Use the builtin assets linking feature.
# Each asset follows the format: <path>;<symbol>. Duplicates are removed
BUILTIN_ASSETS+= \
assets/gdbstub.bin;gdbstub_bin
- Convert
gdbstub.bin
into a C array and include that as a source file.
bin2c gdbstub.bin gdbstub_bin gdbstub.bin.h
- Load
gdbstub.bin
from CD.
Assuming that the following variables:
gdbstub_bin
is the pointer to the start of the binary, andgdbstub_bin_size
is the size (in bytes) of the binary.
- Copy the binary over to the load address.
(void)memcpy(GDBSTUB_LOAD_ADDRESS, gdbstub_bin, gdbstub_bin_size);
- The driver is the device used to send and receive bytes from/to the GDB stub.
static void
_gdb_device_init(void)
{
usb_cart_init();
}
static uint8_t
_gdb_device_byte_read(void)
{
return usb_cart_byte_read();
}
void
_gdb_device_byte_write(uint8_t value)
{
usb_cart_byte_send(value);
}
- Update the driver interface in the GDB stub header.
gdbstub_t * const gdbstub = (gdbstub_t *)gdbstub_bin;
gdbstub->device->init = _gdb_device_init;
gdbstub->device->byte_read = _gdb_device_byte_read;
gdbstub->device->byte_write = _gdb_device_byte_write;
- Initialize the GDB stub.
gdbstub->init();
See the GDB example on usage.