451ab91e |
1 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | * Mupen64plus - debugger.c * |
3 | * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ * |
4 | * Copyright (C) 2008 DarkJeztr * |
5 | * Copyright (C) 2002 davFr * |
6 | * * |
7 | * This program is free software; you can redistribute it and/or modify * |
8 | * it under the terms of the GNU General Public License as published by * |
9 | * the Free Software Foundation; either version 2 of the License, or * |
10 | * (at your option) any later version. * |
11 | * * |
12 | * This program is distributed in the hope that it will be useful, * |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 | * GNU General Public License for more details. * |
16 | * * |
17 | * You should have received a copy of the GNU General Public License * |
18 | * along with this program; if not, write to the * |
19 | * Free Software Foundation, Inc., * |
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
21 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
22 | |
23 | #include <SDL.h> |
24 | |
25 | #include "api/debugger.h" |
26 | |
27 | #include "dbg_types.h" |
28 | #include "debugger.h" |
29 | #include "dbg_breakpoints.h" |
30 | #include "dbg_memory.h" |
31 | |
32 | // State of the Emulation Thread: |
33 | // 0 -> pause, 2 -> run. |
34 | |
35 | int g_DebuggerActive = 0; // whether the debugger is enabled or not |
36 | int run; |
37 | |
38 | static SDL_cond *debugger_done_cond; |
39 | static SDL_mutex *mutex; |
40 | |
41 | uint32 previousPC; |
42 | |
43 | //]=-=-=-=-=-=-=-=-=-=-=[ Initialisation du Debugger ]=-=-=-=-=-=-=-=-=-=-=-=[ |
44 | |
45 | void init_debugger() |
46 | { |
47 | g_DebuggerActive = 1; |
48 | run = 0; |
49 | |
50 | DebuggerCallback(DEBUG_UI_INIT, 0); /* call front-end to initialize user interface */ |
51 | |
52 | init_host_disassembler(); |
53 | |
54 | mutex = SDL_CreateMutex(); |
55 | debugger_done_cond = SDL_CreateCond(); |
56 | } |
57 | |
58 | void destroy_debugger() |
59 | { |
60 | SDL_DestroyMutex(mutex); |
61 | mutex = NULL; |
62 | SDL_DestroyCond(debugger_done_cond); |
63 | debugger_done_cond = NULL; |
64 | g_DebuggerActive = 0; |
65 | } |
66 | |
67 | //]=-=-=-=-=-=-=-=-=-=-=-=-=[ Mise-a-Jour Debugger ]=-=-=-=-=-=-=-=-=-=-=-=-=[ |
68 | |
69 | void update_debugger(uint32 pc) |
70 | // Update debugger state and display. |
71 | // Should be called after each R4300 instruction |
72 | // Checks for breakpoint hits on PC |
73 | { |
74 | int bpt; |
75 | |
76 | if(run!=0) {//check if we hit a breakpoint |
77 | bpt = check_breakpoints(pc); |
78 | if( bpt!=-1 ) { |
79 | run = 0; |
80 | |
81 | if(BPT_CHECK_FLAG(g_Breakpoints[bpt], BPT_FLAG_LOG)) |
82 | log_breakpoint(pc, BPT_FLAG_EXEC, 0); |
83 | } |
84 | } |
85 | |
86 | if(run!=2) { |
87 | DebuggerCallback(DEBUG_UI_UPDATE, pc); /* call front-end to notify user interface to update */ |
88 | } |
89 | if(run==0) { |
90 | // Emulation thread is blocked until a button is clicked. |
91 | SDL_mutexP(mutex); |
92 | SDL_CondWait(debugger_done_cond, mutex); |
93 | SDL_mutexV(mutex); |
94 | } |
95 | |
96 | previousPC = pc; |
97 | } |
98 | |
99 | void debugger_step() |
100 | { |
101 | SDL_CondSignal(debugger_done_cond); |
102 | } |
103 | |
104 | |