Commit 28d29bfe authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Clean up NativeStackSamplerMac

Bug: 851163
Change-Id: I0f37ac73c90f152b05a02904967fecd33cf10b31
Reviewed-on: https://chromium-review.googlesource.com/1105286
Commit-Queue: Xi Cheng <chengx@chromium.org>
Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568294}
parent 502b5a8a
...@@ -66,9 +66,11 @@ std::string GetUniqueId(const void* module_addr) { ...@@ -66,9 +66,11 @@ std::string GetUniqueId(const void* module_addr) {
size_t offset = sizeof(mach_header_64); size_t offset = sizeof(mach_header_64);
size_t offset_limit = sizeof(mach_header_64) + mach_header->sizeofcmds; size_t offset_limit = sizeof(mach_header_64) + mach_header->sizeofcmds;
for (uint32_t i = 0; (i < mach_header->ncmds) &&
(offset + sizeof(load_command) < offset_limit); for (uint32_t i = 0; i < mach_header->ncmds; ++i) {
++i) { if (offset + sizeof(load_command) >= offset_limit)
return std::string();
const load_command* current_cmd = reinterpret_cast<const load_command*>( const load_command* current_cmd = reinterpret_cast<const load_command*>(
reinterpret_cast<const uint8_t*>(mach_header) + offset); reinterpret_cast<const uint8_t*>(mach_header) + offset);
...@@ -123,9 +125,9 @@ size_t GetModuleIndex(const uintptr_t instruction_pointer, ...@@ -123,9 +125,9 @@ size_t GetModuleIndex(const uintptr_t instruction_pointer,
return instruction_pointer >= index.base_address && return instruction_pointer >= index.base_address &&
instruction_pointer < index.end_address; instruction_pointer < index.end_address;
}); });
if (module_index != profile_module_index->end()) { if (module_index != profile_module_index->end())
return module_index->index; return module_index->index;
}
Dl_info inf; Dl_info inf;
if (!dladdr(reinterpret_cast<const void*>(instruction_pointer), &inf)) if (!dladdr(reinterpret_cast<const void*>(instruction_pointer), &inf))
return StackSamplingProfiler::Frame::kUnknownModuleIndex; return StackSamplingProfiler::Frame::kUnknownModuleIndex;
...@@ -173,10 +175,8 @@ uintptr_t RewritePointerIfInOriginalStack( ...@@ -173,10 +175,8 @@ uintptr_t RewritePointerIfInOriginalStack(
auto original_stack_top_int = reinterpret_cast<uintptr_t>(original_stack_top); auto original_stack_top_int = reinterpret_cast<uintptr_t>(original_stack_top);
auto stack_copy_bottom_int = reinterpret_cast<uintptr_t>(stack_copy_bottom); auto stack_copy_bottom_int = reinterpret_cast<uintptr_t>(stack_copy_bottom);
if ((pointer < original_stack_bottom_int) || if (pointer < original_stack_bottom_int || pointer >= original_stack_top_int)
(pointer >= original_stack_top_int)) {
return pointer; return pointer;
}
return stack_copy_bottom_int + (pointer - original_stack_bottom_int); return stack_copy_bottom_int + (pointer - original_stack_bottom_int);
} }
...@@ -288,9 +288,8 @@ bool HasValidRbp(unw_cursor_t* unwind_cursor, uintptr_t stack_top) { ...@@ -288,9 +288,8 @@ bool HasValidRbp(unw_cursor_t* unwind_cursor, uintptr_t stack_top) {
unw_get_reg(unwind_cursor, UNW_X86_64_RSP, &rsp); unw_get_reg(unwind_cursor, UNW_X86_64_RSP, &rsp);
unw_get_reg(unwind_cursor, UNW_X86_64_RBP, &rbp); unw_get_reg(unwind_cursor, UNW_X86_64_RBP, &rbp);
uint32_t offset = GetFrameOffset(proc_info.format) * sizeof(unw_word_t); uint32_t offset = GetFrameOffset(proc_info.format) * sizeof(unw_word_t);
if (rbp < offset || (rbp - offset) < rsp || rbp > stack_top) { if (rbp < offset || (rbp - offset) < rsp || rbp > stack_top)
return false; return false;
}
} }
return true; return true;
} }
...@@ -329,9 +328,8 @@ bool WalkStackFromContext( ...@@ -329,9 +328,8 @@ bool WalkStackFromContext(
// frame. // frame.
size_t module_index = size_t module_index =
GetModuleIndex(rip, current_modules, profile_module_index); GetModuleIndex(rip, current_modules, profile_module_index);
if (module_index == StackSamplingProfiler::Frame::kUnknownModuleIndex) { if (module_index == StackSamplingProfiler::Frame::kUnknownModuleIndex)
return false; return false;
}
callback(static_cast<uintptr_t>(rip), module_index); callback(static_cast<uintptr_t>(rip), module_index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment