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 (©, 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, ©, 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, ©, 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. */