From patchwork Thu Nov 20 21:24:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 3821 Received: (qmail 4534 invoked by alias); 20 Nov 2014 21:24:29 -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 4522 invoked by uid 89); 20 Nov 2014 21:24:29 -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-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, 20 Nov 2014 21:24:26 +0000 Received: by mail-ob0-f202.google.com with SMTP id va2so495922obc.5 for ; Thu, 20 Nov 2014 13:24:24 -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=GUSjZ5EjBcA4gY4DLiiDyb5tgK0Sjdip2VipRsyHlMA=; b=Muoq5Z05IZrE2PrwwoBPoAYMHDyiusUAhfjtaSD7VAfrrQR94llkWty3U1vY2Sb13R Gdq77nDkGK1668yubMdFS+fJQOu8Kjjyj95uUJX1eqOlHFxL6kz5VOYhCdvB/c8ufCmw HWa1W0ZzIs9CBC5TcZyABkPft4mgssxBnlpDQFwgMRvXmUBrt41ZTP0nTx1zoIySNx/1 EdJu54YBuJkUUBo9zCfHp0YK1f3Kw6DPAhlz/bJek3qYEMKGZDItRbT4DbhiqHaA8gn3 kyA6iK2Y99JH+5+XACSuAFOxVLIt7IBkWjPb2s1K7UHSUV2zTsp5GqWqNlVSk9bbFO+Y rVAg== X-Gm-Message-State: ALoCoQl27Xfy13w9J7m5vO9MLnuCW79KoggVjaFyKbwQt7ewu9ptl1i6v5tAOz56nImN+c0hU4yv X-Received: by 10.50.30.5 with SMTP id o5mr10935518igh.1.1416518664914; Thu, 20 Nov 2014 13:24:24 -0800 (PST) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id b3si848682qcq.2.2014.11.20.13.24.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Nov 2014 13:24:24 -0800 (PST) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTPS id b9PchLhC.1; Thu, 20 Nov 2014 13:24:24 -0800 From: Doug Evans To: gdb-patches@sourceware.org, eliz@gnu.org, palves@redhat.com, sergiodj@redhat.com Subject: [PATCH 3/4] python support for fetching separate debug files: add_separate_debug_file Date: Thu, 20 Nov 2014 13:24:23 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes 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. diff --git a/gdb/NEWS b/gdb/NEWS index 3a36fa8..6f2271e 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -15,6 +15,7 @@ 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. + ** 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/python.texi b/gdb/doc/python.texi index 1c9dbb87..b6beec7 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3522,6 +3522,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 5d0933f..7a35652f 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -360,6 +360,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 @@ -427,6 +454,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/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index f09c64c..b3de807 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -81,3 +81,18 @@ gdb_py_test_silent_cmd "python objfile = gdb.objfiles()\[0\]" \ gdb_test "python print (objfile.have_debug_info)" "False" \ "Get objfile have_debug_info" + +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 "python print (objfile.have_debug_info)" "True" \ + "Get have_debug_info on separate debug file" + +gdb_test "p main" "= {int \\(\\)} $hex
" \ + "print main with debug info"