Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/5] Don't memset non-POD types: struct btrace_insn
Date: Thu, 13 Apr 2017 02:28:00 -0000	[thread overview]
Message-ID: <1492050475-9238-5-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1492050475-9238-1-git-send-email-palves@redhat.com>

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:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

	* btrace.c (pt_btrace_insn): New function.
	(ftrace_add_pt): Remove memset call and use pt_btrace_insn.
---
 gdb/btrace.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/gdb/btrace.c b/gdb/btrace.c
index 95dc7ab..30359b6 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1122,6 +1122,17 @@ pt_btrace_insn_flags (const struct pt_insn *insn)
   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


  parent reply	other threads:[~2017-04-13  2:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-13  2:27 [PATCH 0/4] Poison non-POD memset & non-trivially-copyable memcpy/memmove Pedro Alves
2017-04-13  2:28 ` [PATCH 3/5] Don't memset non-POD types: struct bp_location Pedro Alves
2017-04-13  2:28 ` [PATCH 1/5] Poison non-POD memset & non-trivially-copyable memcpy/memmove Pedro Alves
2017-04-20  3:27   ` Simon Marchi
2017-04-25  1:14     ` Pedro Alves
2017-04-25  1:19       ` Pedro Alves
2017-04-25  8:24       ` Yao Qi
2017-04-25  9:24         ` Pedro Alves
2017-04-25 10:02           ` Pedro Alves
2017-04-24  1:12   ` Simon Marchi
2017-04-24  1:53     ` Simon Marchi
2017-04-27 13:58       ` Pedro Alves
2017-04-30  1:51         ` Simon Marchi
2017-05-17 11:35           ` Pedro Alves
2017-05-17 13:11             ` Simon Marchi
2017-05-17 13:20               ` Pedro Alves
2017-04-27 13:57     ` Pedro Alves
2017-04-13  2:28 ` Pedro Alves [this message]
2017-04-13  7:57   ` [PATCH 4/5] Don't memset non-POD types: struct btrace_insn Metzger, Markus T
2017-04-25  1:11     ` Pedro Alves
2017-04-13  2:28 ` [PATCH 2/5] Don't memcpy non-trivially-copyable types: Make enum_flags triv. copyable Pedro Alves
2017-04-20  3:34   ` Simon Marchi
2017-04-25  1:10     ` Pedro Alves
2017-04-13  2:35 ` [PATCH 5/5] Don't memset non-POD types: struct breakpoint Pedro Alves
2017-04-20  4:00   ` Simon Marchi
2017-04-25  1:11     ` Pedro Alves

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=1492050475-9238-5-git-send-email-palves@redhat.com \
    --to=palves@redhat.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