Skip to content

Commit

Permalink
refactor/tracer: make interpreter field optional in Exec{Data,Event}
Browse files Browse the repository at this point in the history
  • Loading branch information
kxxt committed Sep 1, 2024
1 parent 4fa290a commit 406bc6f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ pub struct ExecEvent {
pub filename: Result<PathBuf, InspectError>,
pub argv: Arc<Result<Vec<OutputMsg>, InspectError>>,
pub envp: Arc<Result<BTreeMap<OutputMsg, OutputMsg>, InspectError>>,
pub interpreter: Vec<Interpreter>,
pub interpreter: Option<Vec<Interpreter>>,
pub env_diff: Result<EnvDiff, InspectError>,
pub fdinfo: Arc<FileDescriptorInfoCollection>,
pub result: i64,
Expand Down
39 changes: 22 additions & 17 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,24 +481,26 @@ impl Printer {
// Interpreter

if self.args.trace_interpreter && result == 0 {
// FIXME: show interpreter for errnos other than ENOENT
write!(out, " {} ", "interpreter".purple(),)?;
match exec_data.interpreters.len() {
0 => {
write!(out, "{}", Interpreter::None)?;
}
1 => {
write!(out, "{}", exec_data.interpreters[0])?;
}
_ => {
list_printer.begin(out)?;
for (idx, interpreter) in exec_data.interpreters.iter().enumerate() {
if idx != 0 {
list_printer.comma(out)?;
if let Some(interpreters) = exec_data.interpreters.as_ref() {
// FIXME: show interpreter for errnos other than ENOENT
write!(out, " {} ", "interpreter".purple(),)?;
match interpreters.len() {
0 => {
write!(out, "{}", Interpreter::None)?;
}
1 => {
write!(out, "{}", interpreters[0])?;
}
_ => {
list_printer.begin(out)?;
for (idx, interpreter) in interpreters.iter().enumerate() {
if idx != 0 {
list_printer.comma(out)?;
}
write!(out, "{}", interpreter)?;
}
write!(out, "{}", interpreter)?;
list_printer.end(out)?;
}
list_printer.end(out)?;
}
}
}
Expand Down Expand Up @@ -560,7 +562,10 @@ impl Printer {
"-".bright_red().bold(),
k.cli_escaped_styled(THEME.removed_env_var),
"=".bright_red().strikethrough(),
env.get(&k).unwrap().cli_escaped_styled(THEME.removed_env_var)
env
.get(&k)
.unwrap()
.cli_escaped_styled(THEME.removed_env_var)
)?;
}
list_printer.end(out)?;
Expand Down
4 changes: 2 additions & 2 deletions src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ impl Tracer {
argv,
envp,
read_cwd(pid)?,
interpreters,
Some(interpreters),
read_fds(pid)?,
));
} else if syscallno == nix::libc::SYS_execve {
Expand All @@ -764,7 +764,7 @@ impl Tracer {
argv,
envp,
read_cwd(pid)?,
interpreters,
Some(interpreters),
read_fds(pid)?,
));
} else if syscallno == SYS_clone || syscallno == SYS_clone3 {
Expand Down
4 changes: 2 additions & 2 deletions src/tracer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct ExecData {
pub argv: Arc<Result<Vec<OutputMsg>, InspectError>>,
pub envp: Arc<Result<BTreeMap<OutputMsg, OutputMsg>, InspectError>>,
pub cwd: PathBuf,
pub interpreters: Vec<Interpreter>,
pub interpreters: Option<Vec<Interpreter>>,
pub fdinfo: Arc<FileDescriptorInfoCollection>,
}

Expand All @@ -80,7 +80,7 @@ impl ExecData {
argv: Result<Vec<OutputMsg>, InspectError>,
envp: Result<BTreeMap<OutputMsg, OutputMsg>, InspectError>,
cwd: PathBuf,
interpreters: Vec<Interpreter>,
interpreters: Option<Vec<Interpreter>>,
fdinfo: FileDescriptorInfoCollection,
) -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions src/tracer/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ async fn tracer_emits_exec_event(tracer: TracerFixture) {
assert_eq!(exec.fdinfo.as_ref(), &BaselineInfo::new().unwrap().fdinfo);
// Comm: should be the value before exec
assert_eq!(exec.comm, "tracer");
// Interpreter: doesn't contain errors
for interp in exec.interpreter.iter() {
// Interpreter: is some(ptrace mode supports it) and doesn't contain errors
for interp in exec.interpreter.unwrap().iter() {
assert!(
!matches!(interp, Interpreter::Error(_)),
"error: {:?}",
Expand Down
8 changes: 7 additions & 1 deletion src/tui/details_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ impl DetailsPopupState {
),
(
" Interpreters ",
TracerEventDetails::interpreters_to_string(&exec.interpreter).into(),
Line::from(
exec
.interpreter
.as_deref()
.map(|v| TracerEventDetails::interpreters_to_string(v).into())
.unwrap_or_else(|| "Unknown".set_style(THEME.value_unknown)),
),
),
(
" Stdin ",
Expand Down
2 changes: 2 additions & 0 deletions src/tui/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct Theme {
// Details Popup
pub exec_result_success: Style,
pub exec_result_failure: Style,
pub value_unknown: Style,
pub fd_closed: Style,
pub plus_sign: Style,
pub minus_sign: Style,
Expand Down Expand Up @@ -167,6 +168,7 @@ impl Default for Theme {
exec_result_success: Style::default().green(),
exec_result_failure: Style::default().red(),
fd_closed: Style::default().light_red(),
value_unknown: Style::default().light_red().italic(),
plus_sign: Style::default().light_green(),
minus_sign: Style::default().light_red(),
equal_sign: Style::default().yellow().bold(),
Expand Down

0 comments on commit 406bc6f

Please sign in to comment.