From patchwork Mon Apr 25 03:47:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 11871 Received: (qmail 37333 invoked by alias); 25 Apr 2016 03:47:38 -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 37312 invoked by uid 89); 25 Apr 2016 03:47:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=wondering, jiang, H*M:sk:001a114, H*MI:sk:001a114 X-HELO: mail-pa0-f74.google.com Received: from mail-pa0-f74.google.com (HELO mail-pa0-f74.google.com) (209.85.220.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 25 Apr 2016 03:47:26 +0000 Received: by mail-pa0-f74.google.com with SMTP id vv3so6334166pab.1 for ; Sun, 24 Apr 2016 20:47:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to:cc; bh=RrRv91Gw7VpMqlMEqjZZumCmABYmAPQcsoa4G0QQnbc=; b=QHyrzonepBPjBRt/SfLpZXnA8yQ1jdE32tYjlhWmcRK1iePGWpWCFpukDwnCUgaz8S owwPsamq3oWRmyxyZPYgOf5Z6cLmCNoR5FmnkVYZSfJj+2oZX9A+hokoRx/xBS56m5E+ +q3Gk5p8fmoSN4gD676dby9xLC0e5ja5KUuW9/94O2KsERkFM6dGUJlbtz6fKAdKJL8G l67C8sMLxUn29IiQ3F8mSKgK74ENkMmwObXuJwYSV5xNjYTPllaQtmtfZtQqob8TviyT 5x2rG7D2EmYxs4Op0FDebnrUie6N/cZFB9iOfuOEKrxtjpdvNG4i3rmgwZtFCfFAJCUG yImQ== X-Gm-Message-State: AOPr4FXvTY17fPE004jZF9Ocr9Kdw9afaEjv4N4VsNoPBWPTYg/BXz/hS7U8aKbyx2jTcokbng== MIME-Version: 1.0 X-Received: by 10.98.0.69 with SMTP id 66mr23046656pfa.2.1461556044908; Sun, 24 Apr 2016 20:47:24 -0700 (PDT) Message-ID: <001a1143a21ce09d4c05314708a6@google.com> Date: Mon, 25 Apr 2016 03:47:24 +0000 Subject: Re: [PATCH] fix PR gdb/19914 From: Doug Evans To: Yunlian Jiang Cc: gdb-patches@sourceware.org X-IsSubscribed: yes Yunlian Jiang writes: > ping? > > On Wed, Apr 13, 2016 at 11:18 AM, Yunlian Jiang wrote: > > I have a updated one. It uses separate_debug_objfile_backlink to get > > the real dwp file name if it is a debug file. > > > > --- a/gdb/dwarf2read.c > > +++ b/gdb/dwarf2read.c > > @@ -10835,13 +10835,28 @@ open_and_init_dwp_file (void) > > { > > struct objfile *objfile = dwarf2_per_objfile->objfile; > > struct dwp_file *dwp_file; > > + char *dwp_base_name; > > char *dwp_name; > > bfd *dbfd; > > struct cleanup *cleanups; > > > > /* Try to find first .dwp for the binary file before any symbolic links > > resolving. */ > > + > > + /* If the objfile is a debug file, find the name of the real binary > > + file and get the name of dwp file from there. */ > > + if (objfile->separate_debug_objfile_backlink) > > + { > > + dwp_base_name = xstrprintf ("%s.dwp", > > + lbasename (objfile->separate_debug_objfile_backlink->original_name)); > > + } > > + else > > + dwp_base_name = xstrprintf ("%s.dwp", lbasename (objfile->original_name)); > > + dwp_name = xstrprintf ("%s%s%s", ldirname(objfile->original_name), > > + SLASH_STRING, dwp_base_name); > > + > > dwp_name = xstrprintf ("%s.dwp", objfile->original_name); > > + cleanups = make_cleanup (xfree, dwp_base_name); > > cleanups = make_cleanup (xfree, dwp_name); > > > > dbfd = open_dwp_file (dwp_name); > > > > On Fri, Apr 8, 2016 at 3:54 PM, Doug Evans wrote: > >> Yunlian Jiang writes: > >> > Hi. > >> > > >> > This tries to fix PR gdb/19914. When the object file is not > >> > a binary but a .debug file, the function to try to find the .dwp > >> > file in the debug directory does not work. This one tries to solve > >> > this problem. > >> > > >> > 2016-04-05 Yunlian Jiang > >> > * gdb/dwarf2read.c: Try to find .dwp for .debug > >> > > >> > > >> > diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c > >> > index dcd49e3..551376a 100644 > >> > --- a/gdb/dwarf2read.c > >> > +++ b/gdb/dwarf2read.c > >> > @@ -10854,6 +10854,18 @@ open_and_init_dwp_file (void) > >> > dbfd = open_dwp_file (dwp_name); > >> > } > >> > > >> > + if (dbfd == NULL && strlen(dwp_name) > 10) > >> > + { > >> > + /* Try to find .dwp for the debug file. */ > >> > + if (!strcmp(dwp_name + strlen(dwp_name) - 10, ".debug.dwp")) > >> > + { > >> > + dwp_name[strlen(dwp_name) - 10] = '\0'; > >> > + dwp_name = xstrprintf ("%s.dwp", dwp_name); > >> > + make_cleanup (xfree, dwp_name); > >> > + dbfd = open_dwp_file (dwp_name); > >> > + } > >> > + } > >> > + > >> > if (dbfd == NULL) > >> > { > >> > if (dwarf_read_debug) > >> > >> Hi. > >> > >> I've looked at this a little bit. > >> I don't have time for a complete review at the moment, > >> but one thing I'm wondering about is whether this extra > >> test should go in open_dwp_file instead. > >> > >> Plus, while we're making the assumption that the separate debug > >> file ends with ".debug" that's not necessarily true. > >> Not sure we can do better, but one thought is to look in > >> separate_debug_objfile_backlink and use that. Ok, had time to fully dig into this. There are a couple of problems with the patch. E.g., ldirname malloc's its result, so that needs to be freed. I came up with this (which includes a testcase). Look ok? 2016-04-24 Yunlian Jiang Doug Evans PR symtab/19914 * dwarf2read.c (open_and_init_dwp_file): Look at backlink if objfile is separate debug file. testsuite/ * gdb.dwarf2/dwp-sepdebug.c: New file. * gdb.dwarf2/dwp-sepdebug.exp: New file. +gdb_test "ptype main" {type = int \(int, char \*\*\)} diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 7bbf080..eb81151 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -10838,12 +10838,26 @@ open_and_init_dwp_file (void) struct dwp_file *dwp_file; char *dwp_name; bfd *dbfd; - struct cleanup *cleanups; + struct cleanup *cleanups = make_cleanup (null_cleanup, 0); /* Try to find first .dwp for the binary file before any symbolic links resolving. */ - dwp_name = xstrprintf ("%s.dwp", objfile->original_name); - cleanups = make_cleanup (xfree, dwp_name); + + /* If the objfile is a debug file, find the name of the real binary + file and get the name of dwp file from there. */ + if (objfile->separate_debug_objfile_backlink != NULL) + { + struct objfile *backlink = objfile->separate_debug_objfile_backlink; + const char *backlink_basename = lbasename (backlink->original_name); + char *debug_dirname = ldirname (objfile->original_name); + + make_cleanup (xfree, debug_dirname); + dwp_name = xstrprintf ("%s%s%s.dwp", debug_dirname, + SLASH_STRING, backlink_basename); + } + else + dwp_name = xstrprintf ("%s.dwp", objfile->original_name); + make_cleanup (xfree, dwp_name); dbfd = open_dwp_file (dwp_name); if (dbfd == NULL diff --git a/gdb/testsuite/gdb.dwarf2/dwp-sepdebug.c b/gdb/testsuite/gdb.dwarf2/dwp-sepdebug.c new file mode 100644 index 0000000..bb11da2 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dwp-sepdebug.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2016 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 . */ + +int +main (int argc, char **argv) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/dwp-sepdebug.exp b/gdb/testsuite/gdb.dwarf2/dwp-sepdebug.exp new file mode 100644 index 0000000..a4e7068 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dwp-sepdebug.exp @@ -0,0 +1,40 @@ +# Copyright 2016 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 . + +standard_testfile + +if { [build_executable ${testfile}.exp ${testfile} ${srcfile}] == -1 } { + return -1 +} +if ![remote_file host exists [standard_output_file ${testfile}.dwp]] { + unsupported "testsuite run does not produce dwp files" + return 0 +} + +# Note: the procedure gdb_gnu_strip_debug will produce an executable called +# ${binfile}, which is just like the executable ($binfile) but without +# the debuginfo. Instead $binfile has a .gnu_debuglink section which contains +# the name of a debuginfo only file. This file will be stored in the +# gdb.base/ subdirectory. + +if [gdb_gnu_strip_debug $binfile$EXEEXT] { + # check that you have a recent version of strip and objcopy installed + unsupported "cannot produce separate debug info files" + return -1 +} + +clean_restart "$testfile" +