PR python/13599:
authorTom Tromey <tromey@redhat.com>
Tue, 7 Feb 2012 19:42:27 +0000 (19:42 +0000)
committerTom Tromey <tromey@redhat.com>
Tue, 7 Feb 2012 19:42:27 +0000 (19:42 +0000)
* python/py-symbol.c (sympy_line): New function.
(symbol_object_getset): Add "line".
gdb/doc
* gdb.texinfo (Symbols In Python): Document Symbol.line.
gdb/testsuite
* gdb.python/py-symbol.c (qq): New global.
* gdb.python/py-symbol.exp: Add test for frame-less
lookup_symbol.
* gdb.python/py-symtab.exp: Fix line number.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/python/py-symbol.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-symbol.c
gdb/testsuite/gdb.python/py-symbol.exp
gdb/testsuite/gdb.python/py-symtab.exp

index f85f139..bc8b7d4 100644 (file)
@@ -1,5 +1,11 @@
 2012-02-07  Tom Tromey  <tromey@redhat.com>
 
+       PR python/13599:
+       * python/py-symbol.c (sympy_line): New function.
+       (symbol_object_getset): Add "line".
+
+2012-02-07  Tom Tromey  <tromey@redhat.com>
+
        * charset.c (find_charset_names): Check 'in' against NULL.
 
 2012-02-06  Doug Evans  <dje@google.com>
index 4798b7b..bb9429f 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
   ** A new class, gdb.printing.FlagEnumerationPrinter, can be used to
      apply "flag enum"-style pretty-printing to any enum.
 
+  ** gdb.lookup_symbol can now work when there is no current frame.
+
+  ** gdb.Symbol now has a 'line' attribute, holding the line number in
+     the source at which the symbol was defined.
+
 * GDBserver now supports stdio connections.
   E.g. (gdb) target remote | ssh myhost gdbserver - hello
 
index 4986107..8dd113e 100644 (file)
@@ -1,3 +1,7 @@
+2012-02-07  Tom Tromey  <tromey@redhat.com>
+
+       * gdb.texinfo (Symbols In Python): Document Symbol.line.
+
 2012-01-27  Thomas Schwinge  <thomas@codesourcery.com>
 
        * gdb.textinfo (Packets): Move vCont paragraph to the correct place.
index 5738d14..052820b 100644 (file)
@@ -23967,6 +23967,11 @@ represented as a @code{gdb.Symtab} object.  @xref{Symbol Tables In
 Python}.  This attribute is not writable.
 @end defvar
 
+@defvar Symbol.line
+The line number in the source code at which the symbol was defined.
+This is an integer.
+@end defvar
+
 @defvar Symbol.name
 The name of the symbol as a string.  This attribute is not writable.
 @end defvar
index 9d32a71..d44014c 100644 (file)
@@ -183,6 +183,19 @@ sympy_is_variable (PyObject *self, void *closure)
                              || class == LOC_OPTIMIZED_OUT));
 }
 
+/* Implementation of gdb.Symbol.line -> int.
+   Returns the line number at which the symbol was defined.  */
+
+static PyObject *
+sympy_line (PyObject *self, void *closure)
+{
+  struct symbol *symbol = NULL;
+
+  SYMPY_REQUIRE_VALID (self, symbol);
+
+  return PyInt_FromLong (SYMBOL_LINE (symbol));
+}
+
 /* Implementation of gdb.Symbol.is_valid (self) -> Boolean.
    Returns True if this Symbol still exists in GDB.  */
 
@@ -460,6 +473,8 @@ to display demangled or mangled names.", NULL },
     "True if the symbol is a function or method." },
   { "is_variable", sympy_is_variable, NULL,
     "True if the symbol is a variable." },
+  { "line", sympy_line, NULL,
+    "The source line number at which the symbol was defined." },
   { NULL }  /* Sentinel */
 };
 
index cbaca89..39a952c 100644 (file)
@@ -1,3 +1,10 @@
+2012-01-31  Tom Tromey  <tromey@redhat.com>
+
+       * gdb.python/py-symbol.c (qq): New global.
+       * gdb.python/py-symbol.exp: Add test for frame-less
+       lookup_symbol.
+       * gdb.python/py-symtab.exp: Fix line number.
+
 2012-02-03  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.ada/mi_task_arg: New testcase.
index 72469be..d29849b 100644 (file)
@@ -35,6 +35,8 @@ class SimpleClass
 };
 #endif
 
+int qq;                                /* line of qq */
+
 int func (int arg)
 {
   int i = 2;
index b0e73c3..154eb37 100644 (file)
@@ -42,6 +42,10 @@ gdb_py_test_silent_cmd "python main_func = gdb.lookup_global_symbol(\"main\")" "
 gdb_test "python print main_func.is_function" "True" "Test main_func.is_function"
 gdb_test "python print gdb.lookup_global_symbol(\"junk\")" "None" "Test lookup_global_symbol(\"junk\")"
 
+set qq_line [gdb_get_line_number "line of qq"]
+gdb_test "python print gdb.lookup_symbol('qq')\[0\].line" "$qq_line" \
+    "print line number of qq"
+
 if ![runto_main] then {
     fail "Can't run to main"
     return 0
index f64cb57..490a891 100644 (file)
@@ -43,7 +43,8 @@ if ![runto_main] then {
 global hex decimal
 
 # Setup and get the symbol table.
-gdb_breakpoint [gdb_get_line_number "Block break here."]
+set line_no [gdb_get_line_number "Block break here."]
+gdb_breakpoint $line_no
 gdb_continue_to_breakpoint "Block break here."
 gdb_py_test_silent_cmd "python frame = gdb.selected_frame()" "Get Frame" 0
 gdb_py_test_silent_cmd "python sal = frame.find_sal()" "Get block" 0
@@ -52,7 +53,7 @@ gdb_py_test_silent_cmd "python symtab = sal.symtab" "Get block" 0
 # Test sal.
 gdb_test "python print sal.symtab" ".*gdb.python/py-symbol.c.*" "Test symtab"
 gdb_test "python print sal.pc" "${decimal}" "Test sal.pc"
-gdb_test "python print sal.line" "42" "Test sal.line"
+gdb_test "python print sal.line" "$line_no" "Test sal.line"
 gdb_test "python print sal.is_valid()" "True" "Test sal.is_valid"
 
 # Test symbol table.