| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/profiler/native_stack_sampler.h" | 5 #include "base/profiler/native_stack_sampler.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <libkern/OSByteOrder.h> | 8 #include <libkern/OSByteOrder.h> |
| 9 #include <libunwind.h> | 9 #include <libunwind.h> |
| 10 #include <mach-o/swap.h> | 10 #include <mach-o/swap.h> |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 const char* LibSystemKernelName() { | 159 const char* LibSystemKernelName() { |
| 160 static char path[PATH_MAX]; | 160 static char path[PATH_MAX]; |
| 161 static char* name = nullptr; | 161 static char* name = nullptr; |
| 162 if (name) | 162 if (name) |
| 163 return name; | 163 return name; |
| 164 | 164 |
| 165 Dl_info info; | 165 Dl_info info; |
| 166 dladdr(reinterpret_cast<void*>(_exit), &info); | 166 dladdr(reinterpret_cast<void*>(_exit), &info); |
| 167 strncpy(path, info.dli_fname, PATH_MAX); | 167 strncpy(path, info.dli_fname, PATH_MAX); |
| 168 name = path; | 168 name = path; |
| 169 |
| 170 #if !defined(ADDRESS_SANITIZER) |
| 169 DCHECK_EQ(std::string(name), | 171 DCHECK_EQ(std::string(name), |
| 170 std::string("/usr/lib/system/libsystem_kernel.dylib")); | 172 std::string("/usr/lib/system/libsystem_kernel.dylib")); |
| 173 #endif |
| 171 return name; | 174 return name; |
| 172 } | 175 } |
| 173 | 176 |
| 174 // Walks the stack represented by |thread_state|, calling back to the provided | 177 // Walks the stack represented by |thread_state|, calling back to the provided |
| 175 // lambda for each frame. | 178 // lambda for each frame. |
| 176 template <typename StackFrameCallback> | 179 template <typename StackFrameCallback> |
| 177 void WalkStack(const x86_thread_state64_t& thread_state, | 180 void WalkStack(const x86_thread_state64_t& thread_state, |
| 178 uintptr_t stack_top, | 181 uintptr_t stack_top, |
| 179 const StackFrameCallback& callback) { | 182 const StackFrameCallback& callback) { |
| 180 size_t frame_count = 0; | 183 size_t frame_count = 0; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 462 |
| 460 std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( | 463 std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( |
| 461 PlatformThreadId thread_id, | 464 PlatformThreadId thread_id, |
| 462 AnnotateCallback annotator, | 465 AnnotateCallback annotator, |
| 463 NativeStackSamplerTestDelegate* test_delegate) { | 466 NativeStackSamplerTestDelegate* test_delegate) { |
| 464 return base::MakeUnique<NativeStackSamplerMac>(thread_id, annotator, | 467 return base::MakeUnique<NativeStackSamplerMac>(thread_id, annotator, |
| 465 test_delegate); | 468 test_delegate); |
| 466 } | 469 } |
| 467 | 470 |
| 468 } // namespace base | 471 } // namespace base |
| OLD | NEW |