Skip to content

Commit

Permalink
[debugger] Add symbols in GUI. #4
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 31, 2025
1 parent 1848373 commit d287310
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 18 deletions.
136 changes: 118 additions & 18 deletions platforms/shared/desktop/gui_debug_disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ static DebugSymbol*** dynamic_symbols = NULL;
static std::vector<DisassemblerLine> disassembler_lines(0x10000);
static std::vector<DisassemblerBookmark> bookmarks;
static int selected_address = -1;
static int selected_bank = -1;
static int new_breakpoint_type = HuC6280::HuC6280_BREAKPOINT_TYPE_ROMRAM;
static char new_breakpoint_buffer[10] = "";
static bool new_breakpoint_read = false;
Expand All @@ -70,7 +71,8 @@ static bool goto_back_requested = false;
static int goto_back = 0;
static int pc_pos = 0;
static int goto_address_pos = 0;
static bool add_bookmark = false;
static bool add_bookmark_open = false;
static bool add_symbol_open = false;

static void draw_controls(void);
static void draw_breakpoints(void);
Expand All @@ -87,6 +89,7 @@ static void replace_labels(DisassemblerLine* line, const char* color, const char
static void draw_instruction_name(DisassemblerLine* line, bool is_pc);
static void disassembler_menu(void);
static void add_bookmark_popup(void);
static void add_symbol_popup(void);

void gui_debug_disassembler_init(void)
{
Expand Down Expand Up @@ -132,6 +135,7 @@ void gui_debug_reset(void)
gui_debug_reset_breakpoints();
gui_debug_reset_symbols();
selected_address = -1;
selected_bank = -1;
}

void gui_debug_reset_symbols(void)
Expand Down Expand Up @@ -237,7 +241,12 @@ void gui_debug_toggle_breakpoint(void)

void gui_debug_add_bookmark(void)
{
add_bookmark = true;
add_bookmark_open = true;
}

void gui_debug_add_symbol(void)
{
add_symbol_open = true;
}

void gui_debug_runtocursor(void)
Expand Down Expand Up @@ -272,6 +281,7 @@ void gui_debug_window_disassembler(void)
draw_disassembly();

add_bookmark_popup();
add_symbol_popup();

ImGui::End();
ImGui::PopStyleVar();
Expand Down Expand Up @@ -672,10 +682,14 @@ static void draw_disassembly(void)
else if (is_selected)
{
selected_address = -1;
selected_bank = -1;
new_breakpoint_buffer[0] = 0;
}
else
{
selected_address = line.address;
selected_bank = line.record->bank;
}
}

