Commit graph

23 commits

Author SHA1 Message Date
Christopher Ferris
96722b0fa4 Cleanup the libbacktrace interface a bit.
- Change the field name load_base to load_bias (which is what it really is).
- Add a rel_pc field so that callers do not need to compute it themselves.
- Remove the BacktraceMap::GetRelativePc() since nobody should need to
  compute this themselves.

Bug: 23762183

Test: Compiles and unit tests pass (debuggerd, libbacktrace).
Change-Id: I2cb579767120adf08c407a58f3c487ee3f2b45fc
2017-07-19 15:36:32 -07:00
Christopher Ferris
f5e568e653 Do not access device maps.
It's possible that a device map has memory controlled by a single entry
device driver. Thus, you can deadlock if a process is touching that
device memory and we try to unwind it and also touch that device memory.
Simply skip any attempts to step through, or get function names from
device memory maps.

Bug: 36130325

Test: Ran new unit tests, ran bionic unit tests, ran art ThreadStress.
Change-Id: Ibc62d7ec8106c619ee08968f05e04aea55d7cbfa
2017-03-22 14:55:05 -07:00
Christopher Ferris
82f3bbdc25 Allow calling GetFunctionName before unwinding.
Some extra initialization needs to occur before calling the local/remote
GetFunctioneName.

Also, cleanup the test code a bit:

- Make all local functions static.
- Create a common function to create and finish remote processes.
- Remove unused function.
- Fix the formatting a bit by making it match clang format.

Test: Ran the unit tests.
Change-Id: I998bed1378d582df59fdf9263df6f208db5d795a
2017-03-21 14:21:49 -07:00
Christopher Ferris
c463ba45c4 Add error reporting mechanism for failing Unwind.
Remove the logging of an error if a thread disappears before the unwind
can begin. This can happen, so allow the caller to determine if this
is really a problem worth logging.

Bug: 27449879

(cherry picked from commit 206a3b9798)

Change-Id: If9e7cfeb6eb7b122679a734c1a9eacee8354ef18
2016-03-10 14:14:43 -08:00
Andreas Gampe
a7a7369343 Revert "Do not do local unwinds through .oat or .dex maps."
This reverts commit 4265ed7cc8.

Workaround in libunwind instead: change-id I98be5754cc4de4071616db334dc0c9862d3a2504

Bug: 27391690

(cherry picked from commit 04dcb00ab7)

Change-Id: Id77dc081b655dc0fcb513ad0ee95221d91a301f9
2016-03-02 13:20:35 -08:00
Christopher Ferris
b035a19e4f Do not do local unwinds through .oat or .dex maps.
Bug: 27391690

(cherry picked from commit 4265ed7cc8)

Change-Id: I88a49537544b507a3b0bfa61eafc27400a05281b
2016-03-01 18:19:42 -08:00
Christopher Ferris
ca09ce902c Discards frames for code within library.
When doing a local unwind, do not include the frames that come
from either libunwind or libbacktrace.

Bug: 11518609
Change-Id: I0ec8d823aebbfa0903e61b16b7e5663f3fd65e78
2015-04-01 15:58:20 -07:00
Christopher Ferris
2c43cff01d Refactor the code.
The object hierarchy was confusing and convoluted. This removes
a lot of unnecessary code, and consolidates the BacktraceCurrent
and BacktraceThread code into BacktraceCurrent.

Change-Id: I01c8407d493712a48169df49dd3ff46db4a7c3ae
2015-03-31 10:51:44 -07:00
Christopher Ferris
12385e3ad0 Move map data into backtrace data proper.
The backtrace structure used to include a pointer to a backtrace_map_t
that represented the map data for a particular pc. This introduced a
race condition where the pointer could be discarded, but the backtrace
structure still contained a pointer to garbage memory. Now all of the map
information is right in the structure.

Bug: 19028453
Change-Id: If7088a73f3c6bf1f3bc8cdd2bb4b62e7cab831c0
2015-02-06 15:00:09 -08:00
Christopher Ferris
c58287d601 Only include ucontext.h when necessary.
Change-Id: I29014f6c6b82e0a9797e5d76147b3c4e3d82a7f5
2014-05-09 16:59:06 -07:00
Christopher Ferris
a2efd3ac7a Rewrite unwind thread handling.
This new version doesn't require any specialized thread
implementation, it uses the Current implementation to do its job.
In addition, it runs much faster when multiple threads are trying
to unwind at the same time since the global signal lock is held for
only a small amount of time. Even running through the threads one at
a time should be faster since it no longer requires two passes through
the unwound stacks.

The new code now allows multiple simultaneous unwinds of the
same thread.

