« Return to Thread: [RFC - Python Scripting] Add 'end' attribute to gdb.Symtab_and_line

[RFC - Python Scripting] Add 'end' attribute to gdb.Symtab_and_line

by Siva Chandra :: Rate this Message:

| View in Thread

Hello,

Attached is a patch which adds the 'end' attribute to
gdb.Symtab_and_line.  Essentially, it exposes the 'end' field of
'struct symtab_and_line'.

Though I have named the new attribute 'end' in the attached patch, I
would like to discuss this.  There is already an attribute 'pc' which
is described as "Indicates the current program counter address" in the
documentation.  I do not think this description is accurate: 'pc' is
actually the begin address of the program counter address range for
the current source line.  To indicate the right meaning of 'pc' and
the new 'end' attribute, should they be named 'start_pc' and 'end_pc'
respectively, at least in the python API?

2012-05-21  Siva Chandra Reddy  <sivachandra@...>

        New attribute 'end' for gdb.Symtab_and_line.
        * NEWS (Python Scripting): Add entry about the new attribute.
        * python/py-symtab.c (salpy_get_end): New function which
        implements the get method for the 'end' attribute of
        gdb.Symtab_and_line.
        (sal_object_getset): Add entry for the 'end' attribute.

        doc/
        * gdb.texinfo (Symbol Tables In Python): Add description about
        the new 'end' attribute of gdb.Symtab_and line.

        testsuite/
        * gdb.python/py-symtab.exp: Add tests to test the new
attribute
        'end' of gdb.Symtab_and_line.
        * gdb.python/py-symbol.c: Move break point comment to enable
        testing of gdb.Symtab_and_line.end.

Thanks,
Siva Chandra

Index: NEWS
===================================================================
RCS file: /cvs/src/src/gdb/NEWS,v
retrieving revision 1.524
diff -u -p -r1.524 NEWS
--- NEWS 20 May 2012 20:35:18 -0000 1.524
+++ NEWS 21 May 2012 07:23:07 -0000
@@ -58,6 +58,10 @@
   ** New function gdb.find_pc_line which returns the gdb.Symtab_and_line
      object associated with a PC value.
 
+  ** gdb.Symtab_and_line has new attribute 'end' which holds the open
+     upper bound of the program counter address range for the current
+     source line.
+
 * Go language support.
   GDB now supports debugging programs written in the Go programming
   language.
Index: doc/gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.970
diff -u -p -r1.970 gdb.texinfo
--- doc/gdb.texinfo 20 May 2012 20:35:19 -0000 1.970
+++ doc/gdb.texinfo 21 May 2012 07:23:15 -0000
@@ -25258,6 +25258,11 @@ Indicates the current program counter ad
 writable.
 @end defvar
 
+@defvar Symtab_and_line.end
+Indicates the open upper bound of the program counter address range for
+the current source line.  This attribute is not writable.
+@end defvar
+
 @defvar Symtab_and_line.line
 Indicates the current line number for this object.  This
 attribute is not writable.
Index: python/py-symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/python/py-symtab.c,v
retrieving revision 1.9
diff -u -p -r1.9 py-symtab.c
--- python/py-symtab.c 3 May 2012 07:07:25 -0000 1.9
+++ python/py-symtab.c 21 May 2012 07:23:15 -0000
@@ -237,6 +237,19 @@ salpy_get_pc (PyObject *self, void *clos
   return gdb_py_long_from_ulongest (sal->pc);
 }
 
+/* Implementation of the get method for the 'end' attribute of
+   gdb.Symtab_and_line.  */
+
+static PyObject *
+salpy_get_end (PyObject *self, void *closure)
+{
+  struct symtab_and_line *sal = NULL;
+
+  SALPY_REQUIRE_VALID (self, sal);
+
+  return gdb_py_long_from_ulongest (sal->end);
+}
+
 static PyObject *
 salpy_get_line (PyObject *self, void *closure)
 {
@@ -556,6 +569,7 @@ static PyTypeObject symtab_object_type =
 static PyGetSetDef sal_object_getset[] = {
   { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
   { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
+  { "end", salpy_get_end, NULL, "Return the symtab_and_line's end pc.", NULL },
   { "line", salpy_get_line, NULL,
     "Return the symtab_and_line's line.", NULL },
   {NULL}  /* Sentinel */
Index: testsuite/gdb.python/py-symbol.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-symbol.c,v
retrieving revision 1.6
diff -u -p -r1.6 py-symbol.c
--- testsuite/gdb.python/py-symbol.c 3 May 2012 07:07:26 -0000 1.6
+++ testsuite/gdb.python/py-symbol.c 21 May 2012 07:23:16 -0000
@@ -40,8 +40,8 @@ int qq = 72; /* line of qq */
 int func (int arg)
 {
   int i = 2;
-  i = i * arg;
-  return arg; /* Block break here.  */
+  i = i * arg; /* Block break here.  */
+  return arg;
 }
 
 struct simple_struct
Index: testsuite/gdb.python/py-symtab.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.python/py-symtab.exp,v
retrieving revision 1.9
diff -u -p -r1.9 py-symtab.exp
--- testsuite/gdb.python/py-symtab.exp 3 May 2012 07:07:26 -0000 1.9
+++ testsuite/gdb.python/py-symtab.exp 21 May 2012 07:23:16 -0000
@@ -54,10 +54,13 @@ gdb_py_test_silent_cmd "python static_bl
 gdb_py_test_silent_cmd "python global_symbols = \[\]; static_symbols = \[\]" "Set up symbol name lists" 0
 gdb_py_test_silent_cmd "python for sym in global_block: global_symbols.append(sym.name)" "Get global symbol names" 0
 gdb_py_test_silent_cmd "python for sym in static_block: static_symbols.append(sym.name)" "Get static symbol names" 0
+gdb_py_test_silent_cmd "step" "Step to the next line" 0
+gdb_py_test_silent_cmd "python new_pc = gdb.selected_frame().find_sal().pc" "Get new PC" 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.end == new_pc" "True" "Test sal.end"
 gdb_test "python print sal.line" "$line_no" "Test sal.line"
 gdb_test "python print sal.is_valid()" "True" "Test sal.is_valid"
 

 « Return to Thread: [RFC - Python Scripting] Add 'end' attribute to gdb.Symtab_and_line