From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 01/10] remote: struct remote_state, use op new
Date: Wed, 16 May 2018 14:18:00 -0000 [thread overview]
Message-ID: <20180516141830.16859-2-palves@redhat.com> (raw)
In-Reply-To: <20180516141830.16859-1-palves@redhat.com>
A bit of C++ification.
gdb/ChangeLog:
yyyy-mm-dd Pedro Alves <palves@redhat.com>
(struct vCont_action_support): Use bool and initialize all fields.
(struct readahead_cache): Initialize all fields.
(remote_state): Use bool and initialize all fields.
(remote_state::remote_state, ~remote_state::remote_state): New.
(new_remote_state): Delete.
(_initialize_remote): Use new to allocate remote_state.
---
gdb/remote.c | 115 +++++++++++++++++++++++++++++------------------------------
1 file changed, 56 insertions(+), 59 deletions(-)
diff --git a/gdb/remote.c b/gdb/remote.c
index 58ed9e4f4d..ca72c1a1c2 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -541,16 +541,16 @@ static struct cmd_list_element *remote_show_cmdlist;
struct vCont_action_support
{
/* vCont;t */
- int t;
+ bool t = false;
/* vCont;r */
- int r;
+ bool r = false;
/* vCont;s */
- int s;
+ bool s = false;
/* vCont;S */
- int S;
+ bool S = false;
};
/* Controls whether GDB is willing to use range stepping. */
@@ -577,21 +577,21 @@ struct readahead_cache
{
/* The file descriptor for the file that is being cached. -1 if the
cache is invalid. */
- int fd;
+ int fd = -1;
/* The offset into the file that the cache buffer corresponds
to. */
- ULONGEST offset;
+ ULONGEST offset = 0;
/* The buffer holding the cache contents. */
- gdb_byte *buf;
+ gdb_byte *buf = nullptr;
/* The buffer's size. We try to read as much as fits into a packet
at a time. */
- size_t bufsize;
+ size_t bufsize = 0;
/* Cache hit and miss counters. */
- ULONGEST hit_count;
- ULONGEST miss_count;
+ ULONGEST hit_count = 0;
+ ULONGEST miss_count = 0;
};
/* Description of the remote protocol state for the currently
@@ -600,6 +600,9 @@ struct readahead_cache
struct remote_state
{
+ remote_state ();
+ ~remote_state ();
+
/* A buffer to use for incoming packets, and its current size. The
buffer is grown dynamically for larger incoming packets.
Outgoing packets may also be constructed in this buffer.
@@ -611,13 +614,13 @@ struct remote_state
/* True if we're going through initial connection setup (finding out
about the remote side's threads, relocating symbols, etc.). */
- int starting_up;
+ bool starting_up = false;
/* If we negotiated packet size explicitly (and thus can bypass
heuristics for the largest packet size that will not overflow
a buffer in the stub), this will be set to that packet size.
Otherwise zero, meaning to use the guessed size. */
- long explicit_packet_size;
+ long explicit_packet_size = 0;
/* remote_wait is normally called when the target is running and
waits for a stop reply packet. But sometimes we need to call it
@@ -626,15 +629,15 @@ struct remote_state
the response, we can stash it in BUF and tell remote_wait to
skip calling getpkt. This flag is set when BUF contains a
stop reply packet and the target is not waiting. */
- int cached_wait_status;
+ int cached_wait_status = 0;
/* True, if in no ack mode. That is, neither GDB nor the stub will
expect acks from each other. The connection is assumed to be
reliable. */
- int noack_mode;
+ bool noack_mode = false;
/* True if we're connected in extended remote mode. */
- int extended;
+ bool extended = false;
/* True if we resumed the target and we're waiting for the target to
stop. In the mean time, we can't start another command/query.
@@ -642,14 +645,14 @@ struct remote_state
timeout waiting for a reply that would never come and eventually
we'd close the connection. This can happen in asynchronous mode
because we allow GDB commands while the target is running. */
- int waiting_for_stop_reply;
+ bool waiting_for_stop_reply = false;
/* The status of the stub support for the various vCont actions. */
- struct vCont_action_support supports_vCont;
+ vCont_action_support supports_vCont;
- /* Nonzero if the user has pressed Ctrl-C, but the target hasn't
+ /* True if the user has pressed Ctrl-C, but the target hasn't
responded to that. */
- int ctrlc_pending_p;
+ bool ctrlc_pending_p = false;
/* True if we saw a Ctrl-C while reading or writing from/to the
remote descriptor. At that point it is not safe to send a remote
@@ -657,12 +660,12 @@ struct remote_state
process it once we're done with sending/receiving the current
packet, which should be shortly. If however that takes too long,
and the user presses Ctrl-C again, we offer to disconnect. */
- int got_ctrlc_during_io;
+ bool got_ctrlc_during_io = false;
/* Descriptor for I/O to remote machine. Initialize it to NULL so that
remote_open knows that we don't have a file open when the program
starts. */
- struct serial *remote_desc;
+ struct serial *remote_desc = nullptr;
/* These are the threads which we last sent to the remote system. The
TID member will be -1 for all or -2 for not sent yet. */
@@ -671,26 +674,26 @@ struct remote_state
/* This is the traceframe which we last selected on the remote system.
It will be -1 if no traceframe is selected. */
- int remote_traceframe_number;
+ int remote_traceframe_number = -1;
- char *last_pass_packet;
+ char *last_pass_packet = nullptr;
/* The last QProgramSignals packet sent to the target. We bypass
sending a new program signals list down to the target if the new
packet is exactly the same as the last we sent. IOW, we only let
the target know about program signals list changes. */
- char *last_program_signals_packet;
+ char *last_program_signals_packet = nullptr;
- enum gdb_signal last_sent_signal;
+ gdb_signal last_sent_signal = GDB_SIGNAL_0;
- int last_sent_step;
+ bool last_sent_step = false;
/* The execution direction of the last resume we got. */
- enum exec_direction_kind last_resume_exec_dir;
+ exec_direction_kind last_resume_exec_dir = EXEC_FORWARD;
- char *finished_object;
- char *finished_annex;
- ULONGEST finished_offset;
+ char *finished_object = nullptr;
+ char *finished_annex = nullptr;
+ ULONGEST finished_offset = 0;
/* Should we try the 'ThreadInfo' query packet?
@@ -699,24 +702,24 @@ struct remote_state
query or the older, more complex syntax for thread queries.
This is an auto-detect variable (set to true at each connect,
and set to false when the target fails to recognize it). */
- int use_threadinfo_query;
- int use_threadextra_query;
+ bool use_threadinfo_query = false;
+ bool use_threadextra_query = false;
- threadref echo_nextthread;
- threadref nextthread;
- threadref resultthreadlist[MAXTHREADLISTRESULTS];
+ threadref echo_nextthread {};
+ threadref nextthread {};
+ threadref resultthreadlist[MAXTHREADLISTRESULTS] {};
/* The state of remote notification. */
- struct remote_notif_state *notif_state;
+ struct remote_notif_state *notif_state = nullptr;
/* The branch trace configuration. */
- struct btrace_config btrace_config;
+ struct btrace_config btrace_config {};
/* The argument to the last "vFile:setfs:" packet we sent, used
to avoid sending repeated unnecessary "vFile:setfs:" packets.
Initialized to -1 to indicate that no "vFile:setfs:" packet
has yet been sent. */
- int fs_pid;
+ int fs_pid = -1;
/* A readahead cache for vFile:pread. Often, reading a binary
involves a sequence of small reads. E.g., when parsing an ELF
@@ -764,6 +767,20 @@ struct remote_thread_info : public private_thread_info
int vcont_resumed = 0;
};
+remote_state::remote_state ()
+{
+ /* The default buffer size is unimportant; it will be expanded
+ whenever a larger buffer is needed. */
+ this->buf_size = 400;
+ this->buf = (char *) xmalloc (this->buf_size);
+}
+
+remote_state::~remote_state ()
+{
+ xfree (this->last_pass_packet);
+ xfree (this->last_program_signals_packet);
+}
+
/* This data could be associated with a target, but we do not always
have access to the current target when we need it, so for now it is
static. This will be fine for as long as only one target is in use
@@ -776,26 +793,6 @@ get_remote_state_raw (void)
return remote_state;
}
-/* Allocate a new struct remote_state with xmalloc, initialize it, and
- return it. */
-
-static struct remote_state *
-new_remote_state (void)
-{
- struct remote_state *result = XCNEW (struct remote_state);
-
- /* The default buffer size is unimportant; it will be expanded
- whenever a larger buffer is needed. */
- result->buf_size = 400;
- result->buf = (char *) xmalloc (result->buf_size);
- result->remote_traceframe_number = -1;
- result->last_sent_signal = GDB_SIGNAL_0;
- result->last_resume_exec_dir = EXEC_FORWARD;
- result->fs_pid = -1;
-
- return result;
-}
-
/* Description of the remote protocol for a given architecture. */
struct packet_reg
@@ -14010,7 +14007,7 @@ _initialize_remote (void)
/* Initialize the per-target state. At the moment there is only one
of these, not one per target. Only one target is active at a
time. */
- remote_state = new_remote_state ();
+ remote_state = new struct remote_state ();
add_target (remote_target_info, remote_target::open);
add_target (extended_remote_target_info, extended_remote_target::open);
--
2.14.3
next prev parent reply other threads:[~2018-05-16 14:18 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-16 14:18 [PATCH 00/10] remote: More multi-target preparation Pedro Alves
2018-05-16 14:18 ` Pedro Alves [this message]
2018-05-18 20:57 ` [PATCH 01/10] remote: struct remote_state, use op new Simon Marchi
2018-05-21 15:36 ` [PATCH 1.2 01/10] remote: struct remote_state, use op new, fix leaks Pedro Alves
2018-05-16 14:18 ` [PATCH 09/10] remote: Make vcont_builder a class Pedro Alves
2018-05-22 5:07 ` Simon Marchi
2018-05-22 21:33 ` Pedro Alves
2018-05-16 14:18 ` [PATCH 02/10] remote: Eliminate remote_hostio_close_cleanup Pedro Alves
2018-05-16 17:43 ` Tom Tromey
2018-05-16 18:53 ` Pedro Alves
2018-05-16 19:46 ` Tom Tromey
2018-05-18 21:04 ` Simon Marchi
2018-05-16 14:18 ` [PATCH 10/10] remote: one struct remote_state per struct remote_target Pedro Alves
2018-05-22 5:07 ` Simon Marchi
2018-05-22 21:06 ` Pedro Alves
2018-05-24 17:00 ` [PATCH 11/10] remote_target::m_remote_state, pointer -> object (Re: [PATCH 10/10] remote: one struct remote_state per struct remote_target) Pedro Alves
2018-05-25 5:23 ` Simon Marchi
2018-05-16 14:25 ` [PATCH 05/10] remote: remote_arch_state pointers -> remote_arch_state objects Pedro Alves
2018-05-18 21:17 ` Simon Marchi
2018-05-18 21:18 ` Simon Marchi
2018-05-21 16:12 ` Pedro Alves
2018-05-16 14:25 ` [PATCH 03/10] remote: Make readahead_cache a C++ class Pedro Alves
2018-05-18 21:06 ` Simon Marchi
2018-05-16 14:27 ` [PATCH 04/10] remote: multiple remote_arch_state instances per arch Pedro Alves
2018-05-18 21:09 ` Simon Marchi
2018-05-16 14:28 ` [PATCH 08/10] Handle "show remote memory-write-packet-size" when not connected Pedro Alves
2018-05-18 21:42 ` Simon Marchi
2018-05-21 20:41 ` Pedro Alves
2018-05-22 3:37 ` Simon Marchi
2018-05-22 21:55 ` Sergio Durigan Junior
2018-05-22 23:26 ` [pushed] Fix gdb.base/remote.exp with native-extended-gdbserver board (Re: [PATCH 08/10] Handle "show remote memory-write-packet-size" when not connected) Pedro Alves
2018-05-16 15:46 ` [PATCH 07/10] remote: Move discard_pending_stop_replies call Pedro Alves
2018-05-18 21:29 ` Simon Marchi
2018-05-16 15:50 ` [PATCH 06/10] remote: Small cleanup in compare_section_command Pedro Alves
2018-05-18 21:26 ` 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=20180516141830.16859-2-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).