stacktrace.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2019 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef SDK_ANDROID_NATIVE_API_STACKTRACE_STACKTRACE_H_
  11. #define SDK_ANDROID_NATIVE_API_STACKTRACE_STACKTRACE_H_
  12. #include <string>
  13. #include <vector>
  14. namespace webrtc {
  15. struct StackTraceElement {
  16. // Pathname of shared object (.so file) that contains address.
  17. const char* shared_object_path;
  18. // Execution address relative to the .so base address. This matches the
  19. // addresses you get with "nm", "objdump", and "ndk-stack", as long as the
  20. // code is compiled with position-independent code. Android requires
  21. // position-independent code since Lollipop.
  22. uint32_t relative_address;
  23. // Name of symbol whose definition overlaps the address. This value is null
  24. // when symbol names are stripped.
  25. const char* symbol_name;
  26. };
  27. // Utility to unwind stack for a given thread on Android ARM devices. This works
  28. // on top of unwind.h and unwinds native (C++) stack traces only.
  29. std::vector<StackTraceElement> GetStackTrace(int tid);
  30. // Unwind the stack of the current thread.
  31. std::vector<StackTraceElement> GetStackTrace();
  32. // Get a string representation of the stack trace in a format ndk-stack accepts.
  33. std::string StackTraceToString(
  34. const std::vector<StackTraceElement>& stack_trace);
  35. } // namespace webrtc
  36. #endif // SDK_ANDROID_NATIVE_API_STACKTRACE_STACKTRACE_H_