Skip to content

Commit

Permalink
address_history/mainwindow: Store source row for calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKagstrom committed Jan 12, 2025
1 parent e19c790 commit c0666da
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
8 changes: 3 additions & 5 deletions include/emilpro/address_history.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ public:
{
const ISection* section {nullptr};
uint64_t offset;
uint32_t row {0};

auto operator==(const Entry& other) const
{
return section == other.section && offset == other.offset;
}
bool operator==(const Entry& other) const = default;
};

AddressHistory();

void PushEntry(const ISection& section, uint64_t offset);
void PushEntry(const ISection& section, uint64_t offset, uint32_t row);

void SetIndex(int index);

Expand Down
20 changes: 15 additions & 5 deletions qt/emilpro/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ MainWindow::OnHistoryIndexChanged()
const auto& sym = sym_ref->get();

m_visible_instructions = sym.Instructions();
UpdateInstructionView(sym, sym.Offset());
UpdateInstructionView(sym, sym.Offset(), entry.row);
UpdateSymbolView(sym);
}
}
Expand Down Expand Up @@ -466,7 +466,13 @@ MainWindow::on_instructionTableView_doubleClicked(const QModelIndex& index)
auto sym = refers_to->symbol;

m_visible_instructions = sym->Instructions();
m_address_history.PushEntry(sym->Section(), sym->Offset());

if (insn.Symbol())
{
m_address_history.PushEntry(insn.Section(),
insn.Offset() - insn.Section().StartAddress(), row);
}
m_address_history.PushEntry(sym->Section(), sym->Offset(), 0);

UpdateInstructionView(*sym, sym->Offset());
UpdateSymbolView(*sym);
Expand All @@ -485,7 +491,7 @@ MainWindow::on_instructionTableView_doubleClicked(const QModelIndex& index)
const auto& sym = sym_ref->get();

m_visible_instructions = sym.Instructions();
m_address_history.PushEntry(sym.Section(), sym.Offset());
m_address_history.PushEntry(sym.Section(), result.offset, 0);

UpdateInstructionView(sym, result.offset + section.StartAddress());
UpdateSymbolView(sym);
Expand Down Expand Up @@ -618,7 +624,7 @@ MainWindow::on_symbolTableView_activated(const QModelIndex& index)
sym.WaitForCommit();

m_visible_instructions = sym.Instructions();
m_address_history.PushEntry(sym.Section(), sym.Offset());
m_address_history.PushEntry(sym.Section(), sym.Offset(), 0);

UpdateInstructionView(sym, sym.Offset());
UpdateHistoryView();
Expand Down Expand Up @@ -1032,7 +1038,7 @@ MainWindow::UpdateSymbolView(const emilpro::ISymbol& symbol)
}

void
MainWindow::UpdateInstructionView(const emilpro::ISymbol& symbol, uint64_t offset)
MainWindow::UpdateInstructionView(const emilpro::ISymbol& symbol, uint64_t offset, uint32_t row)
{
m_instruction_view_model->removeRows(0, m_instruction_view_model->rowCount());
auto selected_row = 0;
Expand Down Expand Up @@ -1085,6 +1091,10 @@ MainWindow::UpdateInstructionView(const emilpro::ISymbol& symbol, uint64_t offse
{
selected_row = cur_row;
}
else if (cur_row == row)
{
selected_row = cur_row;
}

m_instruction_view_model->appendRow(lst);
}
Expand Down
2 changes: 1 addition & 1 deletion qt/emilpro/mainwindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private:

void OnHistoryIndexChanged();

void UpdateInstructionView(const emilpro::ISymbol& symbol, uint64_t offset);
void UpdateInstructionView(const emilpro::ISymbol& symbol, uint64_t offset, uint32_t row = 0);

void UpdateRefersToView(const emilpro::ISymbol& symbol);
void UpdateRefersToView(const emilpro::IInstruction& insn);
Expand Down
4 changes: 2 additions & 2 deletions src/address_history/address_history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ AddressHistory::AddressHistory()
}

void
AddressHistory::PushEntry(const ISection& section, uint64_t offset)
AddressHistory::PushEntry(const ISection& section, uint64_t offset, uint32_t row)
{
if (m_entries.empty() == false && m_index != m_entries.size() - 1)
{
m_entries.resize(m_index);
}
m_entries.push_back({&section, offset});
m_entries.push_back({&section, offset, row});
m_index = m_entries.size() - 1;
}

Expand Down
22 changes: 11 additions & 11 deletions test/unittest/test_address_history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ TEST_CASE_FIXTURE(Fixture, "the address history is initially empty")

TEST_CASE_FIXTURE(Fixture, "an entry can be pushed to the address history")
{
history.PushEntry(section, 13);
history.PushEntry(section, 13, 1);
REQUIRE(history.CurrentIndex() == 0);
REQUIRE(history.Entries()[0] == AddressHistory::Entry {&section, 13});
REQUIRE(history.Entries()[0] == AddressHistory::Entry {&section, 13, 1});
}

TEST_CASE_FIXTURE(Fixture, "entries can be selected in the middle of the history")
{
history.PushEntry(section, 13);
history.PushEntry(section2, 14);
history.PushEntry(section, 15);
history.PushEntry(section, 13, 1);
history.PushEntry(section2, 14, 2);
history.PushEntry(section, 15, 3);

REQUIRE(history.CurrentIndex() == 2);
REQUIRE(history.Entries()[0] == AddressHistory::Entry {&section, 13});
REQUIRE(history.Entries()[1] == AddressHistory::Entry {&section2, 14});
REQUIRE(history.Entries()[2] == AddressHistory::Entry {&section, 15});
REQUIRE(history.Entries()[0] == AddressHistory::Entry {&section, 13, 1});
REQUIRE(history.Entries()[1] == AddressHistory::Entry {&section2, 14, 2});
REQUIRE(history.Entries()[2] == AddressHistory::Entry {&section, 15, 3});

WHEN("the first entry is selected")
{
Expand All @@ -47,10 +47,10 @@ TEST_CASE_FIXTURE(Fixture, "entries can be selected in the middle of the history

THEN("a newly pushed entry removes the second")
{
history.PushEntry(section, 99);
history.PushEntry(section, 99, 5);
REQUIRE(history.Entries().size() == 2);
REQUIRE(history.Entries()[0] == AddressHistory::Entry {&section, 13});
REQUIRE(history.Entries()[1] == AddressHistory::Entry {&section, 99});
REQUIRE(history.Entries()[0] == AddressHistory::Entry {&section, 13, 1});
REQUIRE(history.Entries()[1] == AddressHistory::Entry {&section, 99, 5});
}
}
}

0 comments on commit c0666da

Please sign in to comment.