diff --git a/crashtracker-ffi/src/crash_info/datatypes.rs b/crashtracker-ffi/src/crash_info/datatypes.rs index 1b01ec2d4..f22444cb5 100644 --- a/crashtracker-ffi/src/crash_info/datatypes.rs +++ b/crashtracker-ffi/src/crash_info/datatypes.rs @@ -246,6 +246,21 @@ impl<'a> TryFrom> for datadog_crashtracker::SigInfo { } } + +#[repr(C)] +pub struct ProcInfo { + pub pid: u32, +} + +impl TryFrom for datadog_crashtracker::ProcessInfo { + type Error = anyhow::Error; + + fn try_from(value : ProcInfo) -> anyhow::Result { + let pid = value.pid; + Ok(Self { pid }) + } +} + #[repr(C)] pub struct Metadata<'a> { pub library_name: CharSlice<'a>, diff --git a/crashtracker-ffi/src/crash_info/mod.rs b/crashtracker-ffi/src/crash_info/mod.rs index 18e49e0cf..fcd10f360 100644 --- a/crashtracker-ffi/src/crash_info/mod.rs +++ b/crashtracker-ffi/src/crash_info/mod.rs @@ -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 diff --git a/examples/ffi/crashinfo.cpp b/examples/ffi/crashinfo.cpp index 167adf767..5a2f49d28 100644 --- a/examples/ffi/crashinfo.cpp +++ b/examples/ffi/crashinfo.cpp @@ -165,6 +165,12 @@ int main(void) { check_result(ddog_crasht_CrashInfo_set_timestamp(crashinfo.get(), timestamp), "Failed to set timestamp"); + ddog_crasht_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),