This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 4/5] Don't memset non-POD types: struct btrace_insn
On 04/13/2017 08:53 AM, Metzger, Markus T wrote:
>> -----Original Message-----
>> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
>> owner@sourceware.org] On Behalf Of Pedro Alves
>> Sent: Thursday, April 13, 2017 4:28 AM
>> To: gdb-patches@sourceware.org
>> Subject: [PATCH 4/5] Don't memset non-POD types: struct btrace_insn
>
> Hello Pedro,
Hi!
>
>> +/* Return the btrace instruction for INSN. */
>> +
>> +static btrace_insn
>> +pt_btrace_insn (const struct pt_insn &insn)
>> +{
>> + return {(CORE_ADDR) insn.ip, (gdb_byte) insn.size,
>> + pt_reclassify_insn (insn.iclass),
>> + pt_btrace_insn_flags (&insn)};
>> +}
>
> This is the only user of pt_btrace_insn_flags. If you want, you may
> change it to take a const & instead of a const *.
>
> The patch looks good to me.
Thanks Markus. Here's what I pushed now, then.
>From b5c3668253b909fd1f5b011893a35bb8dfd3be9b Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Tue, 25 Apr 2017 01:27:42 +0100
Subject: [PATCH] Don't memset non-POD types: struct btrace_insn
struct btrace_insn is not a POD [1] so we shouldn't be using memset to
initialize it [2].
Use list-initialization instead, wrapped in a "pt insn to btrace insn"
function, which looks like just begging to be added next to the
existing pt_reclassify_insn/pt_btrace_insn_flags functions.
[1] - because its field "flags" is not POD, because enum_flags has a
non-trivial default ctor.
gdb/ChangeLog:
2017-04-25 Pedro Alves <palves@redhat.com>
* btrace.c (pt_btrace_insn_flags): Change parameter type to
reference.
(pt_btrace_insn): New function.
(ftrace_add_pt): Remove memset call and use pt_btrace_insn.
---
gdb/ChangeLog | 7 +++++++
gdb/btrace.c | 23 ++++++++++++++---------
2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5df4a96..1b983b9 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
2017-04-25 Pedro Alves <palves@redhat.com>
+ * btrace.c (pt_btrace_insn_flags): Change parameter type to
+ reference.
+ (pt_btrace_insn): New function.
+ (ftrace_add_pt): Remove memset call and use pt_btrace_insn.
+
+2017-04-25 Pedro Alves <palves@redhat.com>
+
* ada-lang.c (ada_catchpoint_location): Now a "class". Remove
"base" field and inherit from "bp_location" instead. Add
non-default ctor.
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 95dc7ab..238df0a 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1112,16 +1112,27 @@ pt_reclassify_insn (enum pt_insn_class iclass)
/* Return the btrace instruction flags for INSN. */
static btrace_insn_flags
-pt_btrace_insn_flags (const struct pt_insn *insn)
+pt_btrace_insn_flags (const struct pt_insn &insn)
{
btrace_insn_flags flags = 0;
- if (insn->speculative)
+ if (insn.speculative)
flags |= BTRACE_INSN_FLAG_SPECULATIVE;
return flags;
}
+/* Return the btrace instruction for INSN. */
+
+static btrace_insn
+pt_btrace_insn (const struct pt_insn &insn)
+{
+ return {(CORE_ADDR) insn.ip, (gdb_byte) insn.size,
+ pt_reclassify_insn (insn.iclass),
+ pt_btrace_insn_flags (insn)};
+}
+
+
/* Add function branch trace using DECODER. */
static void
@@ -1138,7 +1149,6 @@ ftrace_add_pt (struct pt_insn_decoder *decoder,
end = *pend;
for (;;)
{
- struct btrace_insn btinsn;
struct pt_insn insn;
errcode = pt_insn_sync_forward (decoder);
@@ -1150,7 +1160,6 @@ ftrace_add_pt (struct pt_insn_decoder *decoder,
break;
}
- memset (&btinsn, 0, sizeof (btinsn));
for (;;)
{
errcode = pt_insn_next (decoder, &insn, sizeof(insn));
@@ -1207,11 +1216,7 @@ ftrace_add_pt (struct pt_insn_decoder *decoder,
/* Maintain the function level offset. */
*plevel = std::min (*plevel, end->level);
- btinsn.pc = (CORE_ADDR) insn.ip;
- btinsn.size = (gdb_byte) insn.size;
- btinsn.iclass = pt_reclassify_insn (insn.iclass);
- btinsn.flags = pt_btrace_insn_flags (&insn);
-
+ btrace_insn btinsn = pt_btrace_insn (insn);
ftrace_update_insns (end, &btinsn);
}
--
2.5.5