From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7DD623858C5E for ; Mon, 7 Nov 2022 09:43:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7DD623858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667814230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+olTNzyBcIStPs0Agpu36sti1v9z7D/iAJhjPNSNHKs=; b=PQv0WbXdXHxdR6zsIR3bNkfisxWaO5pkAMgLk1LEmRFXZM7CsMeXPqqpghzY13z8xw0XDF irCPyvMknUwPmpL6kZ2Ly8UzqiP25hMPrAZOdA1vMXchFJ+FqJ6eF2Nd4q8cFfO21uHD66 aAFpuBewl2Trsrp5o6bx3J079Q2B4R8= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-649-kN3JtXegM_eAMws8l-3CWQ-1; Mon, 07 Nov 2022 04:43:49 -0500 X-MC-Unique: kN3JtXegM_eAMws8l-3CWQ-1 Received: by mail-qt1-f198.google.com with SMTP id s14-20020a05622a1a8e00b00397eacd9c1aso7857974qtc.21 for ; Mon, 07 Nov 2022 01:43:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+olTNzyBcIStPs0Agpu36sti1v9z7D/iAJhjPNSNHKs=; b=o/b5Sot7LA7QNU4ZyQ1qqdpgYw9impV004bc/HB2LW45H31aFfMSUIXSQN1E/DKNjj CFq1gEw777VG7xLZcbALgxkqtSlAgKTC2hVarcjLgiYeAk3mOtwNbu1oXUmZU9jm8Jvu Rmt5iGuXDf4rFsQLkxN/LRVavyUMuVnzlxGvTEBAHdoqAyamOju0smarbKTdanz2BBV1 SoD6aRGr6uzXAUHYg3ULDFWzwU4sUjEGQJs/koSvTeIgzkT8fmzkG6VzJeMVzkWW68Kt IR3ZItPkz0Yqz0n4LLs/b/M7pZH9zUSkl9ZpKDkFlWYT4rvMMSH5XZtXJ+s7fLWAGlHP I2sQ== X-Gm-Message-State: ACrzQf2PHf1Ongb6YylH6/8zDPid2gzal+jxM+lMI4lTOMKBKn2fXrGy wc6ZOkyc6Z4aUSYM0/pJhPEIOwmLH8J8bQhIDPdpnLXInInZ22FWoU/wqzKI0PMThSEw1Mk9e1z aShDVBsBwm1HR/SxPBb/8gw== X-Received: by 2002:a05:622a:1316:b0:3a5:62e7:b843 with SMTP id v22-20020a05622a131600b003a562e7b843mr12877614qtk.443.1667814228464; Mon, 07 Nov 2022 01:43:48 -0800 (PST) X-Google-Smtp-Source: AMsMyM7H2/ve7cz/FWkDEnbIwchPqjuqy4oi6pCW7NbgfHnoWp28zkCkt83hbdYCPVdgO6YHDB2tNQ== X-Received: by 2002:a05:622a:1316:b0:3a5:62e7:b843 with SMTP id v22-20020a05622a131600b003a562e7b843mr12877599qtk.443.1667814228100; Mon, 07 Nov 2022 01:43:48 -0800 (PST) Received: from [192.168.0.45] (ip-62-245-66-121.bb.vodafone.cz. [62.245.66.121]) by smtp.gmail.com with ESMTPSA id v14-20020a05620a440e00b006fab416015csm5507533qkp.25.2022.11.07.01.43.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Nov 2022 01:43:47 -0800 (PST) Message-ID: <793ed066-39e5-5902-f9c5-054fa4c96b2f@redhat.com> Date: Mon, 7 Nov 2022 10:43:44 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH] Fix stepping in rtld without debug symbol To: Lancelot SIX , gdb-patches@sourceware.org Cc: lsix@lancelotsix.com References: <20221104182634.3726422-1-lancelot.six@amd.com> From: Bruno Larsen In-Reply-To: <20221104182634.3726422-1-lancelot.six@amd.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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: On 04/11/2022 19:26, Lancelot SIX via Gdb-patches wrote: > 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 Patch looks alright, I just have one nit inlined. > --- > 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 > > 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]] } { I think explicitly saying {nodebug} instead of [list] would make this test clearer. With this fixed, you get my Reviewed-By: Bruno Larsen Cheers, Bruno > + return > +} > + > +if { ![runto_main] } { > + return > +} > + > +gdb_test "step" "Single stepping until exit from function.*" > + > +gdb_continue_to_end "" continue 1 > > base-commit: b0119424d19afcf80997ad5f3128d7ec68e1fafa