Skip to content

Commit

Permalink
Add branch labels to disassembly window
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusbrown committed Jan 19, 2024
1 parent b6510e2 commit 5ad660c
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/window_disassembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,38 @@ static void prog_addr_source_line(uint16_t addr)
}
}

static std::string prog_addr_name(uint16_t addr)
{
if(addr / 4 < absim::INT_VECTOR_INFO.size())
{
auto const& info = absim::INT_VECTOR_INFO[addr / 4];
if(info.name)
return info.name;
}
auto const* sym = arduboy->symbol_for_prog_addr(addr);
if(sym)
{
if(addr == sym->addr)
return sym->name.c_str();
if(arduboy->elf)
{
auto index = arduboy->elf->addr_to_disassembled_index(addr);
auto const& a = arduboy->elf->asm_with_source[index];
if(a.type == a.SYMBOL)
{
auto it = arduboy->elf->text_symbols.find(a.addr);
if(it != arduboy->elf->text_symbols.end())
return it->second.name;
}
}
return fmt::format("{} + {}", sym->name, addr - sym->addr);
}
return "";
}

static void prog_addr_tooltip(uint16_t addr)
{
using namespace ImGui;
auto const* sym = arduboy->symbol_for_prog_addr(addr);
if(addr / 4 < absim::INT_VECTOR_INFO.size())
{
auto const& info = absim::INT_VECTOR_INFO[addr / 4];
Expand All @@ -235,16 +263,13 @@ static void prog_addr_tooltip(uint16_t addr)
Separator();
TextUnformatted(info.desc);
EndTooltip();
return;
}
}
if(sym)
auto name = prog_addr_name(addr);
if(!name.empty())
{
BeginTooltip();
if(addr == sym->addr)
TextUnformatted(sym->name.c_str());
else
Text("%s [%+d]", sym->name.c_str(), addr - sym->addr);
TextUnformatted(name.c_str());
EndTooltip();
}
//BeginTooltip();
Expand All @@ -255,7 +280,8 @@ static void prog_addr_tooltip(uint16_t addr)
static void disassembly_prog_addr(uint16_t addr, int& do_scroll)
{
using namespace ImGui;
auto addr_size = CalcTextSize("0x0000");
auto name = prog_addr_name(addr);
auto addr_size = CalcTextSize(name.empty() ? "0x0000" : name.c_str());
auto saved = GetCursorPos();
Dummy(addr_size);
ImU32 color = IM_COL32(30, 200, 100, 255);
Expand All @@ -267,7 +293,10 @@ static void disassembly_prog_addr(uint16_t addr, int& do_scroll)
}
SetCursorPos(saved);
PushStyleColor(ImGuiCol_Text, color);
Text("0x%04x", addr);
if(!name.empty())
TextUnformatted(name.c_str());
else
Text("0x%04x", addr);
PopStyleColor();
if(IsItemClicked())
{
Expand Down

0 comments on commit 5ad660c

Please sign in to comment.