Skip to content

Commit

Permalink
Find CPU exceptions in the trace browser.
Browse files Browse the repository at this point in the history
In the GUI browser, there are menu options from the Edit menu to jump
to the next or previous CPU exception. In the curses browser, you can
press 'e' or 'E' for the two search directions.

Closes #20.
  • Loading branch information
statham-arm committed Aug 2, 2024
1 parent 9736889 commit 19f7432
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
5 changes: 5 additions & 0 deletions browser/browse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@ bool Browser::TraceView::goto_pc(unsigned long long pc, int dir)
return goto_physline(target_line);
}

bool Browser::TraceView::goto_cpu_exception(int dir)
{
return goto_pc(CPU_EXCEPTION_PC, dir);
}

struct TraceParseContext : ParseContext {
Browser &br;
TraceParseContext(Browser &br) : br(br) {}
Expand Down
1 change: 1 addition & 0 deletions browser/browse.hh
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Browser : public IndexNavigator {
bool goto_visline(unsigned line);
bool goto_buffer_limit(bool end);
bool goto_pc(unsigned long long pc, int dir);
bool goto_cpu_exception(int dir);

bool position_hidden();
bool get_current_pc(unsigned long long &pc);
Expand Down
13 changes: 13 additions & 0 deletions browser/curses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,15 @@ class TraceBuffer : public Window {
}
}

void goto_cpu_exception(int dir)
{
if (vu.goto_cpu_exception(dir)) {
selected_event = UINT_MAX;
update_scrtop(false, 1, 2);
update_other_windows();
}
}

void draw(int x, int y, cursorpos *cp)
{
cp->visible = false;
Expand Down Expand Up @@ -867,6 +876,7 @@ class TraceBuffer : public Window {
{"t", _("Jump to a specified time position")},
{"l", _("Jump to a specified line number of the trace file")},
{"p, P", _("Jump to the next / previous visit to a PC location")},
{"e, E", _("Jump to the next / previous CPU exception, if any")},
{"", ""},
{"r", _("Toggle display of the core registers")},
{"S, D", _("Toggle display of the single / double FP registers")},
Expand Down Expand Up @@ -1080,6 +1090,9 @@ class TraceBuffer : public Window {
if (vu.get_current_pc(pc))
goto_pc(pc, c == 'n' ? +1 : -1);
return true;
} else if (c == 'e' || c == 'E') {
goto_cpu_exception(c == 'e' ? +1 : -1);
return true;
} else if (c == 'r') {
// Toggle core register display window on/off
set_crdisp(crdisp == NULL);
Expand Down
20 changes: 20 additions & 0 deletions browser/wx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,7 @@ class TraceWindow : public TextViewWindow {
void pcedit_unfocused(wxFocusEvent &event);
void reset_pcedit();
template <int direction> void pc_nextprev(wxCommandEvent &event);
template <int direction> void exc_nextprev(wxCommandEvent &event);

virtual bool keypress(wxKeyEvent &event) override;

Expand Down Expand Up @@ -1851,6 +1852,8 @@ TraceWindow::TraceWindow(GuiTarmacBrowserApp *app, Browser &br)
wxWindowID mi_newneonreg = NewControlId();
wxWindowID mi_newmvereg = NewControlId();
wxWindowID mi_recentre = NewControlId();
wxWindowID mi_nextexc = NewControlId();
wxWindowID mi_prevexc = NewControlId();
mi_calldepth = NewControlId();
mi_highlight = NewControlId();
mi_branchtarget = wxID_NONE;
Expand All @@ -1875,6 +1878,12 @@ TraceWindow::TraceWindow(GuiTarmacBrowserApp *app, Browser &br)
newmenu->Append(mi_newmvereg, _("MVE vector reg view"));
filemenu->InsertSeparator(pos++);

newmenu = new wxMenu;
editmenu->AppendSeparator();
editmenu->Append(wxID_ANY, _("Find CPU exception..."), newmenu);
newmenu->Append(mi_nextexc, _("Next"));
newmenu->Append(mi_prevexc, _("Previous"));

wxMenu *viewmenu = new wxMenu;
menubar->Append(viewmenu, _("&View"));
{
Expand Down Expand Up @@ -1903,6 +1912,8 @@ TraceWindow::TraceWindow(GuiTarmacBrowserApp *app, Browser &br)
if (mi_branchtarget != wxID_NONE)
Bind(wxEVT_MENU, &TraceWindow::branchtarget_menuaction, this,
mi_branchtarget);
Bind(wxEVT_MENU, &TraceWindow::exc_nextprev<+1>, this, mi_nextexc);
Bind(wxEVT_MENU, &TraceWindow::exc_nextprev<-1>, this, mi_prevexc);

menubar->Check(mi_calldepth, depth_indentation);
menubar->Check(mi_highlight, syntax_highlight);
Expand Down Expand Up @@ -2612,6 +2623,15 @@ template <int direction> void TraceWindow::pc_nextprev(wxCommandEvent &event)
drawing_area->Refresh();
}

template <int direction> void TraceWindow::exc_nextprev(wxCommandEvent &event)
{
if (vu.goto_cpu_exception(direction)) {
update_location(UpdateLocationType::NewVis);
keep_visnode_in_view();
}
drawing_area->Refresh();
}

bool TraceWindow::keypress(wxKeyEvent &event)
{
switch (event.GetKeyCode()) {
Expand Down
14 changes: 10 additions & 4 deletions lib/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class Index : ParseReceiver {
AVLDisk<SeqOrderPayload, SeqOrderAnnotation> *seqtree;
Time current_time;
bool seen_instruction_at_current_time;
bool seen_cpu_exception_at_current_line;
set<PendingCall> pending_calls;
set<CallReturn> found_callrets;
bool aarch64_used;
Expand Down Expand Up @@ -444,10 +445,13 @@ void Index::got_event(ExceptionEvent &ev)
{
got_event_common(&ev, false);

ByPCPayload bypcp;
bypcp.trace_file_firstline = prev_lineno;
bypcp.pc = CPU_EXCEPTION_PC;
bypcroot = bypctree->insert(bypcroot, bypcp);
if (!seen_cpu_exception_at_current_line) {
ByPCPayload bypcp;
bypcp.trace_file_firstline = prev_lineno;
bypcp.pc = CPU_EXCEPTION_PC;
bypcroot = bypctree->insert(bypcroot, bypcp);
seen_cpu_exception_at_current_line = true;
}
}

void Index::delete_from_memtree(char type, Addr addr, size_t size)
Expand Down Expand Up @@ -922,6 +926,7 @@ void Index::got_event_common(TarmacEvent *event, bool is_instruction)

prev_lineno = lineno;
seen_any_event = true;
seen_cpu_exception_at_current_line = false;
}

if (is_instruction)
Expand Down Expand Up @@ -982,6 +987,7 @@ void Index::open_trace_file()
last_memroot = memroot;
current_time = -(Time)1;
seen_instruction_at_current_time = false;
seen_cpu_exception_at_current_line = false;
bypcroot = 0;
true_lineno = 0;
lineno = 1;
Expand Down

0 comments on commit 19f7432

Please sign in to comment.