Core commit. Compile and run on the OpenPandora
[mupen64plus-pandora.git] / source / mupen64plus-core / doc / emuwiki-api-doc / Mupen64Plus_v2.0_Core_Debugger.txt
1 [[Mupen64Plus v2.0 Core API v1.0|Mupen64Plus v2.0 API]]
2
3 = Mupen64Plus v2.0 Core Debugger API =
4
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.
6
7 == General Debugger Functions ==
8 {| border="1"
9 |Prototype
10 |'''<tt>m64p_error DebugSetCallbacks(void (*dbg_frontend_init)(void), void (*dbg_frontend_update)(unsigned int pc), void (*dbg_frontend_vi)(void))</tt>'''
11 |-
12 |Input Parameters
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.
16 |-
17 |Requirements
18 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
19 |-
20 |Usage
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.
22 |}
23 <br />
24 {| border="1"
25 |Prototype
26 |'''<tt>m64p_error DebugSetCoreCompare(void (*dbg_core_compare)(unsigned int), void (*dbg_core_data_sync)(int, void *))</tt>'''
27 |-
28 |Input Parameters
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.
31 |-
32 |Requirements
33 |The Mupen64Plus library must be initialized before calling this function.
34 |-
35 |Usage
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.
37 |}
38 <br />
39 {| border="1"
40 |Prototype
41 |'''<tt>m64p_error DebugSetRunState(int runstate)</tt>'''
42 |-
43 |Input Parameters
44 |'''<tt>runstate</tt>''' 0 == pause, 1 == single instruction step, 2 == run
45 |-
46 |Requirements
47 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
48 |-
49 |Usage
50 |This function sets the run state of the R4300 CPU emulator.
51 |}
52 <br />
53 {| border="1"
54 |Prototype
55 |'''<tt>int DebugGetState(m64p_dbg_state statenum)</tt>'''
56 |-
57 |Input Parameters
58 |'''<tt>statenum</tt>''' An <tt>m64p_dbg_state</tt> enumerated type specifying which debugger state variable to read.
59 |-
60 |Requirements
61 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
62 |-
63 |Usage
64 |This function reads and returns a debugger state variable, which are enumerated in [[Mupen64Plus v2.0 headers#m64p_types.h|m64p_types.h]].
65 |}
66 <br />
67 {| border="1"
68 |Prototype
69 |'''<tt>m64p_error DebugStep(void)</tt>'''
70 |-
71 |Requirements
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.
73 |-
74 |Usage
75 |This function signals the debugger to advance one instruction when in the stepping mode.
76 |}
77 <br />
78 {| border="1"
79 |Prototype
80 |'''<tt>void DebugDecodeOp(unsigned int instruction, char *op, char *args, int pc)</tt>'''
81 |-
82 |Input Parameters
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
87 |-
88 |Requirements
89 |The Mupen64Plus library must be built with debugger support.
90 |-
91 |Usage
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.
93 |}
94
95 == Memory Functions ==
96 {| border="1"
97 |Prototype
98 |'''<tt>void * DebugMemGetRecompInfo(m64p_dbg_mem_info recomp_type, unsigned int address, int index)</tt>'''
99 |-
100 |Input Parameters
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.
104 |-
105 |Requirements
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.
107 |-
108 |Usage
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.
110 |}
111 <br />
112 {| border="1"
113 |Prototype
114 |'''<tt>int DebugMemGetMemInfo(m64p_dbg_mem_info mem_info_type, unsigned int address)</tt>'''
115 |-
116 |Input Parameters
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.
119 |-
120 |Requirements
121 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
122 |-
123 |Usage
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>.
125 |}
126 <br />
127 {| border="1"
128 |Prototype
129 |'''<tt>void * DebugMemGetPointer(m64p_dbg_memptr_type mem_ptr_type)</tt>'''
130 |-
131 |Input Parameters
132 |'''<tt>mem_ptr_type</tt>''' Memory type to which a pointer is requested.
133 |-
134 |Requirements
135 |The Mupen64Plus library must be initialized before calling this function.
136 |-
137 |Usage
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]]
139 |}
140 <br />
141 {| border="1"
142 |Prototype
143 |
144 {|
145 |-
146 |'''<tt>unsigned long long</tt>''' || '''<tt>DebugMemRead64(unsigned int address)</tt>'''
147 |-
148 |'''<tt>unsigned int</tt>''' || '''<tt>DebugMemRead32(unsigned int address)</tt>'''
149 |-
150 |'''<tt>unsigned short</tt>''' || '''<tt>DebugMemRead16(unsigned int address)</tt>'''
151 |-
152 |'''<tt>unsigned char</tt>''' || '''<tt>DebugMemRead8(unsigned int address)</tt>'''
153 |}
154 |-
155 |Input Parameters
156 |'''<tt>address</tt>''' Memory location (in N64 memory space) from which to retrieve a value.<br />
157 |-
158 |Requirements
159 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
160 |-
161 |Usage
162 |These functions retrieve a value from the emulated N64 memory.  The returned value will be correctly byte-swapped for the host architecture.
163 |}
164 <br />
165 {| border="1"
166 |Prototype
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>'''
171 |-
172 |Input Parameters
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.
175 |-
176 |Requirements
177 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
178 |-
179 |Usage
180 |These functions write a value into the emulated N64 memory.  The given value will be correctly byte-swapped before storage.
181 |}
182
183 == R4300 CPU Functions ==
184 {| border="1"
185 |Prototype
186 |'''<tt>void *DebugGetCPUDataPtr(m64p_dbg_cpu_data cpu_data_type)</tt>'''
187 |-
188 |Input Parameters
189 |'''<tt>cpu_data_type</tt>''' CPU register type to which a pointer is requested.<br />
190 |-
191 |Requirements
192 |The Mupen64Plus library must be initialized before calling this function.
193 |-
194 |Usage
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.
196 |}
197
198 == Breakpoint Functions ==
199 {| border="1"
200 |Prototype
201 |'''<tt>int DebugBreakpointLookup(unsigned int address, unsigned int size, unsigned int flags)</tt>'''
202 |-
203 |Input Parameters
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
207 |-
208 |Requirements
209 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
210 |-
211 |Usage
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.
213 |}
214 <br />
215 {| border="1"
216 |Prototype
217 |'''<tt>int DebugBreakpointCommand(m64p_dbg_bkp_command command, unsigned int index, void *ptr)</tt>'''
218 |-
219 |Input Parameters
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
223 |-
224 |Requirements
225 |The Mupen64Plus library must be built with debugger support and must be initialized before calling this function.
226 |-
227 |Usage
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]].
229 |}
230 <br />
231 {| border="1"
232 !Command!!Return Value!!Function!!<tt>index</tt> Parameter!!<tt>ptr</tt> Parameter
233 |-
234 |M64P_BKP_CMD_ADD_ADDR
235 |Index of new breakpoint
236 |Add an execution breakpoint at a given R4300 address.
237 |R4300 address
238 |unused
239 |-
240 |M64P_BKP_CMD_ADD_STRUCT
241 |Index of new breakpoint
242 |Add a custom breakpoint specified in a <tt>breakpoint</tt> structure.
243 |unused
244 |Pointer to <tt>breakpoint</tt> struct of new breakpoint
245 |-
246 |M64P_BKP_CMD_REPLACE
247 |unused
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
251 |-
252 |M64P_BKP_CMD_REMOVE_ADDR
253 |unused
254 |Remove an existing breakpoint
255 |R4300 address of breakpoint to remove
256 |unused
257 |-
258 |M64P_BKP_CMD_REMOVE_IDX
259 |unused
260 |Remove an existing breakpoint
261 |Index of breakpoint to remove
262 |unused
263 |-
264 |M64P_BKP_CMD_ENABLE
265 |unused
266 |Enable a specified breakpoint
267 |Index of breakpoint to enable
268 |unused
269 |-
270 |M64P_BKP_CMD_DISABLE
271 |unused
272 |Disable a specified breakpoint
273 |Index of breakpoint to disable
274 |unused
275 |-
276 |M64P_BKP_CMD_CHECK
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
280 |unused
281 |}
282