From 499ca74190ea5cab457a29b3d2ecca501c2675ef Mon Sep 17 00:00:00 2001 From: Alex Franchuk Date: Fri, 19 Jan 2024 12:14:50 -0500 Subject: [PATCH] Try macos again. --- samply/src/mac/proc_maps.rs | 16 +++++++++++++--- samply/src/mac/task_profiler.rs | 20 ++++++++++---------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/samply/src/mac/proc_maps.rs b/samply/src/mac/proc_maps.rs index edd6753e..fc97bd88 100644 --- a/samply/src/mac/proc_maps.rs +++ b/samply/src/mac/proc_maps.rs @@ -280,12 +280,16 @@ fn get_dyld_image_info( let mut vmsize: u64 = 0; let mut uuid = None; let mut sections = HashMap::new(); + let mut text_segment_file_range = None; while let Ok(Some(command)) = load_commands.next() { if let Ok(Some((segment, section_data))) = SegmentCommand64::from_command(command) { if segment.name() == b"__TEXT" { base_svma = segment.vmaddr(endian); vmsize = segment.vmsize(endian); + let file_offset = segment.fileoff.get(endian); + let file_size = segment.filesize.get(endian); + text_segment_file_range = Some(file_offset..file_offset + file_size); for section in segment .sections(endian, section_data) @@ -312,12 +316,18 @@ fn get_dyld_image_info( module_info: framehop::ExplicitModuleSectionInfo { base_svma, text_svma: section_svma_range(b"__text"), + text: None, stubs_svma: section_svma_range(b"__stubs"), stub_helper_svma: section_svma_range(b"__stub_helper"), + got_svma: section_svma_range(b"__got"), + unwind_info: None, eh_frame_svma: section_svma_range(b"__eh_frame"), + eh_frame: None, eh_frame_hdr_svma: section_svma_range(b"__eh_frame_hdr"), - got_svma: section_svma_range(b"__got"), - ..Default::default() + eh_frame_hdr: None, + debug_frame: None, + text_segment_file_range, + text_segment: None, }, debug_id: uuid.map(DebugId::from_uuid), code_id: uuid.map(CodeId::MachoUuid), @@ -617,7 +627,7 @@ impl ForeignMemory { } } -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct VmSubData { page_aligned_data: VmData, address_range: std::ops::Range, diff --git a/samply/src/mac/task_profiler.rs b/samply/src/mac/task_profiler.rs index 4b17fd93..0cd7b929 100644 --- a/samply/src/mac/task_profiler.rs +++ b/samply/src/mac/task_profiler.rs @@ -1,7 +1,6 @@ use crossbeam_channel::Receiver; use framehop::{ - CacheNative, ExplicitModuleSectionInfo, FrameAddress, MayAllocateDuringUnwind, Module, - Unwinder, UnwinderNative, + CacheNative, FrameAddress, MayAllocateDuringUnwind, Module, Unwinder, UnwinderNative, }; use fxprof_processed_profile::debugid::DebugId; use fxprof_processed_profile::{LibraryInfo, ProcessHandle, Profile, ThreadHandle, Timestamp}; @@ -42,10 +41,10 @@ use super::proc_maps::{DyldInfo, DyldInfoManager, Modification, StackwalkerRef, use super::sampler::TaskInit; use super::thread_profiler::{get_thread_id, get_thread_name, ThreadProfiler}; -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum UnwindSectionBytes { Remapped(VmSubData), - Mmap(MmapSubData), + Mmap(Arc), Allocated(Arc<[u8]>), } @@ -61,6 +60,7 @@ impl Deref for UnwindSectionBytes { } } +#[derive(Debug)] pub struct MmapSubData { mmap: memmap2::Mmap, offset: usize, @@ -464,8 +464,9 @@ impl TaskProfiler { let debug_id = if let Some(text_first_page) = text_section_start_avma .checked_sub(text_segment_avma.start) .zip(text_section_first_page_end_avma.checked_sub(text_segment_avma.start)) - .and_then(|(rel_start, rel_end)| text_segment.get(rel_start..rel_end)) - { + .and_then(|(rel_start, rel_end)| { + text_segment.get(rel_start as usize..rel_end as usize) + }) { // Generate a debug ID from the __text section. DebugId::from_text_first_page(text_first_page, true) } else { @@ -474,9 +475,8 @@ impl TaskProfiler { lib.debug_id = Some(debug_id); } } - let (text_segment, text_segment_file_range) = text_segment.unzip(); + let (text_segment, _) = text_segment.unzip(); - module_section_info.text_segment_file_range = text_segment_file_range; module_section_info.text_segment = text_segment.clone(); module_section_info.text = text_segment; module_section_info.unwind_info = unwind_info_data.map(UnwindSectionBytes::Remapped); @@ -603,11 +603,11 @@ fn get_debug_frame(file_path: &str) -> Option { debug_frame_section.compressed_file_range().ok()? }; match compressed_range.format { - CompressionFormat::None => Some(UnwindSectionBytes::Mmap(MmapSubData::try_new( + CompressionFormat::None => Some(UnwindSectionBytes::Mmap(Arc::new(MmapSubData::try_new( mmap, compressed_range.offset as usize, compressed_range.uncompressed_size as usize, - )?)), + )?))), CompressionFormat::Unknown => None, CompressionFormat::Zlib => { let compressed_bytes = &mmap[compressed_range.offset as usize..]