Skip to content

Commit dc62d9e

Browse files
committed
Recognize int3 instructions in trace parser
Not quite sure why we'd be seeing this, but let's not crash when we do. For now, treat a software interrupt as a jump. Ref janestreet#257
1 parent 923eaef commit dc62d9e

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

core/event.ml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Kind = struct
77
| Syscall
88
| Sysret
99
| Hardware_interrupt
10+
| Interrupt
1011
| Iret
1112
| Jump
1213
[@@deriving sexp, compare, bin_io]

core/event.mli

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Kind : sig
77
| Syscall
88
| Sysret
99
| Hardware_interrupt
10+
| Interrupt
1011
| Iret
1112
| Jump
1213
[@@deriving sexp, compare]

src/perf_decode.ml

+15-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let perf_callstack_entry_re = Re.Perl.re "^\t *([0-9a-f]+) (.*)$" |> Re.compile
2222

2323
let perf_branches_event_re =
2424
Re.Perl.re
25-
{|^ *(call|return|tr strt|syscall|sysret|hw int|iret|tr end|tr strt tr end|tr end (?:call|return|syscall|sysret|iret)|jmp|jcc) +([0-9a-f]+) (.*) => +([0-9a-f]+) (.*)$|}
25+
{|^ *(call|return|tr strt|syscall|sysret|hw int|iret|int|tr end|tr strt tr end|tr end (?:call|return|syscall|sysret|iret)|jmp|jcc) +([0-9a-f]+) (.*) => +([0-9a-f]+) (.*)$|}
2626
|> Re.compile
2727
;;
2828

@@ -243,6 +243,7 @@ let parse_perf_branches_event ?perf_maps (thread : Event.Thread.t) time line : E
243243
match String.strip kind with
244244
| "call" -> Some Call
245245
| "return" -> Some Return
246+
| "int" -> Some Interrupt
246247
| "jmp" -> Some Jump
247248
| "jcc" -> Some Jump
248249
| "syscall" -> Some Syscall
@@ -495,6 +496,19 @@ let%test_module _ =
495496
(data (Trace (kind Call) (src 0x56234f77576b) (dst 0x56234f4bc7a0)))))) |}]
496497
;;
497498

499+
let%expect_test "software interrupts" =
500+
check
501+
"1907478/1909463 457407.880965552: 1 \
502+
branches:uH: int 564aa58813d4 \
503+
Builtins_RunMicrotasks+0x554 (/usr/local/bin/workload) => 564aa584fa00 \
504+
Builtins_Call_ReceiverIsNotNullOrUndefined+0x0 (/usr/local/bin/workload)";
505+
[%expect
506+
{|
507+
((Ok
508+
((thread ((pid (1907478)) (tid (1909463)))) (time 5d7h3m27.880965552s)
509+
(data (Trace (kind Interrupt) (src 0x564aa58813d4) (dst 0x564aa584fa00)))))) |}]
510+
;;
511+
498512
let%expect_test "decode error with a timestamp" =
499513
check
500514
" instruction trace error type 1 time 47170.086912826 cpu -1 pid 293415 tid \

src/trace_writer.ml

+11-3
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,17 @@ let write_event (T t) ?events_writer event =
10041004
~time;
10051005
(match kind, trace_state_change with
10061006
| Some Call, (None | Some End) -> call t thread_info ~time ~location:dst
1007-
| ( Some (Call | Syscall | Return | Hardware_interrupt | Iret | Sysret | Jump)
1007+
| ( Some
1008+
( Call
1009+
| Syscall
1010+
| Return
1011+
| Hardware_interrupt
1012+
| Iret
1013+
| Interrupt
1014+
| Sysret
1015+
| Jump )
10081016
, Some Start )
1009-
| Some (Hardware_interrupt | Jump), Some End ->
1017+
| Some (Hardware_interrupt | Jump | Interrupt), Some End ->
10101018
raise_s
10111019
[%message
10121020
"BUG: magic-trace devs thought this event was impossible, but you just \
@@ -1093,7 +1101,7 @@ let write_event (T t) ?events_writer event =
10931101
~addr:dst.instruction_pointer
10941102
~time;
10951103
check_current_symbol t thread_info ~time dst)
1096-
| Some Jump, None ->
1104+
| Some (Jump | Interrupt), None ->
10971105
Ocaml_hacks.check_current_symbol_track_entertraps t thread_info ~time dst
10981106
(* (None, _) comes up when perf spews something magic-trace doesn't recognize.
10991107
Instead of crashing, ignore it and keep going. *)

0 commit comments

Comments
 (0)