From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03olkn2041.outbound.protection.outlook.com [40.92.57.41]) by sourceware.org (Postfix) with ESMTPS id 747663858D20 for ; Mon, 28 Oct 2024 04:46:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 747663858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hotmail.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 747663858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.92.57.41 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730090784; cv=pass; b=kXqmMKgULxYvh1SUZqgcz9bMPD+GZqRXvWe6yYjQdhKeOv/NSl4vmUB417SkPRQeXg9auuNxlTowJ8fYpFs2FarkWWYxRK32lGtzcSuDrf1cqW5JKooCGnQLZ1ExPiiVqbB34zICTwlIhHd0yfmPWgB68Ap6vcZ50xVxC+ZNKKo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1730090784; c=relaxed/simple; bh=qyLXPFUg8ndE0nVMLV9EYkK8blTWvS/fiiw7Hoje4H8=; h=DKIM-Signature:Message-ID:Date:To:From:Subject:MIME-Version; b=ZhcZMU2K4uGOdlalV1/6wv70HCXJW8q9DTtmPpQ7t99BMNr4bBw2E+iowTICvkAQQIfCLJQesbupurmbM+IrW7cVppDC1BKSMAIvtup21DkCkmFl9Utkpw9+7g1ggltQ/0c5YiD4S/wMOrVIswf+e3sNUlnIIbR+3nkEIYMmB2Y= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=n2KsxQdHuHS1eNuQhxCfcZoJZCVh/0Yyl8sIBSFB5MTcmzgaH9FK/dPwr592kGYr9rocC2HWdaGRwMXif8+tOfYaJ58ZWKC8RnfUcGkWKoiTTR8dAzk3Gb/57gTLPGxObuIKq6vQ9ApIExoateFhIW7evwqOPZNICsBztnfzrO7en2sQ+1AfeEZAaN2yqgEVQCa8MI9ZqHhh4H4jYDe4IrkBDC4WzaKpb1Cmd1p2o3vJz2rLR8YWmJ4rBFWvRtvGbbS3rhW+itH545vspe5G7iH3v06+jkYfuMVd+CKcxfs9l3rpkvFARLLlHN5a0pnX7d3WnzxecgFQSF0RZ51V+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GxkTz4SNIUKWzaq5MnlS7JvahZH/c6aYPOFKgWb3t88=; b=w7rG3Hvw7U/U9wc50LVtv8D3ESYZQ/bE/hHq3aKlYo6CobzlKEdEkke/JwUXvENuYDwcfUsTDQ/0Jk0uHUjrIvd7FkDztbPH6sNG6C5pqaBGGPoxI34S9DAS/HadavSyJ7Bp7naxT91rWSJOtCTgqJM7TrFU1FWW+ykdtf+wiZFy0U5sPepRcjqv5cbfJX17qnu8HTM/NnWgtWpZPch8LYLJxXtMr7wTjApj0Btqpwzw62hNkLcI8yWpjsIA7t90LTp6l13Sd1cQZqbT3apNV8y64LbVhBGax44VfBs6kHVd6Tl/r8jQb1jJeNglFwVDdSeJ5LK6CgDuhJhivgB9NQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=HOTMAIL.DE; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GxkTz4SNIUKWzaq5MnlS7JvahZH/c6aYPOFKgWb3t88=; b=lGoJXdZ7hXokKLiMp4shp1vUBU3SLV+7rF9M0/jEyix24TpTYneMlLjOzTicK20wL7MUGmMN+eHiu7GRfcdiyDFzkQHaRY63dGLmP/Se7djaayhH3zuZ1+kdvBR4PvCccxqb9wfJpLfkBYIFusofj8EJYzcZvs+nN7nZiyM4YRpeg7gzpma5MUDFLqz1OUknw4a024S0KZwe2iwF2TNtEVDQszAthNNwmXK/5eMgJ2IXGOryuOJcA4vvUcVabeWyQZj/ZTOaIk0S6gCdAKN1+d7O8VK2Q1eUMphVWd5v7eY8jrhY25clhShZECyynmh5Cx5TQm7FcvZrZ1KD/PpadQ== Received: from DU2PR08MB10263.eurprd08.prod.outlook.com (2603:10a6:10:491::6) by GV1PR08MB7379.eurprd08.prod.outlook.com (2603:10a6:150:23::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.24; Mon, 28 Oct 2024 04:46:18 +0000 Received: from DU2PR08MB10263.eurprd08.prod.outlook.com ([fe80::c2a3:fed5:607f:20c8]) by DU2PR08MB10263.eurprd08.prod.outlook.com ([fe80::c2a3:fed5:607f:20c8%5]) with mapi id 15.20.8093.014; Mon, 28 Oct 2024 04:46:18 +0000 Message-ID: Date: Mon, 28 Oct 2024 05:47:03 +0100 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "gdb-patches@sourceware.org" , Andrew Burgess From: Bernd Edlinger Subject: [PATCH v4] Fix signal unsafe call inside a signal Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: FR3P281CA0014.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::7) To DU2PR08MB10263.eurprd08.prod.outlook.com (2603:10a6:10:491::6) X-Microsoft-Original-Message-ID: <37f60e71-da68-4b69-b90d-1f1f054e54d5@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR08MB10263:EE_|GV1PR08MB7379:EE_ X-MS-Office365-Filtering-Correlation-Id: 68b648f7-edfa-4aec-7278-08dcf70b75bb X-Microsoft-Antispam: BCL:0;ARA:14566002|7092599003|461199028|15080799006|5072599009|19110799003|8060799006|6090799003|3412199025|4302099013|440099028|1602099012|10035399004; X-Microsoft-Antispam-Message-Info: =?utf-8?B?d2lBZzdOTXg2OHM2Y1BpT3RhbDM0Ynk4RGpOU2tYVCtlZlRMd29pWXZscEFI?= =?utf-8?B?RlRVQUV3bkgzVzg4T3dheWFMRXNCSjlUNTMwWHVWRWZZTmRVUDhwVzNLRDU1?= =?utf-8?B?SG9MMXlGcks1eWJ6RW9RcnluZm95NDNYRmdyUzFrZC96VFFuSWRCSlZBMkFZ?= =?utf-8?B?RllvVTdINFVtQXhYZHpwQ2dhY3NRVUpBQUt1OER0NUtxM2pPMFQzRXJDcFpm?= =?utf-8?B?OTJzOEhWQThldG54ckFua0RwbzBhNlg1UExjMisraFRxWExkY2JFN2dWdTF0?= =?utf-8?B?eFhXWmIyYmgyWmNVdFBqbUdyazFsTnRCNXU2bkd1MTVnWEhkVjlMT1RjYU9M?= =?utf-8?B?aDFrSS9oVGxweHFhVGxYK1dCcVl4N2pOOHBSeDFHOG42WDhiRVR1RGJKbXI4?= =?utf-8?B?dzBYdTkrS1N2M3A5K01hUE5ZNlNrdE54RVFDanVxOStsTjlBWUZrNzR1ay9R?= =?utf-8?B?T05NN2ZkNGtSOHJHN0JBT3hMVmJuWnFZOHV3c3JQOGEyVFVDb2VFaHN0WHZU?= =?utf-8?B?eHJxVnFBL3pEZ3R4MG5ONjFTVDBNUkxPNWNoWXNWS1YrMm1YRU8zNWRMUU9a?= =?utf-8?B?eXBKcEUzeWVFQ2poUUgyZy85WmZCT09jd0p5b0RKdWVqOURjMFFuMVRqWjdD?= =?utf-8?B?b3dIMWl0VjlydEpvYW9WOFdHazVjZ3NTWkFjbFd5WlhUOWVGdGppUkdpaUVi?= =?utf-8?B?N2V0RVZhNSs2VC8wcW51MVlJdmlFWU5MeEl2NGgyeV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HpOUUpCTUUvTm80NHJ3V2NH?= =?utf-8?B?QzFtblNLRGlWVzRWSWdTdzVZdFJ0bnhoSTUvUGNpOTQ0NVZsbno3VnVzZEhN?= =?utf-8?B?M1dUZWFkV1l4b2JSQzBOaW5ZZTF3TTFkc1JsTHQvZHlacEtFeUpZYnpjRXhl?= =?utf-8?B?UjJFT2pMK1djUjBVY2MzVDZjT1VqelVZTXRQUkJIYWQ3OFBuU1Q5S2N1dHJX?= =?utf-8?B?bWw2Rit1NkJ3VUwreWY5MlJFTDVxQ0h2YjdraER1YzRhdnhNNXh3YlVzWlUw?= =?utf-8?B?b3dSVjZMQ2ROejBWRTZyQzZkelhwV05Eb3lqdE90VzFvOW85cmx6c2NWVm45?= =?utf-8?B?U2dadHl5dk9mTUFxb2hTRlRlL3N6dWp0VUNXcUFQVllnMlZMWjVKRzNRem9L?= =?utf-8?B?bUpja0EzZjFDN3o0ZXhOYUJZeE9SZ2FVV3VuV09uUTI0VDFITHd2ZXp0WTlJ?= =?utf-8?B?T1N4dGxoMUNIQ1FsTUFKdXp1aHlhZ3QrUFpZYmoxSTl3NFdvNUd5Ung2M0h4?= =?utf-8?Q?G9SFGu4Xpsvbi4/YNA2I?= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-37dd7.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 68b648f7-edfa-4aec-7278-08dcf70b75bb X-MS-Exchange-CrossTenant-AuthSource: DU2PR08MB10263.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2024 04:46:17.4388 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR08MB7379 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: It can easily happen that the signal handler function `handle_fatal_signal` uses various signal unsafe functions. The problematic functions are `_` and `strsignal` which can be pre-computed after the `setlocale` call is done. Unfortunately when compiled with --disable-libbacktrace a different code path is used, that calls the glibc function `backtrace` which calls `malloc` and `free` and is therefore also signal unsafe, that is probably unfixable, so there is no attempt to fix anything in this code path. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31713#c9 --- gdb/bt-utils.c | 19 +++++++++-- gdb/bt-utils.h | 2 ++ gdb/event-top.c | 84 ++++++++++++++++++++++++++++++++++++++++++++----- gdb/main.c | 2 ++ 4 files changed, 98 insertions(+), 9 deletions(-) v2: moved initalization of language specific string to an init function v3: addressed review comments v4: improved commit message, addressed review commments diff --git a/gdb/bt-utils.c b/gdb/bt-utils.c index f658ce0d4bc..fb006c29178 100644 --- a/gdb/bt-utils.c +++ b/gdb/bt-utils.c @@ -145,8 +145,23 @@ gdb_internal_backtrace_1 () #else #error "unexpected internal backtrace policy" #endif + +static const char *str_backtrace = "----- Backtrace -----\n"; +static const char *str_backtrace_unavailable = "Backtrace unavailable\n"; + #endif /* GDB_PRINT_INTERNAL_BACKTRACE */ +/* Initialize language specific strings. */ + +void +gdb_internal_backtrace_init_str () +{ +#ifdef GDB_PRINT_INTERNAL_BACKTRACE + str_backtrace = _("----- Backtrace -----\n"); + str_backtrace_unavailable = _("Backtrace unavailable\n"); +#endif +} + /* See bt-utils.h. */ void @@ -161,12 +176,12 @@ gdb_internal_backtrace () gdb_stderr->write_async_safe (msg, strlen (msg)); }; - sig_write (_("----- Backtrace -----\n")); + sig_write (str_backtrace); if (gdb_stderr->fd () > -1) gdb_internal_backtrace_1 (); else - sig_write (_("Backtrace unavailable\n")); + sig_write (str_backtrace_unavailable); sig_write ("---------------------\n"); #endif diff --git a/gdb/bt-utils.h b/gdb/bt-utils.h index ec2d14a5484..6fe7c8c4f3b 100644 --- a/gdb/bt-utils.h +++ b/gdb/bt-utils.h @@ -71,4 +71,6 @@ extern void gdb_internal_backtrace (); extern void gdb_internal_backtrace_set_cmd (const char *args, int from_tty, cmd_list_element *c); +extern void gdb_internal_backtrace_init_str (); + #endif /* BT_UTILS_H */ diff --git a/gdb/event-top.c b/gdb/event-top.c index d3cf144958a..e7556f71453 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -908,6 +908,51 @@ unblock_signal (int sig) return false; } +/* Signal safe language specific strings. */ + +#ifdef GDB_PRINT_INTERNAL_BACKTRACE +static const char *str_fatal_signal; +static const char *str_sigsegv; +#ifdef SIGFPE +static const char *str_sigfpe; +#endif +#ifdef SIGBUS +static const char *str_sigbus; +#endif +#ifdef SIGABRT +static const char *str_sigabrt; +#endif +static const char *str_unknown_signal; +static const char *str_fatal_error_detected_gdb_will_now_terminate; +static const char *str_this_is_a_bug; +static const char *str_for_instructions_see; + +/* Initialize language specific strings. */ + +static void +init_str_handle_fatal_signal () +{ + str_fatal_signal = _("Fatal signal: "); + str_sigsegv = strsignal (SIGSEGV); +#ifdef SIGFPE + str_sigfpe = strsignal (SIGFPE); +#endif +#ifdef SIGBUS + str_sigbus = strsignal (SIGBUS); +#endif +#ifdef SIGABRT + str_sigabrt = strsignal (SIGABRT); +#endif + str_unknown_signal = _("Unknown signal"); + str_fatal_error_detected_gdb_will_now_terminate = + _("A fatal error internal to GDB has been detected, " + "further\ndebugging is not possible. GDB will now " + "terminate.\n\n"); + str_this_is_a_bug = _("This is a bug, please report it."); + str_for_instructions_see = _(" For instructions, see:\n"); +} +#endif + /* Called to handle fatal signals. SIG is the signal number. */ [[noreturn]] static void @@ -926,19 +971,40 @@ handle_fatal_signal (int sig) if (bt_on_fatal_signal) { sig_write ("\n\n"); - sig_write (_("Fatal signal: ")); - sig_write (strsignal (sig)); + sig_write (str_fatal_signal); + switch (sig) + { + case SIGSEGV: + sig_write (str_sigsegv); + break; +#ifdef SIGFPE + case SIGFPE: + sig_write (str_sigfpe); + break; +#endif +#ifdef SIGBUS + case SIGBUS: + sig_write (str_sigbus); + break; +#endif +#ifdef SIGABRT + case SIGABRT: + sig_write (str_sigabrt); + break; +#endif + default: + sig_write (str_unknown_signal); + break; + } sig_write ("\n"); gdb_internal_backtrace (); - sig_write (_("A fatal error internal to GDB has been detected, " - "further\ndebugging is not possible. GDB will now " - "terminate.\n\n")); - sig_write (_("This is a bug, please report it.")); + sig_write (str_fatal_error_detected_gdb_will_now_terminate); + sig_write (str_this_is_a_bug); if (REPORT_BUGS_TO[0] != '\0') { - sig_write (_(" For instructions, see:\n")); + sig_write (str_for_instructions_see); sig_write (REPORT_BUGS_TO); sig_write ("."); } @@ -1066,6 +1132,10 @@ gdb_init_signals (void) create_async_signal_handler (async_sigtstp_handler, NULL, "sigtstp"); #endif +#ifdef GDB_PRINT_INTERNAL_BACKTRACE + init_str_handle_fatal_signal (); +#endif + #ifdef SIGFPE signal (SIGFPE, handle_fatal_signal); #endif diff --git a/gdb/main.c b/gdb/main.c index e4a40c51023..4370e95ada4 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -58,6 +58,7 @@ #include "observable.h" #include "serial.h" #include "cli-out.h" +#include "bt-utils.h" /* The selected interpreter. */ std::string interpreter_p; @@ -676,6 +677,7 @@ captured_main_1 (struct captured_main_args *context) /* Note: `error' cannot be called before this point, because the caller will crash when trying to print the exception. */ main_ui = new ui (stdin, stdout, stderr); + gdb_internal_backtrace_init_str (); current_ui = main_ui; gdb_stdtarg = gdb_stderr; -- 2.39.2