Remove debugging_buildflags.h
Change-Id: I7deebccf6721718da74625c3c0b3d826b5f3f97d
Reviewed-on: https://gn-review.googlesource.com/1140
Reviewed-by: Brett Wilson <brettw@chromium.org>
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/base/debug/profiler.cc b/base/debug/profiler.cc
index 1ee9483..91619a1 100644
--- a/base/debug/profiler.cc
+++ b/base/debug/profiler.cc
@@ -6,7 +6,6 @@
#include <string>
-#include "base/debug/debugging_buildflags.h"
#include "base/process/process_handle.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
@@ -17,52 +16,9 @@
#include "base/win/pe_image.h"
#endif // defined(OS_WIN)
-// TODO(peria): Enable profiling on Windows.
-#if BUILDFLAG(ENABLE_PROFILING) && !defined(NO_TCMALLOC) && !defined(OS_WIN)
-#include "third_party/tcmalloc/chromium/src/gperftools/profiler.h"
-#endif
-
namespace base {
namespace debug {
-// TODO(peria): Enable profiling on Windows.
-#if BUILDFLAG(ENABLE_PROFILING) && !defined(NO_TCMALLOC) && !defined(OS_WIN)
-
-static int profile_count = 0;
-
-void StartProfiling(const std::string& name) {
- ++profile_count;
- std::string full_name(name);
- std::string pid = IntToString(GetCurrentProcId());
- std::string count = IntToString(profile_count);
- ReplaceSubstringsAfterOffset(&full_name, 0, "{pid}", pid);
- ReplaceSubstringsAfterOffset(&full_name, 0, "{count}", count);
- ProfilerStart(full_name.c_str());
-}
-
-void StopProfiling() {
- ProfilerFlush();
- ProfilerStop();
-}
-
-void FlushProfiling() {
- ProfilerFlush();
-}
-
-bool BeingProfiled() {
- return ProfilingIsEnabledForAllThreads();
-}
-
-void RestartProfilingAfterFork() {
- ProfilerRegisterThread();
-}
-
-bool IsProfilingSupported() {
- return true;
-}
-
-#else
-
void StartProfiling(const std::string& name) {
}
@@ -83,8 +39,6 @@
return false;
}
-#endif
-
#if !defined(OS_WIN)
ReturnAddressLocationResolver GetProfilerReturnAddrResolutionFunc() {
diff --git a/base/debug/stack_trace.cc b/base/debug/stack_trace.cc
index 7715121..3a63dae 100644
--- a/base/debug/stack_trace.cc
+++ b/base/debug/stack_trace.cc
@@ -12,190 +12,9 @@
#include "base/logging.h"
#include "base/macros.h"
-#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
-#if defined(OS_LINUX) || defined(OS_ANDROID)
-#include <pthread.h>
-#include "base/process/process_handle.h"
-#include "base/threading/platform_thread.h"
-#endif
-
-#if defined(OS_MACOSX)
-#include <pthread.h>
-#endif
-
-#if defined(OS_LINUX) && defined(__GLIBC__)
-extern "C" void* __libc_stack_end;
-#endif
-
-#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
namespace base {
namespace debug {
-namespace {
-
-#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
-#if defined(__arm__) && defined(__GNUC__) && !defined(__clang__)
-// GCC and LLVM generate slightly different frames on ARM, see
-// https://llvm.org/bugs/show_bug.cgi?id=18505 - LLVM generates
-// x86-compatible frame, while GCC needs adjustment.
-constexpr size_t kStackFrameAdjustment = sizeof(uintptr_t);
-#else
-constexpr size_t kStackFrameAdjustment = 0;
-#endif
-
-uintptr_t GetNextStackFrame(uintptr_t fp) {
- return reinterpret_cast<const uintptr_t*>(fp)[0] - kStackFrameAdjustment;
-}
-
-uintptr_t GetStackFramePC(uintptr_t fp) {
- return reinterpret_cast<const uintptr_t*>(fp)[1];
-}
-
-bool IsStackFrameValid(uintptr_t fp, uintptr_t prev_fp, uintptr_t stack_end) {
- // With the stack growing downwards, older stack frame must be
- // at a greater address that the current one.
- if (fp <= prev_fp) return false;
-
- // Assume huge stack frames are bogus.
- if (fp - prev_fp > 100000) return false;
-
- // Check alignment.
- if (fp & (sizeof(uintptr_t) - 1)) return false;
-
- if (stack_end) {
- // Both fp[0] and fp[1] must be within the stack.
- if (fp > stack_end - 2 * sizeof(uintptr_t)) return false;
-
- // Additional check to filter out false positives.
- if (GetStackFramePC(fp) < 32768) return false;
- }
-
- return true;
-};
-
-// ScanStackForNextFrame() scans the stack for a valid frame to allow unwinding
-// past system libraries. Only supported on Linux where system libraries are
-// usually in the middle of the trace:
-//
-// TraceStackFramePointers
-// <more frames from Chrome>
-// base::WorkSourceDispatch <-- unwinding stops (next frame is invalid),
-// g_main_context_dispatch ScanStackForNextFrame() is called
-// <more frames from glib>
-// g_main_context_iteration
-// base::MessagePumpGlib::Run <-- ScanStackForNextFrame() finds valid frame,
-// base::RunLoop::Run unwinding resumes
-// <more frames from Chrome>
-// __libc_start_main
-//
-// For stack scanning to be efficient it's very important for the thread to
-// be started by Chrome. In that case we naturally terminate unwinding once
-// we reach the origin of the stack (i.e. GetStackEnd()). If the thread is
-// not started by Chrome (e.g. Android's main thread), then we end up always
-// scanning area at the origin of the stack, wasting time and not finding any
-// frames (since Android libraries don't have frame pointers).
-//
-// ScanStackForNextFrame() returns 0 if it couldn't find a valid frame
-// (or if stack scanning is not supported on the current platform).
-uintptr_t ScanStackForNextFrame(uintptr_t fp, uintptr_t stack_end) {
-#if defined(OS_LINUX)
- // Enough to resume almost all prematurely terminated traces.
- constexpr size_t kMaxStackScanArea = 8192;
-
- if (!stack_end) {
- // Too dangerous to scan without knowing where the stack ends.
- return 0;
- }
-
- fp += sizeof(uintptr_t); // current frame is known to be invalid
- uintptr_t last_fp_to_scan = std::min(fp + kMaxStackScanArea, stack_end) -
- sizeof(uintptr_t);
- for (;fp <= last_fp_to_scan; fp += sizeof(uintptr_t)) {
- uintptr_t next_fp = GetNextStackFrame(fp);
- if (IsStackFrameValid(next_fp, fp, stack_end)) {
- // Check two frames deep. Since stack frame is just a pointer to
- // a higher address on the stack, it's relatively easy to find
- // something that looks like one. However two linked frames are
- // far less likely to be bogus.
- uintptr_t next2_fp = GetNextStackFrame(next_fp);
- if (IsStackFrameValid(next2_fp, next_fp, stack_end)) {
- return fp;
- }
- }
- }
-#endif // defined(OS_LINUX)
-
- return 0;
-}
-
-// Links stack frame |fp| to |parent_fp|, so that during stack unwinding
-// TraceStackFramePointers() visits |parent_fp| after visiting |fp|.
-// Both frame pointers must come from __builtin_frame_address().
-// Returns previous stack frame |fp| was linked to.
-void* LinkStackFrames(void* fpp, void* parent_fp) {
- uintptr_t fp = reinterpret_cast<uintptr_t>(fpp) - kStackFrameAdjustment;
- void* prev_parent_fp = reinterpret_cast<void**>(fp)[0];
- reinterpret_cast<void**>(fp)[0] = parent_fp;
- return prev_parent_fp;
-}
-
-#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
-} // namespace
-
-#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-uintptr_t GetStackEnd() {
-#if defined(OS_ANDROID)
- // Bionic reads proc/maps on every call to pthread_getattr_np() when called
- // from the main thread. So we need to cache end of stack in that case to get
- // acceptable performance.
- // For all other threads pthread_getattr_np() is fast enough as it just reads
- // values from its pthread_t argument.
- static uintptr_t main_stack_end = 0;
-
- bool is_main_thread = GetCurrentProcId() == PlatformThread::CurrentId();
- if (is_main_thread && main_stack_end) {
- return main_stack_end;
- }
-
- uintptr_t stack_begin = 0;
- size_t stack_size = 0;
- pthread_attr_t attributes;
- int error = pthread_getattr_np(pthread_self(), &attributes);
- if (!error) {
- error = pthread_attr_getstack(
- &attributes, reinterpret_cast<void**>(&stack_begin), &stack_size);
- pthread_attr_destroy(&attributes);
- }
- DCHECK(!error);
-
- uintptr_t stack_end = stack_begin + stack_size;
- if (is_main_thread) {
- main_stack_end = stack_end;
- }
- return stack_end; // 0 in case of error
-
-#elif defined(OS_LINUX) && defined(__GLIBC__)
-
- if (GetCurrentProcId() == PlatformThread::CurrentId()) {
- // For the main thread we have a shortcut.
- return reinterpret_cast<uintptr_t>(__libc_stack_end);
- }
-
-// No easy way to get end of the stack for non-main threads,
-// see crbug.com/617730.
-#elif defined(OS_MACOSX)
- return reinterpret_cast<uintptr_t>(pthread_get_stackaddr_np(pthread_self()));
-#endif
-
- // Don't know how to get end of the stack.
- return 0;
-}
-#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
StackTrace::StackTrace() : StackTrace(arraysize(trace_)) {}
StackTrace::StackTrace(const void* const* trace, size_t count) {
@@ -220,58 +39,5 @@
return stream.str();
}
-#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
-size_t TraceStackFramePointers(const void** out_trace,
- size_t max_depth,
- size_t skip_initial) {
- // Usage of __builtin_frame_address() enables frame pointers in this
- // function even if they are not enabled globally. So 'fp' will always
- // be valid.
- uintptr_t fp = reinterpret_cast<uintptr_t>(__builtin_frame_address(0)) -
- kStackFrameAdjustment;
-
- uintptr_t stack_end = GetStackEnd();
-
- size_t depth = 0;
- while (depth < max_depth) {
- if (skip_initial != 0) {
- skip_initial--;
- } else {
- out_trace[depth++] = reinterpret_cast<const void*>(GetStackFramePC(fp));
- }
-
- uintptr_t next_fp = GetNextStackFrame(fp);
- if (IsStackFrameValid(next_fp, fp, stack_end)) {
- fp = next_fp;
- continue;
- }
-
- next_fp = ScanStackForNextFrame(fp, stack_end);
- if (next_fp) {
- fp = next_fp;
- continue;
- }
-
- // Failed to find next frame.
- break;
- }
-
- return depth;
-}
-
-ScopedStackFrameLinker::ScopedStackFrameLinker(void* fp, void* parent_fp)
- : fp_(fp),
- parent_fp_(parent_fp),
- original_parent_fp_(LinkStackFrames(fp, parent_fp)) {}
-
-ScopedStackFrameLinker::~ScopedStackFrameLinker() {
- void* previous_parent_fp = LinkStackFrames(fp_, original_parent_fp_);
- CHECK_EQ(parent_fp_, previous_parent_fp)
- << "Stack frame's parent pointer has changed!";
-}
-
-#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
} // namespace debug
} // namespace base
diff --git a/base/debug/stack_trace.h b/base/debug/stack_trace.h
index 81e6672..322e77b 100644
--- a/base/debug/stack_trace.h
+++ b/base/debug/stack_trace.h
@@ -11,7 +11,6 @@
#include <string>
#include "base/base_export.h"
-#include "base/debug/debugging_buildflags.h"
#include "base/macros.h"
#include "build/build_config.h"
@@ -44,11 +43,6 @@
void*));
#endif
-// Returns end of the stack, or 0 if we couldn't get it.
-#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-BASE_EXPORT uintptr_t GetStackEnd();
-#endif
-
// A stacktrace can be helpful in debugging. For example, you can include a
// stacktrace member in a object (probably around #ifndef NDEBUG) so that you
// can later see where the given object was created from.
@@ -108,71 +102,6 @@
size_t count_;
};
-#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-// Traces the stack by using frame pointers. This function is faster but less
-// reliable than StackTrace. It should work for debug and profiling builds,
-// but not for release builds (although there are some exceptions).
-//
-// Writes at most |max_depth| frames (instruction pointers) into |out_trace|
-// after skipping |skip_initial| frames. Note that the function itself is not
-// added to the trace so |skip_initial| should be 0 in most cases.
-// Returns number of frames written.
-BASE_EXPORT size_t TraceStackFramePointers(const void** out_trace,
- size_t max_depth,
- size_t skip_initial);
-
-// Links stack frame |fp| to |parent_fp|, so that during stack unwinding
-// TraceStackFramePointers() visits |parent_fp| after visiting |fp|.
-// Both frame pointers must come from __builtin_frame_address().
-// Destructor restores original linkage of |fp| to avoid corrupting caller's
-// frame register on return.
-//
-// This class can be used to repair broken stack frame chain in cases
-// when execution flow goes into code built without frame pointers:
-//
-// void DoWork() {
-// Call_SomeLibrary();
-// }
-// static __thread void* g_saved_fp;
-// void Call_SomeLibrary() {
-// g_saved_fp = __builtin_frame_address(0);
-// some_library_call(...); // indirectly calls SomeLibrary_Callback()
-// }
-// void SomeLibrary_Callback() {
-// ScopedStackFrameLinker linker(__builtin_frame_address(0), g_saved_fp);
-// ...
-// TraceStackFramePointers(...);
-// }
-//
-// This produces the following trace:
-//
-// #0 SomeLibrary_Callback()
-// #1 <address of the code inside SomeLibrary that called #0>
-// #2 DoWork()
-// ...rest of the trace...
-//
-// SomeLibrary doesn't use frame pointers, so when SomeLibrary_Callback()
-// is called, stack frame register contains bogus value that becomes callback'
-// parent frame address. Without ScopedStackFrameLinker unwinding would've
-// stopped at that bogus frame address yielding just two first frames (#0, #1).
-// ScopedStackFrameLinker overwrites callback's parent frame address with
-// Call_SomeLibrary's frame, so unwinder produces full trace without even
-// noticing that stack frame chain was broken.
-class BASE_EXPORT ScopedStackFrameLinker {
- public:
- ScopedStackFrameLinker(void* fp, void* parent_fp);
- ~ScopedStackFrameLinker();
-
- private:
- void* fp_;
- void* parent_fp_;
- void* original_parent_fp_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedStackFrameLinker);
-};
-
-#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
namespace internal {
#if defined(OS_POSIX) && !defined(OS_ANDROID)
diff --git a/base/debug/stack_trace_unittest.cc b/base/debug/stack_trace_unittest.cc
index 959cd53..1fbeea2 100644
--- a/base/debug/stack_trace_unittest.cc
+++ b/base/debug/stack_trace_unittest.cc
@@ -8,7 +8,6 @@
#include <sstream>
#include <string>
-#include "base/debug/debugging_buildflags.h"
#include "base/debug/stack_trace.h"
#include "base/logging.h"
#include "base/process/kill.h"
@@ -255,66 +254,5 @@
}
#endif // defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_FUCHSIA)
-#if BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
-template <size_t Depth>
-void NOINLINE ExpectStackFramePointers(const void** frames,
- size_t max_depth) {
- code_start:
- // Calling __builtin_frame_address() forces compiler to emit
- // frame pointers, even if they are not enabled.
- EXPECT_NE(nullptr, __builtin_frame_address(0));
- ExpectStackFramePointers<Depth - 1>(frames, max_depth);
-
- constexpr size_t frame_index = Depth - 1;
- const void* frame = frames[frame_index];
- EXPECT_GE(frame, &&code_start) << "For frame at index " << frame_index;
- EXPECT_LE(frame, &&code_end) << "For frame at index " << frame_index;
- code_end: return;
-}
-
-template <>
-void NOINLINE ExpectStackFramePointers<1>(const void** frames,
- size_t max_depth) {
- code_start:
- // Calling __builtin_frame_address() forces compiler to emit
- // frame pointers, even if they are not enabled.
- EXPECT_NE(nullptr, __builtin_frame_address(0));
- size_t count = TraceStackFramePointers(frames, max_depth, 0);
- ASSERT_EQ(max_depth, count);
-
- const void* frame = frames[0];
- EXPECT_GE(frame, &&code_start) << "For the top frame";
- EXPECT_LE(frame, &&code_end) << "For the top frame";
- code_end: return;
-}
-
-#if defined(MEMORY_SANITIZER)
-// The test triggers use-of-uninitialized-value errors on MSan bots.
-// This is expected because we're walking and reading the stack, and
-// sometimes we read fp / pc from the place that previously held
-// uninitialized value.
-#define MAYBE_TraceStackFramePointers DISABLED_TraceStackFramePointers
-#else
-#define MAYBE_TraceStackFramePointers TraceStackFramePointers
-#endif
-TEST_F(StackTraceTest, MAYBE_TraceStackFramePointers) {
- constexpr size_t kDepth = 5;
- const void* frames[kDepth];
- ExpectStackFramePointers<kDepth>(frames, kDepth);
-}
-
-#if defined(OS_ANDROID) || defined(OS_MACOSX)
-#define MAYBE_StackEnd StackEnd
-#else
-#define MAYBE_StackEnd DISABLED_StackEnd
-#endif
-
-TEST_F(StackTraceTest, MAYBE_StackEnd) {
- EXPECT_NE(0u, GetStackEnd());
-}
-
-#endif // BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
-
} // namespace debug
} // namespace base
diff --git a/base/location.h b/base/location.h
index 14fe2fa..3f6b804 100644
--- a/base/location.h
+++ b/base/location.h
@@ -11,7 +11,6 @@
#include <string>
#include "base/base_export.h"
-#include "base/debug/debugging_buildflags.h"
#include "base/hash.h"
namespace base {
@@ -83,22 +82,11 @@
BASE_EXPORT const void* GetProgramCounter();
// The macros defined here will expand to the current function.
-#if BUILDFLAG(ENABLE_LOCATION_SOURCE)
-
-// Full source information should be included.
-#define FROM_HERE FROM_HERE_WITH_EXPLICIT_FUNCTION(__func__)
-#define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \
- ::base::Location::CreateFromHere(function_name, __FILE__, __LINE__)
-
-#else
-
// TODO(http://crbug.com/760702) remove the __FILE__ argument from these calls.
#define FROM_HERE ::base::Location::CreateFromHere(__FILE__)
#define FROM_HERE_WITH_EXPLICIT_FUNCTION(function_name) \
::base::Location::CreateFromHere(function_name, __FILE__, -1)
-#endif
-
} // namespace base
namespace std {
diff --git a/base/trace_event/cfi_backtrace_android.cc b/base/trace_event/cfi_backtrace_android.cc
deleted file mode 100644
index 8fd8b95..0000000
--- a/base/trace_event/cfi_backtrace_android.cc
+++ /dev/null
@@ -1,314 +0,0 @@
-// Copyright 2018 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/trace_event/cfi_backtrace_android.h"
-
-#include <sys/mman.h>
-#include <sys/types.h>
-
-#include "base/android/apk_assets.h"
-
-#if !defined(ARCH_CPU_ARMEL)
-#error This file should not be built for this architecture.
-#endif
-
-/*
-Basics of unwinding:
-For each instruction in a function we need to know what is the offset of SP
-(Stack Pointer) to reach the previous function's stack frame. To know which
-function is being invoked, we need the return address of the next function. The
-CFI information for an instruction is made up of 2 offsets, CFA (Call Frame
-Address) offset and RA (Return Address) offset. The CFA offset is the change in
-SP made by the function till the current instruction. This depends on amount of
-memory allocated on stack by the function plus some registers that the function
-stores that needs to be restored at the end of function. So, at each instruction
-the CFA offset tells the offset from original SP before the function call. The
-RA offset tells us the offset from the previous SP into the current function
-where the return address is stored.
-
-The unwind table file has 2 tables UNW_INDEX and UNW_DATA, inspired from ARM
-EHABI format. The first table contains function addresses and an index into the
-UNW_DATA table. The second table contains one or more rows for the function
-unwind information.
-
-UNW_INDEX contains two columns of N rows each, where N is the number of
-functions.
- 1. First column 4 byte rows of all the function start address as offset from
- start of the binary, in sorted order.
- 2. For each function addr, the second column contains 2 byte indices in order.
- The indices are offsets (in count of 2 bytes) of the CFI data from start of
- UNW_DATA.
-The last entry in the table always contains CANT_UNWIND index to specify the
-end address of the last function.
-
-UNW_DATA contains data of all the functions. Each function data contains N rows.
-The data found at the address pointed from UNW_INDEX will be:
- 2 bytes: N - number of rows that belong to current function.
- N * 4 bytes: N rows of data. 16 bits : Address offset from function start.
- 14 bits : CFA offset / 4.
- 2 bits : RA offset / 4.
-If the RA offset of a row is 0, then use the offset of the previous rows in the
-same function.
-TODO(ssid): Make sure RA offset is always present.
-
-See extract_unwind_tables.py for details about how this data is extracted from
-breakpad symbol files.
-*/
-
-extern "C" {
-extern char __executable_start;
-extern char _etext;
-}
-
-namespace base {
-namespace trace_event {
-
-namespace {
-
-// The value of index when the function does not have unwind information.
-constexpr uint32_t kCantUnwind = 0xFFFF;
-
-// The mask on the CFI row data that is used to get the high 14 bits and
-// multiply it by 4 to get CFA offset. Since the last 2 bits are masked out, a
-// shift is not necessary.
-constexpr uint16_t kCFAMask = 0xfffc;
-
-// The mask on the CFI row data that is used to get the low 2 bits and multiply
-// it by 4 to get the RA offset.
-constexpr uint16_t kRAMask = 0x3;
-constexpr uint16_t kRAShift = 2;
-
-// The code in this file assumes we are running in 32-bit builds since all the
-// addresses in the unwind table are specified in 32 bits.
-static_assert(sizeof(uintptr_t) == 4,
- "The unwind table format is only valid for 32 bit builds.");
-
-// The CFI data in UNW_DATA table starts with number of rows (N) and then
-// followed by N rows of 4 bytes long. The CFIUnwindDataRow represents a single
-// row of CFI data of a function in the table. Since we cast the memory at the
-// address after the address of number of rows, into an array of
-// CFIUnwindDataRow, the size of the struct should be 4 bytes and the order of
-// the members is fixed according to the given format. The first 2 bytes tell
-// the address of function and last 2 bytes give the CFI data for the offset.
-struct CFIUnwindDataRow {
- // The address of the instruction in terms of offset from the start of the
- // function.
- uint16_t addr_offset;
- // Represents the CFA and RA offsets to get information about next stack
- // frame. This is the CFI data at the point before executing the instruction
- // at |addr_offset| from the start of the function.
- uint16_t cfi_data;
-
- // Return the RA offset for the current unwind row.
- size_t ra_offset() const { return (cfi_data & kRAMask) << kRAShift; }
-
- // Returns the CFA offset for the current unwind row.
- size_t cfa_offset() const { return cfi_data & kCFAMask; }
-};
-
-static_assert(
- sizeof(CFIUnwindDataRow) == 4,
- "The CFIUnwindDataRow struct must be exactly 4 bytes for searching.");
-
-} // namespace
-
-// static
-CFIBacktraceAndroid* CFIBacktraceAndroid::GetInitializedInstance() {
- static CFIBacktraceAndroid* instance = new CFIBacktraceAndroid();
- return instance;
-}
-
-CFIBacktraceAndroid::CFIBacktraceAndroid()
- : thread_local_cfi_cache_(
- [](void* ptr) { delete static_cast<CFICache*>(ptr); }) {
- Initialize();
-}
-
-CFIBacktraceAndroid::~CFIBacktraceAndroid() {}
-
-void CFIBacktraceAndroid::Initialize() {
- // The address |_etext| gives the end of the .text section in the binary. This
- // value is more accurate than parsing the memory map since the mapped
- // regions are usualy larger than the .text section.
- executable_end_addr_ = reinterpret_cast<uintptr_t>(&_etext);
- // The address of |__executable_start| gives the start address of the
- // executable. This value is used to find the offset address of the
- // instruction in binary from PC.
- executable_start_addr_ = reinterpret_cast<uintptr_t>(&__executable_start);
-
- // This file name is defined by extract_unwind_tables.gni.
- static constexpr char kCfiFileName[] = "assets/unwind_cfi_32";
- MemoryMappedFile::Region cfi_region;
- int fd = base::android::OpenApkAsset(kCfiFileName, &cfi_region);
- if (fd < 0)
- return;
- cfi_mmap_ = std::make_unique<MemoryMappedFile>();
- // The CFI region starts at |cfi_region.offset|.
- if (!cfi_mmap_->Initialize(base::File(fd), cfi_region))
- return;
-
- ParseCFITables();
- can_unwind_stack_frames_ = true;
-}
-
-void CFIBacktraceAndroid::ParseCFITables() {
- // The first 4 bytes in the file is the size of UNW_INDEX table.
- static constexpr size_t kUnwIndexRowSize =
- sizeof(*unw_index_function_col_) + sizeof(*unw_index_indices_col_);
- size_t unw_index_size = 0;
- memcpy(&unw_index_size, cfi_mmap_->data(), sizeof(unw_index_size));
- DCHECK_EQ(0u, unw_index_size % kUnwIndexRowSize);
- // UNW_INDEX table starts after 4 bytes.
- unw_index_function_col_ =
- reinterpret_cast<const uintptr_t*>(cfi_mmap_->data()) + 1;
- unw_index_row_count_ = unw_index_size / kUnwIndexRowSize;
- unw_index_indices_col_ = reinterpret_cast<const uint16_t*>(
- unw_index_function_col_ + unw_index_row_count_);
-
- // The UNW_DATA table data is right after the end of UNW_INDEX table.
- // Interpret the UNW_DATA table as an array of 2 byte numbers since the
- // indexes we have from the UNW_INDEX table are in terms of 2 bytes.
- unw_data_start_addr_ = unw_index_indices_col_ + unw_index_row_count_;
-}
-
-size_t CFIBacktraceAndroid::Unwind(const void** out_trace, size_t max_depth) {
- // This function walks the stack using the call frame information to find the
- // return addresses of all the functions that belong to current binary in call
- // stack. For each function the CFI table defines the offset of the previous
- // call frame and offset where the return address is stored.
- if (!can_unwind_stack_frames())
- return 0;
-
- // Get the current register state. This register state can be taken at any
- // point in the function and the unwind information would be for this point.
- // Define local variables before trying to get the current PC and SP to make
- // sure the register state obtained is consistent with each other.
- uintptr_t pc = 0, sp = 0;
- asm volatile("mov %0, pc" : "=r"(pc));
- asm volatile("mov %0, sp" : "=r"(sp));
-
- // We can only unwind as long as the pc is within the chrome.so.
- size_t depth = 0;
- while (pc > executable_start_addr_ && pc <= executable_end_addr_ &&
- depth < max_depth) {
- out_trace[depth++] = reinterpret_cast<void*>(pc);
- // The offset of function from the start of the chrome.so binary:
- uintptr_t func_addr = pc - executable_start_addr_;
- CFIRow cfi{};
- if (!FindCFIRowForPC(func_addr, &cfi))
- break;
-
- // The rules for unwinding using the CFI information are:
- // SP_prev = SP_cur + cfa_offset and
- // PC_prev = * (SP_prev - ra_offset).
- sp = sp + cfi.cfa_offset;
- memcpy(&pc, reinterpret_cast<uintptr_t*>(sp - cfi.ra_offset),
- sizeof(uintptr_t));
- }
- return depth;
-}
-
-bool CFIBacktraceAndroid::FindCFIRowForPC(uintptr_t func_addr,
- CFIBacktraceAndroid::CFIRow* cfi) {
- auto* cache = GetThreadLocalCFICache();
- *cfi = {0};
- if (cache->Find(func_addr, cfi))
- return true;
-
- // Consider each column of UNW_INDEX table as arrays of uintptr_t (function
- // addresses) and uint16_t (indices). Define start and end iterator on the
- // first column array (addresses) and use std::lower_bound() to binary search
- // on this array to find the required function address.
- static const uintptr_t* const unw_index_fn_end =
- unw_index_function_col_ + unw_index_row_count_;
- const uintptr_t* found =
- std::lower_bound(unw_index_function_col_, unw_index_fn_end, func_addr);
-
- // If found is start, then the given function is not in the table. If the
- // given pc is start of a function then we cannot unwind.
- if (found == unw_index_function_col_ || *found == func_addr)
- return false;
-
- // std::lower_bound() returns the iter that corresponds to the first address
- // that is greater than the given address. So, the required iter is always one
- // less than the value returned by std::lower_bound().
- --found;
- uintptr_t func_start_addr = *found;
- size_t row_num = found - unw_index_function_col_;
- uint16_t index = unw_index_indices_col_[row_num];
- DCHECK_LE(func_start_addr, func_addr);
- // If the index is CANT_UNWIND then we do not have unwind infomation for the
- // function.
- if (index == kCantUnwind)
- return false;
-
- // The unwind data for the current function is at an offsset of the index
- // found in UNW_INDEX table.
- const uint16_t* unwind_data = unw_data_start_addr_ + index;
- // The value of first 2 bytes is the CFI data row count for the function.
- uint16_t row_count = 0;
- memcpy(&row_count, unwind_data, sizeof(row_count));
- // And the actual CFI rows start after 2 bytes from the |unwind_data|. Cast
- // the data into an array of CFIUnwindDataRow since the struct is designed to
- // represent each row. We should be careful to read only |row_count| number of
- // elements in the array.
- const CFIUnwindDataRow* function_data =
- reinterpret_cast<const CFIUnwindDataRow*>(unwind_data + 1);
-
- // Iterate through the CFI rows of the function to find the row that gives
- // offset for the given instruction address.
- CFIUnwindDataRow cfi_row = {0, 0};
- uint16_t ra_offset = 0;
- for (uint16_t i = 0; i < row_count; ++i) {
- CFIUnwindDataRow row;
- memcpy(&row, function_data + i, sizeof(CFIUnwindDataRow));
- // The return address of the function is the instruction that is not yet
- // been executed. The cfi row specifies the unwind info before executing the
- // given instruction. If the given address is equal to the instruction
- // offset, then use the current row. Or use the row with highest address
- // less than the given address.
- if (row.addr_offset + func_start_addr > func_addr)
- break;
-
- cfi_row = row;
- // The ra offset of the last specified row should be used, if unspecified.
- // So, keep updating the RA offset till we reach the correct CFI row.
- // TODO(ssid): This should be fixed in the format and we should always
- // output ra offset.
- if (cfi_row.ra_offset())
- ra_offset = cfi_row.ra_offset();
- }
- DCHECK_NE(0u, cfi_row.addr_offset);
- *cfi = {cfi_row.cfa_offset(), ra_offset};
- DCHECK(cfi->cfa_offset);
- DCHECK(cfi->ra_offset);
-
- // safe to update since the cache is thread local.
- cache->Add(func_addr, *cfi);
- return true;
-}
-
-CFIBacktraceAndroid::CFICache* CFIBacktraceAndroid::GetThreadLocalCFICache() {
- auto* cache = static_cast<CFICache*>(thread_local_cfi_cache_.Get());
- if (!cache) {
- cache = new CFICache();
- thread_local_cfi_cache_.Set(cache);
- }
- return cache;
-}
-
-void CFIBacktraceAndroid::CFICache::Add(uintptr_t address, CFIRow cfi) {
- cache_[address % kLimit] = {address, cfi};
-}
-
-bool CFIBacktraceAndroid::CFICache::Find(uintptr_t address, CFIRow* cfi) {
- if (cache_[address % kLimit].address == address) {
- *cfi = cache_[address % kLimit].cfi;
- return true;
- }
- return false;
-}
-
-} // namespace trace_event
-} // namespace base
diff --git a/base/trace_event/cfi_backtrace_android.h b/base/trace_event/cfi_backtrace_android.h
deleted file mode 100644
index 0c51332..0000000
--- a/base/trace_event/cfi_backtrace_android.h
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2018 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_TRACE_EVENT_CFI_BACKTRACE_ANDROID_H_
-#define BASE_TRACE_EVENT_CFI_BACKTRACE_ANDROID_H_
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include <memory>
-
-#include "base/base_export.h"
-#include "base/debug/debugging_buildflags.h"
-#include "base/files/memory_mapped_file.h"
-#include "base/gtest_prod_util.h"
-#include "base/threading/thread_local_storage.h"
-
-namespace base {
-namespace trace_event {
-
-// This class is used to unwind stack frames in the current thread. The unwind
-// information (dwarf debug info) is stripped from the chrome binary and we do
-// not build with exception tables (ARM EHABI) in release builds. So, we use a
-// custom unwind table which is generated and added to specific android builds,
-// when add_unwind_tables_in_apk build option is specified. This unwind table
-// contains information for unwinding stack frames when the functions calls are
-// from lib[mono]chrome.so. The file is added as an asset to the apk and the
-// table is used to unwind stack frames for profiling. This class implements
-// methods to read and parse the unwind table and unwind stack frames using this
-// data.
-class BASE_EXPORT CFIBacktraceAndroid {
- public:
- // Creates and initializes by memory mapping the unwind tables from apk assets
- // on first call.
- static CFIBacktraceAndroid* GetInitializedInstance();
-
- // Returns true if stack unwinding is possible using CFI unwind tables in apk.
- // There is no need to check this before each unwind call. Will always return
- // the same value based on CFI tables being present in the binary.
- bool can_unwind_stack_frames() const { return can_unwind_stack_frames_; }
-
- // Returns the program counters by unwinding stack in the current thread in
- // order of latest call frame first. Unwinding works only if
- // can_unwind_stack_frames() returns true. This function allocates memory from
- // heap for caches. For each stack frame, this method searches through the
- // unwind table mapped in memory to find the unwind information for function
- // and walks the stack to find all the return address. This only works until
- // the last function call from the chrome.so. We do not have unwind
- // information to unwind beyond any frame outside of chrome.so. Calls to
- // Unwind() are thread safe and lock free, once Initialize() returns success.
- size_t Unwind(const void** out_trace, size_t max_depth);
-
- private:
- FRIEND_TEST_ALL_PREFIXES(CFIBacktraceAndroidTest, TestCFICache);
- FRIEND_TEST_ALL_PREFIXES(CFIBacktraceAndroidTest, TestFindCFIRow);
- FRIEND_TEST_ALL_PREFIXES(CFIBacktraceAndroidTest, TestUnwinding);
-
- // The CFI information that correspond to an instruction.
- struct CFIRow {
- bool operator==(const CFIBacktraceAndroid::CFIRow& o) const {
- return cfa_offset == o.cfa_offset && ra_offset == o.ra_offset;
- }
-
- // The offset of the call frame address of previous function from the
- // current stack pointer. Rule for unwinding SP: SP_prev = SP_cur +
- // cfa_offset.
- uint16_t cfa_offset = 0;
- // The offset of location of return address from the previous call frame
- // address. Rule for unwinding PC: PC_prev = * (SP_prev - ra_offset).
- uint16_t ra_offset = 0;
- };
-
- // A simple cache that stores entries in table using prime modulo hashing.
- // This cache with 500 entries already gives us 95% hit rate, and fits in a
- // single system page (usually 4KiB). Using a thread local cache for each
- // thread gives us 30% improvements on performance of heap profiling.
- class CFICache {
- public:
- // Add new item to the cache. It replaces an existing item with same hash.
- // Constant time operation.
- void Add(uintptr_t address, CFIRow cfi);
-
- // Finds the given address and fills |cfi| with the info for the address.
- // returns true if found, otherwise false. Assumes |address| is never 0.
- bool Find(uintptr_t address, CFIRow* cfi);
-
- private:
- FRIEND_TEST_ALL_PREFIXES(CFIBacktraceAndroidTest, TestCFICache);
-
- // Size is the highest prime which fits the cache in a single system page,
- // usually 4KiB. A prime is chosen to make sure addresses are hashed evenly.
- static const int kLimit = 509;
-
- struct AddrAndCFI {
- uintptr_t address;
- CFIRow cfi;
- };
- AddrAndCFI cache_[kLimit] = {};
- };
-
- static_assert(sizeof(CFIBacktraceAndroid::CFICache) < 4096,
- "The cache does not fit in a single page.");
-
- CFIBacktraceAndroid();
- ~CFIBacktraceAndroid();
-
- // Initializes unwind tables using the CFI asset file in the apk if present.
- // Also stores the limits of mapped region of the lib[mono]chrome.so binary,
- // since the unwind is only feasible for addresses within the .so file. Once
- // initialized, the memory map of the unwind table is never cleared since we
- // cannot guarantee that all the threads are done using the memory map when
- // heap profiling is turned off. But since we keep the memory map is clean,
- // the system can choose to evict the unused pages when needed. This would
- // still reduce the total amount of address space available in process.
- void Initialize();
-
- // Finds the UNW_INDEX and UNW_DATA tables in from the CFI file memory map.
- void ParseCFITables();
-
- // Finds the CFI row for the given |func_addr| in terms of offset from
- // the start of the current binary.
- bool FindCFIRowForPC(uintptr_t func_addr, CFIRow* out);
-
- CFICache* GetThreadLocalCFICache();
-
- // Details about the memory mapped region which contains the libchrome.so
- // library file.
- uintptr_t executable_start_addr_ = 0;
- uintptr_t executable_end_addr_ = 0;
-
- // The start address of the memory mapped unwind table asset file. Unique ptr
- // because it is replaced in tests.
- std::unique_ptr<MemoryMappedFile> cfi_mmap_;
-
- // The UNW_INDEX table: Start address of the function address column. The
- // memory segment corresponding to this column is treated as an array of
- // uintptr_t.
- const uintptr_t* unw_index_function_col_ = nullptr;
- // The UNW_INDEX table: Start address of the index column. The memory segment
- // corresponding to this column is treated as an array of uint16_t.
- const uint16_t* unw_index_indices_col_ = nullptr;
- // The number of rows in UNW_INDEX table.
- size_t unw_index_row_count_ = 0;
-
- // The start address of UNW_DATA table.
- const uint16_t* unw_data_start_addr_ = nullptr;
-
- bool can_unwind_stack_frames_ = false;
-
- ThreadLocalStorage::Slot thread_local_cfi_cache_;
-};
-
-} // namespace trace_event
-} // namespace base
-
-#endif // BASE_TRACE_EVENT_CFI_BACKTRACE_ANDROID_H_
diff --git a/base/trace_event/cfi_backtrace_android_unittest.cc b/base/trace_event/cfi_backtrace_android_unittest.cc
deleted file mode 100644
index 3ad3d33..0000000
--- a/base/trace_event/cfi_backtrace_android_unittest.cc
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright 2018 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/trace_event/cfi_backtrace_android.h"
-
-#include "base/files/file_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-namespace trace_event {
-
-namespace {
-
-void* GetPC() {
- return __builtin_return_address(0);
-}
-
-} // namespace
-
-TEST(CFIBacktraceAndroidTest, TestUnwinding) {
- auto* unwinder = CFIBacktraceAndroid::GetInitializedInstance();
- EXPECT_TRUE(unwinder->can_unwind_stack_frames());
- EXPECT_GT(unwinder->executable_start_addr_, 0u);
- EXPECT_GT(unwinder->executable_end_addr_, unwinder->executable_start_addr_);
- EXPECT_GT(unwinder->cfi_mmap_->length(), 0u);
-
- const size_t kMaxFrames = 100;
- const void* frames[kMaxFrames];
- size_t unwind_count = unwinder->Unwind(frames, kMaxFrames);
- // Expect at least 2 frames in the result.
- ASSERT_GT(unwind_count, 2u);
- EXPECT_LE(unwind_count, kMaxFrames);
-
- const size_t kMaxCurrentFuncCodeSize = 50;
- const uintptr_t current_pc = reinterpret_cast<uintptr_t>(GetPC());
- const uintptr_t actual_frame = reinterpret_cast<uintptr_t>(frames[2]);
- EXPECT_NEAR(current_pc, actual_frame, kMaxCurrentFuncCodeSize);
-
- for (size_t i = 0; i < unwind_count; ++i) {
- EXPECT_GT(reinterpret_cast<uintptr_t>(frames[i]),
- unwinder->executable_start_addr_);
- EXPECT_LT(reinterpret_cast<uintptr_t>(frames[i]),
- unwinder->executable_end_addr_);
- }
-}
-
-// Flaky: https://bugs.chromium.org/p/chromium/issues/detail?id=829555
-TEST(CFIBacktraceAndroidTest, DISABLED_TestFindCFIRow) {
- auto* unwinder = CFIBacktraceAndroid::GetInitializedInstance();
- /* Input is generated from the CFI file:
- STACK CFI INIT 1000 500
- STACK CFI 1002 .cfa: sp 272 + .ra: .cfa -4 + ^ r4: .cfa -16 +
- STACK CFI 1008 .cfa: sp 544 + .r1: .cfa -0 + ^ r4: .cfa -16 + ^
- STACK CFI 1040 .cfa: sp 816 + .r1: .cfa -0 + ^ r4: .cfa -16 + ^
- STACK CFI 1050 .cfa: sp 816 + .ra: .cfa -8 + ^ r4: .cfa -16 + ^
- STACK CFI 1080 .cfa: sp 544 + .r1: .cfa -0 + ^ r4: .cfa -16 + ^
-
- STACK CFI INIT 2000 22
- STACK CFI 2004 .cfa: sp 16 + .ra: .cfa -12 + ^ r4: .cfa -16 + ^
- STACK CFI 2008 .cfa: sp 16 + .ra: .cfa -12 + ^ r4: .cfa -16 + ^
-
- STACK CFI INIT 2024 100
- STACK CFI 2030 .cfa: sp 48 + .ra: .cfa -12 + ^ r4: .cfa -16 + ^
- STACK CFI 2100 .cfa: sp 64 + .r1: .cfa -0 + ^ r4: .cfa -16 + ^
-
- STACK CFI INIT 2200 10
- STACK CFI 2204 .cfa: sp 44 + .ra: .cfa -8 + ^ r4: .cfa -16 + ^
- */
- uint16_t input[] = {// UNW_INDEX size
- 0x2A,
-
- // UNW_INDEX address column (4 byte rows).
- 0x0, 0x1000, 0x0, 0x1502, 0x0, 0x2000, 0x0, 0x2024, 0x0,
- 0x2126, 0x0, 0x2200, 0x0, 0x2212, 0x0,
-
- // UNW_INDEX index column (2 byte rows).
- 0x0, 0xffff, 0xb, 0x10, 0xffff, 0x15, 0xffff,
-
- // UNW_DATA table.
- 0x5, 0x2, 0x111, 0x8, 0x220, 0x40, 0x330, 0x50, 0x332,
- 0x80, 0x220, 0x2, 0x4, 0x13, 0x8, 0x13, 0x2, 0xc, 0x33,
- 0xdc, 0x40, 0x1, 0x4, 0x2e};
- FilePath temp_path;
- CreateTemporaryFile(&temp_path);
- EXPECT_EQ(
- static_cast<int>(sizeof(input)),
- WriteFile(temp_path, reinterpret_cast<char*>(input), sizeof(input)));
-
- unwinder->cfi_mmap_.reset(new MemoryMappedFile());
- unwinder->cfi_mmap_->Initialize(temp_path);
- unwinder->ParseCFITables();
-
- CFIBacktraceAndroid::CFIRow cfi_row = {0};
- EXPECT_FALSE(unwinder->FindCFIRowForPC(0x01, &cfi_row));
- EXPECT_FALSE(unwinder->FindCFIRowForPC(0x100, &cfi_row));
- EXPECT_FALSE(unwinder->FindCFIRowForPC(0x1502, &cfi_row));
- EXPECT_FALSE(unwinder->FindCFIRowForPC(0x3000, &cfi_row));
- EXPECT_FALSE(unwinder->FindCFIRowForPC(0x2024, &cfi_row));
- EXPECT_FALSE(unwinder->FindCFIRowForPC(0x2212, &cfi_row));
-
- const CFIBacktraceAndroid::CFIRow kRow1 = {0x110, 0x4};
- const CFIBacktraceAndroid::CFIRow kRow2 = {0x220, 0x4};
- const CFIBacktraceAndroid::CFIRow kRow3 = {0x220, 0x8};
- const CFIBacktraceAndroid::CFIRow kRow4 = {0x30, 0xc};
- const CFIBacktraceAndroid::CFIRow kRow5 = {0x2c, 0x8};
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1002, &cfi_row));
- EXPECT_EQ(kRow1, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1003, &cfi_row));
- EXPECT_EQ(kRow1, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1008, &cfi_row));
- EXPECT_EQ(kRow2, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1009, &cfi_row));
- EXPECT_EQ(kRow2, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1039, &cfi_row));
- EXPECT_EQ(kRow2, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1080, &cfi_row));
- EXPECT_EQ(kRow3, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1100, &cfi_row));
- EXPECT_EQ(kRow3, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x2050, &cfi_row));
- EXPECT_EQ(kRow4, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x2208, &cfi_row));
- EXPECT_EQ(kRow5, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x2210, &cfi_row));
- EXPECT_EQ(kRow5, cfi_row);
-
- // Test if cache is used on the future calls to Find, all addresses should
- // have different hash. Resetting the memory map to make sure it is never
- // accessed in Find().
- unwinder->cfi_mmap_.reset(new MemoryMappedFile());
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1002, &cfi_row));
- EXPECT_EQ(kRow1, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1003, &cfi_row));
- EXPECT_EQ(kRow1, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1008, &cfi_row));
- EXPECT_EQ(kRow2, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1009, &cfi_row));
- EXPECT_EQ(kRow2, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1039, &cfi_row));
- EXPECT_EQ(kRow2, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1080, &cfi_row));
- EXPECT_EQ(kRow3, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x1100, &cfi_row));
- EXPECT_EQ(kRow3, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x2050, &cfi_row));
- EXPECT_EQ(kRow4, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x2208, &cfi_row));
- EXPECT_EQ(kRow5, cfi_row);
- EXPECT_TRUE(unwinder->FindCFIRowForPC(0x2210, &cfi_row));
- EXPECT_EQ(kRow5, cfi_row);
-}
-
-TEST(CFIBacktraceAndroidTest, TestCFICache) {
- // Use ASSERT macros in this function since they are in loop and using EXPECT
- // prints too many failures.
- CFIBacktraceAndroid::CFICache cache;
- CFIBacktraceAndroid::CFIRow cfi;
-
- // Empty cache should not find anything.
- EXPECT_FALSE(cache.Find(1, &cfi));
-
- // Insert 1 - 2*kLimit
- for (size_t i = 1; i <= 2 * cache.kLimit; ++i) {
- CFIBacktraceAndroid::CFIRow val = {4 * i, 2 * i};
- cache.Add(i, val);
- ASSERT_TRUE(cache.Find(i, &cfi));
- ASSERT_EQ(cfi, val);
-
- // Inserting more than kLimit items evicts |i - cache.kLimit| from cache.
- if (i >= cache.kLimit)
- ASSERT_FALSE(cache.Find(i - cache.kLimit, &cfi));
- }
- // Cache contains kLimit+1 - 2*kLimit.
-
- // Check that 1 - kLimit cannot be found.
- for (size_t i = 1; i <= cache.kLimit; ++i) {
- ASSERT_FALSE(cache.Find(i, &cfi));
- }
-
- // Check if kLimit+1 - 2*kLimit still exists in cache.
- for (size_t i = cache.kLimit + 1; i <= 2 * cache.kLimit; ++i) {
- CFIBacktraceAndroid::CFIRow val = {4 * i, 2 * i};
- ASSERT_TRUE(cache.Find(i, &cfi));
- ASSERT_EQ(cfi, val);
- }
-
- // Insert 2*kLimit+1, will evict kLimit.
- cfi = {1, 1};
- cache.Add(2 * cache.kLimit + 1, cfi);
- EXPECT_TRUE(cache.Find(2 * cache.kLimit + 1, &cfi));
- EXPECT_FALSE(cache.Find(cache.kLimit + 1, &cfi));
- // Cache contains kLimit+1 - 2*kLimit.
-}
-
-} // namespace trace_event
-} // namespace base
diff --git a/base/trace_event/heap_profiler_allocation_context_tracker.cc b/base/trace_event/heap_profiler_allocation_context_tracker.cc
index 556719e..977f3b1 100644
--- a/base/trace_event/heap_profiler_allocation_context_tracker.cc
+++ b/base/trace_event/heap_profiler_allocation_context_tracker.cc
@@ -8,7 +8,6 @@
#include <iterator>
#include "base/atomicops.h"
-#include "base/debug/debugging_buildflags.h"
#include "base/debug/leak_annotations.h"
#include "base/debug/stack_trace.h"
#include "base/no_destructor.h"
@@ -17,10 +16,6 @@
#include "base/trace_event/heap_profiler_allocation_context.h"
#include "build/build_config.h"
-#if defined(OS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE)
-#include "base/trace_event/cfi_backtrace_android.h"
-#endif
-
#if defined(OS_LINUX) || defined(OS_ANDROID)
#include <sys/prctl.h>
#endif
@@ -219,27 +214,11 @@
// kMaxFrameCount + 1 frames, so that we know if there are more frames
// than our backtrace capacity.
#if !defined(OS_NACL) // We don't build base/debug/stack_trace.cc for NaCl.
-#if defined(OS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE)
- const void* frames[Backtrace::kMaxFrameCount + 1];
- static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount,
- "not requesting enough frames to fill Backtrace");
- size_t frame_count =
- CFIBacktraceAndroid::GetInitializedInstance()->Unwind(
- frames, arraysize(frames));
-#elif BUILDFLAG(CAN_UNWIND_WITH_FRAME_POINTERS)
- const void* frames[Backtrace::kMaxFrameCount + 1];
- static_assert(arraysize(frames) >= Backtrace::kMaxFrameCount,
- "not requesting enough frames to fill Backtrace");
- size_t frame_count = debug::TraceStackFramePointers(
- frames, arraysize(frames),
- 1 /* exclude this function from the trace */);
-#else
// Fall-back to capturing the stack with base::debug::StackTrace,
// which is likely slower, but more reliable.
base::debug::StackTrace stack_trace(Backtrace::kMaxFrameCount + 1);
size_t frame_count = 0u;
const void* const* frames = stack_trace.Addresses(&frame_count);
-#endif
// If there are too many frames, keep the ones furthest from main().
size_t backtrace_capacity = backtrace_end - backtrace;
diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc
index 54c93a2..9e595d6 100644
--- a/base/trace_event/memory_dump_manager.cc
+++ b/base/trace_event/memory_dump_manager.cc
@@ -41,10 +41,6 @@
#if defined(OS_ANDROID)
#include "base/trace_event/java_heap_dump_provider_android.h"
-#if BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE)
-#include "base/trace_event/cfi_backtrace_android.h"
-#endif
-
#endif // defined(OS_ANDROID)
namespace base {
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h
index 38528aa..2569f5e 100644
--- a/base/trace_event/trace_event.h
+++ b/base/trace_event/trace_event.h
@@ -15,7 +15,6 @@
#include <string>
#include "base/atomicops.h"
-#include "base/debug/debugging_buildflags.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "base/time/time_override.h"
@@ -439,24 +438,6 @@
INTERNAL_TRACE_EVENT_UID(ScopedContext) \
INTERNAL_TRACE_EVENT_UID(scoped_context)(context);
-#if BUILDFLAG(ENABLE_LOCATION_SOURCE)
-
-// Implementation detail: internal macro to trace a task execution with the
-// location where it was posted from.
-//
-// This implementation is for when location sources are available.
-// TODO(ssid): The program counter of the current task should be added here.
-#define INTERNAL_TRACE_TASK_EXECUTION(run_function, task) \
- TRACE_EVENT2("toplevel", run_function, "src_file", \
- (task).posted_from.file_name(), "src_func", \
- (task).posted_from.function_name()); \
- TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION INTERNAL_TRACE_EVENT_UID( \
- task_event)((task).posted_from.file_name()); \
- TRACE_HEAP_PROFILER_API_SCOPED_WITH_PROGRAM_COUNTER \
- INTERNAL_TRACE_EVENT_UID(task_pc_event)((task).posted_from.program_counter());
-
-#else
-
// TODO(http://crbug.com760702) remove file name and just pass the program
// counter to the heap profiler macro.
// TODO(ssid): The program counter of the current task should be added here.
@@ -467,8 +448,6 @@
TRACE_HEAP_PROFILER_API_SCOPED_WITH_PROGRAM_COUNTER \
INTERNAL_TRACE_EVENT_UID(task_pc_event)((task).posted_from.program_counter());
-#endif
-
namespace trace_event_internal {
// Specify these values when the corresponding argument of AddTraceEvent is not
diff --git a/tools/gn/bootstrap/bootstrap.py b/tools/gn/bootstrap/bootstrap.py
index cbbce40..e964f84 100755
--- a/tools/gn/bootstrap/bootstrap.py
+++ b/tools/gn/bootstrap/bootstrap.py
@@ -227,16 +227,6 @@
mkdir_p(root_gen_dir)
write_buildflag_header_manually(root_gen_dir,
- 'base/debug/debugging_buildflags.h',
- {
- 'ENABLE_LOCATION_SOURCE': 'false',
- 'ENABLE_PROFILING': 'false',
- 'CAN_UNWIND_WITH_FRAME_POINTERS': 'false',
- 'UNSAFE_DEVELOPER_BUILD': 'false',
- 'CAN_UNWIND_WITH_CFI_TABLE': 'false',
- })
-
- write_buildflag_header_manually(root_gen_dir,
'base/memory/protected_memory_buildflags.h',
{ 'USE_LLD': 'false' })