Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: "gdb-patches@sourceware.org ml" <gdb-patches@sourceware.org>
Subject: [RFA] Constify find_condition_and_thread
Date: Fri, 01 Mar 2013 18:18:00 -0000	[thread overview]
Message-ID: <5130F0FD.2040203@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 566 bytes --]

Hi,

I'm getting ready to submit a rewrite of my explicit location patchset, 
and I found $SUBJECT to be necessary.

I admit, I am not 100% happy with this, but the use of parse_exp_1 
really complicates things. I made an attempt at "fixing" parse_exp_1, 
but that leads to an enormous maze of changes.

Comments?
Keith

ChangeLog
  2012-03-01  Keith Seitz  <keiths@redhat.com>

	* cli/cli-utils.c (skip_to_space_const): New function.
	* cli/cli-utils.h (skip_to_space_const): Declare.
	* breakpoint.c (find_condition_and_thread): Constify TOK
	and update function.

[-- Attachment #2: constify-find_condition_and_thread.patch --]
[-- Type: text/x-patch, Size: 3690 bytes --]

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index fb57a57..a1877e3 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9374,7 +9374,7 @@ invalid_thread_id_error (int id)
    If no thread is found, *THREAD is set to -1.  */
 
 static void
-find_condition_and_thread (char *tok, CORE_ADDR pc,
+find_condition_and_thread (const char *tok, CORE_ADDR pc,
 			   char **cond_string, int *thread, int *task,
 			   char **rest)
 {
@@ -9385,12 +9385,12 @@ find_condition_and_thread (char *tok, CORE_ADDR pc,
 
   while (tok && *tok)
     {
-      char *end_tok;
+      const char *end_tok;
       int toklen;
-      char *cond_start = NULL;
-      char *cond_end = NULL;
+      const char *cond_start = NULL;
+      const char *cond_end = NULL;
 
-      tok = skip_spaces (tok);
+      tok = skip_spaces_const (tok);
 
       if ((*tok == '"' || *tok == ',') && rest)
 	{
@@ -9398,41 +9398,57 @@ find_condition_and_thread (char *tok, CORE_ADDR pc,
 	  return;
 	}
 
-      end_tok = skip_to_space (tok);
+      end_tok = skip_to_space_const (tok);
 
       toklen = end_tok - tok;
 
       if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
 	{
+	  char *copy, *orig;
+	  struct cleanup *cleanup;
 	  struct expression *expr;
 
 	  tok = cond_start = end_tok + 1;
-	  expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
+	  orig = copy = xstrdup (tok);
+	  cleanup = make_cleanup (xfree, orig);
+	  expr = parse_exp_1 (&copy, pc, block_for_pc (pc), 0);
 	  xfree (expr);
+	  tok += copy - orig;
+	  do_cleanups (cleanup);
 	  cond_end = tok;
 	  *cond_string = savestring (cond_start, cond_end - cond_start);
 	}
       else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
 	{
-	  char *tmptok;
+	  char *tmptok, *copy;
 
 	  tok = end_tok + 1;
-	  tmptok = tok;
-	  *thread = strtol (tok, &tok, 0);
-	  if (tok == tmptok)
-	    error (_("Junk after thread keyword."));
+	  tmptok = copy = xstrdup (tok);
+	  *thread = strtol (copy, &copy, 0);
+	  if (copy == tmptok)
+	    {
+	      xfree (tmptok);
+	      error (_("Junk after thread keyword."));
+	    }
+	  tok += copy - tmptok;
+	  xfree (tmptok);
 	  if (!valid_thread_id (*thread))
 	    invalid_thread_id_error (*thread);
 	}
       else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0)
 	{
-	  char *tmptok;
+	  char *tmptok, *copy;
 
 	  tok = end_tok + 1;
-	  tmptok = tok;
-	  *task = strtol (tok, &tok, 0);
-	  if (tok == tmptok)
-	    error (_("Junk after task keyword."));
+	  tmptok = copy = xstrdup (tok);
+	  *task = strtol (copy, &copy, 0);
+	  if (copy == tmptok)
+	    {
+	      xfree (tmptok);
+	      error (_("Junk after task keyword."));
+	    }
+	  tok += copy - tmptok;
+	  xfree (tmptok);
 	  if (!valid_task_id (*task))
 	    error (_("Unknown task %d."), *task);
 	}
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index 933fb89..844dee4 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -247,6 +247,18 @@ skip_to_space (char *chp)
   return chp;
 }
 
+/* A const-correct version of the above.  */
+
+const char *
+skip_to_space_const (const char *chp)
+{
+  if (chp == NULL)
+    return NULL;
+  while (*chp && !isspace (*chp))
+    chp++;
+  return chp;
+}
+
 /* See documentation in cli-utils.h.  */
 
 char *
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 6f28e13..ae8ca7b 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -103,6 +103,10 @@ extern const char *skip_spaces_const (const char *inp);
 
 extern char *skip_to_space (char *inp);
 
+/* A const-correct version of the above.  */
+
+extern const char *skip_to_space_const (const char *inp);
+
 /* Reverse S to the last non-whitespace character without skipping past
    START.  */
 

             reply	other threads:[~2013-03-01 18:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-01 18:18 Keith Seitz [this message]
2013-03-01 18:40 ` Eli Zaretskii
2013-03-01 18:56   ` Pedro Alves
2013-03-01 19:33     ` Tom Tromey
2013-03-02  7:30       ` Eli Zaretskii
2013-03-01 18:56 ` 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=5130F0FD.2040203@redhat.com \
    --to=keiths@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