Fix a segmentation fault when changing perspectives.
[dolphin.git] / Source / Core / DebuggerWX / Src / CodeWindow.cpp
bloba1cc531ecdbb48c778acd76ed7416fd538e808cb
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 // Include
19 #include "Common.h"
21 #include <wx/button.h>
22 #include <wx/textctrl.h>
23 #include <wx/textdlg.h>
24 #include <wx/listctrl.h>
25 #include <wx/thread.h>
26 #include <wx/mstream.h>
27 #include <wx/tipwin.h>
29 #include "Host.h"
31 #include "Debugger.h"
33 #include "RegisterWindow.h"
34 #include "BreakpointWindow.h"
35 #include "MemoryWindow.h"
36 #include "JitWindow.h"
38 #include "CodeWindow.h"
39 #include "CodeView.h"
41 #include "FileUtil.h"
42 #include "Core.h"
43 #include "HW/Memmap.h"
44 #include "HLE/HLE.h"
45 #include "Boot/Boot.h"
46 #include "LogManager.h"
47 #include "HW/CPU.h"
48 #include "PowerPC/PowerPC.h"
49 #include "Debugger/PPCDebugInterface.h"
50 #include "Debugger/Debugger_SymbolMap.h"
51 #include "PowerPC/PPCAnalyst.h"
52 #include "PowerPC/Profiler.h"
53 #include "PowerPC/PPCSymbolDB.h"
54 #include "PowerPC/SignatureDB.h"
55 #include "PowerPC/PPCTables.h"
56 #include "PowerPC/JitCommon/JitBase.h"
57 #include "PowerPC/JitCommon/JitCache.h" // for ClearCache()
59 #include "PluginManager.h"
60 #include "ConfigManager.h"
62 extern "C" // Bitmaps
64 #include "../resources/toolbar_play.c"
65 #include "../resources/toolbar_pause.c"
66 #include "../resources/toolbar_add_memorycheck.c"
67 #include "../resources/toolbar_delete.c"
68 #include "../resources/toolbar_add_breakpoint.c"
71 class CPluginInfo;
72 class CPluginManager;
74 // -------
75 // Main
77 BEGIN_EVENT_TABLE(CCodeWindow, wxPanel)
79 // Menu bar
80 EVT_MENU(IDM_AUTOMATICSTART, CCodeWindow::OnCPUMode) // Options
81 EVT_MENU(IDM_BOOTTOPAUSE, CCodeWindow::OnCPUMode)
82 EVT_MENU(IDM_FONTPICKER, CCodeWindow::OnChangeFont)
84 EVT_MENU(IDM_INTERPRETER, CCodeWindow::OnCPUMode) // Jit
85 EVT_MENU(IDM_JITNOBLOCKCACHE, CCodeWindow::OnCPUMode)
87 EVT_MENU(IDM_JITOFF, CCodeWindow::OnCPUMode)
88 EVT_MENU(IDM_JITLSOFF, CCodeWindow::OnCPUMode)
89 EVT_MENU(IDM_JITLSLXZOFF, CCodeWindow::OnCPUMode)
90 EVT_MENU(IDM_JITLSLWZOFF, CCodeWindow::OnCPUMode)
91 EVT_MENU(IDM_JITLSLBZXOFF, CCodeWindow::OnCPUMode)
92 EVT_MENU(IDM_JITLSFOFF, CCodeWindow::OnCPUMode)
93 EVT_MENU(IDM_JITLSPOFF, CCodeWindow::OnCPUMode)
94 EVT_MENU(IDM_JITFPOFF, CCodeWindow::OnCPUMode)
95 EVT_MENU(IDM_JITIOFF, CCodeWindow::OnCPUMode)
96 EVT_MENU(IDM_JITPOFF, CCodeWindow::OnCPUMode)
97 EVT_MENU(IDM_JITSROFF, CCodeWindow::OnCPUMode)
99 EVT_MENU(IDM_CLEARCODECACHE, CCodeWindow::OnJitMenu)
100 EVT_MENU(IDM_LOGINSTRUCTIONS, CCodeWindow::OnJitMenu)
101 EVT_MENU(IDM_SEARCHINSTRUCTION, CCodeWindow::OnJitMenu)
103 EVT_MENU(IDM_REGISTERWINDOW, CCodeWindow::OnToggleWindow) // View
104 EVT_MENU(IDM_BREAKPOINTWINDOW, CCodeWindow::OnToggleWindow)
105 EVT_MENU(IDM_MEMORYWINDOW, CCodeWindow::OnToggleWindow)
106 EVT_MENU(IDM_JITWINDOW, CCodeWindow::OnToggleWindow)
107 EVT_MENU(IDM_SOUNDWINDOW, CCodeWindow::OnToggleWindow)
108 EVT_MENU(IDM_VIDEOWINDOW, CCodeWindow::OnToggleWindow)
110 EVT_MENU(IDM_CLEARSYMBOLS, CCodeWindow::OnSymbolsMenu)
111 EVT_MENU(IDM_LOADMAPFILE, CCodeWindow::OnSymbolsMenu)
112 EVT_MENU(IDM_SCANFUNCTIONS, CCodeWindow::OnSymbolsMenu)
113 EVT_MENU(IDM_SAVEMAPFILE, CCodeWindow::OnSymbolsMenu)
114 EVT_MENU(IDM_SAVEMAPFILEWITHCODES, CCodeWindow::OnSymbolsMenu)
115 EVT_MENU(IDM_CREATESIGNATUREFILE, CCodeWindow::OnSymbolsMenu)
116 EVT_MENU(IDM_USESIGNATUREFILE, CCodeWindow::OnSymbolsMenu)
117 EVT_MENU(IDM_PATCHHLEFUNCTIONS, CCodeWindow::OnSymbolsMenu)
118 EVT_MENU(IDM_RENAME_SYMBOLS, CCodeWindow::OnSymbolsMenu)
120 EVT_MENU(IDM_PROFILEBLOCKS, CCodeWindow::OnProfilerMenu)
121 EVT_MENU(IDM_WRITEPROFILE, CCodeWindow::OnProfilerMenu)
123 // Toolbar
124 EVT_MENU(IDM_STEP, CCodeWindow::OnCodeStep)
125 EVT_MENU(IDM_STEPOVER, CCodeWindow::OnCodeStep)
126 EVT_MENU(IDM_SKIP, CCodeWindow::OnCodeStep)
127 EVT_MENU(IDM_SETPC, CCodeWindow::OnCodeStep)
128 EVT_MENU(IDM_GOTOPC, CCodeWindow::OnCodeStep)
129 EVT_TEXT(IDM_ADDRBOX, CCodeWindow::OnAddrBoxChange)
131 // Other
132 EVT_LISTBOX(ID_SYMBOLLIST, CCodeWindow::OnSymbolListChange)
133 EVT_LISTBOX(ID_CALLSTACKLIST, CCodeWindow::OnCallstackListChange)
134 EVT_LISTBOX(ID_CALLERSLIST, CCodeWindow::OnCallersListChange)
135 EVT_LISTBOX(ID_CALLSLIST, CCodeWindow::OnCallsListChange)
137 EVT_HOST_COMMAND(wxID_ANY, CCodeWindow::OnHostMessage)
139 END_EVENT_TABLE()
141 // Class
142 CCodeWindow::CCodeWindow(const SCoreStartupParameter& _LocalCoreStartupParameter, CFrame *parent,
143 wxWindowID id, const wxPoint& position, const wxSize& size, long style, const wxString& name)
144 : wxPanel((wxWindow*)parent, id, position, size, style, name)
145 , Parent(parent)
146 , m_RegisterWindow(NULL)
147 , m_BreakpointWindow(NULL)
148 , m_MemoryWindow(NULL)
149 , m_JitWindow(NULL)
150 , codeview(NULL)
152 InitBitmaps();
154 CreateGUIControls(_LocalCoreStartupParameter);
156 // Connect keyboard
157 wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN,
158 wxKeyEventHandler(CCodeWindow::OnKeyDown),
159 (wxObject*)0, this);
162 wxMenuBar *CCodeWindow::GetMenuBar()
164 return Parent->GetMenuBar();
167 wxAuiToolBar *CCodeWindow::GetToolBar()
169 return Parent->m_ToolBarDebug;
172 // ----------
173 // Events
175 void CCodeWindow::OnKeyDown(wxKeyEvent& event)
177 event.Skip();
179 if ((event.GetKeyCode() == WXK_SPACE) && Parent->IsActive()) SingleCPUStep();
182 void CCodeWindow::OnHostMessage(wxCommandEvent& event)
184 switch (event.GetId())
186 case IDM_NOTIFYMAPLOADED:
187 NotifyMapLoaded();
188 break;
190 case IDM_UPDATEDISASMDIALOG:
191 Update();
192 if (codeview) codeview->Center(PC);
193 if (m_RegisterWindow) m_RegisterWindow->NotifyUpdate();
194 break;
196 case IDM_UPDATEBREAKPOINTS:
197 Update();
198 if (m_BreakpointWindow) m_BreakpointWindow->NotifyUpdate();
199 break;
203 // The Play, Stop, Step, Skip, Go to PC and Show PC buttons go here
204 void CCodeWindow::OnCodeStep(wxCommandEvent& event)
206 switch (event.GetId())
208 case IDM_STEP:
209 SingleCPUStep();
210 break;
212 case IDM_STEPOVER:
213 CCPU::EnableStepping(true); // TODO: Huh?
214 break;
216 case IDM_SKIP:
217 PC += 4;
218 Update();
219 break;
221 case IDM_SETPC:
222 PC = codeview->GetSelection();
223 Update();
224 break;
226 case IDM_GOTOPC:
227 JumpToAddress(PC);
228 break;
231 UpdateButtonStates();
232 // Update all toolbars in the aui manager
233 Parent->UpdateGUI();
236 void CCodeWindow::JumpToAddress(u32 _Address)
238 codeview->Center(_Address);
239 UpdateLists();
242 void CCodeWindow::OnCodeViewChange(wxCommandEvent &event)
244 UpdateLists();
247 void CCodeWindow::OnAddrBoxChange(wxCommandEvent& event)
249 if (!GetToolBar()) return;
251 wxTextCtrl* pAddrCtrl = (wxTextCtrl*)GetToolBar()->FindControl(IDM_ADDRBOX);
252 wxString txt = pAddrCtrl->GetValue();
254 std::string text(txt.mb_str());
255 text = StripSpaces(text);
256 if (text.size() == 8)
258 u32 addr;
259 sscanf(text.c_str(), "%08x", &addr);
260 JumpToAddress(addr);
263 event.Skip(1);
266 void CCodeWindow::OnCallstackListChange(wxCommandEvent& event)
268 int index = callstack->GetSelection();
269 if (index >= 0)
271 u32 address = (u32)(u64)(callstack->GetClientData(index));
272 if (address)
273 JumpToAddress(address);
277 void CCodeWindow::OnCallersListChange(wxCommandEvent& event)
279 int index = callers->GetSelection();
280 if (index >= 0)
282 u32 address = (u32)(u64)(callers->GetClientData(index));
283 if (address)
284 JumpToAddress(address);
288 void CCodeWindow::OnCallsListChange(wxCommandEvent& event)
290 int index = calls->GetSelection();
291 if (index >= 0)
293 u32 address = (u32)(u64)(calls->GetClientData(index));
294 if (address)
295 JumpToAddress(address);
299 void CCodeWindow::SingleCPUStep()
301 CCPU::StepOpcode(&sync_event);
302 wxThread::Sleep(20);
303 // need a short wait here
304 JumpToAddress(PC);
305 Update();
306 Host_UpdateLogDisplay();
309 void CCodeWindow::UpdateLists()
311 callers->Clear();
312 u32 addr = codeview->GetSelection();
313 Symbol *symbol = g_symbolDB.GetSymbolFromAddr(addr);
314 if (!symbol)
315 return;
316 for (int i = 0; i < (int)symbol->callers.size(); i++)
318 u32 caller_addr = symbol->callers[i].callAddress;
319 Symbol *caller_symbol = g_symbolDB.GetSymbolFromAddr(caller_addr);
320 if (caller_symbol)
322 int idx = callers->Append(wxString::FromAscii(StringFromFormat
323 ("< %s (%08x)", caller_symbol->name.c_str(), caller_addr).c_str()));
324 callers->SetClientData(idx, (void*)caller_addr);
328 calls->Clear();
329 for (int i = 0; i < (int)symbol->calls.size(); i++)
331 u32 call_addr = symbol->calls[i].function;
332 Symbol *call_symbol = g_symbolDB.GetSymbolFromAddr(call_addr);
333 if (call_symbol)
335 int idx = calls->Append(wxString::FromAscii(StringFromFormat
336 ("> %s (%08x)", call_symbol->name.c_str(), call_addr).c_str()));
337 calls->SetClientData(idx, (void*)call_addr);
342 void CCodeWindow::UpdateCallstack()
344 if (Core::GetState() == Core::CORE_STOPPING) return;
346 callstack->Clear();
348 std::vector<Dolphin_Debugger::CallstackEntry> stack;
350 bool ret = Dolphin_Debugger::GetCallstack(stack);
352 for (size_t i = 0; i < stack.size(); i++)
354 int idx = callstack->Append(wxString::FromAscii(stack[i].Name.c_str()));
355 callstack->SetClientData(idx, (void*)(u64)stack[i].vAddress);
358 if (!ret)
359 callstack->Append(wxString::FromAscii("invalid callstack"));
362 void CCodeWindow::CreateGUIControls(const SCoreStartupParameter& _LocalCoreStartupParameter)
364 // Configure the code window
365 wxBoxSizer* sizerBig = new wxBoxSizer(wxHORIZONTAL);
366 wxBoxSizer* sizerLeft = new wxBoxSizer(wxVERTICAL);
368 DebugInterface* di = &PowerPC::debug_interface;
370 codeview = new CCodeView(di, &g_symbolDB, this, ID_CODEVIEW);
371 sizerBig->Add(sizerLeft, 2, wxEXPAND);
372 sizerBig->Add(codeview, 5, wxEXPAND);
374 sizerLeft->Add(callstack = new wxListBox(this, ID_CALLSTACKLIST,
375 wxDefaultPosition, wxSize(90, 100)), 0, wxEXPAND);
376 sizerLeft->Add(symbols = new wxListBox(this, ID_SYMBOLLIST,
377 wxDefaultPosition, wxSize(90, 100), 0, NULL, wxLB_SORT), 1, wxEXPAND);
378 sizerLeft->Add(calls = new wxListBox(this, ID_CALLSLIST, wxDefaultPosition,
379 wxSize(90, 100), 0, NULL, wxLB_SORT), 0, wxEXPAND);
380 sizerLeft->Add(callers = new wxListBox(this, ID_CALLERSLIST, wxDefaultPosition,
381 wxSize(90, 100), 0, NULL, wxLB_SORT), 0, wxEXPAND);
383 SetSizer(sizerBig);
385 sizerLeft->SetSizeHints(this);
386 sizerLeft->Fit(this);
387 sizerBig->SetSizeHints(this);
388 sizerBig->Fit(this);
390 sync_event.Init();
393 // Create CPU Mode menus
394 void CCodeWindow::CreateMenu(const SCoreStartupParameter& _LocalCoreStartupParameter,
395 wxMenuBar * _pMenuBar)
397 pMenuBar = _pMenuBar;
399 // CPU Mode
400 wxMenu* pCoreMenu = new wxMenu;
402 wxMenuItem* interpreter = pCoreMenu->Append(IDM_INTERPRETER, _T("&Interpreter core")
403 , wxString::FromAscii("This is necessary to get break points"
404 " and stepping to work as explained in the Developer Documentation. But it can be very"
405 " slow, perhaps slower than 1 fps.")
406 , wxITEM_CHECK);
407 interpreter->Check(_LocalCoreStartupParameter.iCPUCore == 0);
408 pCoreMenu->AppendSeparator();
410 jitblocklinking = pCoreMenu->Append(IDM_JITBLOCKLINKING, _T("&JIT Block Linking off"),
411 _T("Provide safer execution by not linking the JIT blocks."),
412 wxITEM_CHECK);
414 jitnoblockcache = pCoreMenu->Append(IDM_JITNOBLOCKCACHE, _T("&Disable JIT Cache"),
415 _T("Avoid any involuntary JIT cache clearing, this may prevent Zelda TP from crashing.")
416 _T(" [This option must be selected before a game is started.]"),
417 wxITEM_CHECK);
418 pCoreMenu->Append(IDM_CLEARCODECACHE, _T("&Clear JIT cache"));
420 pCoreMenu->AppendSeparator();
421 pCoreMenu->Append(IDM_LOGINSTRUCTIONS, _T("&Log JIT instruction coverage"));
422 pCoreMenu->Append(IDM_SEARCHINSTRUCTION, _T("&Search for an op"));
424 pCoreMenu->AppendSeparator();
425 jitoff = pCoreMenu->Append(IDM_JITOFF, _T("&JIT off (JIT core)"),
426 _T("Turn off all JIT functions, but still use the JIT core from Jit.cpp"),
427 wxITEM_CHECK);
428 jitlsoff = pCoreMenu->Append(IDM_JITLSOFF, _T("&JIT LoadStore off"),
429 wxEmptyString, wxITEM_CHECK);
430 jitlslbzxoff = pCoreMenu->Append(IDM_JITLSLBZXOFF, _T(" &JIT LoadStore lbzx off"),
431 wxEmptyString, wxITEM_CHECK);
432 jitlslxzoff = pCoreMenu->Append(IDM_JITLSLXZOFF, _T(" &JIT LoadStore lXz off"),
433 wxEmptyString, wxITEM_CHECK);
434 jitlslwzoff = pCoreMenu->Append(IDM_JITLSLWZOFF, _T(" &JIT LoadStore lwz off"),
435 wxEmptyString, wxITEM_CHECK);
436 jitlspoff = pCoreMenu->Append(IDM_JITLSFOFF, _T("&JIT LoadStore Floating off"),
437 wxEmptyString, wxITEM_CHECK);
438 jitlsfoff = pCoreMenu->Append(IDM_JITLSPOFF, _T("&JIT LoadStore Paired off"),
439 wxEmptyString, wxITEM_CHECK);
440 jitfpoff = pCoreMenu->Append(IDM_JITFPOFF, _T("&JIT FloatingPoint off"),
441 wxEmptyString, wxITEM_CHECK);
442 jitioff = pCoreMenu->Append(IDM_JITIOFF, _T("&JIT Integer off"),
443 wxEmptyString, wxITEM_CHECK);
444 jitpoff = pCoreMenu->Append(IDM_JITPOFF, _T("&JIT Paired off"),
445 wxEmptyString, wxITEM_CHECK);
446 jitsroff = pCoreMenu->Append(IDM_JITSROFF, _T("&JIT SystemRegisters off"),
447 wxEmptyString, wxITEM_CHECK);
449 pMenuBar->Append(pCoreMenu, _T("&JIT"));
451 CreateMenuSymbols();
454 // Create View menu
455 void CCodeWindow::CreateMenuView(wxMenuBar * _pMenuBar, wxMenu* _pMenu)
457 wxMenuItem* pRegister = _pMenu->Append(IDM_REGISTERWINDOW, _T("&Registers"),
458 wxEmptyString, wxITEM_CHECK);
459 pRegister->Check(bRegisterWindow);
460 wxMenuItem* pBreakPoints = _pMenu->Append(IDM_BREAKPOINTWINDOW, _T("&BreakPoints"),
461 wxEmptyString, wxITEM_CHECK);
462 pBreakPoints->Check(bBreakpointWindow);
463 wxMenuItem* pMemory = _pMenu->Append(IDM_MEMORYWINDOW, _T("&Memory"),
464 wxEmptyString, wxITEM_CHECK);
465 pMemory->Check(bMemoryWindow);
466 wxMenuItem* pJit = _pMenu->Append(IDM_JITWINDOW, _T("&Jit"),
467 wxEmptyString, wxITEM_CHECK);
468 pJit->Check(bJitWindow);
469 wxMenuItem* pSound = _pMenu->Append(IDM_SOUNDWINDOW, _T("&Sound"),
470 wxEmptyString, wxITEM_CHECK);
471 pSound->Check(bSoundWindow);
472 wxMenuItem* pVideo = _pMenu->Append(IDM_VIDEOWINDOW, _T("&Video"),
473 wxEmptyString, wxITEM_CHECK);
474 pVideo->Check(bVideoWindow);
477 void CCodeWindow::CreateMenuOptions(wxMenuBar * _pMenuBar, wxMenu* _pMenu)
479 wxMenuItem* boottopause = _pMenu->Append(IDM_BOOTTOPAUSE, _T("Boot to pause"),
480 wxT("Start the game directly instead of booting to pause"), wxITEM_CHECK);
481 boottopause->Check(bBootToPause);
483 wxMenuItem* automaticstart = _pMenu->Append(IDM_AUTOMATICSTART, _T("&Automatic start")
484 , wxString::FromAscii(
485 "Automatically load the Default ISO when Dolphin starts, or the last game you loaded,"
486 " if you have not given it an elf file with the --elf command line. [This can be"
487 " convenient if you are bug-testing with a certain game and want to rebuild"
488 " and retry it several times, either with changes to Dolphin or if you are"
489 " developing a homebrew game.]")
490 , wxITEM_CHECK);
491 automaticstart->Check(bAutomaticStart);
493 _pMenu->Append(IDM_FONTPICKER, _T("&Font..."), wxEmptyString, wxITEM_NORMAL);
496 // CPU Mode and JIT Menu
497 void CCodeWindow::OnCPUMode(wxCommandEvent& event)
499 switch (event.GetId())
501 case IDM_INTERPRETER:
502 PowerPC::SetMode(UseInterpreter() ? PowerPC::MODE_INTERPRETER : PowerPC::MODE_JIT);
503 break;
504 case IDM_BOOTTOPAUSE:
505 bBootToPause = !bBootToPause;
506 return;
507 case IDM_AUTOMATICSTART:
508 bAutomaticStart = !bAutomaticStart;
509 return;
510 case IDM_JITOFF:
511 Core::g_CoreStartupParameter.bJITOff = event.IsChecked();
512 break;
513 case IDM_JITLSOFF:
514 Core::g_CoreStartupParameter.bJITLoadStoreOff = event.IsChecked();
515 break;
516 case IDM_JITLSLXZOFF:
517 Core::g_CoreStartupParameter.bJITLoadStorelXzOff = event.IsChecked();
518 break;
519 case IDM_JITLSLWZOFF:
520 Core::g_CoreStartupParameter.bJITLoadStorelwzOff = event.IsChecked();
521 break;
522 case IDM_JITLSLBZXOFF:
523 Core::g_CoreStartupParameter.bJITLoadStorelbzxOff = event.IsChecked();
524 break;
525 case IDM_JITLSFOFF:
526 Core::g_CoreStartupParameter.bJITLoadStoreFloatingOff = event.IsChecked();
527 break;
528 case IDM_JITLSPOFF:
529 Core::g_CoreStartupParameter.bJITLoadStorePairedOff = event.IsChecked();
530 break;
531 case IDM_JITFPOFF:
532 Core::g_CoreStartupParameter.bJITFloatingPointOff = event.IsChecked();
533 break;
534 case IDM_JITIOFF:
535 Core::g_CoreStartupParameter.bJITIntegerOff = event.IsChecked();
536 break;
537 case IDM_JITPOFF:
538 Core::g_CoreStartupParameter.bJITPairedOff = event.IsChecked();
539 break;
540 case IDM_JITSROFF:
541 Core::g_CoreStartupParameter.bJITSystemRegistersOff = event.IsChecked();
542 break;
545 // Clear the JIT cache to enable these changes
546 jit->ClearCache();
547 // Update
548 UpdateButtonStates();
551 void CCodeWindow::OnJitMenu(wxCommandEvent& event)
553 switch (event.GetId())
555 case IDM_LOGINSTRUCTIONS:
556 PPCTables::LogCompiledInstructions();
557 break;
559 case IDM_CLEARCODECACHE:
560 jit->ClearCache();
561 break;
563 case IDM_SEARCHINSTRUCTION:
565 wxString str;
566 str = wxGetTextFromUser(_(""), wxT("Op?"), wxEmptyString, this);
567 for (u32 addr = 0x80000000; addr < 0x80100000; addr += 4)
569 const char *name = PPCTables::GetInstructionName(Memory::ReadUnchecked_U32(addr));
570 if (name && !strcmp((const char *)str.mb_str(), name))
572 std::string mb_str(str.mb_str());
573 NOTICE_LOG(POWERPC, "Found %s at %08x", mb_str.c_str(), addr);
576 break;
581 // Shortcuts
582 bool CCodeWindow::UseInterpreter()
584 return GetMenuBar()->IsChecked(IDM_INTERPRETER);
587 bool CCodeWindow::BootToPause()
589 return GetMenuBar()->IsChecked(IDM_BOOTTOPAUSE);
592 bool CCodeWindow::AutomaticStart()
594 return GetMenuBar()->IsChecked(IDM_AUTOMATICSTART);
597 bool CCodeWindow::JITNoBlockCache()
599 return GetMenuBar()->IsChecked(IDM_JITNOBLOCKCACHE);
602 bool CCodeWindow::JITBlockLinking()
604 return GetMenuBar()->IsChecked(IDM_JITBLOCKLINKING);
607 // Toolbar
608 void CCodeWindow::InitBitmaps()
610 // load original size 48x48
611 m_Bitmaps[Toolbar_DebugGo] = wxGetBitmapFromMemory(toolbar_play_png);
612 m_Bitmaps[Toolbar_Step] = wxGetBitmapFromMemory(toolbar_add_breakpoint_png);
613 m_Bitmaps[Toolbar_StepOver] = wxGetBitmapFromMemory(toolbar_add_memcheck_png);
614 m_Bitmaps[Toolbar_Skip] = wxGetBitmapFromMemory(toolbar_add_memcheck_png);
615 m_Bitmaps[Toolbar_GotoPC] = wxGetBitmapFromMemory(toolbar_add_memcheck_png);
616 m_Bitmaps[Toolbar_SetPC] = wxGetBitmapFromMemory(toolbar_add_memcheck_png);
617 m_Bitmaps[Toolbar_DebugPause] = wxGetBitmapFromMemory(toolbar_pause_png);
619 // scale to 24x24 for toolbar
620 for (size_t n = Toolbar_DebugGo; n < ToolbarDebugBitmapMax; n++)
621 m_Bitmaps[n] = wxBitmap(m_Bitmaps[n].ConvertToImage().Scale(24, 24));
624 void CCodeWindow::PopulateToolbar(wxAuiToolBar* toolBar)
626 int w = m_Bitmaps[Toolbar_DebugGo].GetWidth(),
627 h = m_Bitmaps[Toolbar_DebugGo].GetHeight();
629 toolBar->SetToolBitmapSize(wxSize(w, h));
630 toolBar->AddTool(IDM_STEP, _T("Step"), m_Bitmaps[Toolbar_Step]);
631 toolBar->AddTool(IDM_STEPOVER, _T("Step Over"), m_Bitmaps[Toolbar_StepOver]);
632 toolBar->AddTool(IDM_SKIP, _T("Skip"), m_Bitmaps[Toolbar_Skip]);
633 toolBar->AddSeparator();
634 toolBar->AddTool(IDM_GOTOPC, _T("Show PC"), m_Bitmaps[Toolbar_GotoPC]);
635 toolBar->AddTool(IDM_SETPC, _T("Set PC"), m_Bitmaps[Toolbar_SetPC]);
636 toolBar->AddSeparator();
637 toolBar->AddControl(new wxTextCtrl(toolBar, IDM_ADDRBOX, _T("")));
639 toolBar->Realize();
642 // Update GUI
643 void CCodeWindow::Update()
645 if (!codeview) return;
647 codeview->Refresh();
648 UpdateCallstack();
649 UpdateButtonStates();
651 // Do not automatically show the current PC position when a breakpoint is hit or
652 // when we pause since this can be called at other times too.
653 //codeview->Center(PC);
656 void CCodeWindow::UpdateButtonStates()
658 bool Initialized = (Core::GetState() != Core::CORE_UNINITIALIZED);
659 bool Pause = (Core::GetState() == Core::CORE_PAUSE);
660 bool Stepping = CCPU::IsStepping();
661 wxAuiToolBar* ToolBar = GetToolBar();
663 // Toolbar
664 if (!ToolBar) return;
666 if (!Initialized)
668 ToolBar->EnableTool(IDM_STEPOVER, false);
669 ToolBar->EnableTool(IDM_SKIP, false);
671 else
673 if (!Stepping)
675 ToolBar->EnableTool(IDM_STEPOVER, false);
676 ToolBar->EnableTool(IDM_SKIP, false);
678 else
680 ToolBar->EnableTool(IDM_STEPOVER, true);
681 ToolBar->EnableTool(IDM_SKIP, true);
685 ToolBar->EnableTool(IDM_STEP, Initialized && Stepping);
687 if (ToolBar) ToolBar->Realize();
689 // Menu bar
690 // ------------------
691 GetMenuBar()->Enable(IDM_INTERPRETER, Pause); // CPU Mode
693 GetMenuBar()->Enable(IDM_JITNOBLOCKCACHE, !Initialized);
695 GetMenuBar()->Enable(IDM_JITOFF, Pause);
696 GetMenuBar()->Enable(IDM_JITLSOFF, Pause);
697 GetMenuBar()->Enable(IDM_JITLSLXZOFF, Pause);
698 GetMenuBar()->Enable(IDM_JITLSLWZOFF, Pause);
699 GetMenuBar()->Enable(IDM_JITLSLBZXOFF, Pause);
700 GetMenuBar()->Enable(IDM_JITLSFOFF, Pause);
701 GetMenuBar()->Enable(IDM_JITLSPOFF, Pause);
702 GetMenuBar()->Enable(IDM_JITFPOFF, Pause);
703 GetMenuBar()->Enable(IDM_JITIOFF, Pause);
704 GetMenuBar()->Enable(IDM_JITPOFF, Pause);
705 GetMenuBar()->Enable(IDM_JITSROFF, Pause);
707 GetMenuBar()->Enable(IDM_CLEARCODECACHE, Pause); // JIT Menu
708 GetMenuBar()->Enable(IDM_SEARCHINSTRUCTION, Initialized);
710 GetMenuBar()->Enable(IDM_CLEARSYMBOLS, Initialized); // Symbols menu
711 GetMenuBar()->Enable(IDM_SCANFUNCTIONS, Initialized);
712 GetMenuBar()->Enable(IDM_LOADMAPFILE, Initialized);
713 GetMenuBar()->Enable(IDM_SAVEMAPFILE, Initialized);
714 GetMenuBar()->Enable(IDM_SAVEMAPFILEWITHCODES, Initialized);
715 GetMenuBar()->Enable(IDM_CREATESIGNATUREFILE, Initialized);
716 GetMenuBar()->Enable(IDM_RENAME_SYMBOLS, Initialized);
717 GetMenuBar()->Enable(IDM_USESIGNATUREFILE, Initialized);
718 GetMenuBar()->Enable(IDM_PATCHHLEFUNCTIONS, Initialized);
720 // Update Fonts
721 callstack->SetFont(DebuggerFont);
722 symbols->SetFont(DebuggerFont);
723 callers->SetFont(DebuggerFont);
724 calls->SetFont(DebuggerFont);