Change find_pcs_for_symtab_line to return a std::vector

This changes find_pcs_for_symtab_line to return a std::vector.  This
allows the removal of some cleanups.

gdb/ChangeLog
2017-04-12  Tom Tromey  <tom@tromey.com>

	* symtab.h (find_pcs_for_symtab_line): Change return type.
	* symtab.c (find_pcs_for_symtab_line): Change return type.
	* python/py-linetable.c (build_line_table_tuple_from_pcs): Change
	type of "vec".  Update.
	(ltpy_get_pcs_for_line): Update.
	* linespec.c (decode_digits_ordinary): Update.
This commit is contained in:
Tom Tromey 2017-04-06 16:38:56 -06:00
parent 93921405a4
commit 67d8990150
5 changed files with 28 additions and 30 deletions

View file

@ -1,3 +1,12 @@
2017-04-12 Tom Tromey <tom@tromey.com>
* symtab.h (find_pcs_for_symtab_line): Change return type.
* symtab.c (find_pcs_for_symtab_line): Change return type.
* python/py-linetable.c (build_line_table_tuple_from_pcs): Change
type of "vec". Update.
(ltpy_get_pcs_for_line): Update.
* linespec.c (decode_digits_ordinary): Update.
2017-04-12 Tom Tromey <tom@tromey.com> 2017-04-12 Tom Tromey <tom@tromey.com>
* tracepoint.c (actions_command): Update. * tracepoint.c (actions_command): Update.

View file

@ -3469,9 +3469,7 @@ decode_digits_ordinary (struct linespec_state *self,
for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); ++ix) for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); ++ix)
{ {
int i; std::vector<CORE_ADDR> pcs;
VEC (CORE_ADDR) *pcs;
CORE_ADDR pc;
/* The logic above should ensure this. */ /* The logic above should ensure this. */
gdb_assert (elt != NULL); gdb_assert (elt != NULL);
@ -3479,7 +3477,7 @@ decode_digits_ordinary (struct linespec_state *self,
set_current_program_space (SYMTAB_PSPACE (elt)); set_current_program_space (SYMTAB_PSPACE (elt));
pcs = find_pcs_for_symtab_line (elt, line, best_entry); pcs = find_pcs_for_symtab_line (elt, line, best_entry);
for (i = 0; VEC_iterate (CORE_ADDR, pcs, i, pc); ++i) for (CORE_ADDR pc : pcs)
{ {
struct symtab_and_line sal; struct symtab_and_line sal;
@ -3490,8 +3488,6 @@ decode_digits_ordinary (struct linespec_state *self,
sal.pc = pc; sal.pc = pc;
add_sal_to_sals_basic (sals, &sal); add_sal_to_sals_basic (sals, &sal);
} }
VEC_free (CORE_ADDR, pcs);
} }
} }

View file

@ -115,30 +115,28 @@ build_linetable_entry (int line, CORE_ADDR address)
return (PyObject *) obj; 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. 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 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. */ address. */
static PyObject * 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; int i;
vec_len = VEC_length (CORE_ADDR, vec); if (pcs.size () < 1)
if (vec_len < 1)
Py_RETURN_NONE; Py_RETURN_NONE;
gdbpy_ref<> tuple (PyTuple_New (vec_len)); gdbpy_ref<> tuple (PyTuple_New (pcs.size ()));
if (tuple == NULL) if (tuple == NULL)
return 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)); gdbpy_ref<> obj (build_linetable_entry (line, pc));
if (obj == NULL) if (obj == NULL)
@ -160,8 +158,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
struct symtab *symtab; struct symtab *symtab;
gdb_py_longest py_line; gdb_py_longest py_line;
struct linetable_entry *best_entry = NULL; struct linetable_entry *best_entry = NULL;
VEC (CORE_ADDR) *pcs = NULL; std::vector<CORE_ADDR> pcs;
PyObject *tuple;
LTPY_REQUIRE_VALID (self, symtab); LTPY_REQUIRE_VALID (self, symtab);
@ -178,10 +175,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
} }
END_CATCH END_CATCH
tuple = build_line_table_tuple_from_pcs (py_line, pcs); return build_line_table_tuple_from_pcs (py_line, pcs);
VEC_free (CORE_ADDR, pcs);
return tuple;
} }
/* Implementation of gdb.LineTable.has_line (self, line) -> Boolean. /* Implementation of gdb.LineTable.has_line (self, line) -> Boolean.

View file

@ -3289,15 +3289,15 @@ done:
} }
/* Given SYMTAB, returns all the PCs function in the symtab that /* Given SYMTAB, returns all the PCs function in the symtab that
exactly match LINE. Returns NULL if there are no exact matches, exactly match LINE. Returns an empty vector if there are no exact
but updates BEST_ITEM in this case. */ matches, but updates BEST_ITEM in this case. */
VEC (CORE_ADDR) * std::vector<CORE_ADDR>
find_pcs_for_symtab_line (struct symtab *symtab, int line, find_pcs_for_symtab_line (struct symtab *symtab, int line,
struct linetable_entry **best_item) struct linetable_entry **best_item)
{ {
int start = 0; int start = 0;
VEC (CORE_ADDR) *result = NULL; std::vector<CORE_ADDR> result;
/* First, collect all the PCs that are at this line. */ /* First, collect all the PCs that are at this line. */
while (1) while (1)
@ -3320,8 +3320,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line,
break; break;
} }
VEC_safe_push (CORE_ADDR, result, result.push_back (SYMTAB_LINETABLE (symtab)->item[idx].pc);
SYMTAB_LINETABLE (symtab)->item[idx].pc);
start = idx + 1; start = idx + 1;
} }

View file

@ -20,7 +20,7 @@
#if !defined (SYMTAB_H) #if !defined (SYMTAB_H)
#define SYMTAB_H 1 #define SYMTAB_H 1
#include "vec.h" #include <vector>
#include "gdb_vecs.h" #include "gdb_vecs.h"
#include "gdbtypes.h" #include "gdbtypes.h"
#include "common/enum-flags.h" #include "common/enum-flags.h"
@ -1618,8 +1618,8 @@ void iterate_over_symtabs (const char *name,
gdb::function_view<bool (symtab *)> callback); gdb::function_view<bool (symtab *)> callback);
VEC (CORE_ADDR) *find_pcs_for_symtab_line (struct symtab *symtab, int line, std::vector<CORE_ADDR> find_pcs_for_symtab_line
struct linetable_entry **best_entry); (struct symtab *symtab, int line, struct linetable_entry **best_entry);
/* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback /* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
is called once per matching symbol SYM. The callback should return is called once per matching symbol SYM. The callback should return