1 [[Mupen64Plus v2.0 Core API v1.0|Mupen64Plus v2.0 API]]
3 = Mupen64Plus v2.0 Core Debugger API =
5 Most libmupen64plus functions return an <tt>m64p_error</tt> return code, which is an enumerated type defined in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]]. Front-end code should check the return value of each call to a libmupen64plus function.
7 == General Debugger Functions ==
10 |'''<tt>m64p_error DebugSetCallbacks(void (*dbg_frontend_init)(void), void (*dbg_frontend_update)(unsigned int pc), void (*dbg_frontend_vi)(void))</tt>'''
13 |'''<tt>dbg_frontend_init</tt>''' Pointer to function which is called when debugger is initialized.<br />
14 '''<tt>dbg_frontend_update</tt>''' Pointer to function which is called after debugger hits a breakpoint or executes one instruction in stepping mode.<br />
15 '''<tt>dbg_frontend_vi</tt>''' Pointer to function which is called during each vertical interrupt.
18 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
21 |This function is called by the front-end to supply debugger callback function pointers. If debugger is enabled and then later disabled within the GUI, this function may be called with NULL pointers in order to disable the callbacks.
26 |'''<tt>m64p_error DebugSetCoreCompare(void (*dbg_core_compare)(unsigned int), void (*dbg_core_data_sync)(int, void *))</tt>'''
29 |'''<tt>dbg_core_compare</tt>''' Pointer to function which is called after each R4300 instruction, for comparing the operation of one R4300 emulator core against another.<br />
30 '''<tt>dbg_core_data_sync</tt>''' Pointer to function which is used to transfer data from the sending emulator core to the receiving core, such as controller button press or movement data.
33 |The Mupen64Plus library must be initialized before calling this function.
36 |This function is called by the front-end to supply callback function pointers for the Core Comparison feature. This feature is designed to work as follows. The front-end application will set up some channel for communicating data between two separately running instances of mupen64plus. For example, the unix console front-end will use named FIFOs. The front-end will register callback functions for comparing the 2 cores' states via this <tt>DebugSetCoreCompare</tt> API call. When the <tt>dbg_core_compare</tt> callback fires, the front-end will use the <tt>DebugGetCPUDataPtr</tt> function (and <tt>DebugMemGetPointer</tt> function if desired) to transmit emulator core state data from the 'sending' instance to the 'receiving' instance. The receiving instance may then check the core state data against it's own internal state and report any discrepancies. When the <tt>dbg_core_data_sync</tt> callback fires, the front-end should transmit a block of data from the sending instance to the receiving instance. This is for the purposes of synchronizing events such as controller inputs or state loading commands, so that the 2 cores may stay synchronized. This feature does not require the <tt>M64CAPS_DEBUGGER</tt> capability to built into the core, but it does require the <tt>M64CAPS_CORE_COMPARE</tt> capability.
41 |'''<tt>m64p_error DebugSetRunState(int runstate)</tt>'''
44 |'''<tt>runstate</tt>''' 0 == pause, 1 == single instruction step, 2 == run
47 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
50 |This function sets the run state of the R4300 CPU emulator.
55 |'''<tt>int DebugGetState(m64p_dbg_state statenum)</tt>'''
58 |'''<tt>statenum</tt>''' An <tt>m64p_dbg_state</tt> enumerated type specifying which debugger state variable to read.
61 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
64 |This function reads and returns a debugger state variable, which are enumerated in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]].
69 |'''<tt>m64p_error DebugStep(void)</tt>'''
72 |The Mupen64Plus library must be built with debugger support and must be initialized, the emulator core must be executing a ROM, and the debugger must be active before calling this function.
75 |This function signals the debugger to advance one instruction when in the stepping mode.
80 |'''<tt>void DebugDecodeOp(unsigned int instruction, char *op, char *args, int pc)</tt>'''
83 |'''<tt>instruction</tt>''' 32-bit R4300 instruction opcode<br />
84 '''<tt>op</tt>''' Pointer to character array to store decoded instruction mnemonic<br />
85 '''<tt>args</tt>''' Pointer to character array to store instruction arguments<br />
86 '''<tt>pc</tt>''' Program Counter address at which '''<tt>instruction</tt>''' is stored
89 |The Mupen64Plus library must be built with debugger support.
92 |This is a helper function for the debugger front-end. This instruction takes a PC value and an R4300 instruction opcode and writes the disassembled instruction mnemonic and arguments into character buffers. This is intended to be used to display disassembled code.
95 == Memory Functions ==
98 |'''<tt>void * DebugMemGetRecompInfo(m64p_dbg_mem_info recomp_type, unsigned int address, int index)</tt>'''
101 |'''<tt>recomp_type</tt>''' Type of information to retrieve about a recompiled machine instruction. Must be a M64P_DBG_RECOMP_* type.<br />
102 '''<tt>address</tt>''' Program Counter value (in N64 memory space) of R4300 instruction about which to retrieve the recompiled x86 instructions.<br />
103 '''<tt>index</tt>''' Index of recompiled instruction about which to receive information.
106 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function. This function may not be available on all platforms.
109 |This function is used by the front-end to retrieve disassembly information about recompiled code. For example, the dynamic recompiler may take a single R4300 instruction and compile it into 10 x86 instructions. This function may then be used to retrieve the disassembled code of the 10 x86 instructions. For '''<tt>recomp_type</tt>''' of <tt>M64P_DBG_RECOMP_OPCODE</tt> or <tt>M64P_DBG_RECOMP_ARGS</tt>, a character pointer will be returned which gives the disassembled instruction code. For '''<tt>recomp_type</tt>''' of <tt>M64P_DBG_RECOMP_ADDR</tt>, a pointer to the recompiled x86 instruction will be given.
114 |'''<tt>int DebugMemGetMemInfo(m64p_dbg_mem_info mem_info_type, unsigned int address)</tt>'''
117 |'''<tt>mem_info_type</tt>''' Type of information to retrieve about an N64 memory location. Must be a M64P_DBG_MEM_* type.<br />
118 '''<tt>address</tt>''' Memory location (in N64 memory space) about which to retrieve some information.
121 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
124 |This function returns an integer value regarding the memory location '''<tt>address</tt>''', corresponding to the information requested by '''<tt>mem_info_type</tt>''', which is a type enumerated in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]]. For example, if '''<tt>address</tt>''' contains R4300 program code, the front-end may request the number of x86 instructions emitted by the dynamic recompiler by requesting <tt>M64P_DBG_MEM_NUM_RECOMPILED</tt>.
129 |'''<tt>void * DebugMemGetPointer(m64p_dbg_memptr_type mem_ptr_type)</tt>'''
132 |'''<tt>mem_ptr_type</tt>''' Memory type to which a pointer is requested.
135 |The Mupen64Plus library must be initialized before calling this function.
138 |This function returns a memory pointer (in x86 memory space) to a block of emulated N64 memory. This may be used to retrieve a pointer to a special N64 block (such as the serial, video, or audio registers) or the RDRAM. The '''<tt>m64p_dbg_memptr_type</tt>''' type is enumerated in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]]
146 |'''<tt>unsigned long long</tt>''' || '''<tt>DebugMemRead64(unsigned int address)</tt>'''
148 |'''<tt>unsigned int</tt>''' || '''<tt>DebugMemRead32(unsigned int address)</tt>'''
150 |'''<tt>unsigned short</tt>''' || '''<tt>DebugMemRead16(unsigned int address)</tt>'''
152 |'''<tt>unsigned char</tt>''' || '''<tt>DebugMemRead8(unsigned int address)</tt>'''
156 |'''<tt>address</tt>''' Memory location (in N64 memory space) from which to retrieve a value.<br />
159 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
162 |These functions retrieve a value from the emulated N64 memory. The returned value will be correctly byte-swapped for the host architecture.
167 |'''<tt>void DebugMemWrite64(unsigned int address, unsigned long long value)</tt>'''<br />
168 '''<tt>void DebugMemWrite32(unsigned int address, unsigned int value)</tt>'''<br />
169 '''<tt>void DebugMemWrite16(unsigned int address, unsigned short value)</tt>'''<br />
170 '''<tt>void DebugMemWrite8(unsigned int address, unsigned char value)</tt>'''
173 |'''<tt>address</tt>''' Memory location (in N64 memory space) to which to write a value.<br />
174 '''<tt>value</tt>''' Value to write into emulated memory.
177 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
180 |These functions write a value into the emulated N64 memory. The given value will be correctly byte-swapped before storage.
183 == R4300 CPU Functions ==
186 |'''<tt>void *DebugGetCPUDataPtr(m64p_dbg_cpu_data cpu_data_type)</tt>'''
189 |'''<tt>cpu_data_type</tt>''' CPU register type to which a pointer is requested.<br />
192 |The Mupen64Plus library must be initialized before calling this function.
195 |This function returns a memory pointer (in x86 memory space) to a specific register in the emulated R4300 CPU. The '''<tt>m64p_dbg_cpu_data</tt>''' type is enumerated in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]]. It is important to note that when the R4300 CPU core is in the Cached Interpreter or Dynamic Recompiler modes, the address of the PC register is not constant; it will change after each instruction is executed. The pointers to all other registers will never change, as the other registers are global variables.
198 == Breakpoint Functions ==
201 |'''<tt>int DebugBreakpointLookup(unsigned int address, unsigned int size, unsigned int flags)</tt>'''
204 |'''<tt>address</tt>''' Starting address (in R4300 memory space) to search<br />
205 '''<tt>size</tt>''' Size of address space in bytes to search<br />
206 '''<tt>flags</tt>''' Breakpoint flags
209 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
212 |This function searches through all current breakpoints in the debugger to find one that matches the given input parameters. If a matching breakpoint is found, the index number is returned. If no breakpoints are found, -1 is returned.
217 |'''<tt>int DebugBreakpointCommand(m64p_dbg_bkp_command command, unsigned int index, void *ptr)</tt>'''
220 |'''<tt>command</tt>''' Enumerated value specifying the breakpoint command to execute<br />
221 '''<tt>index</tt>''' Purpose varies by command, see table below<br />
222 '''<tt>ptr</tt>''' Purpose varies by command, see table below
225 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
228 |This function is used to process common breakpoint commands, such as adding, removing, or searching the breakpoints. The meanings of the '''<tt>index</tt>''' and '''<tt>ptr</tt>''' input parameters vary by command, and are given in the table below. The '''<tt>m64p_dbg_bkp_command</tt>''' type is enumerated in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]].
232 !Command!!Return Value!!Function!!<tt>index</tt> Parameter!!<tt>ptr</tt> Parameter
234 |M64P_BKP_CMD_ADD_ADDR
235 |Index of new breakpoint
236 |Add an execution breakpoint at a given R4300 address.
240 |M64P_BKP_CMD_ADD_STRUCT
241 |Index of new breakpoint
242 |Add a custom breakpoint specified in a <tt>breakpoint</tt> structure.
244 |Pointer to <tt>breakpoint</tt> struct of new breakpoint
246 |M64P_BKP_CMD_REPLACE
248 |Replace an existing breakpoint with one specified by a <tt>breakpoint</tt> structure.
249 |Index of breakpoint to replace
250 |Pointer to <tt>breakpoint</tt> struct of new breakpoint
252 |M64P_BKP_CMD_REMOVE_ADDR
254 |Remove an existing breakpoint
255 |R4300 address of breakpoint to remove
258 |M64P_BKP_CMD_REMOVE_IDX
260 |Remove an existing breakpoint
261 |Index of breakpoint to remove
266 |Enable a specified breakpoint
267 |Index of breakpoint to enable
270 |M64P_BKP_CMD_DISABLE
272 |Disable a specified breakpoint
273 |Index of breakpoint to disable
277 |Index of breakpoint if found, otherwise -1
278 |Search for an execution breakpoint at a given address
279 |R4300 address at which to search