Android: Add helper methods for printing native stack traces

This CL adds utility functions to unwind the stack for a given thread on
Android ARM devices. This works on top of unwind.h and unwinds native
(C++) stack traces only. Unwinding a thread from another thread is done
by overriding the signal handler with a custom function and then
interrupting the specific thread.

Bug: webrtc:10168
Change-Id: If5adffd3a6bb57bf502168743e09a7eefc292bf3
Reviewed-on: https://webrtc-review.googlesource.com/c/118141
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26328}
This commit is contained in:
Magnus Jedvert
2019-01-20 11:46:32 +01:00
committed by Commit Bot
parent 982639c019
commit dc32cc00e8
4 changed files with 476 additions and 0 deletions

View File

@ -0,0 +1,42 @@
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef SDK_ANDROID_NATIVE_API_STACKTRACE_STACKTRACE_H_
#define SDK_ANDROID_NATIVE_API_STACKTRACE_STACKTRACE_H_
#include <string>
#include <vector>
namespace webrtc {
struct StackTraceElement {
// Pathname of shared object (.so file) that contains address.
const char* shared_object_path;
// Execution address relative to the .so base address. This matches the
// addresses you get with "nm", "objdump", and "ndk-stack", as long as the
// code is compiled with position-independent code. Android requires
// position-independent code since Lollipop.
uint32_t relative_address;
// Name of symbol whose definition overlaps the address. This value is null
// when symbol names are stripped.
const char* symbol_name;
};
// Utility to unwind stack for a given thread on Android ARM devices. This works
// on top of unwind.h and unwinds native (C++) stack traces only.
std::vector<StackTraceElement> GetStackTrace(int tid);
// Get a string representation of the stack trace in a format ndk-stack accepts.
std::string StackTraceToString(
const std::vector<StackTraceElement>& stack_trace);
} // namespace webrtc
#endif // SDK_ANDROID_NATIVE_API_STACKTRACE_STACKTRACE_H_