Commit 5ca76e90 authored by Siddhartha's avatar Siddhartha Committed by Commit Bot

Android: Get register context from signal handler

1. Gets the register context from signal handler and sets all registers
correctly before using libunwind. This avoids crashes if registers are
used for unwinding frames.
2. Removes the need for unwinding signal handler function since we get
the context of the stopped function directly.

BUG=859260,888434

Change-Id: Ib337f20c19e25e2f82e61b08f8e9ed4ac1195fde
Reviewed-on: https://chromium-review.googlesource.com/c/1307055
Commit-Queue: ssid <ssid@chromium.org>
Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605121}
parent c00450e6
......@@ -5,13 +5,21 @@
#ifndef COMPONENTS_TRACING_COMMON_STACK_UNWINDER_ANDROID_H_
#define COMPONENTS_TRACING_COMMON_STACK_UNWINDER_ANDROID_H_
#include <ucontext.h>
#include <map>
#include <vector>
#include "base/debug/proc_maps_linux.h"
#include "base/profiler/native_stack_sampler.h"
#include "base/threading/platform_thread.h"
#include "components/tracing/tracing_export.h"
namespace jni_generator {
struct JniJavaCallContextUnchecked;
}
struct unw_context_t;
namespace tracing {
// Utility to unwind stacks for current thread on ARM devices. Contains ability
......@@ -24,6 +32,8 @@ namespace tracing {
// instances of this class.
class TRACING_EXPORT StackUnwinderAndroid {
public:
using JniMarker = jni_generator::JniJavaCallContextUnchecked;
StackUnwinderAndroid();
~StackUnwinderAndroid();
......@@ -53,6 +63,24 @@ class TRACING_EXPORT StackUnwinderAndroid {
bool is_initialized() const { return is_initialized_; }
private:
// Sends a SIGURG signal to the thread with id |tid| and copies the stack
// segment of the thread, along with register context. Returns true on
// success.
bool SuspendThreadAndRecordStack(
base::PlatformThreadId tid,
base::NativeStackSampler::StackBuffer* stack_buffer,
uintptr_t* sp,
size_t* stack_size,
unw_context_t* context,
ucontext_t* signal_context) const;
// Replaces any pointers to the old stack to point to the new stack segment.
// Returns the jni markers found on stack while scanning stack for pointers.
std::vector<const JniMarker*> RewritePointersAndGetMarkers(
base::NativeStackSampler::StackBuffer* stack_buffer,
uintptr_t sp,
size_t stack_size) const;
bool is_initialized_ = false;
// Stores all the memory mapped regions in the current process, including all
......
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