From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA] Remove a VEC from py-unwind.c
Date: Tue, 05 Jun 2018 16:04:00 -0000 [thread overview]
Message-ID: <20180605160450.19876-1-tom@tromey.com> (raw)
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-05 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<>.
---
gdb/ChangeLog | 11 +++++++++
gdb/python/py-unwind.c | 60 +++++++++++++++++++++++---------------------------
2 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 1d235fceed1..569d1f48d87 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;
--
2.13.6
next reply other threads:[~2018-06-05 16:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-05 16:04 Tom Tromey [this message]
2018-06-27 18:44 ` Andrew Burgess
2018-06-27 20:21 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180605160450.19876-1-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).