Commit 988f9956 authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Include required unwindstack types in native_unwinder_android

Users of native_unwinder_android require access to the Maps and Memory
destructors since NativeUnwinderAndroid vends unique_ptrs to those types
in its public interface. Because of this the forward declarations are
not useful and the headers should be directly included instead.

libunwindstack include paths are now properly set up by
//third_party/libunwindstack as of https://crrev.com/2208607, so
include_dirs declarations by users are removed.

The change also moves the unwindstack_internal_android.* contents into
native_unwinder_android.* since the only reason for keeping that content
separate was to hide the Maps and Memory types.

Bug: 1083530
Change-Id: Ibf89a4a485bd90930c3a1aab213a3da44142b12b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209531Reviewed-by: default avatarEtienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Auto-Submit: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770681}
parent 3ebc7803
...@@ -2425,14 +2425,12 @@ if (is_android && (current_cpu == "arm" || current_cpu == "arm64")) { ...@@ -2425,14 +2425,12 @@ if (is_android && (current_cpu == "arm" || current_cpu == "arm64")) {
sources = [ sources = [
"profiler/native_unwinder_android.cc", "profiler/native_unwinder_android.cc",
"profiler/native_unwinder_android.h", "profiler/native_unwinder_android.h",
"profiler/unwindstack_internal_android.cc",
"profiler/unwindstack_internal_android.h",
] ]
include_dirs = [ "//third_party/libunwindstack/src/libunwindstack/include" ] public_deps = [
":base",
public_deps = [ ":base" ] "//third_party/libunwindstack",
deps = [ "//third_party/libunwindstack" ] ]
} }
} }
...@@ -2981,8 +2979,6 @@ test("base_unittests") { ...@@ -2981,8 +2979,6 @@ test("base_unittests") {
if (!exclude_unwind_tables && if (!exclude_unwind_tables &&
(current_cpu == "arm" || current_cpu == "arm64")) { (current_cpu == "arm" || current_cpu == "arm64")) {
sources += [ "profiler/native_unwinder_android_unittest.cc" ] sources += [ "profiler/native_unwinder_android_unittest.cc" ]
include_dirs =
[ "//third_party/libunwindstack/src/libunwindstack/include" ]
deps += [ deps += [
":base_profiler_test_support_java", ":base_profiler_test_support_java",
":base_profiler_test_support_jni_headers", ":base_profiler_test_support_jni_headers",
......
...@@ -10,15 +10,12 @@ ...@@ -10,15 +10,12 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Elf.h" #include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Elf.h"
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Maps.h"
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Memory.h"
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Regs.h" #include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Regs.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/profiler/module_cache.h" #include "base/profiler/module_cache.h"
#include "base/profiler/native_unwinder.h" #include "base/profiler/native_unwinder.h"
#include "base/profiler/profile_builder.h" #include "base/profiler/profile_builder.h"
#include "base/profiler/unwindstack_internal_android.h"
#include "build/build_config.h" #include "build/build_config.h"
#if defined(ARCH_CPU_ARM_FAMILY) && defined(ARCH_CPU_32_BITS) #if defined(ARCH_CPU_ARM_FAMILY) && defined(ARCH_CPU_32_BITS)
...@@ -88,6 +85,23 @@ void CopyToRegisterContext(unwindstack::Regs* regs, ...@@ -88,6 +85,23 @@ void CopyToRegisterContext(unwindstack::Regs* regs,
} // namespace } // namespace
UnwindStackMemoryAndroid::UnwindStackMemoryAndroid(uintptr_t stack_ptr,
uintptr_t stack_top)
: stack_ptr_(stack_ptr), stack_top_(stack_top) {
DCHECK_LE(stack_ptr_, stack_top_);
}
UnwindStackMemoryAndroid::~UnwindStackMemoryAndroid() = default;
size_t UnwindStackMemoryAndroid::Read(uint64_t addr, void* dst, size_t size) {
if (addr < stack_ptr_)
return 0;
if (size >= stack_top_ || addr > stack_top_ - size)
return 0;
memcpy(dst, reinterpret_cast<void*>(addr), size);
return size;
}
// static // static
std::unique_ptr<unwindstack::Maps> NativeUnwinderAndroid::CreateMaps() { std::unique_ptr<unwindstack::Maps> NativeUnwinderAndroid::CreateMaps() {
auto maps = std::make_unique<unwindstack::LocalMaps>(); auto maps = std::make_unique<unwindstack::LocalMaps>();
......
...@@ -6,14 +6,26 @@ ...@@ -6,14 +6,26 @@
#define BASE_PROFILER_NATIVE_UNWINDER_ANDROID_H_ #define BASE_PROFILER_NATIVE_UNWINDER_ANDROID_H_
#include "base/profiler/unwinder.h" #include "base/profiler/unwinder.h"
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Maps.h"
namespace unwindstack { #include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Memory.h"
class Maps;
class Memory;
} // namespace unwindstack
namespace base { namespace base {
// Implementation of unwindstack::Memory that restricts memory access to a stack
// buffer, used by NativeUnwinderAndroid. While unwinding, only memory accesses
// within the stack should be performed to restore registers.
class UnwindStackMemoryAndroid : public unwindstack::Memory {
public:
UnwindStackMemoryAndroid(uintptr_t stack_ptr, uintptr_t stack_top);
~UnwindStackMemoryAndroid() override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
private:
const uintptr_t stack_ptr_;
const uintptr_t stack_top_;
};
// Native unwinder implementation for Android, using libunwindstack. // Native unwinder implementation for Android, using libunwindstack.
class NativeUnwinderAndroid : public Unwinder { class NativeUnwinderAndroid : public Unwinder {
public: public:
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/profiler/stack_copier_signal.h" #include "base/profiler/stack_copier_signal.h"
#include "base/profiler/stack_sampling_profiler_test_util.h" #include "base/profiler/stack_sampling_profiler_test_util.h"
#include "base/profiler/thread_delegate_posix.h" #include "base/profiler/thread_delegate_posix.h"
#include "base/profiler/unwindstack_internal_android.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/profiler/unwindstack_internal_android.h"
#include <string.h>
#include "base/logging.h"
namespace base {
UnwindStackMemoryAndroid::UnwindStackMemoryAndroid(uintptr_t stack_ptr,
uintptr_t stack_top)
: stack_ptr_(stack_ptr), stack_top_(stack_top) {
DCHECK_LE(stack_ptr_, stack_top_);
}
UnwindStackMemoryAndroid::~UnwindStackMemoryAndroid() = default;
size_t UnwindStackMemoryAndroid::Read(uint64_t addr, void* dst, size_t size) {
if (addr < stack_ptr_)
return 0;
if (size >= stack_top_ || addr > stack_top_ - size)
return 0;
memcpy(dst, reinterpret_cast<void*>(addr), size);
return size;
}
} // namespace base
\ No newline at end of file
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_PROFILER_UNWINDSTACK_INTERNAL_ANDROID_H_
#define BASE_PROFILER_UNWINDSTACK_INTERNAL_ANDROID_H_
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Maps.h"
#include "third_party/libunwindstack/src/libunwindstack/include/unwindstack/Memory.h"
// Avoid including this file directly in a header as it leaks headers from
// libunwindstack. In particular, it's not to be included directly or
// transitively from native_unwinder_android.h
namespace base {
// Implementation of unwindstack::Memory that restricts memory access to a stack
// buffer, used by NativeUnwinderAndroid. While unwinding, only memory accesses
// within the stack should be performed to restore registers.
class UnwindStackMemoryAndroid : public unwindstack::Memory {
public:
UnwindStackMemoryAndroid(uintptr_t stack_ptr, uintptr_t stack_top);
~UnwindStackMemoryAndroid() override;
size_t Read(uint64_t addr, void* dst, size_t size) override;
private:
const uintptr_t stack_ptr_;
const uintptr_t stack_top_;
};
} // namespace base
#endif // BASE_PROFILER_UNWINDSTACK_INTERNAL_ANDROID_H_
\ No newline at end of file
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