Debugging Features

The toolchain offers the ability to debug your programs using the CEmu emulator.

Add #include <debug.h> to a source file, and use make debug instead of make to build a debug program. You may need to run make clean beforehand in order to ensure all source files are rebuilt.

Printing to the console

Printing is a classic debugging technique. dbg_printf() allows you to print variables and strings to the CEmu console. It uses the standard printf format specifiers.

Here are some examples:

int var = 10;
unsigned code = 3;

dbg_printf("Initialized some things...\n");
dbg_printf("var value: %d\n", var);
dbg_printf("PROGRAM ABORTED (code = %u)\n", code);

To view the output of these functions within CEmu, enable the console using Docks > Console.

debug.h

#include <debug.h>

API Documentation

These debug functions are provided to help in the process of debugging an application.

To enable them, use make debug when compiling a program.

Defines

dbgout

Standard debug output.

dbgerr

Standard error debug output.

DBG_WATCHPOINT_READ

Break on read.

DBG_WATCHPOINT_WRITE

Break on write.

DBG_WATCHPOINT_EXECUTE

Break on execute.

DBG_WATCHPOINT_ALL

Break on read, write, or execute.

DBG_WATCHPOINT_NONE

Remove watchpoint.

dbg_printf(...)

Used to print to the emulator console.

See the syntax for ‘printf’ for format specifiers.

Note

Does not support floats unless HAS_PRINTF = YES.

Parameters
  • ...[in] Uses printf-formated specifier string.

dbg_sprintf(out, ...)

Used to print to the emulator console.

See the syntax for ‘printf’ for format specifiers.

Note

Does not support floats unless HAS_PRINTF = YES.

Parameters
  • out[in] Use dbgout for normal output and dbgerr for errors.

  • ...[in] Uses printf-formated specifier string.

dbg_ClearConsole()

Clears the emulation console.

Functions

void dbg_Debugger(void)

Opens the emulator’s debugger immediately.

void dbg_WatchpointSet(void *address, size_t size, uint8_t mask)

Sets a watchpoint to open the debugger when an address is read, written, or executed.

Use the masks DBG_WATCHPOINT_READ, DBG_WATCHPOINT_WRITE, and DBG_WATCHPOINT_EXECUTE respectively to configure the watchpoint.

Parameters
  • address[in] Watchpoint address.

  • size[in] Watchpoint size in bytes. Currently must be 1.

  • mask[in] Watchpoint mask, use DBG_WATCHPOINT_NONE to remove the watchpoint.

void dbg_WatchpointRemoveAll(void)

Removes all watchpoints.