Skip to content

Commit

Permalink
Expose set_procinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
gleocadie committed Nov 22, 2024
1 parent ef8ca7d commit d021cf2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crashtracker-ffi/src/crash_info/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,21 @@ impl<'a> TryFrom<SigInfo<'a>> for datadog_crashtracker::SigInfo {
}
}


#[repr(C)]
pub struct ProcInfo {
pub pid: u32,
}

impl TryFrom<ProcInfo> for datadog_crashtracker::ProcessInfo {
type Error = anyhow::Error;

fn try_from(value : ProcInfo) -> anyhow::Result<Self> {
let pid = value.pid;
Ok(Self { pid })
}
}

#[repr(C)]
pub struct Metadata<'a> {
pub library_name: CharSlice<'a>,
Expand Down
19 changes: 19 additions & 0 deletions crashtracker-ffi/src/crash_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,25 @@ pub unsafe extern "C" fn ddog_crasht_CrashInfo_set_timestamp_to_now(
.into()
}

/// Sets crashinfo procinfo
///
/// # Safety
/// `crashinfo` must be a valid pointer to a `CrashInfo` object.
#[no_mangle]
#[must_use]
pub unsafe extern "C" fn ddog_crasht_CrashInfo_set_procinfo(
crashinfo: *mut CrashInfo,
procinfo: ProcInfo
) -> Result {
(|| {
let crashinfo = crashinfo_ptr_to_inner(crashinfo)?;
let procinfo = procinfo.try_into()?;
crashinfo.set_procinfo(procinfo)
})()
.context("ddog_crasht_CrashInfo_set_procinfo failed")
.into()
}

/// Exports `crashinfo` to the backend at `endpoint`
/// Note that we support the "file://" endpoint for local file output.
/// # Safety
Expand Down
6 changes: 6 additions & 0 deletions examples/ffi/crashinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ int main(void) {
check_result(ddog_crasht_CrashInfo_set_timestamp(crashinfo.get(), timestamp),
"Failed to set timestamp");

ddog_Procinfo procinfo = {
.pid = 42
};

check_result(ddog_crasht_CrashInfo_set_procinfo(crashinfo.get(), procinfo));

auto endpoint = ddog_endpoint_from_filename(to_slice_c_char("/tmp/test"));

check_result(ddog_crasht_CrashInfo_upload_to_endpoint(crashinfo.get(), endpoint),
Expand Down

0 comments on commit d021cf2

Please sign in to comment.