Skip to content

Commit

Permalink
Initial impl of detecting CPU exceptions in a trace file.
Browse files Browse the repository at this point in the history
No functional change yet, except in the diagnostic output of
'parsertest'.

This adds a fifth overload of got_event() in the ParseReceiver base
class. EXC or E lines that describe CPU exceptions are no longer
classed as TextOnlyEvent: they're now ExceptionEvent.

At present the only nontrivial implementation of the new function is
in 'parsertest', which changes its diagnostic output to prove it's
recognised a CPU exception. In the next commit, I'll do something more
interesting with it.

Currently, the only information we parse out of a CPU exception line
is that it _is_ a CPU exception: we don't detect the exception type,
or the PC at which it occurred, or anything else. I don't currently
have a large enough corpus of test input to be sure of the right way
to extract that information, and also, I don't currently have any good
ideas for what the tools could do with the information if it was
available.
  • Loading branch information
statham-arm committed Aug 2, 2024
1 parent 5444331 commit 0190734
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 11 deletions.
6 changes: 6 additions & 0 deletions include/libtarmac/parser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ struct MemoryEvent : TarmacEvent {
}
};

struct ExceptionEvent : TarmacEvent {
ExceptionEvent(Time time) : TarmacEvent(time) {}
~ExceptionEvent() {}
};

