From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 4/6] Simple cleanup removals in remote.c
Date: Mon, 16 Oct 2017 03:04:00 -0000 [thread overview]
Message-ID: <20171016030427.21349-5-tom@tromey.com> (raw)
In-Reply-To: <20171016030427.21349-1-tom@tromey.com>
This removes a few cleanups in remote.c using the usual techniques:
std::vector, unique_xmalloc_ptr, and gdb::def_vector.
ChangeLog
2017-10-15 Tom Tromey <tom@tromey.com>
* remote.c (remote_register_number_and_offset): Use std::vector.
(remote_set_syscall_catchpoint): Use gdb::unique_xmalloc_ptr.
(putpkt_binary): Use gdb::def_vector.
(compare_sections_command): Likewise.
---
gdb/ChangeLog | 7 ++++++
gdb/remote.c | 71 +++++++++++++++++++++++------------------------------------
2 files changed, 35 insertions(+), 43 deletions(-)
diff --git a/gdb/remote.c b/gdb/remote.c
index e2bdd115f9..43cc661daf 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -803,21 +803,15 @@ int
remote_register_number_and_offset (struct gdbarch *gdbarch, int regnum,
int *pnum, int *poffset)
{
- struct packet_reg *regs;
- struct cleanup *old_chain;
-
gdb_assert (regnum < gdbarch_num_regs (gdbarch));
- regs = XCNEWVEC (struct packet_reg, gdbarch_num_regs (gdbarch));
- old_chain = make_cleanup (xfree, regs);
+ std::vector<packet_reg> regs (gdbarch_num_regs (gdbarch));
- map_regcache_remote_table (gdbarch, regs);
+ map_regcache_remote_table (gdbarch, regs.data ());
*pnum = regs[regnum].pnum;
*poffset = regs[regnum].offset;
- do_cleanups (old_chain);
-
return *pnum != -1;
}
@@ -2062,7 +2056,7 @@ remote_set_syscall_catchpoint (struct target_ops *self,
int pid, int needed, int any_count,
int table_size, int *table)
{
- char *catch_packet;
+ const char *catch_packet;
enum packet_result result;
int n_sysno = 0;
@@ -2092,6 +2086,7 @@ remote_set_syscall_catchpoint (struct target_ops *self,
pid, needed, any_count, n_sysno);
}
+ gdb::unique_xmalloc_ptr<char> built_packet;
if (needed)
{
/* Prepare a packet with the sysno list, assuming max 8+1
@@ -2099,46 +2094,45 @@ remote_set_syscall_catchpoint (struct target_ops *self,
big, fallback on the non-selective packet. */
const int maxpktsz = strlen ("QCatchSyscalls:1") + n_sysno * 9 + 1;
- catch_packet = (char *) xmalloc (maxpktsz);
- strcpy (catch_packet, "QCatchSyscalls:1");
+ built_packet.reset ((char *) xmalloc (maxpktsz));
+ strcpy (built_packet.get (), "QCatchSyscalls:1");
if (!any_count)
{
int i;
char *p;
- p = catch_packet;
+ p = built_packet.get ();
p += strlen (p);
/* Add in catch_packet each syscall to be caught (table[i] != 0). */
for (i = 0; i < table_size; i++)
{
if (table[i] != 0)
- p += xsnprintf (p, catch_packet + maxpktsz - p, ";%x", i);
+ p += xsnprintf (p, built_packet.get () + maxpktsz - p,
+ ";%x", i);
}
}
- if (strlen (catch_packet) > get_remote_packet_size ())
+ if (strlen (built_packet.get ()) > get_remote_packet_size ())
{
/* catch_packet too big. Fallback to less efficient
non selective mode, with GDB doing the filtering. */
- catch_packet[sizeof ("QCatchSyscalls:1") - 1] = 0;
+ catch_packet = "QCatchSyscalls:1";
}
+ else
+ catch_packet = built_packet.get ();
}
else
- catch_packet = xstrdup ("QCatchSyscalls:0");
+ catch_packet = "QCatchSyscalls:0";
- {
- struct cleanup *old_chain = make_cleanup (xfree, catch_packet);
- struct remote_state *rs = get_remote_state ();
+ struct remote_state *rs = get_remote_state ();
- putpkt (catch_packet);
- getpkt (&rs->buf, &rs->buf_size, 0);
- result = packet_ok (rs->buf, &remote_protocol_packets[PACKET_QCatchSyscalls]);
- do_cleanups (old_chain);
- if (result == PACKET_OK)
- return 0;
- else
- return -1;
- }
+ putpkt (catch_packet);
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ result = packet_ok (rs->buf, &remote_protocol_packets[PACKET_QCatchSyscalls]);
+ if (result == PACKET_OK)
+ return 0;
+ else
+ return -1;
}
/* If 'QProgramSignals' is supported, tell the remote stub what
@@ -8762,8 +8756,8 @@ putpkt_binary (const char *buf, int cnt)
struct remote_state *rs = get_remote_state ();
int i;
unsigned char csum = 0;
- char *buf2 = (char *) xmalloc (cnt + 6);
- struct cleanup *old_chain = make_cleanup (xfree, buf2);
+ gdb::def_vector<char> data (cnt + 6);
+ char *buf2 = data.data ();
int ch;
int tcount = 0;
@@ -8866,7 +8860,6 @@ putpkt_binary (const char *buf, int cnt)
case '+':
if (remote_debug)
fprintf_unfiltered (gdb_stdlog, "Ack\n");
- do_cleanups (old_chain);
return 1;
case '-':
if (remote_debug)
@@ -8875,10 +8868,7 @@ putpkt_binary (const char *buf, int cnt)
case SERIAL_TIMEOUT:
tcount++;
if (tcount > 3)
- {
- do_cleanups (old_chain);
- return 0;
- }
+ return 0;
break; /* Retransmit buffer. */
case '$':
{
@@ -8962,7 +8952,6 @@ putpkt_binary (const char *buf, int cnt)
#endif
}
- do_cleanups (old_chain);
return 0;
}
@@ -10331,7 +10320,6 @@ static void
compare_sections_command (const char *args, int from_tty)
{
asection *s;
- struct cleanup *old_chain;
gdb_byte *sectdata;
const char *sectname;
bfd_size_type size;
@@ -10372,11 +10360,10 @@ compare_sections_command (const char *args, int from_tty)
matched = 1; /* Do this section. */
lma = s->lma;
- sectdata = (gdb_byte *) xmalloc (size);
- old_chain = make_cleanup (xfree, sectdata);
- bfd_get_section_contents (exec_bfd, s, sectdata, 0, size);
+ gdb::def_vector<gdb_byte> sectdata (size);
+ bfd_get_section_contents (exec_bfd, s, sectdata.data (), 0, size);
- res = target_verify_memory (sectdata, lma, size);
+ res = target_verify_memory (sectdata.data (), lma, size);
if (res == -1)
error (_("target memory fault, section %s, range %s -- %s"), sectname,
@@ -10393,8 +10380,6 @@ compare_sections_command (const char *args, int from_tty)
printf_filtered ("MIS-MATCHED!\n");
mismatched++;
}
-
- do_cleanups (old_chain);
}
if (mismatched > 0)
warning (_("One or more sections of the target image does not match\n\
--
2.13.6
next prev parent reply other threads:[~2017-10-16 3:04 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-16 3:04 [RFA 0/6] more cleanup removals Tom Tromey
2017-10-16 3:04 ` [RFA 3/6] Remove cleanup from ppc-linux-nat.c Tom Tromey
2017-10-16 20:28 ` Simon Marchi
2017-10-16 3:04 ` [RFA 1/6] Use std::vector in end_symtab_get_static_block Tom Tromey
2017-10-16 20:18 ` Simon Marchi
2017-10-16 21:59 ` Tom Tromey
2017-10-20 15:33 ` Ulrich Weigand
2017-10-20 16:47 ` Pedro Alves
2017-10-23 16:16 ` Ulrich Weigand
2017-10-24 13:55 ` Tom Tromey
2017-10-24 14:41 ` [pushed] " Ulrich Weigand
2017-10-16 3:04 ` [RFA 6/6] Return unique_xmalloc_ptr from target_fileio_read_stralloc Tom Tromey
2017-10-16 21:07 ` Simon Marchi
2017-10-16 3:04 ` [RFA 2/6] Remove some cleanups from probe.c Tom Tromey
2017-10-16 20:26 ` Simon Marchi
2017-10-16 3:04 ` [RFA 5/6] Return unique_xmalloc_ptr from target_read_stralloc Tom Tromey
2017-10-16 21:02 ` Simon Marchi
2017-10-16 3:04 ` Tom Tromey [this message]
2017-10-16 20:43 ` [RFA 4/6] Simple cleanup removals in remote.c Simon Marchi
2017-10-16 21:14 ` Tom Tromey
2017-10-16 21:37 ` Simon Marchi
2017-10-16 21:50 ` Tom Tromey
2017-10-16 22:35 ` Pedro Alves
2017-10-16 23:00 ` Tom Tromey
2017-10-16 23:34 ` [PATCH 1/2] Introduce string_appendf/string_vappendf (Re: [RFA 4/6] Simple cleanup removals in remote.c) Pedro Alves
2017-10-19 3:11 ` Simon Marchi
2017-10-19 3:13 ` Simon Marchi
2017-10-30 0:16 ` Simon Marchi
2017-10-30 11:48 ` Pedro Alves
2017-10-16 23:38 ` [PATCH 2/2] remote.c, QCatchSyscalls: Build std::string instead of unique_xmalloc_ptr " Pedro Alves
2017-10-19 3:17 ` Simon Marchi
2017-10-30 11:49 ` 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=20171016030427.21349-5-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).