diff options
author | Yabin Cui <yabinc@google.com> | 2019-05-02 12:58:05 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2019-05-06 14:58:15 -0700 |
commit | 847f3fdda58fbbb4807b2b7deeff5dd06f6b9eb7 (patch) | |
tree | 2fd801b70dc0e20e38d1bf7fa7dc1d2a95dac08b /simpleperf/thread_tree_test.cpp | |
parent | e85543e73fbdb5f96aaaacc3890a58058582667f (diff) | |
download | extras-847f3fdda58fbbb4807b2b7deeff5dd06f6b9eb7.tar.gz |
simpleperf: fix segfault caused by reused thread ids.
simpleperf thinks a thread id is bound to a unique thread, and doesn't
handle thread exit records when building a thread tree. However, in a
long recording, if a thread exits, its thread id may be reused to create
new threads. It can cause segfault in simpleperf.
This CL fix this by handling thread exit records and destroying ThreadEntry
for destroyed threads. Also adjust cmd_report and cmd_report_sample for
the change.
Also fix a python test failed in the new android version.
Bug: 130157407
Test: run simpleperf_unit_test.
Test: record zygote for a long time while app keeps restarting.
Test: run python tests.
Change-Id: Ib77e772190edb29c4ab1dd42f888fbc415e4900d
Diffstat (limited to 'simpleperf/thread_tree_test.cpp')
-rw-r--r-- | simpleperf/thread_tree_test.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/simpleperf/thread_tree_test.cpp b/simpleperf/thread_tree_test.cpp index be3d8bfa..d00ebcb9 100644 --- a/simpleperf/thread_tree_test.cpp +++ b/simpleperf/thread_tree_test.cpp @@ -105,3 +105,18 @@ TEST_F(ThreadTreeTest, jit_maps_before_fork) { ASSERT_TRUE(map != nullptr); ASSERT_EQ(map->flags, map_flags::PROT_JIT_SYMFILE_MAP); } + +TEST_F(ThreadTreeTest, reused_tid) { + // Process 1 has thread 1 and 2. + thread_tree_.ForkThread(1, 2, 1, 1); + // Thread 2 exits. + thread_tree_.ExitThread(1, 2); + // Thread 1 forks process 2. + thread_tree_.ForkThread(2, 2, 1, 1); +} + +TEST_F(ThreadTreeTest, reused_tid_without_thread_exit) { + // Similar to the above test, but the thread exit record is missing. + thread_tree_.ForkThread(1, 2, 1, 1); + thread_tree_.ForkThread(2, 2, 1, 1); +} |