[4/6] Add LineTableEntry.column to python line table interface

Message ID 20200516172632.4803-5-ssbssa@yahoo.de
State New
Headers show
Series
  • Step program considering the source column information
Related show

Commit Message

Simon Marchi via Gdb-patches May 16, 2020, 5:26 p.m.
---
 gdb/python/py-linetable.c | 30 ++++++++++++++++++++++++------
 gdb/symtab.c              |  5 ++++-
 gdb/symtab.h              |  3 ++-
 3 files changed, 30 insertions(+), 8 deletions(-)

-- 
2.26.2

Comments

Tom de Vries May 27, 2020, 1:50 p.m. | #1
On 16-05-2020 19:26, Hannes Domani via Gdb-patches wrote:
> diff --git a/gdb/symtab.h b/gdb/symtab.h

> index c936c858e6..fb1b8c9393 100644

> --- a/gdb/symtab.h

> +++ b/gdb/symtab.h

> @@ -2274,7 +2274,8 @@ void iterate_over_symtabs (const char *name,

>  

>  

>  std::vector<CORE_ADDR> find_pcs_for_symtab_line

> -    (struct symtab *symtab, int line, struct linetable_entry **best_entry);

> +    (struct symtab *symtab, int line, struct linetable_entry **best_entry,

> +     std::vector<int> *columns = nullptr);

>  

>  /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS.  The callback

>     is called once per matching symbol SYM.  The callback should return

> 


Hi,

I just tried to build this, and ran into:
...
In file included from /data/gdb_versions/devel/src/gdb/gdb_curses.h:55:0,
                 from /data/gdb_versions/devel/src/gdb/tui/tui-data.h:26,
                 from /data/gdb_versions/devel/src/gdb/tui/tui-command.h:25,
                 from /data/gdb_versions/devel/src/gdb/tui/tui.c:26:
/data/gdb_versions/devel/src/gdb/symtab.h:2276:24: error: expected ','
or '...' before '(' token
      std::vector<int> *columns = nullptr);
                        ^
make[1]: *** [Makefile:1610: tui/tui.o] Error 1
...

The "columns" string is defined as a macro by /usr/include/ncurses/term.h:
...
#define columns                        CUR Numbers[0]
...
so after preprocessing we have:
...
std::vector<CORE_ADDR> find_pcs_for_symtab_line
    (struct symtab *symtab, int line, struct linetable_entry **best_entry,
     std::vector<int> *
# 2276 "/data/gdb_versions/devel/src/gdb/symtab.h" 3 4
                      ((TERMTYPE *)(_nc_cur_term()))-> Numbers[0]
# 2276 "/data/gdb_versions/devel/src/gdb/symtab.h"
                              = nullptr);
...

Thanks,
- Tom
Tom Tromey May 27, 2020, 2:36 p.m. | #2
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:


Tom> The "columns" string is defined as a macro by /usr/include/ncurses/term.h:
Tom> ...
Tom> #define columns                        CUR Numbers[0]

FWIW I think it would be fine to add a #undef for this to gdb_curses.h.

Tom

Patch

diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 858313bb22..f0aa736ac7 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -24,6 +24,8 @@  typedef struct {
   PyObject_HEAD
   /* The line table source line.  */
   int line;
+  /* The line table source column.  */
+  int column;
   /* The pc associated with the source line.  */
   CORE_ADDR pc;
 } linetable_entry_object;
@@ -99,7 +101,7 @@  symtab_to_linetable_object (PyObject *symtab)
    and an address.  */
 
 static PyObject *
