Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recognize int3 instructions in trace parser #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions core/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Kind = struct
| Syscall
| Sysret
| Hardware_interrupt
| Interrupt
| Iret
| Jump
[@@deriving sexp, compare, bin_io]
Expand Down
1 change: 1 addition & 0 deletions core/event.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Kind : sig
| Syscall
| Sysret
| Hardware_interrupt
| Interrupt
| Iret
| Jump
[@@deriving sexp, compare]
Expand Down
16 changes: 15 additions & 1 deletion src/perf_decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let perf_callstack_entry_re = Re.Perl.re "^\t *([0-9a-f]+) (.*)$" |> Re.compile

let perf_branches_event_re =
Re.Perl.re
{|^ *(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]+) (.*)$|}
{|^ *(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]+) (.*)$|}
|> Re.compile
;;

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

let%expect_test "software interrupts" =
check
"1907478/1909463 457407.880965552: 1 \
branches:uH: int 564aa58813d4 \
Builtins_RunMicrotasks+0x554 (/usr/local/bin/workload) => 564aa584fa00 \
Builtins_Call_ReceiverIsNotNullOrUndefined+0x0 (/usr/local/bin/workload)";
[%expect
{|
((Ok
((thread ((pid (1907478)) (tid (1909463)))) (time 5d7h3m27.880965552s)
(data (Trace (kind Interrupt) (src 0x564aa58813d4) (dst 0x564aa584fa00)))))) |}]
;;

let%expect_test "decode error with a timestamp" =
check
" instruction trace error type 1 time 47170.086912826 cpu -1 pid 293415 tid \
Expand Down
14 changes: 11 additions & 3 deletions src/trace_writer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,17 @@ let write_event (T t) ?events_writer event =
~time;
(match kind, trace_state_change with
| Some Call, (None | Some End) -> call t thread_info ~time ~location:dst
| ( Some (Call | Syscall | Return | Hardware_interrupt | Iret | Sysret | Jump)
| ( Some
( Call
| Syscall
| Return
| Hardware_interrupt
| Iret
| Interrupt
| Sysret
| Jump )
, Some Start )
| Some (Hardware_interrupt | Jump), Some End ->
| Some (Hardware_interrupt | Jump | Interrupt), Some End ->
raise_s
[%message
"BUG: magic-trace devs thought this event was impossible, but you just \
Expand Down Expand Up @@ -1093,7 +1101,7 @@ let write_event (T t) ?events_writer event =
~addr:dst.instruction_pointer
~time;
check_current_symbol t thread_info ~time dst)
| Some Jump, None ->
| Some (Jump | Interrupt), None ->
Ocaml_hacks.check_current_symbol_track_entertraps t thread_info ~time dst
(* (None, _) comes up when perf spews something magic-trace doesn't recognize.
Instead of crashing, ignore it and keep going. *)
Expand Down