From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13999 invoked by alias); 1 Mar 2013 18:18:48 -0000 Received: (qmail 13984 invoked by uid 22791); 1 Mar 2013 18:18:47 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_SPAMHAUS_DROP,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,RP_MATCHES_RCVD,SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Mar 2013 18:18:39 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r21IIdBT003913 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 1 Mar 2013 13:18:39 -0500 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r21IIbPo004145 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO) for ; Fri, 1 Mar 2013 13:18:38 -0500 Message-ID: <5130F0FD.2040203@redhat.com> Date: Fri, 01 Mar 2013 18:18:00 -0000 From: Keith Seitz User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: "gdb-patches@sourceware.org ml" Subject: [RFA] Constify find_condition_and_thread Content-Type: multipart/mixed; boundary="------------040901080802080806020207" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2013-03/txt/msg00034.txt.bz2 This is a multi-part message in MIME format. --------------040901080802080806020207 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 566 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 * 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. --------------040901080802080806020207 Content-Type: text/x-patch; name="constify-find_condition_and_thread.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="constify-find_condition_and_thread.patch" Content-length: 3690 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. */ --------------040901080802080806020207--