bool enable_bg_color = false;
Expand Down Expand Up @@ -782,6 +796,7 @@ static void draw_context_menu(DisassemblerLine* line)
if (ImGui::BeginPopupContextItem())
{
selected_address = line->address;
selected_bank = line->record->bank;

if (ImGui::Selectable("Run To Cursor"))
{
Expand All @@ -793,6 +808,11 @@ static void draw_context_menu(DisassemblerLine* line)
gui_debug_add_bookmark();
}

if (ImGui::Selectable("Add Symbol..."))
{
gui_debug_add_symbol();
}

if (ImGui::Selectable("Toggle Breakpoint"))
{
gui_debug_toggle_breakpoint();
Expand Down Expand Up @@ -1249,6 +1269,11 @@ static void disassembler_menu(void)

ImGui::Separator();

if (ImGui::MenuItem("Add Symbol..."))
{
gui_debug_add_symbol();
}

if (ImGui::MenuItem("Load Symbols..."))
{
open_symbols = true;
Expand All @@ -1270,38 +1295,42 @@ static void disassembler_menu(void)

static void add_bookmark_popup(void)
{
if (add_bookmark)
if (add_bookmark_open)
{
ImGui::OpenPopup("Add Bookmark");
add_bookmark = false;
add_bookmark_open = false;
}

if (ImGui::BeginPopupModal("Add Bookmark", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
static char address[5] = "";
static char name[32] = "";
static char address_bookmark[5] = "";
static char name_bookmark[32] = "";
static bool bookmark_modified = false;
u16 bookmark_address = (u16)selected_address;

if (bookmark_address > 0)
snprintf(address, 5, "%04X", bookmark_address);
if (!bookmark_modified && bookmark_address >= 0)
snprintf(address_bookmark, 5, "%04X", bookmark_address);

ImGui::Text("Name:");
ImGui::PushItemWidth(200);ImGui::SetItemDefaultFocus();
ImGui::InputText("##name", name, IM_ARRAYSIZE(name));
ImGui::InputText("##name", name_bookmark, IM_ARRAYSIZE(name_bookmark));

ImGui::Text("Address:");
ImGui::PushItemWidth(50);
ImGui::InputTextWithHint("##bookaddr", "XXXX", address, IM_ARRAYSIZE(address), ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase);
if (ImGui::InputTextWithHint("##bookaddr", "XXXX", address_bookmark, IM_ARRAYSIZE(address_bookmark), ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase))
{
bookmark_modified = true;
}

ImGui::Separator();

if (ImGui::Button("OK", ImVec2(90, 0)))
{
try
{
bookmark_address = (int)std::stoul(address, 0, 16);
bookmark_address = (int)std::stoul(address_bookmark, 0, 16);

if (strlen(name) == 0)
if (strlen(name_bookmark) == 0)
{
Memory* memory = emu_get_core()->GetMemory();
Memory::GG_Disassembler_Record* record = memory->GetDisassemblerRecord(bookmark_address);
Expand All @@ -1312,30 +1341,101 @@ static void add_bookmark_popup(void)
size_t pos = instr.find("{}");
if (pos != std::string::npos)
instr.replace(pos, 2, "");
snprintf(name, 32, "%s", instr.c_str());
snprintf(name_bookmark, 32, "%s", instr.c_str());
}
else
{
snprintf(name, 32, "Bookmark_%04X", bookmark_address);
snprintf(name_bookmark, 32, "Bookmark_%04X", bookmark_address);
}
}

DisassemblerBookmark bookmark;
bookmark.address = bookmark_address;
snprintf(bookmark.name, 32, "%s", name);
snprintf(bookmark.name, 32, "%s", name_bookmark);
bookmarks.push_back(bookmark);
ImGui::CloseCurrentPopup();

address[0] = 0;
name[0] = 0;
address_bookmark[0] = 0;
name_bookmark[0] = 0;
bookmark_modified = false;
}
catch(const std::invalid_argument&)
{
}
}

ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(90, 0))) { ImGui::CloseCurrentPopup(); }
if (ImGui::Button("Cancel", ImVec2(90, 0)))
{
address_bookmark[0] = 0;
name_bookmark[0] = 0;
bookmark_modified = false;
ImGui::CloseCurrentPopup();
}

ImGui::EndPopup();
}
}

static void add_symbol_popup(void)
{
if (add_symbol_open)
{
ImGui::OpenPopup("Add Symbol");
add_symbol_open = false;
}

if (ImGui::BeginPopupModal("Add Symbol", NULL, ImGuiWindowFlags_AlwaysAutoResize))
{
static char address[8] = "";
static char name[32] = "";
static bool symbol_modified = false;

if (!symbol_modified && selected_address >= 0 && selected_bank >= 0)
snprintf(address, 8, "%02X:%04X", selected_bank, selected_address);

ImGui::Text("Name:");
ImGui::PushItemWidth(200);ImGui::SetItemDefaultFocus();
ImGui::InputText("##symname", name, IM_ARRAYSIZE(name));

ImGui::Text("Address:");
ImGui::PushItemWidth(70);
if (ImGui::InputTextWithHint("##symaddr", "XX:XXXX", address, IM_ARRAYSIZE(address), ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CharsUppercase))
{
symbol_modified = true;
}

ImGui::Separator();

if (ImGui::Button("OK", ImVec2(90, 0)))
{
try
{
if (strlen(name) != 0)
{
char symbol[128] = { };
snprintf(symbol, 128, "%s %s", address, name);
add_symbol(symbol);

ImGui::CloseCurrentPopup();
address[0] = 0;
name[0] = 0;
symbol_modified = false;
}
}
catch(const std::invalid_argument&)
{
}
}

ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(90, 0)))
{
ImGui::CloseCurrentPopup();
address[0] = 0;
name[0] = 0;
symbol_modified = false;
}

ImGui::EndPopup();
}
Expand Down
1 change: 1 addition & 0 deletions platforms/shared/desktop/gui_debug_disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ EXTERN void gui_debug_reset_breakpoints(void);
EXTERN void gui_debug_load_symbols_file(const char* file_path);
EXTERN void gui_debug_toggle_breakpoint(void);
EXTERN void gui_debug_add_bookmark(void);
EXTERN void gui_debug_add_symbol(void);
EXTERN void gui_debug_runtocursor(void);
EXTERN void gui_debug_go_back(void);
EXTERN void gui_debug_window_disassembler(void);
Expand Down

0 comments on commit d287310

Please sign in to comment.