diff options
author | Sim Sun <simsun@fb.com> | 2022-03-02 22:15:27 -0800 |
---|---|---|
committer | Christopher Ferris <cferris@google.com> | 2022-03-03 10:40:56 -0800 |
commit | 1af21effefbd57060f6e215e893ccddd10776f2a (patch) | |
tree | 65d7fd8a5b9f0183014df71e386c5b2aa2e4a6fb | |
parent | 875fd55938fe993973948bfb59b9c3814c338ef4 (diff) | |
download | unwinding-1af21effefbd57060f6e215e893ccddd10776f2a.tar.gz |
Allow unwinding main thread in ThreadUnwinder.
The check in ThreadUnwinder was overly aggressive, it should only
disallow unwinding itself. Unfortunately, it only disallowed
unwinding the main thread.
Add new unit tests to verify this behavior.
Test: New unit tests pass that verify thread unwinding behavior.
Signed-off-by: Sim Sun <simsun@fb.com>
Change-Id: If75399911f2f98f3155592fc292341d7b9e5e023
-rw-r--r-- | libunwindstack/ThreadUnwinder.cpp | 2 | ||||
-rw-r--r-- | libunwindstack/tests/UnwindTest.cpp | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/libunwindstack/ThreadUnwinder.cpp b/libunwindstack/ThreadUnwinder.cpp index 9a8a0a6..2bdb910 100644 --- a/libunwindstack/ThreadUnwinder.cpp +++ b/libunwindstack/ThreadUnwinder.cpp @@ -149,7 +149,7 @@ void ThreadUnwinder::UnwindWithSignal(int signal, pid_t tid, std::unique_ptr<Reg const std::vector<std::string>* initial_map_names_to_skip, const std::vector<std::string>* map_suffixes_to_ignore) { ClearErrors(); - if (tid == pid_) { + if (tid == static_cast<pid_t>(android::base::GetThreadId())) { last_error_.code = ERROR_UNSUPPORTED; return; } diff --git a/libunwindstack/tests/UnwindTest.cpp b/libunwindstack/tests/UnwindTest.cpp index 80f931b..2ed1b9b 100644 --- a/libunwindstack/tests/UnwindTest.cpp +++ b/libunwindstack/tests/UnwindTest.cpp @@ -570,6 +570,28 @@ TEST_F(UnwindTest, thread_unwind_cur_pid) { EXPECT_EQ(ERROR_UNSUPPORTED, unwinder.LastErrorCode()); } +TEST_F(UnwindTest, thread_unwind_cur_thread) { + std::thread thread([]() { + ThreadUnwinder unwinder(512); + ASSERT_TRUE(unwinder.Init()); + unwinder.UnwindWithSignal(SIGRTMIN, android::base::GetThreadId()); + EXPECT_EQ(0U, unwinder.NumFrames()); + EXPECT_EQ(ERROR_UNSUPPORTED, unwinder.LastErrorCode()); + }); + thread.join(); +} + +TEST_F(UnwindTest, thread_unwind_cur_pid_from_thread) { + std::thread thread([]() { + ThreadUnwinder unwinder(512); + ASSERT_TRUE(unwinder.Init()); + unwinder.UnwindWithSignal(SIGRTMIN, getpid()); + EXPECT_NE(0U, unwinder.NumFrames()); + EXPECT_NE(ERROR_UNSUPPORTED, unwinder.LastErrorCode()); + }); + thread.join(); +} + static std::thread* CreateUnwindThread(std::atomic_int& tid, ThreadUnwinder& unwinder, std::atomic_bool& start_unwinding, std::atomic_int& unwinders) { |