-build_linetable_entry (int line, CORE_ADDR address)
+build_linetable_entry (int line, int column, CORE_ADDR address)
 {
   linetable_entry_object *obj;
 
@@ -108,6 +110,7 @@  build_linetable_entry (int line, CORE_ADDR address)
   if (obj != NULL)
     {
       obj->line = line;
+      obj->column = column;
       obj->pc = address;
     }
 
@@ -121,7 +124,8 @@  build_linetable_entry (int line, CORE_ADDR address)
    address.  */
 
 static PyObject *
-build_line_table_tuple_from_pcs (int line, const std::vector<CORE_ADDR> &pcs)
+build_line_table_tuple_from_pcs (int line, const std::vector<CORE_ADDR> &pcs,
+				 const std::vector<int> &columns)
 {
   int i;
 
@@ -136,7 +140,7 @@  build_line_table_tuple_from_pcs (int line, const std::vector<CORE_ADDR> &pcs)
   for (i = 0; i < pcs.size (); ++i)
     {
       CORE_ADDR pc = pcs[i];
-      gdbpy_ref<> obj (build_linetable_entry (line, pc));
+      gdbpy_ref<> obj (build_linetable_entry (line, columns[i], pc));
 
       if (obj == NULL)
 	return NULL;
@@ -158,6 +162,7 @@  ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
   gdb_py_longest py_line;
   struct linetable_entry *best_entry = NULL;
   std::vector<CORE_ADDR> pcs;
+  std::vector<int> columns;
 
   LTPY_REQUIRE_VALID (self, symtab);
 
@@ -166,14 +171,14 @@  ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
 
   try
     {
-      pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry);
+      pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry, &columns);
     }
   catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
 
-  return build_line_table_tuple_from_pcs (py_line, pcs);
+  return build_line_table_tuple_from_pcs (py_line, pcs, columns);
 }
 
 /* Implementation of gdb.LineTable.has_line (self, line) -> Boolean.
@@ -339,6 +344,17 @@  ltpy_entry_get_pc (PyObject *self, void *closure)
   return  gdb_py_object_from_longest (obj->pc).release ();
 }
 
+/* Implementation of gdb.LineTableEntry.column (self) -> Long.  Returns
+   a long integer associated with the line table entry.  */
+
+static PyObject *
+ltpy_entry_get_column (PyObject *self, void *closure)
+{
+  linetable_entry_object *obj = (linetable_entry_object *) self;
+
+  return gdb_py_object_from_longest (obj->column).release ();
+}
+
 /* LineTable iterator functions.  */
 
 /* Return a new line table iterator.  */
@@ -422,7 +438,7 @@  ltpy_iternext (PyObject *self)
       item = &(SYMTAB_LINETABLE (symtab)->item[iter_obj->current_index]);
     }
 
-  obj = build_linetable_entry (item->line, item->pc);
+  obj = build_linetable_entry (item->line, item->column, item->pc);
   iter_obj->current_index++;
 
   return obj;
@@ -548,6 +564,8 @@  static gdb_PyGetSetDef linetable_entry_object_getset[] = {
     "The line number in the source file.", NULL },
   { "pc", ltpy_entry_get_pc, NULL,
     "The memory address for this line number.", NULL },
+  { "column", ltpy_entry_get_column, NULL,
+    "The column number in the source file.", NULL },
   { NULL }  /* Sentinel */
 };
 
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 999c0af8dc..19a3d86f24 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3472,7 +3472,8 @@  find_line_symtab (struct symtab *sym_tab, int line,
 
 std::vector<CORE_ADDR>
 find_pcs_for_symtab_line (struct symtab *symtab, int line,
-			  struct linetable_entry **best_item)
+			  struct linetable_entry **best_item,
+			  std::vector<int> *columns)
 {
   int start = 0;
   std::vector<CORE_ADDR> result;
@@ -3500,6 +3501,8 @@  find_pcs_for_symtab_line (struct symtab *symtab, int line,
 	}
 
       result.push_back (SYMTAB_LINETABLE (symtab)->item[idx].pc);
+      if (columns != nullptr)
+	columns->push_back (SYMTAB_LINETABLE (symtab)->item[idx].column);
       start = idx + 1;
     }
 
diff --git a/gdb/symtab.h b/gdb/symtab.h
index c936c858e6..fb1b8c9393 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2274,7 +2274,8 @@  void iterate_over_symtabs (const char *name,
 
 
 std::vector<CORE_ADDR> find_pcs_for_symtab_line
-    (struct symtab *symtab, int line, struct linetable_entry **best_entry);
+    (struct symtab *symtab, int line, struct linetable_entry **best_entry,
+     std::vector<int> *columns = nullptr);
 
 /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS.  The callback
    is called once per matching symbol SYM.  The callback should return