From patchwork Fri Nov 4 18:26:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lancelot SIX X-Patchwork-Id: 59954 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B0033858287 for ; Fri, 4 Nov 2022 18:28:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B0033858287 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667586520; bh=7CLTcKQg+kRW2vPu3jd/lkhFtlpI1fFjEuRje1K2jCQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=u1YpPt9yJvQNHRdGUCZwGiQWhID3lzcJGlI1Iq4lNWm0e4N/MGgQUbzSREUQDAnpX ksJq4XfDFqk61XQrcXTAezDv+adtL4FIjB3QlMa8vW9SLgkmPrxDUuazz2XqPKZGMW fZ0TjQgXNdnuysPSBmAYPQoCT0yHzPmvHu2po7P8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2047.outbound.protection.outlook.com [40.107.94.47]) by sourceware.org (Postfix) with ESMTPS id E4CA2385842F for ; Fri, 4 Nov 2022 18:27:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4CA2385842F ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZW0tXTU1M9y1BY+0QtXD5YTlNMBqzyTmtFCDivgkOuuxqyKi9LRL143Aj01vOgRRdhxQRUrO4wuiWgnftqOaBc5Smc3QinIO4VrWiHFzSth4mlhgO71qKqMAYG5h/DUNVsdjyhQnE7aezmBnp6svZYY2lIZuSL07lzR4ZZkpcVvRC6yPSX4FHtnC5i3Nmfl/hjiBd04l5/ULoq+m0qJ9b4sOOKR5AjfNeiX2TItkcTO65B0+7p4OebHEx1qcvRHmJR+Rpw2RU0Z8o9cnTritzZrNvYvm/JSoKocBtUPMp4iv1FcEWVqG3IzXVJtpO5/nXyeUKhBlBuRJxuDHU0zDGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=7CLTcKQg+kRW2vPu3jd/lkhFtlpI1fFjEuRje1K2jCQ=; b=P9XkKcLMtMjx9LPEtGSwUGAii0s2J05WyrKGdcL2CNuu6o0SNvUxe3y2vcyC5iL8YdI5chJ6ANUUZghvf21tMQFEf2+3ZZnufnhlPABnNLrYNF5CtpGX8o4Bo0l6Ln2STMNnOMx74xI0CWxkkJLO4A8zPQ58DOvvPdxp4H6agxXWZUGxKcITr9iTOZ3lFZV0yVPNa1rBQdV8TS/El5wa8cPkzoJwoMg1wcXafiUe6fdvTFk4QW1an5jipFnpujh36svqU0k5BOmgp9ZOoy1EB0fn757DuILtHefjukkoXFKKUe9qDhEn2TVUh1Ldgc/4nfzXAMN7PLfGZyy8AXc4Jw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=sourceware.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from BN9PR03CA0278.namprd03.prod.outlook.com (2603:10b6:408:f5::13) by BL0PR12MB5506.namprd12.prod.outlook.com (2603:10b6:208:1cb::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22; Fri, 4 Nov 2022 18:27:11 +0000 Received: from BN8NAM11FT108.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f5:cafe::33) by BN9PR03CA0278.outlook.office365.com (2603:10b6:408:f5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.23 via Frontend Transport; Fri, 4 Nov 2022 18:27:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT108.mail.protection.outlook.com (10.13.176.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5791.20 via Frontend Transport; Fri, 4 Nov 2022 18:27:11 +0000 Received: from khazad-dum.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 4 Nov 2022 13:27:07 -0500 To: Subject: [PATCH] Fix stepping in rtld without debug symbol Date: Fri, 4 Nov 2022 18:26:34 +0000 Message-ID: <20221104182634.3726422-1-lancelot.six@amd.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT108:EE_|BL0PR12MB5506:EE_ X-MS-Office365-Filtering-Correlation-Id: 2872efda-c573-4af5-2a4c-08dabe9230a3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rBFRGpI+raDDOVhdB1rDQSF7jk9t2AmxBTI/jfgIt+rbwTjfkklI3OQIBd6KAxzSkjRFAe0KoJFsrLf5G1IBOdiojDWTZE4eksvkU78Q80mllmoM/xJL7CJNUg6Y7myBY45hEXy+NjhEuZRprrCpRovFMA0LoR2TCes11Z5JtvnKwKZoXotikX9K03TPoG7fL8hgvjwPyQa11KJR0e35jq07OtfwsWLTkodW72KdlaE/5UUxQzdHekjH00zjjV1wE+w8A/IIg5KaWDMrbgVhDKIkqSlaf3o9L3SY0ZD5C1JA9uibTNPYRH3PRnZhiT5QqR7nHpwEWKWOddTV55KLdOEaxUe0Jlm8q4TtFnnuWVRvb/qkq/efbAhXUhNnGl41oT8ENainQjfxEUphY/qrRorO/kAL5wWzWt731KzFLc6kc+sXaerAQrWAPWJwwhPpF0ADXM0SfhWHi1DNJZySOXdThx073pqrOLbcWLQS+VDWIwPfz12kjpFDaDnk71fRkL4876cHlKBrKPW8Sti9zbLFs6VCv/6q2uII9Bb3TBnTp9J+0rEri7PS7NC1lI+SlwvUhjKDHYyT/1C+D3NTcD3iJ8NrxHGxM6r2knNZBCuTVQbURUJ7aOfqETDkH3YwfxVRj6NJay66Ikmro1YrOr07Wy9z229dDOvBkzQbGB16/58UaM8ciakpFt27J3vAqpU3rK4rmg1zZCpsqOCKyFXenkKMQMVMkbPS8aXcJfir6hR7r6L1/9D9Z6wARynqV9RP18NfJyMQk/YrNqvHWpkPzy0ug9Tf3sRXpT8X2ZlB/9j8kGz3Hg+TK7vitAYafTnOl9Cc7eoWc8kX2BVwCS3bIK5s4vIcLN+4vOIJYSg= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230022)(4636009)(136003)(39860400002)(376002)(396003)(346002)(451199015)(46966006)(40470700004)(36840700001)(83380400001)(2616005)(186003)(478600001)(1076003)(26005)(5660300002)(336012)(966005)(8936002)(41300700001)(16526019)(6916009)(47076005)(6666004)(40480700001)(426003)(8676002)(2906002)(4326008)(70586007)(36756003)(70206006)(40460700003)(81166007)(36860700001)(356005)(7696005)(82740400003)(82310400005)(316002)(86362001)(54906003)(2004002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Nov 2022 18:27:11.6379 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2872efda-c573-4af5-2a4c-08dabe9230a3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT108.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB5506 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Lancelot SIX via Gdb-patches From: Lancelot SIX Reply-To: Lancelot SIX Cc: lsix@lancelotsix.com, Lancelot SIX Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Commit be6276e0aed "Allow debugging of runtime loader / dynamic linker" introduced a small regression when stepping into the runtime loader / dynamic linker from function we do not have debug information for. This is reported in PR/29747. This can be shown by the following example (given by Simon Marchi in buzilla bug report): $ cat test.c #include int main() { printf("Hi\n"); return 0; } $ gcc test.c -O0 -o test $ ./gdb -q -nx --data-directory=data-directory test -ex start -ex s Reading symbols from test... (No debugging symbols found in test) Temporary breakpoint 1 at 0x1151 Starting program: .../binutils-gdb/gdb/test [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Temporary breakpoint 1, 0x0000555555555151 in main () Single stepping until exit from function main, which has no line number information. /home/smarchi/src/binutils-gdb/gdb/infrun.c:6960:64: runtime error: member call on null pointer of type 'struct symbol' The crash happens here: #0 __sanitizer::Die () at ../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cpp:50 #1 0x00007ffff5dd7128 in __ubsan::__ubsan_handle_type_mismatch_v1_abort (Data=, Pointer=) at ../../../../src/libsanitizer/ubsan/ubsan_handlers.cpp:148 #2 0x000055556183e1a7 in process_event_stop_test (ecs=0x7fffffffccd0) at .../binutils-gdb/gdb/infrun.c:6960 #3 0x0000555561838ea4 in handle_signal_stop (ecs=0x7fffffffccd0) at .../binutils-gdb/gdb/infrun.c:6615 #4 0x000055556182f77b in handle_inferior_event (ecs=0x7fffffffccd0) at .../binutils-gdb/gdb/infrun.c:5866 When evaluating: 6956 if (execution_direction != EXEC_REVERSE 6957 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE 6958 && in_solib_dynsym_resolve_code (ecs->event_thread->stop_pc ()) 6959 && !in_solib_dynsym_resolve_code ( 6961 ecs->event_thread->control.step_start_function->value_block () 6962 ->entry_pc ())) we dereference, ecs->event_thread->control.step_start_function which is nullptr. This patch changes this condition so it evaluates to true if ecs->event_thread->control.step_start_function is nullptr since this matches the behaviour before be6276e0aed. Tested on ubuntu-22.04 x86_64. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29747 Reviewed-By: Bruno Larsen --- gdb/infrun.c | 7 +++-- gdb/testsuite/gdb.base/rtld-step-nodebugsym.c | 25 +++++++++++++++ .../gdb.base/rtld-step-nodebugsym.exp | 31 +++++++++++++++++++ 3 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.base/rtld-step-nodebugsym.c create mode 100644 gdb/testsuite/gdb.base/rtld-step-nodebugsym.exp base-commit: b0119424d19afcf80997ad5f3128d7ec68e1fafa diff --git a/gdb/infrun.c b/gdb/infrun.c index 5ff0dc44d03..6da46b75ac7 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -6956,9 +6956,10 @@ process_event_stop_test (struct execution_control_state *ecs) if (execution_direction != EXEC_REVERSE && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE && in_solib_dynsym_resolve_code (ecs->event_thread->stop_pc ()) - && !in_solib_dynsym_resolve_code ( - ecs->event_thread->control.step_start_function->value_block () - ->entry_pc ())) + && (ecs->event_thread->control.step_start_function == nullptr + || !in_solib_dynsym_resolve_code ( + ecs->event_thread->control.step_start_function->value_block () + ->entry_pc ()))) { CORE_ADDR pc_after_resolver = gdbarch_skip_solib_resolver (gdbarch, ecs->event_thread->stop_pc ()); diff --git a/gdb/testsuite/gdb.base/rtld-step-nodebugsym.c b/gdb/testsuite/gdb.base/rtld-step-nodebugsym.c new file mode 100644 index 00000000000..4ad96db1445 --- /dev/null +++ b/gdb/testsuite/gdb.base/rtld-step-nodebugsym.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +int +main (void) +{ + printf ("hello wolrd"); + return 0; +} diff --git a/gdb/testsuite/gdb.base/rtld-step-nodebugsym.exp b/gdb/testsuite/gdb.base/rtld-step-nodebugsym.exp new file mode 100644 index 00000000000..3bc6929102c --- /dev/null +++ b/gdb/testsuite/gdb.base/rtld-step-nodebugsym.exp @@ -0,0 +1,31 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test stepping through a runtime loader / dynamic linker (RTLD) without +# debug info. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} [list]] } { + return +} + +if { ![runto_main] } { + return +} + +gdb_test "step" "Single stepping until exit from function.*" + +gdb_continue_to_end "" continue 1