If the underlying local map changes, it's possible for multiple
threads to try and modify the map data associated with the UnwindLocalMap
object. Add a lock when generating the local map to avoid this problem.
In addition, add a read lock whenever any caller gets the maps iterator.
Updated all iterator callers to make this lock.
Bug: 29387050
Change-Id: Ie34822c3d8fd3bdb3dd126aeeb399969c36508c1
LOCAL_LDLIBS should only be used with -l flags for NDK and some host
libraries. Other uses should use LOCAL_SHARED_LIBRARIES.
LOCAL_LDFLAGS should not contain -l entries, they should be in
LOCAL_LDLIBS instead.
LOCAL_CFLAGS should not contain -I entries, those should use
LOCAL_C_INCLUDES instead.
Change-Id: Ic901aa14651572ac682166becd4f0cd86baecc34
As device may not have libbacktrace_offline shared library, simpleperf
no longer rely on it. So there is no reason to keep libbacktrace_offline
shared library.
Bug: 28152982
Change-Id: If8e31b1434646dbbfed60264eb25f034bc5d6946
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
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
Change-Id: Ie81718d53fb0e519fa0a7db9fd5f314b72bfa431
Sometimes, the new pss is significantly less than the stable pss. Do
not fail if this case occurs.
Change-Id: Ic7da87275a821818e375d05cac10e84c62710c5e
When creating an UnwindMapLocal fails in the Build() function call,
the destructor for UnwindMap is called. Unfortunately, the map_cursor_
member variable has not been initialized, so the call to destroy it
winds up operating on garbage data.
Part of this is a result of a bad class hierarchy, so this refactors
the classes slightly, and properly initializes the map_cursor_ member
variable in the base class.
Bug: 26931578
Change-Id: I885596bf65e4ef63559cee2c56cd41576d5ecc1b
BacktraceOffline is the only code that uses libLLVM. Create
a new shared library, backtrace_offline.so, that references this
so that including libbacktrace.so doesn't wind up pulling in libLLVM.
Change-Id: I90c502d833f6c464c3810dffde52a0c6da241cce
The check_unreadble_elf_* tests only create a readable map. I changed
libunwind to disallow unwinding through non-executable maps, so make
the maps executable too.
Bug: 26589772
Change-Id: Idbe6426ac4d3243779b819c8f1aebdcdacb0669f
Before, an anonymous map wound up printing the pc as relative.
Unfortunately, this meant that it was impossible to tell the actual
pc. The new code prints the map name as <anonymous:map_start> and
still prints the pc as relative.
In addition, add the start of the map for map names that begin with a
'[' character.
Bug: 25844836
Change-Id: Ie0b6149dde258fe13f0e5a3e5739d85374512f4b
This change makes sure -fno-omit-frame-pointer flag is not
overrided by flags set in $(LLVM_HOST_BUILD_MK).
Change-Id: I53037b0eab6bd1272cec0f5c9caa058ad1a55419
(This might want to be unified with the very similar code in bionic, but
that's a job for another day.)
Change-Id: I5dade498f781305fa9909ee01f1f4bebc537c169
This reverts commit ab5e583327.
And statically link llvm libraries on host to remove dependency
on 32-bit llvm shared library which is not included in the prebuilt.
Bug: 22229391
Change-Id: I8210687655ee1809fd820ab2a6ca5dfaf3f9096d
Using llvm makes libbacktrace stops building for 32 bit on linux host x86_64.
This reverts commit c9c6b6ee77.
Change-Id: Ieb807db881d7bb3132cd09e25fd08c28766ca0a8
If the signal handler doesn't fire in the given time when trying to unwind
a thread, put on a logging handler. This prevents crashes if the signal
does eventually fire.
Bug: 23783762
(cherry picked from commit d7226f9a14)
Change-Id: Ib990a06733cc93717752ab4998f4ae26afd7e249
If the signal handler doesn't fire in the given time when trying to unwind
a thread, put on a logging handler. This prevents crashes if the signal
does eventually fire.
Bug: 23783762
Change-Id: Ib7abb36b71d079a7043117697c41b535319586fd
The dlopen of a shared library in an apk results in large map offsets.
Unfortunately, the current way that the frame data is printed, it's
impossible to tell what the relative pc is relative to. With the
addition of the offset, it's possible to figure out what the relative
pc actually references.
Bug: 23348999
(cherry picked from commit e0ab23223a)
Change-Id: I950f92c1cb29ee05eed777f47453efa03318cf3e
The dlopen of a shared library in an apk results in large map offsets.
Unfortunately, the current way that the frame data is printed, it's
impossible to tell what the relative pc is relative to. With the
addition of the offset, it's possible to figure out what the relative
pc actually references.
Bug: 23348999
Change-Id: Ia51b669ea3f810158cfd0d71d9ae89bf9a3170d3
Upstream clang has a new diagnostic, '-Wmismatched-new-delete' to
generate a warning (that becomes an error with -Werror) when delete is
used to deallocate pointers created with 'new[]'. This patch fixes
'delete's that trigger this warning/error.
Change-Id: I7551e856b4b13bfae4cb78b5664d8652322683cf
This error message has no meaning and makes it look like an unwinding
failure occurred. These messages are showing up more often now
that a lot more of debuggerd is using the ReadWord and Read calls.
If a higher level function wants to indicate there is an error, then
it can add a more meaningful error.
Bug: 21818730
(cherry picked from commit 35c8136d96)
Change-Id: Ie6e20fbc18702fde935f2cf8cbf1b297fda43282
This error message has no meaning and makes it look like an unwinding
failure occurred. These messages are showing up more often now
that a lot more of debuggerd is using the ReadWord and Read calls.
If a higher level function wants to indicate there is an error, then
it can add a more meaningful error.
Bug: 21818730
Change-Id: I83aca9cf241aee99e7425059b1b6e0d229c08a5e
If the signal to dump a thread is never delivered, then it's
possible for a deadlock. The signal handler is responsible for
unlocking and deleting the ThreadEntry created for the pid/tid
combination. This means if the signal is lost, the ThreadEntry
gets stuck locked and never deleted. If a second attempt to get
a backtrace of this thread occurs, there is a deadlock.
Also, decrease the timeout from 10 seconds to 5 seconds. The original
10 seconds was because the unwind was actually done in the signal
handler. Now the signal handler does nothing but copy the ucontext
structure and let the caller do the unwind.
Bug: 21086132
(cherry picked from commit 2d09171758)
Change-Id: I414c500eb08983a5017caf3fce4f499465575a9d
If the signal to dump a thread is never delivered, then it's
possible for a deadlock. The signal handler is responsible for
unlocking and deleting the ThreadEntry created for the pid/tid
combination. This means if the signal is lost, the ThreadEntry
gets stuck locked and never deleted. If a second attempt to get
a backtrace of this thread occurs, there is a deadlock.
Also, decrease the timeout from 10 seconds to 5 seconds. The original
10 seconds was because the unwind was actually done in the signal
handler. Now the signal handler does nothing but copy the ucontext
structure and let the caller do the unwind.
Bug: 21086132
Change-Id: Idc735dbf6147ec879d35bd4f034c5d227e26a98d
Under some conditions, /proc/<pid>/maps might return nothing. If we
try and unwind in this case, we'll crash. Check this case and fail
the unwind.
Add checks that no other functions try and use map_ without
checking for nullptr.
Add logging when an unwind fails so it's clear what happened.
Bug: 21162746
Change-Id: I56ce51dda0cfc9db20475a441f118108196aa07c
(cherry picked from commit 30c942cf10)
Under some conditions, /proc/<pid>/maps might return nothing. If we
try and unwind in this case, we'll crash. Check this case and fail
the unwind.
Add checks that no other functions try and use map_ without
checking for nullptr.
Add logging when an unwind fails so it's clear what happened.
Bug: 21162746
Change-Id: I56ce51dda0cfc9db20475a441f118108196aa07c
Also simplifies the Darwin implementation of gettid, because
apparently libbacktrace had a better way of doing it.
Bug: 19517541
(cherry picked from commit 23f750b068)
Change-Id: I2f888e8ed7a2f5719973786cbcbb399a81867ee9
The BacktracePtrace::Read function crashes if the number of bytes to
read is less than the number of bytes needed to align the read to
a word_t boundary.
Fix this and add a test for this case.
Change-Id: I50808849ece44928f65dba1d25309e3885c829a2
(cherry picked from commit 944f417ccb)
The BacktracePtrace::Read function crashes if the number of bytes to
read is less than the number of bytes needed to align the read to
a word_t boundary.
Fix this and add a test for this case.
Change-Id: I50808849ece44928f65dba1d25309e3885c829a2
The new linker relocation packing support uses non-zero load bases,
so we better handle them properly.
Also print out the load base for a map if it's non-zero.
Bug: 20687795
(cherry picked from commit 329ed7dae4)
Change-Id: Ibc37d8c8bb032820dca4e7531184349ba6d402d2
The new linker relocation packing support uses non-zero load bases,
so we better handle them properly.
Also print out the load base for a map if it's non-zero.
Bug: 20687795
Change-Id: Iec2d1db2051e7b4a278c1dfa57d745128a7f2974
Also simplifies the Darwin implementation of gettid, because
apparently libbacktrace had a better way of doing it.
Change-Id: I9e14f9176b167405a5aaa5b8a0db0327c7126271
When doing a local unwind, do not include the frames that come
from either libunwind or libbacktrace.
Bug: 11518609
Change-Id: I0ec8d823aebbfa0903e61b16b7e5663f3fd65e78
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
The latest clang (r230699) does not allow SP/PC to be declared in inline asm
lists. This is a problem for libraries that are attempting to save all
register state.
Change-Id: I1ce80530f8be85fd74e949d0c65b60080e0aaf2a
Included tests for this new feature.
Changed the NULLs to nullptr in backtrace_test.
Changed UniquePtr to std::unique_ptr in backtrace_test.
Change-Id: I92375465b8f8ba84589834cc162db5915bf1be81
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
Switch to the better supported pthread_cond to handle the Wait/Wake
functions.
Also, increase the number of simultaneous threads in the thread tests.
Bug: 18381207
(cherry picked from commit db44538387)
Change-Id: Id326a7a7b92cb61573def3f761597c40f3ef2f4b
The ucontext_t data structure could be bigger than the kernel data
structure. Since the unwinder only cares about the mcontext data, only
copy that out of the structure. The mcontext data is the same size in
the kernel and in the ucontext_t structure.
Bug: 15189014
Change-Id: I5978169c4425b8212e11db85a57eb319cd0e264b
The libc++ version of libbacktrace on the host was still linking against
libstdc++, and this was causing problems in art.
Change-Id: I1d14fb9e18abd074affcf46c8044407041970669
These headers are needed for pid_t and free when using libc++ headers (POSIX
does not require that the symbols be exposed with the previous includes).
Change-Id: Ia51a4fdfdbae7377130a43c401c2d8d241671d1e
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
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
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
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
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
Use a bit better name for this. The other name was a bit confusing.
Change-Id: I1261f2ee3854a9c8b82133ad0bfbbbe48b43c9ac
(cherry picked from commit 242b1a8c7a)
Conflicts:
libbacktrace/Backtrace.cpp
Allow the use of the same map info to be shared when getting information on
multiple threads from the same pid.
Change-Id: I2e460e20154a10f4894ae563331fb32179e4551f
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
We're seeing major stack trace generation performance
regression and want to find out whether it's libunwind.
Bug: 12181612
Change-Id: I3866ea956859f5cbdfe4f1ee6f20a2b6d39962c4
In order to be explicit in the Backtrace::Create() calls, adding a couple
of defines and some comments to describe what they mean.
Change-Id: I6ad08c529791821496a95fa33cea1c95b0a7eada
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
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
- Add a wait for stop to backtrace_test. There is a possible race
condition that is exposed when using libunwind.
- Fix a few calls to unwind function calls.
Bug: 8410085
Change-Id: I7487d687f6d4b7b05b8a96ad1c5f7183681e5c95
This library will be used to abstract away getting backtrace
data from how it is implemented. This is the first step to
replacing libcorkscrew with libunwind.
Bug: 8410085
Change-Id: Ie8f159e96a055d378e1ddc72d40239fba4cf52b7