New python method gdb.Objfile.add_separate_debug_file.
authorDoug Evans <dje@google.com>
Thu, 4 Dec 2014 20:01:22 +0000 (12:01 -0800)
committerDoug Evans <dje@google.com>
Thu, 4 Dec 2014 20:01:22 +0000 (12:01 -0800)
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.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/python.texi
gdb/python/py-objfile.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-objfile.exp

index e6da0b5d9437002310f13f22a0bb34a3cf356cdb..8023f03179f6585c3562b9dc4bc3a2050ed214fb 100644 (file)
@@ -1,3 +1,9 @@
+2014-12-04  Doug Evans  <dje@google.com>
+
+       * 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  <dje@google.com>
 
        * NEWS: Mention gdb.Objfile.build_id.
index 16ed91eb8c877a70ec7ab70ce15f7ac2ba28361d..c30cda27a2edc1be94c121011e97111dbcc1e497 100644 (file)
--- 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.
index 7f36a311cd635d1e45b4ceff6712d11ec5fc93c2..09318aa8e66418656853cd44ebc5675d17895868 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-04  Doug Evans  <dje@google.com>
+
+       * python.texi (Objfiles In Python): Document
+       Objfile.add_separate_debug_file.
+
 2014-12-04  Doug Evans  <dje@google.com>
 
        * python.texi (Objfiles In Python): Document Objfile.build_id.
index a9514100f42043829694e59ff13020b8778e7b7a..f2e4a6ee813fe3bbb078da64043cb6d58c5c3f9a 100644 (file)
@@ -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.
 
index 05a7c21ff406909a34036bf5693f8c5c0e30dc9b..292d310801fdd4b4f4e78af53dcfe1982d9b8fe9 100644 (file)
@@ -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;
+}
+
 \f
 
 /* 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 }
 };
 
index b19a5c078d4206cca15526e4d6fcad3bf9f85ba8..dbbcfa2b9f1bd2f89c9ef5b4c94eb9879f8a4e4d 100644 (file)
@@ -1,3 +1,8 @@
+2014-12-04  Doug Evans  <dje@google.com>
+
+       * gdb.python/py-objfile.exp: Add tests for
+       objfile.add_separate_debug_file.
+
 2014-12-04  Doug Evans  <dje@google.com>
 
        * lib/gdb.exp (get_build_id): New function.
index 74384edde7e396cfbe5c33998dede93440fabba9..6c36f8e072d50fc70f7c0a4fdbe13d93ba688ded 100644 (file)
@@ -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" "= {<text variable, no debug info>} $hex <main>" \
+    "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 <main>" \
+    "print main with debug info"
This page took 0.043468 seconds and 4 git commands to generate.