Skip to content

Commit

Permalink
[Crashtracking] Add PDB info to crash info (#655)
Browse files Browse the repository at this point in the history
* Add PDB info to crash info
* Add normalized frames in example
  • Loading branch information
gleocadie authored Oct 1, 2024
1 parent 98ad3dc commit dcf22a9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
25 changes: 20 additions & 5 deletions crashtracker-ffi/src/crash_info/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ pub enum NormalizedAddressTypes {
// Make None 0 so that default construction gives none
None = 0,
Elf,
Pdb,
}

#[repr(C)]
pub struct NormalizedAddress<'a> {
file_offset: u64,
build_id: ByteSlice<'a>,
age: u64,
path: CharSlice<'a>,
typ: NormalizedAddressTypes,
}
Expand Down Expand Up @@ -111,20 +113,33 @@ impl<'a> TryFrom<&NormalizedAddress<'a>> for datadog_crashtracker::NormalizedAdd
type Error = anyhow::Error;

fn try_from(value: &NormalizedAddress<'a>) -> Result<Self, Self::Error> {
let to_opt_bytes = |v: ByteSlice| {
if v.is_empty() {
None
} else {
Some(Vec::from(v.as_bytes()))
}
};
match &value.typ {
NormalizedAddressTypes::Elf => {
let build_id = if value.build_id.is_empty() {
None
} else {
Some(Vec::from(value.build_id.as_bytes()))
};
let build_id = to_opt_bytes(value.build_id);
let path = value.path.try_to_utf8()?.into();
let meta = datadog_crashtracker::NormalizedAddressMeta::Elf { build_id, path };
Ok(Self {
file_offset: value.file_offset,
meta,
})
}
NormalizedAddressTypes::Pdb => {
let guid = to_opt_bytes(value.build_id);
let path = value.path.try_to_utf8()?.into();
let age = value.age;
let meta = datadog_crashtracker::NormalizedAddressMeta::Pdb { path, guid, age };
Ok(Self {
file_offset: value.file_offset,
meta,
})
}
_ => anyhow::bail!("Unsupported normalized address type {:?}", value.typ),
}
}
Expand Down
5 changes: 5 additions & 0 deletions crashtracker/src/crash_info/stacktrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ pub enum NormalizedAddressMeta {
path: PathBuf,
build_id: Option<Vec<u8>>,
},
Pdb {
path: PathBuf,
guid: Option<Vec<u8>>,
age: u64,
},
Unknown,
Unexpected(String),
}
Expand Down
43 changes: 43 additions & 0 deletions examples/ffi/crashinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ static ddog_CharSlice to_slice_string(std::string const &s) {
return {.ptr = s.data(), .len = s.length()};
}

template <class T>
static ddog_ByteSlice to_byte_slice(T const& c) {
return {.ptr = reinterpret_cast<const std::uint8_t*>(c.data()), .len = c.size()};
}

struct Deleter {
void operator()(ddog_crasht_CrashInfo *object) { ddog_crasht_CrashInfo_drop(object); }
};
Expand Down Expand Up @@ -73,6 +78,44 @@ void add_stacktrace(std::unique_ptr<ddog_crasht_CrashInfo, Deleter> &crashinfo)
.symbol_address = 0};
trace.push_back(frame);
}

std::vector<std::uint8_t> build_id = {42};
std::string filePath = "/usr/share/somewhere";
// test with normalized
auto elfFrameWithNormalization = ddog_crasht_StackFrame{
.ip = 42,
.module_base_address = 0,
.names = {.ptr = &names[0], .len = 1}, // just for the test
.normalized_ip = {
.file_offset = 1,
.build_id = to_byte_slice(build_id),
.path = to_slice_c_char(filePath.c_str(), filePath.size()),
.typ = DDOG_CRASHT_NORMALIZED_ADDRESS_TYPES_ELF,
},
.sp = 0,
.symbol_address = 0,
};

trace.push_back(elfFrameWithNormalization);

// Windows-kind of frame
auto dllFrameWithNormalization = ddog_crasht_StackFrame{
.ip = 42,
.module_base_address = 0,
.names = {.ptr = &names[0], .len = 1}, // just for the test
.normalized_ip = {
.file_offset = 1,
.build_id = to_byte_slice(build_id),
.age = 21,
.path = to_slice_c_char(filePath.c_str(), filePath.size()),
.typ = DDOG_CRASHT_NORMALIZED_ADDRESS_TYPES_PDB,
},
.sp = 0,
.symbol_address = 0,
};

trace.push_back(dllFrameWithNormalization);

ddog_crasht_Slice_StackFrame trace_slice = {.ptr = trace.data(), .len = trace.size()};

check_result(
Expand Down

0 comments on commit dcf22a9

Please sign in to comment.