From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH] Introduce skip_to_char and use it
Date: Tue, 26 Jan 2016 21:54:00 -0000 [thread overview]
Message-ID: <1453845250-30360-1-git-send-email-simon.marchi@ericsson.com> (raw)
For a forthcoming patch, I need a "skip_to_colon" function. I noticed
there are two skip_to_semicolon (one in gdb and one in gdbserver).
I thought we could put it in common/, and generalize it for any
character. To me,
p = skip_to_char (p, ';');
is at least as clear as
p = skip_to_semicolon (p);
so I decided to just remove skip_to_semicolon and use skip_to_char.
gdb/ChangeLog:
* common/common-utils.h (skip_to_char): New declaration.
* common/common-utils.c (skip_to_char): New function.
* remote.c (skip_to_semicolon): Remove.
(remote_parse_stop_reply): Use skip_to_char instead of
skip_to_semicolon.
gdb/gdbserver/ChangeLog:
* server.c (skip_to_semicolon): Remove.
(process_point_options): Use skip_to_char instead of
skip_to_semicolon.
---
gdb/common/common-utils.c | 12 ++++++++++++
gdb/common/common-utils.h | 5 +++++
gdb/gdbserver/server.c | 15 +++------------
gdb/remote.c | 26 ++++++++------------------
4 files changed, 28 insertions(+), 30 deletions(-)
diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index 33668f3..32720b2 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -288,3 +288,15 @@ skip_to_space_const (const char *chp)
chp++;
return chp;
}
+
+char *
+skip_to_char (char *chp, char to)
+{
+ if (chp == NULL)
+ return NULL;
+
+ while (*chp != '\0' && *chp != to)
+ chp++;
+
+ return chp;
+}
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index 47def11..67b9df7 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -97,4 +97,9 @@ extern const char *skip_spaces_const (const char *inp);
extern const char *skip_to_space_const (const char *inp);
+/* Skip characters until CHP points to a character with value TO, or the end of
+ the string. Return the updated pointer. If CHP is NULL, return NULL. */
+
+extern char *skip_to_char (char *chp, char to);
+
#endif
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 301dea9..6d70ee7 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3820,15 +3820,6 @@ main (int argc, char *argv[])
gdb_assert_not_reached ("captured_main should never return");
}
-/* Skip PACKET until the next semi-colon (or end of string). */
-
-static void
-skip_to_semicolon (char **packet)
-{
- while (**packet != '\0' && **packet != ';')
- (*packet)++;
-}
-
/* Process options coming from Z packets for a breakpoint. PACKET is
the packet buffer. *PACKET is updated to point to the first char
after the last processed option. */
@@ -3856,7 +3847,7 @@ process_point_options (struct breakpoint *bp, char **packet)
if (debug_threads)
debug_printf ("Found breakpoint condition.\n");
if (!add_breakpoint_condition (bp, &dataptr))
- skip_to_semicolon (&dataptr);
+ dataptr = skip_to_char (dataptr, ';');
}
else if (startswith (dataptr, "cmds:"))
{
@@ -3866,14 +3857,14 @@ process_point_options (struct breakpoint *bp, char **packet)
persist = (*dataptr == '1');
dataptr += 2;
if (add_breakpoint_commands (bp, &dataptr, persist))
- skip_to_semicolon (&dataptr);
+ dataptr = skip_to_char (dataptr, ';');
}
else
{
fprintf (stderr, "Unknown token %c, ignoring.\n",
*dataptr);
/* Skip tokens until we find one that we recognize. */
- skip_to_semicolon (&dataptr);
+ dataptr = skip_to_char (dataptr, ';');
}
}
*packet = dataptr;
diff --git a/gdb/remote.c b/gdb/remote.c
index b0303f6..a65a384 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -6387,16 +6387,6 @@ peek_stop_reply (ptid_t ptid)
stop_reply_match_ptid_and_ws, &ptid);
}
-/* Skip PACKET until the next semi-colon (or end of string). */
-
-static char *
-skip_to_semicolon (char *p)
-{
- while (*p != '\0' && *p != ';')
- p++;
- return p;
-}
-
/* Helper for remote_parse_stop_reply. Return nonzero if the substring
starting with P and ending with PEND matches PREFIX. */
@@ -6499,7 +6489,7 @@ Packet: '%s'\n"),
/* The value part is documented as "must be empty",
though we ignore it, in case we ever decide to make
use of it in a backward compatible way. */
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
}
else if (strprefix (p, p1, "hwbreak"))
{
@@ -6511,19 +6501,19 @@ Packet: '%s'\n"),
error (_("Unexpected hwbreak stop reason"));
/* See above. */
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
}
else if (strprefix (p, p1, "library"))
{
event->ws.kind = TARGET_WAITKIND_LOADED;
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
}
else if (strprefix (p, p1, "replaylog"))
{
event->ws.kind = TARGET_WAITKIND_NO_HISTORY;
/* p1 will indicate "begin" or "end", but it makes
no difference for now, so ignore it. */
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
}
else if (strprefix (p, p1, "core"))
{
@@ -6545,7 +6535,7 @@ Packet: '%s'\n"),
else if (strprefix (p, p1, "vforkdone"))
{
event->ws.kind = TARGET_WAITKIND_VFORK_DONE;
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
}
else if (strprefix (p, p1, "exec"))
{
@@ -6574,7 +6564,7 @@ Packet: '%s'\n"),
else if (strprefix (p, p1, "create"))
{
event->ws.kind = TARGET_WAITKIND_THREAD_CREATED;
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
}
else
{
@@ -6583,7 +6573,7 @@ Packet: '%s'\n"),
if (skipregs)
{
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
p++;
continue;
}
@@ -6620,7 +6610,7 @@ Packet: '%s'\n"),
{
/* Not a number. Silently skip unknown optional
info. */
- p = skip_to_semicolon (p1 + 1);
+ p = skip_to_char (p1 + 1, ';');
}
}
--
2.5.1
next reply other threads:[~2016-01-26 21:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-26 21:54 Simon Marchi [this message]
2016-01-27 1:32 ` Sergio Durigan Junior
2016-01-27 11:22 ` Pedro Alves
2016-01-27 11:53 ` Andreas Schwab
2016-01-27 18:04 ` Sergio Durigan Junior
2016-01-27 18:27 ` Simon Marchi
2016-01-27 21:04 ` 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=1453845250-30360-1-git-send-email-simon.marchi@ericsson.com \
--to=simon.marchi@ericsson.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