From patchwork Thu Dec 18 23:32:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4351 Received: (qmail 786 invoked by alias); 18 Dec 2014 23:32:10 -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 774 invoked by uid 89); 18 Dec 2014 23:32:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ob0-f202.google.com Received: from mail-ob0-f202.google.com (HELO mail-ob0-f202.google.com) (209.85.214.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 18 Dec 2014 23:32:07 +0000 Received: by mail-ob0-f202.google.com with SMTP id va2so1483608obc.1 for ; Thu, 18 Dec 2014 15:32:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=0aI/Rphda7AU0gwyyDYBhmQ9TmXjKsW/0jYxKMGO/mM=; b=b0hDP9PY+IVh7nQPP9y6m3mFyz52lJAF1eEdN8o8lL+gWKgQWPojrb3jwDLVinQvbJ oqo+ThrgGJHXeZLa86RYg4zXHrX0AguM3F0nIIPih9EtTkeeSJD/FQ2onCbl9yH5h8J3 +jK+H9HjK6pYykZDq3qpzEZyykZFc//ieYZzEgSJaWEQj+QC/Mb4Myq/xpBIFOuSROWa YWKQE/n+5K0ynBibwSycmwyskQFKP5DJt7kZzDjpAiSg2N6dELU/UVAgiR834AbBF96f uNSBGNKGWEkAmfvZRkeWxvtrQ5Q2LIbLqpNNrsD3vu3bqmQ8s+hzYIdrp7wJSF5Hg+9Y sxjA== X-Gm-Message-State: ALoCoQl9eWU95AgfPHsjfrvQwRdwqvrX8X+irA9D7zSI3wbCi0td1QSoNrpiQHfiibhSM6zxlEWXdiEK4VMobkgtH06SyBPxeXdnV1DtgIlosMz27Rpg7nLcDOgVklNxnF2RBuKPxMdyV7qQ3pxLsHF+MSyBtaWL1X8HAyPFUTNzWq4bUCZC0RY= X-Received: by 10.224.1.201 with SMTP id 9mr3869229qag.6.1418945525284; Thu, 18 Dec 2014 15:32:05 -0800 (PST) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id 5si396183yhd.6.2014.12.18.15.32.05 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Dec 2014 15:32:05 -0800 (PST) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTPS id avpbLeDP.1; Thu, 18 Dec 2014 15:32:05 -0800 From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH] Allow gdb.lookup_objfile to work with symlinked binary Date: Thu, 18 Dec 2014 15:32:04 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. This patch enhances gdb.lookup_objfile so that it works with a symlinked binary. Regression tested on amd64-linux. 2014-12-18 Doug Evans * objfiles.c (objfile_filename): New function. * objfiles.h (objfile_filename): Declare it. (objfile_name): Add function comment. * python/py-objfile.c (objfpy_lookup_objfile_by_name): Try both the bfd file name (which may be realpath'd), and the original name. testsuite/ * gdb.python/py-objfile.exp: Test gdb.lookup_objfile on symlinked binary. diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 4dcd2e1..ceee634 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -1492,7 +1492,7 @@ default_iterate_over_objfiles_in_search_order } } -/* Return canonical name for OBJFILE. */ +/* See objfiles.h. */ const char * objfile_name (const struct objfile *objfile) @@ -1506,6 +1506,17 @@ objfile_name (const struct objfile *objfile) /* See objfiles.h. */ const char * +objfile_filename (const struct objfile *objfile) +{ + if (objfile->obfd != NULL) + return bfd_get_filename (objfile->obfd); + + return NULL; +} + +/* See objfiles.h. */ + +const char * objfile_debug_name (const struct objfile *objfile) { return lbasename (objfile->original_name); diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 084af39..da2f62c 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -699,8 +699,17 @@ extern void default_iterate_over_objfiles_in_search_order void set_objfile_per_bfd (struct objfile *obj); +/* Return canonical name for OBJFILE. + This is the real file name if the file has been opened. + Otherwise it is the original name supplied by the user. */ + const char *objfile_name (const struct objfile *objfile); +/* Return the (real) file name of OBJFILE if the file has been opened, + otherwise return NULL. */ + +const char *objfile_filename (const struct objfile *objfile); + /* Return the name to print for OBJFILE in debugging messages. */ extern const char *objfile_debug_name (const struct objfile *objfile); diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index e78ceba..36eff35 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -438,12 +438,18 @@ objfpy_lookup_objfile_by_name (const char *name) ALL_OBJFILES (objfile) { + const char *filename; + if ((objfile->flags & OBJF_NOT_FILENAME) != 0) continue; /* Don't return separate debug files. */ if (objfile->separate_debug_objfile_backlink != NULL) continue; - if (compare_filenames_for_search (objfile_name (objfile), name)) + + filename = objfile_filename (objfile); + if (filename != NULL && compare_filenames_for_search (filename, name)) + return objfile; + if (compare_filenames_for_search (objfile->original_name, name)) return objfile; } diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 5d3c084..0a2004f 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -115,3 +115,14 @@ if { [get_python_valueof "sep_objfile.build_id" "None"] != "None" } { gdb_test "python print (gdb.lookup_objfile (sep_objfile.build_id, by_build_id=True))" \ "Objfile not found\\.\r\n${python_error_text}" } + +# An objfile that was a symlink to a differently named file is still +# findable with its original name. +set symlink_binary [standard_output_file "symlink-binary"] +remote_exec host "rm -f ${symlink_binary}" +remote_exec host "ln -sf ${testfile} ${symlink_binary}" +if [remote_file host exists "${symlink_binary}"] { + clean_restart "${symlink_binary}" + gdb_test "python print (gdb.lookup_objfile (\"${symlink_binary}\").filename)" \ + "${testfile}" "gdb.lookup_objfile of symlinked binary" +}