DGen/SDL
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Macros | Functions | Variables
debug.cpp File Reference
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <assert.h>
#include "musa/m68k.h"
#include "pd.h"
#include "md.h"
#include "system.h"
#include "debug.h"
#include "linenoise/linenoise.h"

Classes

class  md
 List of commands. More...

Macros

#define CURRENT_DEBUG_CONTEXT_NAME   debug_context_names[debug_context]
#define REGID(id)   { # id, M68K_REG_ ## id }
#define PRINT_Z80_FLAGS(x)
#define MAX_DISASM   128

Functions

void completion (const char *buf, linenoiseCompletions *lc)
 Linenoise completion callback.
static int debug_strtou32 (const char *str, uint32_t *ret)
 A simple wrapper around strtoul() with error check.
static int debug_is_bp_set ()
 Check if at least one breakpoint is set.
static int debug_is_wp_set ()
 Check if at least one watchpoint is set.
static int debug_next_free_wp_m68k ()
 Get the ID of the next free M68K watchpoint.
static int debug_next_free_bp_m68k ()
 Get the ID of the next free M68K breakpoint.
void debug_init ()
 Initialise the debugger.
static int debug_find_bp_m68k (uint32_t addr)
 Find the index of a M68K breakpoint.
static int debug_find_wp_m68k (uint32_t addr)
 Find the index of a M68K watchpoint by its start address.
static void debug_m68k_bp_set_hit ()
 Set a global flag to enter the debugger when hitting a breakpoint.
static void debug_m68k_wp_set_hit ()
 Set a global flag to enter the debugger when hitting a watchpoint.
static void debug_print_hex_buf (unsigned char *buf, size_t len, size_t addr_label_start)
 Pretty prints hex dump.
static void debug_print_wp (int idx)
 Print a watchpoint in a human-readable form.
static int debug_should_wp_fire (struct dgen_wp *w)
 Check the given watchpoint against cached memory to see if it should fire.
int debug_musa_callback ()
 Breakpoint/watchpoint handler for Musashi, fired before every M68K instruction.
static void debug_rm_bp_m68k (int index)
 Remove a M68K breakpoint.
static void debug_rm_wp_m68k (int index)
 Remove a M68K watchpoint.
static void debug_list_bps_m68k ()
 Pretty print M68K breakpoints.
static void debug_list_wps_m68k ()
 Pretty print M68K watchpoints.
static int debug_set_bp_m68k (uint32_t addr)
 Add a M68K breakpoint.
static int debug_parse_cpu (char *arg)
 Convert a core name to a context ID.
uint32_t m68k_read_disassembler_8 (unsigned int addr)
uint32_t m68k_read_disassembler_16 (unsigned int addr)
uint32_t m68k_read_disassembler_32 (unsigned int addr)

Variables

struct dgen_bp debug_bp_m68k [MAX_BREAKPOINTS]
struct dgen_wp debug_wp_m68k [MAX_WATCHPOINTS]
int debug_step_m68k
unsigned int debug_trace_m68k
int m68k_bp_hit = 0
int m68k_wp_hit = 0
int debug_context = DBG_CONTEXT_M68K
const char * debug_context_names []
const char * psg_aliases [] = { "sn", "sn76489", "psg", NULL }
 Aliases for the various cores.
const char * fm_aliases [] = { "fm", "ym", "ym2612", NULL }
 Aliases for YM2612 core.
const char * z80_aliases [] = { "z80", "z", NULL}
 Aliases for Z80 core.
const char * m68k_aliases [] = { "m68k", "m", "68000", "m68000", NULL}
 Aliases for M68K core.

Macro Definition Documentation

#define CURRENT_DEBUG_CONTEXT_NAME   debug_context_names[debug_context]
#define MAX_DISASM   128
#define PRINT_Z80_FLAGS (   x)
Value:
printf("\t <S=%u, Z= %u, H=%u, P/V=%u, N=%u, C=%u>\n", \
(x & Z80_SR_SIGN) ? 1 : 0, \
(x & Z80_SR_ZERO) ? 1 : 0, \
(x & Z80_SR_HALF_CARRY) ? 1 : 0, \
(x & Z80_SR_PARITY_OVERFLOW) ? 1 : 0, \
(x & Z80_SR_ADD_SUB) ? 1 : 0, \
(x & Z80_SR_CARRY) ? 1 : 0);
#define REGID (   id)    { # id, M68K_REG_ ## id }

Function Documentation

void completion ( const char *  buf,
linenoiseCompletions lc 
)

Linenoise completion callback.

