-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathstrace_minimal.rs
49 lines (44 loc) · 1.24 KB
/
strace_minimal.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
use clap::Parser;
use reverie::syscalls::Displayable;
use reverie::syscalls::Syscall;
use reverie::Error;
use reverie::Guest;
use reverie::Tool;
use reverie_util::CommonToolArguments;
#[derive(Default)]
struct StraceTool {}
#[reverie::tool]
impl Tool for StraceTool {
type GlobalState = ();
type ThreadState = ();
async fn handle_syscall_event<T: Guest<Self>>(
&self,
guest: &mut T,
syscall: Syscall,
) -> Result<i64, Error> {
eprintln!(
"[pid {}] {} = ?",
guest.tid(),
syscall.display_with_outputs(&guest.memory()),
);
guest.tail_inject(syscall).await
}
}
#[tokio::main]
async fn main() -> Result<(), Error> {
let args = CommonToolArguments::from_args();
let log_guard = args.init_tracing();
let tracer = reverie_ptrace::TracerBuilder::<StraceTool>::new(args.into())
.spawn()
.await?;
let (status, _) = tracer.wait().await?;
drop(log_guard); // Flush logs before exiting.
status.raise_or_exit()
}