From 91e1ee4a3763027a070c93ebf08d7eead7ace806 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 11 Jul 2018 11:13:16 -0700 Subject: Move libbacktrace off cutils. There's still in a test, but I don't understand why that isn't just std::atomic. Also add a shared tgkill wrapper to libbase. Bug: N/A Test: ran tests Change-Id: Idd4baa1e1670a84b3a8f35803cc5ffe5aae008a6 --- libbacktrace/Android.bp | 4 ---- libbacktrace/Backtrace.cpp | 4 ++-- libbacktrace/BacktraceCurrent.cpp | 13 +++++++------ libbacktrace/BacktraceMap.cpp | 2 -- libbacktrace/BacktracePtrace.cpp | 1 - libbacktrace/UnwindStack.cpp | 4 ---- libbacktrace/backtrace_benchmarks.cpp | 3 ++- libbacktrace/backtrace_offline_test.cpp | 4 ++-- libbacktrace/backtrace_test.cpp | 16 ++++++++-------- libbacktrace/thread_utils.c | 29 ----------------------------- libbacktrace/thread_utils.h | 32 -------------------------------- libunwindstack/tests/UnwindTest.cpp | 4 ++-- 12 files changed, 23 insertions(+), 93 deletions(-) delete mode 100644 libbacktrace/thread_utils.c delete mode 100644 libbacktrace/thread_utils.h diff --git a/libbacktrace/Android.bp b/libbacktrace/Android.bp index b4bf35f..a10e636 100644 --- a/libbacktrace/Android.bp +++ b/libbacktrace/Android.bp @@ -42,7 +42,6 @@ libbacktrace_sources = [ "Backtrace.cpp", "BacktraceCurrent.cpp", "BacktracePtrace.cpp", - "thread_utils.c", "ThreadEntry.cpp", "UnwindStack.cpp", "UnwindStackMap.cpp", @@ -94,7 +93,6 @@ cc_library { ], static_libs: [ - "libcutils", "libprocinfo", ], @@ -145,7 +143,6 @@ cc_test { "backtrace_offline_test.cpp", "backtrace_test.cpp", "GetPss.cpp", - "thread_utils.c", ], cflags: [ @@ -159,7 +156,6 @@ cc_test { "libbacktrace", "libdexfile", "libbase", - "libcutils", "liblog", "libunwindstack", ], diff --git a/libbacktrace/Backtrace.cpp b/libbacktrace/Backtrace.cpp index 6445a7c..6bec63c 100644 --- a/libbacktrace/Backtrace.cpp +++ b/libbacktrace/Backtrace.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -31,7 +32,6 @@ #include "BacktraceLog.h" #include "UnwindStack.h" -#include "thread_utils.h" using android::base::StringPrintf; @@ -124,7 +124,7 @@ Backtrace* Backtrace::Create(pid_t pid, pid_t tid, BacktraceMap* map) { if (pid == BACKTRACE_CURRENT_PROCESS) { pid = getpid(); if (tid == BACKTRACE_CURRENT_THREAD) { - tid = gettid(); + tid = android::base::GetThreadId(); } } else if (tid == BACKTRACE_CURRENT_THREAD) { tid = pid; diff --git a/libbacktrace/BacktraceCurrent.cpp b/libbacktrace/BacktraceCurrent.cpp index f6f4423..39cb995 100644 --- a/libbacktrace/BacktraceCurrent.cpp +++ b/libbacktrace/BacktraceCurrent.cpp @@ -28,13 +28,13 @@ #include +#include #include #include #include "BacktraceAsyncSafeLog.h" #include "BacktraceCurrent.h" #include "ThreadEntry.h" -#include "thread_utils.h" bool BacktraceCurrent::ReadWord(uint64_t ptr, word_t* out_value) { if (!VerifyReadWordArgs(ptr, out_value)) { @@ -76,7 +76,7 @@ bool BacktraceCurrent::Unwind(size_t num_ignore_frames, void* ucontext) { return UnwindFromContext(num_ignore_frames, ucontext); } - if (Tid() != gettid()) { + if (Tid() != android::base::GetThreadId()) { return UnwindThread(num_ignore_frames); } @@ -114,16 +114,17 @@ class ErrnoRestorer { static void SignalLogOnly(int, siginfo_t*, void*) { ErrnoRestorer restore; - BACK_ASYNC_SAFE_LOGE("pid %d, tid %d: Received a spurious signal %d\n", getpid(), gettid(), - THREAD_SIGNAL); + BACK_ASYNC_SAFE_LOGE("pid %d, tid %d: Received a spurious signal %d\n", getpid(), + static_cast(android::base::GetThreadId()), THREAD_SIGNAL); } static void SignalHandler(int, siginfo_t*, void* sigcontext) { ErrnoRestorer restore; - ThreadEntry* entry = ThreadEntry::Get(getpid(), gettid(), false); + ThreadEntry* entry = ThreadEntry::Get(getpid(), android::base::GetThreadId(), false); if (!entry) { - BACK_ASYNC_SAFE_LOGE("pid %d, tid %d entry not found", getpid(), gettid()); + BACK_ASYNC_SAFE_LOGE("pid %d, tid %d entry not found", getpid(), + static_cast(android::base::GetThreadId())); return; } diff --git a/libbacktrace/BacktraceMap.cpp b/libbacktrace/BacktraceMap.cpp index 399721d..6a967f7 100644 --- a/libbacktrace/BacktraceMap.cpp +++ b/libbacktrace/BacktraceMap.cpp @@ -32,8 +32,6 @@ #include #endif -#include "thread_utils.h" - using android::base::StringPrintf; std::string backtrace_map_t::Name() const { diff --git a/libbacktrace/BacktracePtrace.cpp b/libbacktrace/BacktracePtrace.cpp index bf6b16f..9da457d 100644 --- a/libbacktrace/BacktracePtrace.cpp +++ b/libbacktrace/BacktracePtrace.cpp @@ -28,7 +28,6 @@ #include "BacktraceLog.h" #include "BacktracePtrace.h" -#include "thread_utils.h" #if !defined(__APPLE__) static bool PtraceRead(pid_t tid, uint64_t addr, word_t* out_value) { diff --git a/libbacktrace/UnwindStack.cpp b/libbacktrace/UnwindStack.cpp index e087b2e..4e7f761 100644 --- a/libbacktrace/UnwindStack.cpp +++ b/libbacktrace/UnwindStack.cpp @@ -23,10 +23,6 @@ #include #include -#if !defined(__ANDROID__) -#include -#endif - #include #include #include diff --git a/libbacktrace/backtrace_benchmarks.cpp b/libbacktrace/backtrace_benchmarks.cpp index a23e3b4..099ac60 100644 --- a/libbacktrace/backtrace_benchmarks.cpp +++ b/libbacktrace/backtrace_benchmarks.cpp @@ -27,6 +27,7 @@ #include #include +#include #include @@ -154,7 +155,7 @@ using BacktraceCreateFn = decltype(Backtrace::Create); static void CreateBacktrace(benchmark::State& state, BacktraceMap* map, BacktraceCreateFn fn) { while (state.KeepRunning()) { - std::unique_ptr backtrace(fn(getpid(), gettid(), map)); + std::unique_ptr backtrace(fn(getpid(), android::base::GetThreadId(), map)); backtrace->Unwind(0); } } diff --git a/libbacktrace/backtrace_offline_test.cpp b/libbacktrace/backtrace_offline_test.cpp index 9877f29..7d1027e 100644 --- a/libbacktrace/backtrace_offline_test.cpp +++ b/libbacktrace/backtrace_offline_test.cpp @@ -31,9 +31,9 @@ #include #include #include +#include #include #include -#include #include @@ -99,7 +99,7 @@ struct OfflineThreadArg { static void* OfflineThreadFunc(void* arg) { OfflineThreadArg* fn_arg = reinterpret_cast(arg); - fn_arg->tid = gettid(); + fn_arg->tid = android::base::GetThreadId(); test_get_context_and_wait(&fn_arg->ucontext, &fn_arg->exit_flag); return nullptr; } diff --git a/libbacktrace/backtrace_test.cpp b/libbacktrace/backtrace_test.cpp index f78a31f..06a32c7 100644 --- a/libbacktrace/backtrace_test.cpp +++ b/libbacktrace/backtrace_test.cpp @@ -47,16 +47,15 @@ #include #include #include +#include #include #include -#include #include // For the THREAD_SIGNAL definition. #include "BacktraceCurrent.h" #include "backtrace_testlib.h" -#include "thread_utils.h" // Number of microseconds per milliseconds. #define US_PER_MSEC 1000 @@ -525,7 +524,7 @@ TEST(libbacktrace, ptrace_threads) { } void VerifyLevelThread(void*) { - std::unique_ptr backtrace(Backtrace::Create(getpid(), gettid())); + std::unique_ptr backtrace(Backtrace::Create(getpid(), android::base::GetThreadId())); ASSERT_TRUE(backtrace.get() != nullptr); ASSERT_TRUE(backtrace->Unwind(0)); VERIFY_NO_ERROR(backtrace->GetError().error_code); @@ -538,7 +537,7 @@ TEST(libbacktrace, thread_current_level) { } static void VerifyMaxThread(void*) { - std::unique_ptr backtrace(Backtrace::Create(getpid(), gettid())); + std::unique_ptr backtrace(Backtrace::Create(getpid(), android::base::GetThreadId())); ASSERT_TRUE(backtrace.get() != nullptr); ASSERT_TRUE(backtrace->Unwind(0)); ASSERT_EQ(BACKTRACE_UNWIND_ERROR_EXCEED_MAX_FRAMES_LIMIT, backtrace->GetError().error_code); @@ -553,7 +552,7 @@ TEST(libbacktrace, thread_current_max) { static void* ThreadLevelRun(void* data) { thread_t* thread = reinterpret_cast(data); - thread->tid = gettid(); + thread->tid = android::base::GetThreadId(); EXPECT_NE(test_level_one(1, 2, 3, 4, ThreadSetState, data), 0); return nullptr; } @@ -644,7 +643,7 @@ TEST(libbacktrace, thread_ignore_frames) { static void* ThreadMaxRun(void* data) { thread_t* thread = reinterpret_cast(data); - thread->tid = gettid(); + thread->tid = android::base::GetThreadId(); EXPECT_NE(test_recursive_call(MAX_BACKTRACE_FRAMES+10, ThreadSetState, data), 0); return nullptr; } @@ -994,7 +993,7 @@ static void InitMemory(uint8_t* memory, size_t bytes) { static void* ThreadReadTest(void* data) { thread_t* thread_data = reinterpret_cast(data); - thread_data->tid = gettid(); + thread_data->tid = android::base::GetThreadId(); // Create two map pages. // Mark the second page as not-readable. @@ -1816,7 +1815,8 @@ TEST(libbacktrace, unwind_remote_through_signal_using_action) { static void TestFrameSkipNumbering(create_func_t create_func, map_create_func_t map_create_func) { std::unique_ptr map(map_create_func(getpid(), false)); - std::unique_ptr backtrace(create_func(getpid(), gettid(), map.get())); + std::unique_ptr backtrace( + create_func(getpid(), android::base::GetThreadId(), map.get())); backtrace->Unwind(1); ASSERT_NE(0U, backtrace->NumFrames()); ASSERT_EQ(0U, backtrace->GetFrame(0)->num); diff --git a/libbacktrace/thread_utils.c b/libbacktrace/thread_utils.c deleted file mode 100644 index e75f56e..0000000 --- a/libbacktrace/thread_utils.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "thread_utils.h" - -#if !defined(__BIONIC__) - -// glibc doesn't implement or export tgkill. -#include -#include - -int tgkill(int tgid, int tid, int sig) { - return syscall(__NR_tgkill, tgid, tid, sig); -} - -#endif diff --git a/libbacktrace/thread_utils.h b/libbacktrace/thread_utils.h deleted file mode 100644 index 9590657..0000000 --- a/libbacktrace/thread_utils.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2013 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _LIBBACKTRACE_THREAD_UTILS_H -#define _LIBBACKTRACE_THREAD_UTILS_H - -#include - -#if !defined(__ANDROID__) -#include -#endif - -__BEGIN_DECLS - -int tgkill(int tgid, int tid, int sig); - -__END_DECLS - -#endif /* _LIBBACKTRACE_THREAD_UTILS_H */ diff --git a/libunwindstack/tests/UnwindTest.cpp b/libunwindstack/tests/UnwindTest.cpp index 83695bb..ea992c7 100644 --- a/libunwindstack/tests/UnwindTest.cpp +++ b/libunwindstack/tests/UnwindTest.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -231,8 +232,7 @@ TEST_F(UnwindTest, from_context) { usleep(1000); } ASSERT_NE(0, tid.load()); - // Portable tgkill method. - ASSERT_EQ(0, syscall(__NR_tgkill, getpid(), tid.load(), SIGUSR1)) << "Error: " << strerror(errno); + ASSERT_EQ(0, tgkill(getpid(), tid.load(), SIGUSR1)) << "Error: " << strerror(errno); // Wait for context data. void* ucontext; -- cgit v1.2.3