From patchwork Thu Nov 20 21:22:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 3819 Received: (qmail 2706 invoked by alias); 20 Nov 2014 21:22:45 -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 2696 invoked by uid 89); 20 Nov 2014 21:22:45 -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, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-qa0-f74.google.com Received: from mail-qa0-f74.google.com (HELO mail-qa0-f74.google.com) (209.85.216.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 20 Nov 2014 21:22:43 +0000 Received: by mail-qa0-f74.google.com with SMTP id i13so245789qae.5 for ; Thu, 20 Nov 2014 13:22:41 -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=DeWkxPjzVMK+pl3VZAsFPSsEJza0T52efrLKNEFcgIA=; b=e1nT7srvs5VJ47xBgaOCVnloU5YledNOsIQXZ8ah5vu/Oz92p0Z2Ps0+1EiM1yGEtR pJD/NeI6/6mZt0BKm6FNfY/QLtQGQkmWn/H9XDkvzMv8DPHL7tHo4l4tdAkywcr1byAV iW40KXqgBRzeX73MQOq1RXEtgvuA8xKeYpQR9nAvIMfaJBPw4kRFgOF7lK271vKZGjOC EswBae1TnvYlhfK+y5wN80BTGcwSVZTuSIdxo3WWjv3Y1IQK9aAmyHgyFcCIe91u8fBA guvoVbK0wfCt9e3YT4pcJBnCr9X1THOGntfehd4DXHGIOpshIIuEHFxwjxw8WXIMP54x oNMg== X-Gm-Message-State: ALoCoQnwQHyA6rCBNZIS7JTampb3W3RSWoC/yuS54vxID6aSTvdWdZRoZV0MtELiHFw5+PuyRseH X-Received: by 10.236.11.78 with SMTP id 54mr551537yhw.17.1416518561282; Thu, 20 Nov 2014 13:22:41 -0800 (PST) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id b3si847512qcq.2.2014.11.20.13.22.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Nov 2014 13:22:41 -0800 (PST) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTPS id ioHJ7fMW.1; Thu, 20 Nov 2014 13:22:41 -0800 From: Doug Evans To: gdb-patches@sourceware.org, eliz@gnu.org, palves@redhat.com, sergiodj@redhat.com Subject: [PATCH 2/4] python support for fetching separate debug files: have_debug_info Date: Thu, 20 Nov 2014 13:22:39 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes This patch provides an API call to determine whether debug information is present. It's based on the same test that gdb internally uses to decide whether to look for separate debug files. 2014-11-20 Doug Evans * NEWS: Mention gdb.Objfile.have_debug_info. * python/py-objfile.c (objfpy_get_have_debug_info): New function. (objfile_getset): Add "have_debug_info". doc/ * python.texi (Objfiles In Python): Document Objfile.have_debug_info. testsuite/ * gdb.python/py-objfile.exp: Add tests for objfile.have_debug_info. diff --git a/gdb/NEWS b/gdb/NEWS index eecc7da..3a36fa8 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -13,6 +13,8 @@ which is the gdb.Progspace object of the containing program space. ** gdb.Objfile objects have a new attribute "build_id", which is the build ID generated when the file was built. + ** gdb.Objfile objects have a new attribute "have_debug_info", which is + a boolean indicating if debug information for the objfile is present. ** A new event "gdb.clear_objfiles" has been added, triggered when selecting a new file to debug. ** You can now add attributes to gdb.Objfile and gdb.Progspace objects. diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index a47a259..1c9dbb87 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3457,6 +3457,15 @@ command-line option in @ref{Options, , Command Line Options, ld.info, The GNU Linker}. @end defvar +@defvar Objfile.have_debug_info +A boolean indicating if debug information for the objfile is present. +Note that a program compiled without @samp{-g} may still have some debug +information, e.g., from the @code{C} runtime. Thus a value of @code{True} +for this attribute does not mean that debug information is present for +every source file in the program. It only means that debug information +is present for at least one source file. +@end defvar + @defvar Objfile.progspace The containing program space of the objfile as a @code{gdb.Progspace} object. @xref{Progspaces In Python}. diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 05a7c21..5d0933f 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -112,6 +112,32 @@ objfpy_get_build_id (PyObject *self, void *closure) Py_RETURN_NONE; } +/* An Objfile method which returns whether there debug information + has been stripped. */ + +static PyObject * +objfpy_get_have_debug_info (PyObject *self, void *closure) +{ + objfile_object *obj = (objfile_object *) self; + struct objfile *objfile = obj->objfile; + + if (objfile != NULL) + { + /* This uses the same test that the file readers use, e.g., + elf_symfile_read, because its main purpose is to decide whether + separate debug info files should be fetched. + See elf_symfile_read. */ + if (!objfile_has_partial_symbols (objfile) + && !objfile_has_full_symbols (objfile) + && objfile->separate_debug_objfile == NULL + && objfile->separate_debug_objfile_backlink == NULL) + Py_RETURN_FALSE; + Py_RETURN_TRUE; + } + + Py_RETURN_FALSE; +} + /* An Objfile method which returns the objfile's progspace, or None. */ static PyObject * @@ -412,6 +438,8 @@ static PyGetSetDef objfile_getset[] = "The objfile's filename, or None.", NULL }, { "build_id", objfpy_get_build_id, NULL, "The objfile's build id, or None.", NULL }, + { "have_debug_info", objfpy_get_have_debug_info, NULL, + "True if there is debug information for the objfile.", NULL }, { "progspace", objfpy_get_progspace, NULL, "The objfile's progspace, or None.", NULL }, { "pretty_printers", objfpy_get_printers, objfpy_set_printers, diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 74384ed..f09c64c 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -49,6 +49,9 @@ if [string compare $binfile_build_id ""] { unsupported "build-id is not supported by the compiler" } +gdb_test "python print (objfile.have_debug_info)" "True" \ + "Get objfile have_debug_info" + gdb_test "python print (objfile.progspace)" "" \ "Get objfile program space" gdb_test "python print (objfile.is_valid())" "True" \ @@ -61,3 +64,20 @@ gdb_py_test_silent_cmd "python objfile.random_attribute = 42" \ "Set random attribute in objfile" 1 gdb_test "python print (objfile.random_attribute)" "42" \ "Verify set of random attribute in objfile" + +# Now build another copy of the testcase, this time without debug info. + +if { [prepare_for_testing ${testfile}.exp ${testfile}2 ${srcfile} {nodebug ldflags=-Wl,--strip-debug}] } { + return -1 +} + +if ![runto_main] { + fail "Can't run to main" + return 0 +} + +gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \ + "Get no-debug objfile file" 1 + +gdb_test "python print (objfile.have_debug_info)" "False" \ + "Get objfile have_debug_info"