Cemu/src/gui/wxgui/debugger/DebuggerWindow2.h
Crementif 7ff99a5e13
debugger: Add support for loading symbols from .map file (#1916)
Map has to have the same name as the debugger/*.xml files, but with a .map extension
2026-05-19 00:21:14 +02:00

174 lines
4.9 KiB
C++

#pragma once
#include "wxgui/debugger/DisasmCtrl.h"
#include "config/XMLConfig.h"
#include "Cafe/HW/Espresso/Debugger/Debugger.h"
#include "Cafe/OS/RPL/rpl.h"
#include "Cafe/HW/Espresso/Debugger/GDBStub.h"
#include <wx/bitmap.h>
#include <wx/frame.h>
#include <wx/mstream.h>
class BreakpointWindow;
class RegisterWindow;
class DumpWindow;
class ModuleWindow;
class SymbolWindow;
class wxStaticText;
struct RPLStoredSymbol;
wxDECLARE_EVENT(wxEVT_UPDATE_VIEW, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_BREAKPOINT_HIT, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_RUN, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_BREAKPOINT_CHANGE, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_MOVE_TO_DISASM_ADDR, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_NOTIFY_MODULE_LOADED, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_NOTIFY_MODULE_UNLOADED, wxCommandEvent);
wxDECLARE_EVENT(wxEVT_NOTIFY_GRAPHIC_PACKS_MODIFIED, wxCommandEvent);
extern class DebuggerWindow2* s_debuggerWindow;
struct DebuggerConfig
{
DebuggerConfig()
: pin_to_main(true), break_on_start(true), log_memory_breakpoints(false), show_register(true), show_dump(true), show_stack(true), show_breakpoints(true), show_modules(true), show_symbols(true) {}
bool pin_to_main;
bool break_on_start;
bool log_memory_breakpoints;
bool show_register;
bool show_dump;
bool show_stack;
bool show_breakpoints;
bool show_modules;
bool show_symbols;
void Load(XMLConfigParser& parser);
void Save(XMLConfigParser& parser);
};
typedef XMLDataConfig<DebuggerConfig> XMLDebuggerConfig;
struct DebuggerModuleInfo
{
struct ModuleArea
{
MPTR base;
MPTR origBase;
uint32 size;
bool ContainsAddress(MPTR addr) const
{
return addr >= base && (addr < (base+size));
}
bool ContainsOriginalAddress(MPTR addr) const
{
return addr >= origBase && (addr < (origBase + size));
}
};
std::string moduleName;
uint32 patchCRC;
ModuleArea textArea;
ModuleArea dataArea;
DebuggerModuleInfo(RPLModule* module);
};
struct DebuggerModuleStorage
{
DebuggerModuleInfo moduleInfo;
bool delete_breakpoints_after_saving;
std::vector<RPLStoredSymbol*> loaded_map_symbols;
void Load(XMLConfigParser& parser);
void Save(XMLConfigParser& parser);
};
typedef XMLDataConfig<DebuggerModuleStorage> XMLDebuggerModuleConfig;
static wxBitmap LoadThemedBitmapFromPNG(const uint8* data, size_t size, const wxColour& tint)
{
wxMemoryInputStream strm(data, size);
wxImage img(strm, wxBITMAP_TYPE_PNG);
img.Replace(0x00, 0x00, 0x00, tint.Red(), tint.Green(), tint.Blue());
return wxBitmap(img);
}
class DebuggerWindow2 : public wxFrame, public DebuggerCallbacks
{
public:
void CreateToolBar();
void LoadModuleStorage(const struct DebuggerModuleInfo& moduleInfo);
void SaveModuleStorage(const struct DebuggerModuleInfo& moduleInfo, bool deleteModuleStorage);
DebuggerWindow2(wxFrame& parent, const wxRect& display_size);
~DebuggerWindow2();
void CleanupForDestroy();
void OnParentMove(const wxPoint& position, const wxSize& size);
void OnGameLoaded();
XMLDebuggerConfig& GetConfig();
bool Show(bool show = true) override;
std::wstring GetModuleStoragePath(std::string module_name, uint32_t crc_hash) const;
private:
void OnBreakpointHit(wxCommandEvent& event);
void OnRunProgram(wxCommandEvent& event);
void OnToolClicked(wxCommandEvent& event);
void OnBreakpointChange(wxCommandEvent& event);
void OnOptionsInput(wxCommandEvent& event);
void OnWindowMenu(wxCommandEvent& event);
void OnUpdateView(wxCommandEvent& event);
void OnExit(wxCommandEvent& event);
void OnShow(wxShowEvent& event);
void OnClose(wxCloseEvent& event);
void OnMoveToDisasmAddr(wxCommandEvent& event);
void OnNotifyModuleLoaded(wxCommandEvent& event);
void OnNotifyModuleUnloaded(wxCommandEvent& event);
void OnNotifyGraphicPacksModified(wxCommandEvent& event);
// events from DisasmCtrl
void OnDisasmCtrlGotoAddress(wxCommandEvent& event);
void CreateMenuBar();
void UpdateModuleLabel(uint32 address = 0);
void LoadModuleMap(DebuggerModuleStorage& moduleStorage);
void UnloadModuleMap(DebuggerModuleStorage& moduleStorage);
std::wstring GetModuleMapPath(std::string module_name, uint32_t crc_hash) const;
void UpdateViewThreadsafe() override;
void NotifyDebugBreakpointHit() override;
void NotifyRun() override;
void MoveToAddressInDisassembly(MPTR address) override;
void NotifyGraphicPacksModified() override;
void NotifyModuleLoaded(struct RPLModule* module) override;
void NotifyModuleUnloaded(struct RPLModule* module) override;
XMLDebuggerConfig m_config;
std::vector<std::unique_ptr<XMLDebuggerModuleConfig>> m_modulesStorage;
wxPoint m_main_position;
wxSize m_main_size;
RegisterWindow* m_register_window;
DumpWindow* m_dump_window;
BreakpointWindow* m_breakpoint_window;
ModuleWindow* m_module_window;
SymbolWindow* m_symbol_window;
DisasmCtrl* m_disasm_ctrl;
wxToolBar* m_toolbar;
wxBitmap m_run, m_pause;
uint32 m_module_address;
wxStaticText* m_module_label;
bool m_forceInterpreter{false};
wxDECLARE_EVENT_TABLE();
};