Debian Codegraph @

third_party/rust/minidump-writer/src/linux/sections/thread_names_stream.rs

raw
1 use super::*;
2
3 pub fn write(
4 buffer: &mut DumpBuf,
5 dumper: &PtraceDumper,
6 ) -> Result<MDRawDirectory, errors::SectionThreadNamesError> {
7 // Only count threads that have a name
8 let num_threads = dumper.threads.iter().filter(|t| t.name.is_some()).count();
9 // Memory looks like this:
10 // <num_threads><thread_1><thread_2>...
11
12 let list_header = MemoryWriter::<u32>::alloc_with_val(buffer, num_threads as u32)?;
13
14 let mut dirent = MDRawDirectory {
15 stream_type: MDStreamType::ThreadNamesStream as u32,
16 location: list_header.location(),
17 };
18
19 let mut thread_list = MemoryArrayWriter::<MDRawThreadName>::alloc_array(buffer, num_threads)?;
20 dirent.location.data_size += thread_list.location().data_size;
21
22 for (idx, item) in dumper.threads.iter().enumerate() {
23 if let Some(name) = &item.name {
24 let pos = write_string_to_location(buffer, name)?;
25 let thread = MDRawThreadName {
26 thread_id: item.tid.try_into()?,
27 thread_name_rva: pos.rva.into(),
28 };
29 thread_list.set_value_at(buffer, thread, idx)?;
30 }
31 }
32 Ok(dirent)
33 }