Skip to content

Commit

Permalink
update frontend code to work with main-branch libprobe
Browse files Browse the repository at this point in the history
  • Loading branch information
Ex-32 committed Jul 24, 2024
1 parent 4dae6ea commit edaf78a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 29 deletions.
8 changes: 4 additions & 4 deletions probe_src/probe_frontend/cli/src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ impl Dump for ops::Path {
impl Dump for ops::CloneOp {
fn dump(&self) -> String {
format!(
"[ child_process_id={}, child_thread_id={}, errno={} ]",
self.child_process_id, self.child_thread_id, self.ferrno,
"[ task_type={}, task_id={}, errno={} ]",
self.task_type, self.task_id, self.ferrno,
)
}
}
Expand Down Expand Up @@ -248,8 +248,8 @@ impl Dump for ops::InitThreadOp {
impl Dump for ops::WaitOp {
fn dump(&self) -> String {
format!(
"[ pid={}, options={}, status={}, ret={}, errno={} ]",
self.pid, self.options, self.status, self.ret, self.ferrno,
"[ task_type={}, task_id={}, options={}, status={}, errno={} ]",
self.task_type, self.task_id, self.options, self.status, self.ferrno,
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions probe_src/probe_frontend/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn main() -> Result<()> {

let matches = command!()
.about("Generate or manipulate Provenance for Replay OBservation Engine (PROBE) logs.")
.propagate_version(true)
.subcommands([
Command::new("record")
.args([
Expand Down Expand Up @@ -72,7 +73,7 @@ fn main() -> Result<()> {
.default_value("probe_log")
.value_parser(value_parser!(OsString)),
])
.about("Write the data from probe log data in a human-readable manne"),
.about("Write the data from probe log data in a human-readable manner"),
Command::new("__gdb-exec-shim").hide(true).arg(
arg!(<CMD> ... "Command to run")
.required(true)
Expand Down Expand Up @@ -141,6 +142,7 @@ fn main() -> Result<()> {

Err(e).wrap_err("Shim failed to exec")
}
_ => Err(eyre!("unexpected subcommand")),
None => Err(eyre!("Subcommand expected, try --help for more info")),
_ => Err(eyre!("Unknown subcommand")),
}
}
2 changes: 2 additions & 0 deletions probe_src/probe_frontend/lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ fn main() {
#include <sys/stat.h>
#include <sys/types.h>
#include <utime.h>
#include <threads.h>
#include <pthread.h>
// HACK: defining this manually instead of using <sys/resource.h> is
// a huge hack, but it greatly reduces the generated code complexity
Expand Down
19 changes: 12 additions & 7 deletions probe_src/probe_frontend/lib/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ impl FfiFrom<C_Op> for OpInternal {
pub struct Op {
pub data: OpInternal,
pub time: Timespec,
pub pthread_id: pthread_t,
pub iso_c_thread_id: thrd_t,

#[serde(serialize_with = "Op::serialize_type")]
#[serde(skip_deserializing)]
Expand All @@ -307,6 +309,8 @@ impl FfiFrom<C_Op> for Op {
Ok(Self {
data: value.ffi_into(ctx)?,
time: value.time.ffi_into(ctx)?,
pthread_id: value.pthread_id,
iso_c_thread_id: value.iso_c_thread_id,

_type: (),
})
Expand Down Expand Up @@ -340,11 +344,12 @@ mod tests {

// since we're defining a custom version of the rusage struct (indirectly through rust-bindgen)
// we should at least check that they're the same size.
#[test]
fn rusage_size() {
assert_eq!(
std::mem::size_of::<libc::rusage>(),
std::mem::size_of::<C_rusage>()
);
}
// FIXME: muslc has a different sized rusage struct so libc::rusage doesn't match
// #[test]
// fn rusage_size() {
// assert_eq!(
// std::mem::size_of::<libc::rusage>(),
// std::mem::size_of::<C_rusage>()
// );
// }
}
8 changes: 4 additions & 4 deletions probe_src/probe_frontend/lib/src/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ impl<'a> OpsArena<'a> {
.wrap_err("Failed to create ArenaHeader for OpsArena")?;

if ((header.used - size_of::<ArenaHeader>()) % size_of::<C_Op>()) != 0 {
return Err(ArenaError::Misaligned.into());
return Err(ArenaError::Misaligned { size: header.used }.into());
}

let count = (header.used - size_of::<ArenaHeader>()) / size_of::<C_Op>();

log::debug!("[unsafe] converting Vec<u8> to &[RawOp] of size {}", count);
log::debug!("[unsafe] converting Vec<u8> to &[C_Op] of size {}", count);
let ops = unsafe {
let ptr = bytes.as_ptr().add(size_of::<ArenaHeader>()) as *const C_Op;
std::slice::from_raw_parts(ptr, count)
Expand Down Expand Up @@ -422,8 +422,8 @@ pub enum ArenaError {

/// Returned if an [`OpsArena`]'s size isn't isn't `HEADER_SIZE + (N * OP_SIZE)` when `N` is
/// some integer.
#[error("Arena alignment error: used arena size minus header isn't a multiple of op size")]
Misaligned,
#[error("Arena alignment error: arena size ({size}) minus header isn't a multiple of op size")]
Misaligned { size: usize },

/// Returned if the instantiation in a [`ArenaHeader`] doesn't match the indicated one
#[error("Header contained Instantiation ID {header}, but {passed} was indicated")]
Expand Down
9 changes: 5 additions & 4 deletions probe_src/probe_frontend/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ pub fn make_rust_op(input: TokenStream) -> TokenStream {
.into()))
}
};
// filter out any identifier starting with __ since every example i've seen in
// glibc of "__ident" is padding or reserved space.
if ident.to_string().starts_with("__") {
return None;
let ident_str = ident.to_string();
for prefix in ["__spare", "__reserved"] {
if ident_str.starts_with(prefix) {
return None;
}
}

let pair = convert_bindgen_type(&field.ty).map(|ty| (ident, ty));
Expand Down
8 changes: 4 additions & 4 deletions probe_src/probe_frontend/macros/src/pygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ fn convert_to_pytype(ty: &syn::Type) -> MacroResult<String> {
Ok(match name.as_str() {
// that's a lot of ways to say "int", python ints are bigints so we don't have to
// care about size
"__dev_t" | "__gid_t" | "__ino_t" | "__mode_t" | "__s32" | "__s64"
"TaskType" | "__dev_t" | "__gid_t" | "__ino_t" | "__mode_t" | "__s32" | "__s64"
| "__suseconds_t" | "__syscall_slong_t" | "__syseconds_t" | "__time_t"
| "__u16" | "__u32" | "__u64" | "__uid_t" | "c_int" | "c_long" | "c_uint"
| "dev_t" | "gid_t" | "i128" | "i16" | "i32" | "i64" | "i8" | "ino_t" | "isize"
| "mode_t" | "pid_t" | "u128" | "u16" | "u32" | "u64" | "u8" | "uid_t"
| "usize" => "int".to_owned(),
| "c_ulong" | "dev_t" | "gid_t" | "i128" | "i16" | "i32" | "i64" | "i8"
| "ino_t" | "isize" | "mode_t" | "pid_t" | "pthread_t" | "thrd_t" | "u128"
| "u16" | "u32" | "u64" | "u8" | "uid_t" | "usize" => "int".to_owned(),

// float, python uses doubles for everything
"f32" | "f64" => "float".to_owned(),
Expand Down
10 changes: 6 additions & 4 deletions probe_src/probe_frontend/python/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class ExecOp:
class CloneOp:
flags: int
run_pthread_atfork_handlers: bool
child_process_id: int
child_thread_id: int
task_type: int
task_id: int
ferrno: int


Expand Down Expand Up @@ -172,10 +172,10 @@ class ReaddirOp:

@dataclass(init=True, frozen=True)
class WaitOp:
pid: int
task_type: int
task_id: int
options: int
status: int
ret: int
ferrno: int


Expand Down Expand Up @@ -206,6 +206,8 @@ class UpdateMetadataOp:
class Op:
data: OpInternal
time: Timespec
pthread_id: int
iso_c_thread_id: int


@dataclass(init=True, frozen=True)
Expand Down

0 comments on commit edaf78a

Please sign in to comment.