/* Python interface to line tables.
- Copyright (C) 2013-2017 Free Software Foundation, Inc.
+ Copyright (C) 2013-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "python-internal.h"
-#include "py-ref.h"
typedef struct {
PyObject_HEAD
return (PyObject *) obj;
}
-/* Internal helper function to build a Python Tuple from a GDB Vector.
+/* Internal helper function to build a Python Tuple from a vector.
A line table entry can have multiple PCs for a given source line.
Construct a Tuple of all entries for the given source line, LINE
- from the line table VEC. Construct one line table entry object per
+ from the line table PCS. Construct one line table entry object per
address. */
static PyObject *
-build_line_table_tuple_from_pcs (int line, VEC (CORE_ADDR) *vec)
+build_line_table_tuple_from_pcs (int line, const std::vector<CORE_ADDR> &pcs)
{
- int vec_len = 0;
- CORE_ADDR pc;
int i;
- vec_len = VEC_length (CORE_ADDR, vec);
- if (vec_len < 1)
+ if (pcs.size () < 1)
Py_RETURN_NONE;
- gdbpy_ref<> tuple (PyTuple_New (vec_len));
+ gdbpy_ref<> tuple (PyTuple_New (pcs.size ()));
if (tuple == NULL)
return NULL;
- for (i = 0; VEC_iterate (CORE_ADDR, vec, i, pc); ++i)
+ for (i = 0; i < pcs.size (); ++i)
{
+ CORE_ADDR pc = pcs[i];
gdbpy_ref<> obj (build_linetable_entry (line, pc));
if (obj == NULL)
struct symtab *symtab;
gdb_py_longest py_line;
struct linetable_entry *best_entry = NULL;
- VEC (CORE_ADDR) *pcs = NULL;
- PyObject *tuple;
+ std::vector<CORE_ADDR> pcs;
LTPY_REQUIRE_VALID (self, symtab);
if (! PyArg_ParseTuple (args, GDB_PY_LL_ARG, &py_line))
return NULL;
- TRY
+ try
{
pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry);
}
- CATCH (except, RETURN_MASK_ALL)
+ catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
- END_CATCH
-
- tuple = build_line_table_tuple_from_pcs (py_line, pcs);
- VEC_free (CORE_ADDR, pcs);
- return tuple;
+ return build_line_table_tuple_from_pcs (py_line, pcs);
}
/* Implementation of gdb.LineTable.has_line (self, line) -> Boolean.
include in the source set. */
if (item->line > 0)
{
- gdbpy_ref<> line (gdb_py_object_from_longest (item->line));
+ gdbpy_ref<> line = gdb_py_object_from_longest (item->line);
if (line == NULL)
return NULL;
{
linetable_entry_object *obj = (linetable_entry_object *) self;
- return gdb_py_object_from_longest (obj->line);
+ return gdb_py_object_from_longest (obj->line).release ();
}
/* Implementation of gdb.LineTableEntry.pc (self) -> Long. Returns a
{
linetable_entry_object *obj = (linetable_entry_object *) self;
- return gdb_py_object_from_longest (obj->pc);
+ return gdb_py_object_from_longest (obj->pc).release ();
}
/* LineTable iterator functions. */
ltpy_iterator_object *iter_obj = (ltpy_iterator_object *) obj;
Py_DECREF (iter_obj->source);
+ Py_TYPE (obj)->tp_free (obj);
}
/* Return a reference to the line table iterator. */