From: Alan Hayward <Alan.Hayward@arm.com>
To: Pedro Alves <palves@redhat.com>
Cc: Yao Qi <qiyaoltc@gmail.com>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
nd <nd@arm.com>
Subject: Re: [PATCH] Remove an instance of MAX_REGISTER_SIZE from record-full.c
Date: Thu, 22 Jun 2017 13:44:00 -0000 [thread overview]
Message-ID: <D85DADE7-7422-4320-8C6E-2B8F49CB6A3C@arm.com> (raw)
In-Reply-To: <ac1e5d07-afe4-45c3-5b00-d794329d87d2@redhat.com>
> On 21 Jun 2017, at 11:52, Pedro Alves <palves@redhat.com> wrote:
>
> On 06/12/2017 02:59 PM, Alan Hayward wrote:
>
>> diff --git a/gdb/record-full.c b/gdb/record-full.c
>> index 31ff558d2a633cff71d3e6082e42f5d6fb88bcf1..4f73e2a5ad0d4a2407b31a1d391e813147e15798 100644
>> --- a/gdb/record-full.c
>> +++ b/gdb/record-full.c
>> @@ -698,7 +698,7 @@ record_full_exec_insn (struct regcache *regcache,
>> {
>> case record_full_reg: /* reg */
>> {
>> - gdb_byte reg[MAX_REGISTER_SIZE];
>> + gdb_byte *reg = (gdb_byte *) xmalloc (entry->u.reg.len);
>>
>> if (record_debug > 1)
>> fprintf_unfiltered (gdb_stdlog,
>> @@ -711,6 +711,7 @@ record_full_exec_insn (struct regcache *regcache,
>> regcache_cooked_write (regcache, entry->u.reg.num,
>> record_full_get_loc (entry));
>> memcpy (record_full_get_loc (entry), reg, entry->u.reg.len);
>> + xfree (reg);
>
> You can use
> gdb::byte_vector reg (entry->u.reg.len);
> to avoid the explicit xfree here.
>
> (and a potential leak if regcache_* throws).
>
> Thanks,
> Pedro Alves
>
Updated and retested.
Ok to commit?
Alan.
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 13a0a78a52acdc20c8c4634118be941b1ff55871..c1a95a75ca67c6ad3b286e4b0ed892b27508108b 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -36,6 +36,7 @@
#include "observer.h"
#include "infrun.h"
#include "common/gdb_unlinker.h"
+#include "common/byte-vector.h"
#include <signal.h>
@@ -698,7 +699,7 @@ record_full_exec_insn (struct regcache *regcache,
{
case record_full_reg: /* reg */
{
- gdb_byte reg[MAX_REGISTER_SIZE];
+ gdb::byte_vector reg (entry->u.reg.len);
if (record_debug > 1)
fprintf_unfiltered (gdb_stdlog,
@@ -707,10 +708,10 @@ record_full_exec_insn (struct regcache *regcache,
host_address_to_string (entry),
entry->u.reg.num);
- regcache_cooked_read (regcache, entry->u.reg.num, reg);
+ regcache_cooked_read (regcache, entry->u.reg.num, reg.data ());
regcache_cooked_write (regcache, entry->u.reg.num,
record_full_get_loc (entry));
- memcpy (record_full_get_loc (entry), reg, entry->u.reg.len);
+ memcpy (record_full_get_loc (entry), reg.data (), entry->u.reg.len);
}
break;
next prev parent reply other threads:[~2017-06-22 13:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-12 9:34 Alan Hayward
2017-06-12 11:05 ` Yao Qi
2017-06-12 13:59 ` Alan Hayward
2017-06-21 9:31 ` Alan Hayward
2017-06-21 10:33 ` Yao Qi
2017-06-21 10:52 ` Pedro Alves
2017-06-22 13:44 ` Alan Hayward [this message]
2017-06-22 13:45 ` 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=D85DADE7-7422-4320-8C6E-2B8F49CB6A3C@arm.com \
--to=alan.hayward@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=nd@arm.com \
--cc=palves@redhat.com \
--cc=qiyaoltc@gmail.com \
/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).