Finally, add the ability to unwind from a ucontext_t passed in. This
functionality doesn't work for remote unwinds yet.

Change-Id: I4d181d7ca5ffd2acfd1686e668e6d21e36b425cb
2014-05-08 14:42:16 -07:00
Christopher Ferris
17224d57fb Avoid logging functions from signal handler.
(cherry picked from commit 9007677fcb)

Change-Id: Ic0163f43308c6a281ab3757d90933e5127843fed
2014-04-15 12:18:44 -07:00
Christopher Ferris
e296091060 Create an UnwindMapLocal object.
The way libunwind handles local unwinds is different from remote unwinds,
so create a new map object to handle the differences.

Add new test to verify the map data is being generated correctly.

Add new tests to check for leaks.

Refactor the BACK_LOGW code into a single header file.

Change-Id: I01f3cbfc4b927646174ea1b614fa25d23b9b3427
2014-04-03 14:19:24 -07:00
Pavel Chupin
c6c194ced0 LP64: Enable debuggerd/libbacktrace/libunwind.
Change-Id: I2e432839f86c33c2adbaac8cc12ca8961956044b
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2014-01-30 17:15:24 -08:00
Christopher Ferris
5c40019a92 Clean up UnwindCurrent.cpp's use of ucontext.h.
Change-Id: I9eff7486b9fe89eac57b5555649b871bc6f1cc77
2014-01-30 10:37:39 -08:00
Christopher Ferris
df2906186b Re-enable libunwind for arm.
Update to handle the new optimized way that libunwind works.

In addition, a small refactor of the BacktraceMap code.

A few new tests of for good measure.

Change-Id: I2f9b4f5ad5a0dfe907b31febee76e4b9b94fb76f
2014-01-28 12:03:36 -08:00
Christopher Ferris
edbe3b4b56 Get arm64 to compile.
Change-Id: Ica021aa134388fe7069a5de5df8036ecf0d570f8
2014-01-27 10:52:08 -08:00
Christopher Ferris
46756821c4 Rewrite libbacktrace to be all C++.
This includes removing the map_info.c source and replacing it with the
BacktraceMap class to handle all map related code.

Change all callers of libbacktrace map functionality.

Also modify the corkscrew thread code so that it doesn't need to build
the map twice (once in the corkscrew format and once in the libbacktrace
format).

Change-Id: I32865a39f83a3dd6f958fc03c2759ba47d12382e
2014-01-16 16:12:29 -08:00
Christopher Ferris
20303f856f Next phase of the move, reformat use C++ features.
Use the libbacktrace C++ interface instead of the C interface in debuggerd.

Reformat the debuggerd code to be closer to Google C++ style.

Fix all debuggerd casts to be C++ casts.

Add a frame number to the frame data structure for ease of formatting and
add another FormatFrameData function.

Change the format_test to use the new FormatFrameData function.

Modify all of the backtrace_test to use the C++ interface.

Change-Id: I10e1610861acf7f4a3ad53276b74971cfbfda464
2014-01-13 14:21:52 -08:00
Christopher Ferris
9846497f79 Refactor to share map_info amongst threads.
Allow the use of the same map info to be shared when getting information on
multiple threads from the same pid.

Change-Id: I2e460e20154a10f4894ae563331fb32179e4551f
2014-01-08 15:32:28 -08:00
Christopher Ferris
ddc4f093f7 Fix the ucontext for mips/x86.
Remove the mips ucontext definition, there is no need for it any more.

Fix the mips/x86 ucontext copy code to copy the entire uc_mcontext data
across.

Fix a potential memory leak too.

Change-Id: I4272022da5281ed881e2d59a3e19e7f33c01aceb
2014-01-07 14:36:03 -08:00
Christopher Ferris
8ed46278be More libbacktrace fixes.
Included in minor fix ups is the addition of a warning macro to replace
all of the ALOGW calls.

Fix a race where multiple threads could be attempting to unwind the threads
of the current process at the same time.

Bug: 8410085

Change-Id: I02a65dc778dde690e5f95fc8ff069a32d0832fd1
2013-10-30 14:14:54 -07:00
Christopher Ferris
17e91d44ed Rewrite libbacktrace using C++.
The old code was essentially trying to be C++ in C and was awkward. This
change makes it all objects with a thin layer that C code can use.

There is a C++ backtrace object that is not very useful, this code will
replace it.

This change also includes moving the backtrace test to a gtest, and adding
coverage of all major functionality.

Bug: 8410085
Change-Id: Iae0f1b09b3dd60395f71ed66010c1ea5cdd37841
2013-10-28 17:55:25 -07:00