struct TextOnlyEvent : TarmacEvent {
std::string type, msg;
TextOnlyEvent(Time time, const std::string &type, const std::string &msg)
Expand All @@ -134,6 +139,7 @@ class ParseReceiver {
virtual void got_event(RegisterEvent &) {}
virtual void got_event(MemoryEvent &) {}
virtual void got_event(TextOnlyEvent &) {}
virtual void got_event(ExceptionEvent &) {}

// start and end describe a half-open interval of locations in the
// input string, i.e. including line[start] and not including
Expand Down
36 changes: 34 additions & 2 deletions lib/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ class TarmacLineParserImpl {
if (tok == "EXC" || tok == "Reset") {
// Sometimes used to report an exception event relating to the
// instruction, e.g. because it was illegal. We abandon parsing
// this as an instruction event, and decide it's text-only.
// this as an instruction event, and treat it as an exception.
tok = lex(); // now tok.startpos begins unparsed text
highlight(tok.startpos, line.size(), HL_TEXT_EVENT);
TextOnlyEvent ev(time, "EXC", line.substr(tok.startpos));
ExceptionEvent ev(time);
receiver->got_event(ev);
return;
}
Expand Down Expand Up @@ -1178,6 +1178,38 @@ class TarmacLineParserImpl {
i = j;
}
}
} else if (tok == "EXC") {
// Trace event type that reports CPU exceptions in the
// ES-style format. Sometimes there's an ES token before
// it, which we handle above.
ExceptionEvent ev(time);
receiver->got_event(ev);
} else if (tok == "E") {
// Trace event type that reports (among other things) CPU
// exceptions in the IT-style format.
//
// For a CPU exception, the usual format seems to be
// [<time>] E <pc> [<extra>] <excid> CoreEvent_<description>
// but our ExceptionEvent doesn't have any fields to store any
// of that except the time.
//
// However, this event type is also used for things that
// aren't CPU exceptions. In particular, sometimes the "E"
// event type token is followed immediately by
// DebugEvent_<something>, with no intervening pc value or
// exception type, and we're not interested in those.

string type(tok.s);
tok = lex();

if (tok.starts_with("DebugEvent_")) {
// Not interesting enough to make an ExceptionEvent
TextOnlyEvent ev(time, type, line.substr(tok.startpos));
receiver->got_event(ev);
} else {
ExceptionEvent ev(time);
receiver->got_event(ev);
}
} else if (tok == "Tarmac") {
// Header line seen at the start of some trace files. Typically
// says "Tarmac Text Rev 1" or "Tarmac Text Rev 3t", or similar.
Expand Down
24 changes: 16 additions & 8 deletions tests/parsertest.ref
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Parse warning: unsupported system operation 'AT'
--- Tarmac line: 0 clk cpu1 R r1 00000000
* RegisterEvent time=0 reg=r1 offset=0 bytes=00:00:00:00
--- Tarmac line: 0 clk cpu0 E 10001848 00000001 CoreEvent_RESET
* TextOnlyEvent time=0 type="E" text="10001848 00000001 CoreEvent_RESET"
* ExceptionEvent time=0
--- Tarmac line: 0 clk cpu0 R r13_main_s 30040000
* RegisterEvent time=0 reg=r13 offset=0 bytes=30:04:00:00
--- Tarmac line: 0 clk cpu0 R MSP_S 30040000
Expand All @@ -98,7 +98,7 @@ Parse warning: unsupported system operation 'AT'
* MemoryEvent time=180000140000 read=true known=true addr=10006fffcc0 size=8 contents=10005101000
--- Tarmac line: Tarmac Text Rev 3t
--- Tarmac line: 17000 ns ES EXC [0x00] Reset
* TextOnlyEvent time=17000 type="EXC" text="[0x00] Reset"
* ExceptionEvent time=17000
--- Tarmac line: BR (00000000) A
* TextOnlyEvent time=17000 type="BR" text="(00000000) A"
--- Tarmac line: 41000 ns ES (00000000:e59ff018) A svc: LDR pc,{pc}+0x20 ; 0x20
Expand Down Expand Up @@ -152,7 +152,7 @@ Parse warning: unsupported system operation 'AT'
* RegisterEvent time=23233000 reg=v0 offset=0 bytes=77:66:55:44:33:22:11:00
--- Tarmac line: Tarmac Text Rev 3t
--- Tarmac line: 499294 ns ES EXC Reset
* TextOnlyEvent time=499294 type="EXC" text="Reset"
* ExceptionEvent time=499294
--- Tarmac line: R CPSR 000003cd
* RegisterEvent time=499294 reg=psr offset=0 bytes=00:00:03:cd
--- Tarmac line: R SPSR_EL3 00000000000001cd
Expand Down Expand Up @@ -198,9 +198,9 @@ Parse warning: unsupported system operation 'AT'
--- Tarmac line: 6379085 cs W04 X ffffffbdc3c15c30 010c010b
* MemoryEvent time=6379085 read=false known=true addr=ffffffbdc3c15c30 size=4 contents=10c010b
--- Tarmac line: 12345 ns ES Reset
* TextOnlyEvent time=12345 type="EXC" text=""
* ExceptionEvent time=12345
--- Tarmac line: EXC [0x00] Reset
* TextOnlyEvent time=12345 type="EXC" text="[0x00] Reset"
* ExceptionEvent time=12345
--- Tarmac line: 123 ns R Q0 -------- -------- 3ff6a09e 667f3bcd
* RegisterEvent time=123 reg=q0 offset=0 bytes=3f:f6:a0:9e:66:7f:3b:cd
--- Tarmac line: 124 ns R Q0 3ff428a2 f98d728b -------- --------
Expand Down Expand Up @@ -229,8 +229,8 @@ Parse warning: unsupported system operation 'AT'
* RegisterEvent time=16465 reg=v5 offset=0 bytes=00:00:00:00:00:00:00:00
--- Tarmac line: R V5<127:64> 00000000
* RegisterEvent time=16465 reg=v5 offset=8 bytes=00:00:00:00:00:00:00:00
--- Tarmac line: 1234567 cs E dummy header line to reset timestamp for next two lines
* TextOnlyEvent time=1234567 type="E" text="dummy header line to reset timestamp for next two lines"
--- Tarmac line: 1234567 cs E DebugEvent_dummy to reset timestamp for next two lines
* TextOnlyEvent time=1234567 type="E" text="DebugEvent_dummy to reset timestamp for next two lines"
--- Tarmac line: LD 000000007ff80fe0 ........ 44444444 ........ 2222..11 S:007ff80fe0 nGnRnE OSH
* MemoryEvent time=1234567 read=true known=true addr=7ff80fe8 size=4 contents=44444444
* MemoryEvent time=1234567 read=true known=true addr=7ff80fe2 size=2 contents=2222
Expand All @@ -257,7 +257,7 @@ Parse warning: unsupported system operation 'AT'
--- Tarmac line: 608 clk R Q0 93c467e3 7db0c7a4 d1be3f81 0152cb56
* RegisterEvent time=608 reg=q0 offset=0 bytes=93:c4:67:e3:7d:b0:c7:a4:d1:be:3f:81:01:52:cb:56
--- Tarmac line: 15000 ps ES EXC [1] Reset
* TextOnlyEvent time=15000 type="EXC" text="[1] Reset"
* ExceptionEvent time=15000
--- Tarmac line: R MSP_S 00000000
* RegisterEvent time=15000 reg=r13 offset=0 bytes=00:00:00:00
--- Tarmac line: R XPSR f9000000
Expand Down Expand Up @@ -286,3 +286,11 @@ Parse warning: unsupported system operation 'AT'
* RegisterEvent time=8677000000 reg=xsp offset=0 bytes=fe:dc:ba:98:76:54:32:10
--- Tarmac line: R X0 -------- --------
--- Tarmac line: R X1 --------
--- Tarmac line: 0 ps E 00000000 00000000 CoreEvent_Reset
* ExceptionEvent time=0
--- Tarmac line: 39000000 ps E 00008100 00000084 CoreEvent_CURRENT_SPx_SYNC
* ExceptionEvent time=39000000
--- Tarmac line: 0 tic ES EXC Reset
* ExceptionEvent time=0
--- Tarmac line: EXC [0x200] Synchronous Current EL with SP_ELx
* ExceptionEvent time=0
9 changes: 8 additions & 1 deletion tests/parsertest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Tarmac Text Rev 3t
# in which the bytes written/read are not all contiguous. The parser
# should generate multiple memory access events for each one.

1234567 cs E dummy header line to reset timestamp for next two lines
1234567 cs E DebugEvent_dummy to reset timestamp for next two lines
LD 000000007ff80fe0 ........ 44444444 ........ 2222..11 S:007ff80fe0 nGnRnE OSH
ST 000000009ffdb810 ....0000 ........ 88888888 88888888 S:009ffdb810 NM NSH IWTNA OWTNA

Expand Down Expand Up @@ -293,3 +293,10 @@ R SP_EL2 fedcba98 76543210
# signs to fill X1.
R X0 -------- --------
R X1 --------

# CPU exceptions. "E" is IT style; "ES EXC" and "EXC" are ES style.
0 ps E 00000000 00000000 CoreEvent_Reset
39000000 ps E 00008100 00000084 CoreEvent_CURRENT_SPx_SYNC
0 tic ES EXC Reset
EXC [0x200] Synchronous Current EL with SP_ELx

5 changes: 5 additions & 0 deletions tools/parsertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class TestReceiver : public ParseReceiver {
<< dec << " disassembly=\"" << ev.disassembly << "\"" << endl;
}

void got_event(ExceptionEvent &ev)
{
os << "* ExceptionEvent" << " time=" << ev.time << endl;
}

void got_event(TextOnlyEvent &ev)
{
os << "* TextOnlyEvent"
Expand Down

0 comments on commit 0190734

Please sign in to comment.