Skip to content

Commit

Permalink
feat: in/out arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma-s1n committed May 30, 2024
1 parent 8175b09 commit e96706c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
90 changes: 90 additions & 0 deletions src/strace/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,96 @@ mod tests {
})
);
}

#[cfg_attr(
feature = "parser-regex",
ignore = "in/out arguments not supported by regex-parser"
)]
#[test]
fn test_clone3() {
let _ = simple_logger::SimpleLogger::new().init();

assert_eq!(
parse_line(
"664767 0.000014 clone3({flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, child_tid=0x7f3b7c000990, parent_tid=0x7f3b7c000990, exit_signal=0, stack=0x7f3b7b800000, stack_size=0x7ff880, tls=0x7f3b7c0006c0} => {parent_tid=[664773]}, 88) = 664773",
&[]
)
.unwrap(),
ParseResult::Syscall(Syscall {
pid: 664767,
rel_ts: 0.000014,
name: "clone3".to_owned(),
args: vec![
Expression::Struct(HashMap::from([
(
"flags".to_owned(),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::BinaryOr(vec![
IntegerExpressionValue::NamedConst("CLONE_VM".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_FS".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_FILES".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_SIGHAND".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_THREAD".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_SYSVSEM".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_SETTLS".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_PARENT_SETTID".to_owned()),
IntegerExpressionValue::NamedConst("CLONE_CHILD_CLEARTID".to_owned()),
]),
metadata: None
}),
),
(
"child_tid".to_owned(),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::Literal(0x7f3b7c000990),
metadata: None,
}),
),
(
"parent_tid".to_owned(),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::Literal(0x7f3b7c000990),
metadata: None,
}),
),
(
"exit_signal".to_owned(),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::Literal(0),
metadata: None,
}),
),
(
"stack".to_owned(),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::Literal(0x7f3b7b800000),
metadata: None,
}),
),
(
"stack_size".to_owned(),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::Literal(0x7ff880),
metadata: None,
}),
),
(
"tls".to_owned(),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::Literal(0x7f3b7c0006c0),
metadata: None,
}),
),
])),
Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::Literal(88),
metadata: None,
}),
],
ret_val: 664773
})
);
}
}

#[cfg(all(feature = "nightly", test))]
Expand Down
12 changes: 10 additions & 2 deletions src/strace/parser/peg.pest
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ rel_ts = { ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+ }

name = { symbol_name }

arguments = { (expression ~ (", " ~ expression)*)? }
arguments = { (argument ~ (", " ~ argument)*)? }

ret_val = { int ~ (" " ~ ANY*)? }


// Subrules

argument = {
#in_out = in_out_argument |
#in = in_argument
}
in_argument = { expression }
in_out_argument = { expression ~ " => " ~ expression}

expression = {
#macro = macro |
#int = int |
Expand Down Expand Up @@ -90,7 +97,8 @@ buffer = {
buffer_char = { !"\"" ~ ANY }
buffer_byte = { "\\x" ~ ASCII_HEX_DIGIT{2} }

macro = { symbol_name ~ "(" ~ arguments ~ ")" }
macro = { symbol_name ~ "(" ~ macro_arguments ~ ")" }
macro_arguments = { (expression ~ (", " ~ expression)*)? }

array = { "[" ~ (expression ~ (", " ~ expression)*)? ~ "]" }

Expand Down
12 changes: 11 additions & 1 deletion src/strace/parser/peg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,17 @@ impl TryFrom<Pair<'_, Rule>> for Syscall {
.next()
.ok_or_else(|| anyhow::anyhow!("Missing arguments node"))?
.into_inner()
.map(|p| pair_descend(p, 1)?.try_into())
.map(|p| {
let p = pair_descend(p, 1)?;
match p.as_node_tag() {
Some("in") => pair_descend(p, 2)?.try_into(),
Some("in_out") => {
// Only take the 'in' part, ignore the rest
pair_descend(p, 2)?.try_into()
}
_ => anyhow::bail!("Unhandled pair: {p:?}"),
}
})
.collect::<Result<_, _>>()?
} else {
vec![]
Expand Down

0 comments on commit e96706c

Please sign in to comment.