From patchwork Fri Dec 5 18:37:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4092 Received: (qmail 11313 invoked by alias); 5 Dec 2014 18:37:51 -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 11233 invoked by uid 89); 5 Dec 2014 18:37:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: mail-oi0-f73.google.com Received: from mail-oi0-f73.google.com (HELO mail-oi0-f73.google.com) (209.85.218.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 05 Dec 2014 18:37:48 +0000 Received: by mail-oi0-f73.google.com with SMTP id a141so123750oig.4 for ; Fri, 05 Dec 2014 10:37:46 -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:mime-version:content-type :content-transfer-encoding:message-id:date:to:subject:in-reply-to :references; bh=+KDoE8ww+NiVNsqU2dD0iyd/gRtdnfukp4iogLwrIto=; b=G1zACv9M6zSDqRim8lJ39Aj1B8oNrjYazArzv3wCj1uHbK76Bw1v18i+KRcsdhxKAL 2BmAyoI7rBr2fvfWRX29eJIDk9wTm5UEtWTzWy0BBqx4IqT/wMsv93Wwbr5eHP+Qy8E2 4sxVYvZVL1ajjzD6TbwOovd+tZoJT9qPH4+qK4Cuaya/73R7iNdeLuOrbF+pWRxL26Du rBXpQGHYQbGa7MxZsMtQgOGH7fvgmAbWt5R5LpdZrlHBa0/uKh4Bq3iUa6p+Wi1cWfs1 +RX6PNNwn6cimPqv5DhTNpaHbYAHy1VgLt5mOCkmByOyR2CkVKPlHYRcFA8I3uLekqdk Y2pg== X-Gm-Message-State: ALoCoQkKod0CK9hjMfW49fD+jMMxBtE8CM6Pz0ADjr+9peM+9nibhHQQXeIfcRHS0sl3tLE8WFHNKU9xin+z9JX9Slketr7jMVKyo1GaWXR6XWI2dB9U+O5zSVZ7bMn99Wy4ICUo+UU61sO2rvkMZ02ft6waH+gdHBgqKgin4VMQE7bm5FPM3Fo= X-Received: by 10.182.27.244 with SMTP id w20mr15100394obg.46.1417804666334; Fri, 05 Dec 2014 10:37:46 -0800 (PST) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id r6si1303492yhg.1.2014.12.05.10.37.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Dec 2014 10:37:46 -0800 (PST) Received: from ruffy2.mtv.corp.google.com ([172.17.128.107]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id PaXOOH3U.1; Fri, 05 Dec 2014 10:37:46 -0800 From: Doug Evans MIME-Version: 1.0 Message-ID: <21633.64377.220637.598758@ruffy2.mtv.corp.google.com> Date: Fri, 5 Dec 2014 10:37:45 -0800 To: Eli Zaretskii , gdb-patches@sourceware.org Subject: Re: [PATCH 3/4] python support for fetching separate debug files: add_separate_debug_file In-Reply-To: <834mtt56i1.fsf@gnu.org> References: <834mtt56i1.fsf@gnu.org> X-IsSubscribed: yes Eli Zaretskii writes: > > From: Doug Evans > > Date: Thu, 20 Nov 2014 13:24:23 -0800 > > > > This patch provides an API call to add a separate debug file to an > > objfile. > > > > 2014-11-20 Doug Evans > > > > * NEWS: Mention gdb.Objfile.add_separate_debug_file. > > * python/py-objfile.c (objfpy_add_separate_debug_file): New function. > > (objfile_getset): Add "add_separate_debug_file". > > > > doc/ > > * python.texi (Objfiles In Python): Document > > Objfile.add_separate_debug_file. > > > > testsuite/ > > * gdb.python/py-objfile.exp: Add tests for > > objfile.add_separate_debug_file. > > OK for the documentation parts. > > Thanks. Thanks. Here is what I committed. [minor changes from original to account for patch 2/4 not committed yet] commit 86e4ed39595933e04a9dcbc7dec18c1056c9cbe1 Author: Doug Evans Date: Thu Dec 4 12:01:22 2014 -0800 New python method gdb.Objfile.add_separate_debug_file. gdb/ChangeLog: * NEWS: Mention gdb.Objfile.add_separate_debug_file. * python/py-objfile.c (objfpy_add_separate_debug_file): New function. (objfile_getset): Add "add_separate_debug_file". gdb/doc/ChangeLog: * python.texi (Objfiles In Python): Document Objfile.add_separate_debug_file. gdb/testsuite/ChangeLog: * gdb.python/py-objfile.exp: Add tests for objfile.add_separate_debug_file. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e6da0b5..8023f03 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2014-12-04 Doug Evans + * NEWS: Mention gdb.Objfile.add_separate_debug_file. + * python/py-objfile.c (objfpy_add_separate_debug_file): New function. + (objfile_getset): Add "add_separate_debug_file". + +2014-12-04 Doug Evans + * NEWS: Mention gdb.Objfile.build_id. * build-id.c (build_id_bfd_get): Make non-static. * build-id.h (build_id_bfd_get): Add declaration. diff --git a/gdb/NEWS b/gdb/NEWS index 16ed91e..c30cda2 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -23,6 +23,7 @@ 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 method "add_separate_debug_file". ** 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/ChangeLog b/gdb/doc/ChangeLog index 7f36a31..09318aa 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,5 +1,10 @@ 2014-12-04 Doug Evans + * python.texi (Objfiles In Python): Document + Objfile.add_separate_debug_file. + +2014-12-04 Doug Evans + * python.texi (Objfiles In Python): Document Objfile.build_id. 2014-12-02 Nick Bull diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index a951410..f2e4a6e 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3562,6 +3562,17 @@ longer. All other @code{gdb.Objfile} methods will throw an exception if it is invalid at the time the method is called. @end defun +@defun Objfile.add_separate_debug_file (file) +Add @var{file} to the list of files that @value{GDBN} will search for +debug information for the objfile. +This is useful when the debug info has been removed from the program +and stored in a separate file. @value{GDBN} has built-in support for +finding separate debug info files (@pxref{Separate Debug Files}), but if +the file doesn't live in one of the standard places that @value{GDBN} +searches then this function can be used to add a debug info file +from a different place. +@end defun + @node Frames In Python @subsubsection Accessing inferior stack frames from Python. diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 05a7c21..292d310 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -334,6 +334,33 @@ objfpy_is_valid (PyObject *self, PyObject *args) Py_RETURN_TRUE; } +/* Implementation of gdb.Objfile.add_separate_debug_file (self) -> Boolean. */ + +static PyObject * +objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw) +{ + static char *keywords[] = { "file_name", NULL }; + objfile_object *obj = (objfile_object *) self; + const char *file_name; + int symfile_flags = 0; + volatile struct gdb_exception except; + + OBJFPY_REQUIRE_VALID (obj); + + if (!PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name)) + return NULL; + + TRY_CATCH (except, RETURN_MASK_ALL) + { + bfd *abfd = symfile_bfd_open (file_name); + + symbol_file_add_separate (abfd, file_name, symfile_flags, obj->objfile); + } + GDB_PY_HANDLE_EXCEPTION (except); + + Py_RETURN_NONE; +} + /* Clear the OBJFILE pointer in an Objfile object and remove the @@ -401,6 +428,11 @@ static PyMethodDef objfile_object_methods[] = "is_valid () -> Boolean.\n\ Return true if this object file is valid, false if not." }, + { "add_separate_debug_file", (PyCFunction) objfpy_add_separate_debug_file, + METH_VARARGS | METH_KEYWORDS, + "add_separate_debug_file (file_name).\n\ +Add FILE_NAME to the list of files containing debug info for the objfile." }, + { NULL } }; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b19a5c0..dbbcfa2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2014-12-04 Doug Evans + * gdb.python/py-objfile.exp: Add tests for + objfile.add_separate_debug_file. + +2014-12-04 Doug Evans + * lib/gdb.exp (get_build_id): New function. (build_id_debug_filename_get): Rewrite to use it. * gdb.python/py-objfile.exp: Add test for objfile.build_id. diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 74384ed..6c36f8e 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -61,3 +61,29 @@ 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 "p main" "= {} $hex
" \ + "print main without debug info" + +gdb_py_test_silent_cmd "python objfile.add_separate_debug_file(\"${binfile}\")" \ + "Add separate debug file file" 1 + +gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \ + "Get separate debug info objfile" 1 + +gdb_test "p main" "= {int \\(\\)} $hex
" \ + "print main with debug info"