From patchwork Fri Oct 16 20:47:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 9198 Received: (qmail 85947 invoked by alias); 16 Oct 2015 20:47:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 85936 invoked by uid 89); 16 Oct 2015 20:47:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 16 Oct 2015 20:47:52 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 2BDFB4C0B3 for ; Fri, 16 Oct 2015 20:47:51 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-96.ams2.redhat.com [10.36.116.96]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9GKlng0023595 for ; Fri, 16 Oct 2015 16:47:50 -0400 Subject: [PATCH 3/3] Find symbols even for deleted executables From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Fri, 16 Oct 2015 22:47:49 +0200 Message-ID: <20151016204749.27288.28498.stgit@host1.jankratochvil.net> In-Reply-To: <20151016204733.27288.56498.stgit@host1.jankratochvil.net> References: <20151016204733.27288.56498.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes Hi, I have found I already posted a mostly the same patch before: [patch] Attach to running but deleted executable https://sourceware.org/ml/gdb-patches/2010-03/msg00950.html Message-ID: <20100328183529.GA4691@host0.dyn.jankratochvil.net> I can refer to the discussion therein. I had to disable (->untested) the attach-pie-noexec.exp testfile as I do not know how to "hide" the main executable from GDB after this fix. I wrote that testfile myself before so I do not feel guilty to disable it. This fix works even for gdbserver in extended mode as gdbserver also calls linux_proc_pid_to_exec_file(). No regressions on {x86_64,x86_64-m32,i686}-fedora24pre-linux-gnu. Thanks, Jan gdb/ChangeLog 2015-10-16 Jan Kratochvil * nat/linux-procfs.c (linux_proc_pid_to_exec_file): Do not resolve the link for deleted targets. gdb/testsuite/ChangeLog 2015-10-16 Jan Kratochvil * gdb.base/attach-kills.exp (bt from commandline, attach for deleted) (bt from attach): New tests. * gdb.base/attach-pie-noexec.exp (attach): Add untested. --- gdb/testsuite/gdb.base/attach-kills.exp | 15 +++++++++++++++ gdb/testsuite/gdb.base/attach-pie-noexec.exp | 13 ++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c index 24bcb01..ad3c24d 100644 --- a/gdb/nat/linux-procfs.c +++ b/gdb/nat/linux-procfs.c @@ -263,10 +263,14 @@ linux_proc_pid_to_exec_file (int pid) static char buf[PATH_MAX]; char name[PATH_MAX]; ssize_t len; + const char deleted[]=" (deleted)"; + const size_t deleted_len = strlen (deleted); xsnprintf (name, PATH_MAX, "/proc/%d/exe", pid); len = readlink (name, buf, PATH_MAX - 1); - if (len <= 0) + if (len <= 0 + || (len > deleted_len + && memcmp (deleted, &buf[len - deleted_len], deleted_len) == 0)) strcpy (buf, name); else buf[len] = '\0'; diff --git a/gdb/testsuite/gdb.base/attach-kills.exp b/gdb/testsuite/gdb.base/attach-kills.exp index d77524d..21703fd 100644 --- a/gdb/testsuite/gdb.base/attach-kills.exp +++ b/gdb/testsuite/gdb.base/attach-kills.exp @@ -60,4 +60,19 @@ gdb_test_multiple "" $test { } } +gdb_test "bt" " in main \[^\r\n\]*[string_to_regexp $srcfile]:\[0-9\]+" \ + "bt from commandline" + +clean_restart + +set test "attach for deleted" +gdb_test_multiple "attach $testpid" $test { + -re "Attaching to process $testpid\r\n.*\r\n$gdb_prompt $" { + pass $test + } +} + +gdb_test "bt" " in main \[^\r\n\]*[string_to_regexp $srcfile]:\[0-9\]+" \ + "bt from attach" + kill_wait_spawned_process $test_spawn_id diff --git a/gdb/testsuite/gdb.base/attach-pie-noexec.exp b/gdb/testsuite/gdb.base/attach-pie-noexec.exp index fc53b2d..216adfb 100644 --- a/gdb/testsuite/gdb.base/attach-pie-noexec.exp +++ b/gdb/testsuite/gdb.base/attach-pie-noexec.exp @@ -60,7 +60,18 @@ set testpid [spawn_id_get_pid $test_spawn_id] gdb_start file delete -- $binfile -gdb_test "attach $testpid" "Attaching to process $testpid\r\n.*: No such file or directory\\." "attach" + +set test "attach" +gdb_test_multiple "attach $testpid" $test { + -re "Attaching to process $testpid\r\n.*: No such file or directory\\.\r\n$gdb_prompt $" { + pass $test + } + -re "Attaching to process $testpid\r\nReading symbols from /proc/$testpid/exe\\.\\.\\.done\\.\r\n.*\r\n$gdb_prompt $" { + # Nothing gets really tested despite it PASSes below. + untested "$test" + } +} + gdb_test "set architecture $arch" "The target architecture is assumed to be $arch" gdb_test "info shared" "From\[ \t\]+To\[ \t\]+Syms Read\[ \t\]+Shared Object Library\r\n0x.*"