Parameters:
bufString so far.
lcList of linenoise completions.
static int debug_find_bp_m68k ( uint32_t  addr)
static

Find the index of a M68K breakpoint.

Parameters:
addrAddress to look for.
Returns:
-1 if no breakpoint is found, otherwise its index in debug_bp_m68k[].
static int debug_find_wp_m68k ( uint32_t  addr)
static

Find the index of a M68K watchpoint by its start address.

Parameters:
addrAddress to look for.
Returns:
-1 if no watchpoint at the given address, otherwise its index in debug_wp_m68k[].
void debug_init ( void  )

Initialise the debugger.

All breakpoints are disabled by default.

static int debug_is_bp_set ( )
static

Check if at least one breakpoint is set.

Returns:
1 if true, or if the user has "stepped", 0 otherwise.
static int debug_is_wp_set ( )
static

Check if at least one watchpoint is set.

Returns:
1 if true, 0 otherwise.
static void debug_list_bps_m68k ( )
static

Pretty print M68K breakpoints.

static void debug_list_wps_m68k ( )
static

Pretty print M68K watchpoints.

static void debug_m68k_bp_set_hit ( )
static

Set a global flag to enter the debugger when hitting a breakpoint.

static void debug_m68k_wp_set_hit ( )
static

Set a global flag to enter the debugger when hitting a watchpoint.

int debug_musa_callback ( void  )

Breakpoint/watchpoint handler for Musashi, fired before every M68K instruction.

Returns:
1 if a break/watchpoint is hit, 0 otherwise.
static int debug_next_free_bp_m68k ( )
static

Get the ID of the next free M68K breakpoint.

Returns:
ID or -1 if none free.
static int debug_next_free_wp_m68k ( )
static

Get the ID of the next free M68K watchpoint.

Returns:
ID or -1 if none free.
static int debug_parse_cpu ( char *  arg)
static

Convert a core name to a context ID.

Parameters:
[in]argNUL-terminated core name.
Returns:
Core context ID or -1 on error.
static void debug_print_hex_buf ( unsigned char *  buf,
size_t  len,
size_t  addr_label_start 
)
static

Pretty prints hex dump.

Parameters:
[in]bufBuffer to pretty print.
lenNumber of bytes to print.
addr_label_startThe address of the first byte.
static void debug_print_wp ( int  idx)
static

Print a watchpoint in a human-readable form.

Parameters:
idxIndex of watchpoint to print.
static void debug_rm_bp_m68k ( int  index)
static

Remove a M68K breakpoint.

Parameters:
indexIndex of breakpoint to remove.
static void debug_rm_wp_m68k ( int  index)
static

Remove a M68K watchpoint.

Parameters:
indexIndex of watchpoint to remove.
static int debug_set_bp_m68k ( uint32_t  addr)
static

Add a M68K breakpoint.

Parameters:
addrAddress to break on.
Returns:
Always 1.
static int debug_should_wp_fire ( struct dgen_wp w)
static

Check the given watchpoint against cached memory to see if it should fire.

Parameters:
[in]wWatch point to check.
Returns:
1 if true, else 0.
static int debug_strtou32 ( const char *  str,
uint32_t *  ret 
)
static

A simple wrapper around strtoul() with error check.

Parameters:
[in]strString to convert to number.
[out]retNumber "str" represents.
Returns:
-1 on error.
uint32_t m68k_read_disassembler_16 ( unsigned int  addr)
uint32_t m68k_read_disassembler_32 ( unsigned int  addr)
uint32_t m68k_read_disassembler_8 ( unsigned int  addr)

Callbacks for Musashi.


Variable Documentation

struct dgen_bp debug_bp_m68k[MAX_BREAKPOINTS]
int debug_context = DBG_CONTEXT_M68K
const char* debug_context_names[]
Initial value:
{"M68K", "Z80", "YM2612", "SN76489"}
int debug_step_m68k
unsigned int debug_trace_m68k
struct dgen_wp debug_wp_m68k[MAX_WATCHPOINTS]
const char* fm_aliases[] = { "fm", "ym", "ym2612", NULL }

Aliases for YM2612 core.

const char* m68k_aliases[] = { "m68k", "m", "68000", "m68000", NULL}

Aliases for M68K core.

int m68k_bp_hit = 0
int m68k_wp_hit = 0
const char* psg_aliases[] = { "sn", "sn76489", "psg", NULL }

Aliases for the various cores.

Aliases for SN76489 core.

const char* z80_aliases[] = { "z80", "z", NULL}

Aliases for Z80 core.