Skip to content

Commit

Permalink
Try macos again.
Browse files Browse the repository at this point in the history
  • Loading branch information
afranchuk committed Jan 19, 2024
1 parent 70f3289 commit 499ca74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
16 changes: 13 additions & 3 deletions samply/src/mac/proc_maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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),
Expand Down Expand Up @@ -617,7 +627,7 @@ impl ForeignMemory {
}
}

#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct VmSubData {
page_aligned_data: VmData,
address_range: std::ops::Range<u64>,
Expand Down
20 changes: 10 additions & 10 deletions samply/src/mac/task_profiler.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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<MmapSubData>),
Allocated(Arc<[u8]>),
}

Expand All @@ -61,6 +60,7 @@ impl Deref for UnwindSectionBytes {
}
}

#[derive(Debug)]
pub struct MmapSubData {
mmap: memmap2::Mmap,
offset: usize,
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -603,11 +603,11 @@ fn get_debug_frame(file_path: &str) -> Option<UnwindSectionBytes> {
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..]
Expand Down

0 comments on commit 499ca74

Please sign in to comment.