diff options
Diffstat (limited to 'debuggerd/handler/debuggerd_handler.cpp')
-rw-r--r-- | debuggerd/handler/debuggerd_handler.cpp | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/debuggerd/handler/debuggerd_handler.cpp b/debuggerd/handler/debuggerd_handler.cpp index 35be2bf31..b60739794 100644 --- a/debuggerd/handler/debuggerd_handler.cpp +++ b/debuggerd/handler/debuggerd_handler.cpp @@ -1,17 +1,29 @@ /* - * Copyright 2008 The Android Open Source Project + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. * - * 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 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. * - * 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. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ #include "debuggerd/handler.h" @@ -155,14 +167,18 @@ static bool get_main_thread_name(char* buf, size_t len) { * could allocate memory or hold a lock. */ static void log_signal_summary(const siginfo_t* info) { - char main_thread_name[MAX_TASK_NAME_LEN + 1]; - if (!get_main_thread_name(main_thread_name, sizeof(main_thread_name))) { - strncpy(main_thread_name, "<unknown>", sizeof(main_thread_name)); + char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination + if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(thread_name), 0, 0, 0) != 0) { + strcpy(thread_name, "<name unknown>"); + } else { + // short names are null terminated by prctl, but the man page + // implies that 16 byte names are not. + thread_name[MAX_TASK_NAME_LEN] = 0; } if (info->si_signo == BIONIC_SIGNAL_DEBUGGER) { - async_safe_format_log(ANDROID_LOG_INFO, "libc", "Requested dump for pid %d (%s)", __getpid(), - main_thread_name); + async_safe_format_log(ANDROID_LOG_INFO, "libc", "Requested dump for tid %d (%s)", __gettid(), + thread_name); return; } @@ -177,13 +193,9 @@ static void log_signal_summary(const siginfo_t* info) { get_signal_sender(sender_desc, sizeof(sender_desc), info); } - char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination - if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(thread_name), 0, 0, 0) != 0) { - strcpy(thread_name, "<name unknown>"); - } else { - // short names are null terminated by prctl, but the man page - // implies that 16 byte names are not. - thread_name[MAX_TASK_NAME_LEN] = 0; + char main_thread_name[MAX_TASK_NAME_LEN + 1]; + if (!get_main_thread_name(main_thread_name, sizeof(main_thread_name))) { + strncpy(main_thread_name, "<unknown>", sizeof(main_thread_name)); } async_safe_format_log(ANDROID_LOG_FATAL, "libc", @@ -532,13 +544,8 @@ static void debuggerd_signal_handler(int signal_number, siginfo_t* info, void* c log_signal_summary(info); - // If we got here due to the signal BIONIC_SIGNAL_DEBUGGER, it's possible - // this is not the main thread, which can cause the intercept logic to fail - // since the intercept is only looking for the main thread. In this case, - // setting crashing_tid to pid instead of the current thread's tid avoids - // the problem. debugger_thread_info thread_info = { - .crashing_tid = (signal_number == BIONIC_SIGNAL_DEBUGGER) ? __getpid() : __gettid(), + .crashing_tid = __gettid(), .pseudothread_tid = -1, .siginfo = info, .ucontext = context, |