diff options
author | Tom Tromey <tom@tromey.com> | 2018-06-05 10:02:45 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-06-27 14:50:10 -0600 |
commit | 0c6aef226ede6ef6547adb170fb5afb002e96257 (patch) | |
tree | dd3e16398c5500834e1b7b34fcfa6c793a6f5c53 /gdb | |
parent | 6317728958287f0876f04941267de5d87eefa578 (diff) | |
download | gdb-0c6aef226ede6ef6547adb170fb5afb002e96257.zip gdb-0c6aef226ede6ef6547adb170fb5afb002e96257.tar.gz gdb-0c6aef226ede6ef6547adb170fb5afb002e96257.tar.bz2 |
Remove a VEC from py-unwind.c
This removes a use of VEC from py-unwind.c, replacing it wit
std::vector. It also changes saved_regs to hold a gdbpy_ref<>,
simplifying the memory management.
Tested against gdb.python on x86-64 Fedora 26.
gdb/ChangeLog
2018-06-27 Tom Tromey <tom@tromey.com>
* python/py-unwind.c (unwind_info_object) <saved_regs>: Now a
std::vector.
(unwind_infopy_str, pyuw_create_unwind_info)
(unwind_infopy_add_saved_register, pyuw_sniffer)
(unwind_infopy_dealloc, unwind_infopy_add_saved_register):
Update.
(struct saved_reg): Add constructor.
<value>: Now a gdbpy_ref<>.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 11 | ||||
-rw-r--r-- | gdb/python/py-unwind.c | 60 |
2 files changed, 39 insertions, 32 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a125b72..2075f47 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,16 @@ 2018-06-27 Tom Tromey <tom@tromey.com> + * python/py-unwind.c (unwind_info_object) <saved_regs>: Now a + std::vector. + (unwind_infopy_str, pyuw_create_unwind_info) + (unwind_infopy_add_saved_register, pyuw_sniffer) + (unwind_infopy_dealloc, unwind_infopy_add_saved_register): + Update. + (struct saved_reg): Add constructor. + <value>: Now a gdbpy_ref<>. + +2018-06-27 Tom Tromey <tom@tromey.com> + * machoread.c (macho_symfile_read): Define "symbol_table" earlier. 2018-06-27 Simon Marchi <simon.marchi@ericsson.com> diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index 1d235fc..569d1f4 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -46,12 +46,17 @@ typedef struct /* Saved registers array item. */ -typedef struct +struct saved_reg { + saved_reg (int n, gdbpy_ref<> &&v) + : number (n), + value (std::move (v)) + { + } + int number; - PyObject *value; -} saved_reg; -DEF_VEC_O (saved_reg); + gdbpy_ref<> value; +}; /* The data we keep for the PyUnwindInfo: pending_frame, saved registers and frame ID. */ @@ -67,7 +72,7 @@ typedef struct struct frame_id frame_id; /* Saved registers array. */ - VEC (saved_reg) *saved_regs; + std::vector<saved_reg> *saved_regs; } unwind_info_object; /* The data we keep for a frame we can unwind: frame ID and an array of @@ -196,17 +201,15 @@ unwind_infopy_str (PyObject *self) fprint_frame_id (&stb, unwind_info->frame_id); { const char *sep = ""; - int i; struct value_print_options opts; - saved_reg *reg; get_user_print_options (&opts); stb.printf ("\nSaved registers: ("); - for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++) + for (const saved_reg ® : *unwind_info->saved_regs) { - struct value *value = value_object_to_value (reg->value); + struct value *value = value_object_to_value (reg.value.get ()); - stb.printf ("%s(%d, ", sep, reg->number); + stb.printf ("%s(%d, ", sep, reg.number); if (value != NULL) { TRY @@ -249,7 +252,7 @@ pyuw_create_unwind_info (PyObject *pyo_pending_frame, unwind_info->frame_id = frame_id; Py_INCREF (pyo_pending_frame); unwind_info->pending_frame = pyo_pending_frame; - unwind_info->saved_regs = VEC_alloc (saved_reg, 4); + unwind_info->saved_regs = new std::vector<saved_reg>; return (PyObject *) unwind_info; } @@ -303,24 +306,19 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args) } } { - int i; - saved_reg *reg; - - for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++) + gdbpy_ref<> new_value = gdbpy_ref<>::new_reference (pyo_reg_value); + bool found = false; + for (saved_reg ® : *unwind_info->saved_regs) { - if (regnum == reg->number) + if (regnum == reg.number) { - Py_DECREF (reg->value); + found = true; + reg.value = std::move (new_value); break; } } - if (reg == NULL) - { - reg = VEC_safe_push (saved_reg, unwind_info->saved_regs, NULL); - reg->number = regnum; - } - Py_INCREF (pyo_reg_value); - reg->value = pyo_reg_value; + if (!found) + unwind_info->saved_regs->emplace_back (regnum, std::move (new_value)); } Py_RETURN_NONE; } @@ -335,9 +333,7 @@ unwind_infopy_dealloc (PyObject *self) saved_reg *reg; Py_XDECREF (unwind_info->pending_frame); - for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++) - Py_DECREF (reg->value); - VEC_free (saved_reg, unwind_info->saved_regs); + delete unwind_info->saved_regs; Py_TYPE (self)->tp_free (self); } @@ -560,9 +556,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, { unwind_info_object *unwind_info = (unwind_info_object *) pyo_unwind_info.get (); - int reg_count = VEC_length (saved_reg, unwind_info->saved_regs); - saved_reg *reg; - int i; + int reg_count = unwind_info->saved_regs->size (); cached_frame = ((cached_frame_info *) @@ -573,9 +567,11 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, cached_frame->reg_count = reg_count; /* Populate registers array. */ - for (i = 0; VEC_iterate (saved_reg, unwind_info->saved_regs, i, reg); i++) + for (int i = 0; i < unwind_info->saved_regs->size (); ++i) { - struct value *value = value_object_to_value (reg->value); + saved_reg *reg = &(*unwind_info->saved_regs)[i]; + + struct value *value = value_object_to_value (reg->value.get ()); size_t data_size = register_size (gdbarch, reg->number); cached_frame->reg[i].num = reg->number; |