aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Seitz <keiths@redhat.com>2013-10-02 00:46:07 +0000
committerKeith Seitz <keiths@redhat.com>2013-10-02 00:46:07 +0000
commitd7561cbbf27a8ff771f85baf6696aa7645250484 (patch)
treeeb81d452fe456e9a043cc453bf8b65617b40e915
parent62574b938f80a485874b85a770d03bf0f21eece5 (diff)
downloadgdb-d7561cbbf27a8ff771f85baf6696aa7645250484.zip
gdb-d7561cbbf27a8ff771f85baf6696aa7645250484.tar.gz
gdb-d7561cbbf27a8ff771f85baf6696aa7645250484.tar.bz2
Constification of parse_linespec and fallout:
https://sourceware.org/ml/gdb-patches/2013-09/msg01017.html https://sourceware.org/ml/gdb-patches/2013-09/msg01018.html https://sourceware.org/ml/gdb-patches/2013-09/msg01019.html https://sourceware.org/ml/gdb-patches/2013-09/msg01020.html
-rw-r--r--gdb/ChangeLog119
-rw-r--r--gdb/ada-exp.y15
-rw-r--r--gdb/ada-lex.l3
-rw-r--r--gdb/c-exp.y53
-rw-r--r--gdb/c-lang.h2
-rw-r--r--gdb/cli/cli-cmds.c2
-rw-r--r--gdb/cli/cli-setshow.c2
-rw-r--r--gdb/completer.c11
-rw-r--r--gdb/completer.h5
-rw-r--r--gdb/defs.h2
-rw-r--r--gdb/f-exp.y10
-rw-r--r--gdb/gdbtypes.c2
-rw-r--r--gdb/gdbtypes.h2
-rw-r--r--gdb/go-exp.y17
-rw-r--r--gdb/jv-exp.y20
-rw-r--r--gdb/linespec.c42
-rw-r--r--gdb/m2-exp.y6
-rw-r--r--gdb/macroexp.c18
-rw-r--r--gdb/macroexp.h2
-rw-r--r--gdb/objc-lang.c9
-rw-r--r--gdb/objc-lang.h3
-rw-r--r--gdb/p-exp.y42
-rw-r--r--gdb/parse.c22
-rw-r--r--gdb/parser-defs.h8
-rw-r--r--gdb/utils.c2
-rw-r--r--gdb/utils.h2
26 files changed, 289 insertions, 132 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d1b7d70..9f19d9e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,122 @@
+2013-10-01 Keith Seitz <keiths@redhat.com>
+
+ * linespec.c (struct ls_parser): Make 'saved_arg' const.
+ (parse_linespec): Make 'argptr' const.
+ Remove temporary cast of 'argptr' to const char **.
+ (decode_line_full): Pass const pointer to parse_linespec.
+ (decode_line_1): Likewise.
+ (decode_objc): Make local variable 'new_argptr' const.
+ (find_function_symbols): Remove temporary cast to char *
+ to find_imps.
+ * objc-lang.c (find_imps): Make argument 'method' const.
+ Return const.
+ * objc-lang.h (find_imps): Likewise.
+
+2013-10-01 Keith Seitz <keiths@redhat.com>
+
+ * completer.c (skip_quoted_chars): Make all arguments const.
+ Return const.
+ (skip_quoted): Likewise.
+ * completer.h (skip_quoted_chars): Likewise.
+ (skip_quoted): Likewise.
+ * defs.h (skip_quoted): Remove duplicate declaration.
+ * jv-exp.y: Include completer.h.
+ (yylex): Remove unneccessary cast to char * fro skip_quoted.
+ * p-exp.y: Include completer.h.
+
+2013-10-01 Keith Seitz <keiths@redhat.com>
+
+ * c-exp.y (parse_number): Make first argument const.
+ Make a copy of the input to manipulate.
+ (c_parse_escape): Make first argument const.
+ Make local variable 'tokptr' const.
+ (parse_string_or_char): Make first two arguments const.
+ (macro_original_text): Make const.
+ (lex_one_token): Make local variable 'tokstart' const.
+ Likewise for local variables named 'p'.
+ Cast away const for struct stoken (temporary).
+ * c-lang.h (c_parse_escpae): Make first argument const.
+ * cli/cli-cmds.c (echo_command): Make local variable 'p'
+ const.
+ * cli/cli-setshow.c (do_set_command): Likewise for 'p' in
+ var_string case.
+ * f-exp.y (parse_number): Make first argument const.
+ (match_string_literal): Make local variable 'tokstart'
+ const.
+ (yylex): Make local variable 'p' const.
+ Cast away const for struct stoken (temporary).
+ * go-exp.y (parse_number): Make first argument const.
+ (parse_string_or_char): Likewise.
+ Make local variable 'tokstart' const.
+ (lex_one_token): Likewise for numerous locals called 'p'.
+ Cast away const for struct stoken (temporary).
+ * jv-exp.y (parse_number): Make first argument const.
+ Make local variables 'tokstart' and 'tokptr' const.
+ Cast away const for call to skip_quoted (temporary).
+ (yylex): Make local variable 'p' const.
+ Cast away const for struct stoken (temporary).
+ * m2-exp.y (parse_number): Make local variable 'p' const.
+ (yylex): Likewise for 'tokstart'.
+ Cast away const for struct stoken (temporary).
+ Make local variable 'p' const.
+ * macroexp.c (get_character_constant): Pass a const string
+ to c_parse_escape.
+ (get_string_literal): Likewise.
+ (macro_expand_next): Make first argument const.
+ Cast away const for init_shared_buffer.
+ * macroexp.h (macro_expand_next): Make first argument const.
+ * p-exp.y (yylex): Make a local copy of 'lexptr'.
+ Pass a const string to c_parse_escape.
+ Make local variables 'p' and 'namestart' const.
+ * parse.c (lexptr): Make const.
+ (prev_lexptr): Likewise.
+ (find_template_name_end): Return const.
+ Make argument const, too.
+ (parse_exp_in_context): Make first argument const.
+ Remove the entire const_hack.
+ (parse_exp_in_context_1): Make first argument const.
+ * parser-defs.h (find_template_name_end): Return const.
+ Make argument const, too.
+ (lexptr): Make const.
+ (prev_lexptr): Likewise.
+ * utils.c (parse_escape): Make second argument const.
+ * utils.h (parse_escape): Likewise.
+
+2013-10-01 Keith Seitz <keiths@redhat.com>
+
+ * ada-exp.y (write_object_renaming): Update: struct stoken.ptr
+ is now const.
+ (block_lookup): Make 'raw_name' and 'name' const.
+ * ada-lex.l (processString): Update for struct stoken.ptr.
+ * c-exp.y (qualified_name : TYPENAME COLONCOLON '~' name): Likewise.
+ (operator_stoken): Likewise.
+ (lex_one_token): Remove temporary cast to char * for
+ 'yylval.sval.ptr'.
+ * f-exp.y (yylex): Likewise.
+ * gdb-types.c (lookup_struct_elt_type): Make argument 'name' const.
+ * gdbtypes.h (lookup_struct_elt_type): Likewisee.
+ * go-exp.y (lex_one_token): Remove temporary cast to char * for
+ 'yylval.sval.ptr'.
+ * jv-exp.y (QualifiedName): Update for struct stoken.ptr.
+ (yylex): Remove temporary cast to char * for 'yylval.sval.ptr'.
+ * linespec.c (struct ls_parser): Make 'stream' const.
+ (find_parameter_list_end): Make argument 'input' and local
+ variable 'p' const.
+ (linespec_lexer_lex_string): Make local variables 'start' and
+ 'p' const.
+ Use skip_spaces_const instead of skip_spaces.
+ (linespec_lexer_peek_token): Make local variable 'saved_stream'
+ const.
+ (parse_linespec): Temporarily cast 'argptr' to const for
+ 'parser->lexer.stream'.
+ * m2-exp.y (yylex): Remove temporary cast to char * for
+ 'yylval.sval.ptr'.
+ * objc-lang.c (add_msglist): Make local variable 'p' const.
+ * p-exp.y (exp : exp '['): Update for struct stoken.ptr.
+ (exp : STRING): Make 'sp' const.
+ (parse_number): Make argument 'p' const.
+ * parser-defs.h (struct stoken): Make 'ptr' const.
+
2013-10-01 Doug Evans <dje@google.com>
* cli/cli-decode.c: Remove unnecessary inclusion of tui/tui.h.
diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 877dfaf..5270461 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -136,7 +136,7 @@ static void write_name_assoc (struct stoken);
static void write_exp_op_with_string (enum exp_opcode, struct stoken);
-static struct block *block_lookup (struct block *, char *);
+static struct block *block_lookup (struct block *, const char *);
static LONGEST convert_char_literal (struct type *, LONGEST);
@@ -952,6 +952,8 @@ write_object_renaming (const struct block *orig_left_context,
{
struct stoken field_name;
const char *end;
+ char *buf;
+
renaming_expr += 1;
if (slice_state != SIMPLE_INDEX)
@@ -960,9 +962,10 @@ write_object_renaming (const struct block *orig_left_context,
if (end == NULL)
end = renaming_expr + strlen (renaming_expr);
field_name.length = end - renaming_expr;
- field_name.ptr = malloc (end - renaming_expr + 1);
- strncpy (field_name.ptr, renaming_expr, end - renaming_expr);
- field_name.ptr[end - renaming_expr] = '\000';
+ buf = malloc (end - renaming_expr + 1);
+ field_name.ptr = buf;
+ strncpy (buf, renaming_expr, end - renaming_expr);
+ buf[end - renaming_expr] = '\000';
renaming_expr = end;
write_exp_op_with_string (STRUCTOP_STRUCT, field_name);
break;
@@ -980,9 +983,9 @@ write_object_renaming (const struct block *orig_left_context,
}
static struct block*
-block_lookup (struct block *context, char *raw_name)
+block_lookup (struct block *context, const char *raw_name)
{
- char *name;
+ const char *name;
struct ada_symbol_info *syms;
int nsyms;
struct symtab *symtab;
diff --git a/gdb/ada-lex.l b/gdb/ada-lex.l
index 93df2fb..2f9e1b3 100644
--- a/gdb/ada-lex.l
+++ b/gdb/ada-lex.l
@@ -497,7 +497,8 @@ processString (const char *text, int len)
const char *lim = text + len;
struct stoken result;
- q = result.ptr = obstack_alloc (&temp_parse_space, len);
+ q = obstack_alloc (&temp_parse_space, len);
+ result.ptr = q;
p = text;
while (p < lim)
{
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 3a51878..77713dd 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -164,7 +164,7 @@ void yyerror (char *);
%{
/* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (const char *, int, int, YYSTYPE *);
static struct stoken operator_stoken (const char *);
static void check_parameter_typelist (VEC (type_ptr) *);
static void write_destructor_name (struct stoken);
@@ -970,18 +970,20 @@ qualified_name: TYPENAME COLONCOLON name
{
struct type *type = $1.type;
struct stoken tmp_token;
+ char *buf;
+
CHECK_TYPEDEF (type);
if (TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION
&& TYPE_CODE (type) != TYPE_CODE_NAMESPACE)
error (_("`%s' is not defined as an aggregate type."),
TYPE_SAFE_NAME (type));
-
- tmp_token.ptr = (char*) alloca ($4.length + 2);
+ buf = alloca ($4.length + 2);
+ tmp_token.ptr = buf;
tmp_token.length = $4.length + 1;
- tmp_token.ptr[0] = '~';
- memcpy (tmp_token.ptr+1, $4.ptr, $4.length);
- tmp_token.ptr[tmp_token.length] = 0;
+ buf[0] = '~';
+ memcpy (buf+1, $4.ptr, $4.length);
+ buf[tmp_token.length] = 0;
/* Check for valid destructor name. */
destructor_name_p (tmp_token.ptr, $1.type);
@@ -1651,13 +1653,16 @@ operator_stoken (const char *op)
{
static const char *operator_string = "operator";
struct stoken st = { NULL, 0 };
+ char *buf;
+
st.length = strlen (operator_string) + strlen (op);
- st.ptr = malloc (st.length + 1);
- strcpy (st.ptr, operator_string);
- strcat (st.ptr, op);
+ buf = malloc (st.length + 1);
+ strcpy (buf, operator_string);
+ strcat (buf, op);
+ st.ptr = buf;
/* The toplevel (c_parse) will free the memory allocated here. */
- make_cleanup (free, st.ptr);
+ make_cleanup (free, buf);
return st;
};
@@ -1699,7 +1704,7 @@ check_parameter_typelist (VEC (type_ptr) *params)
/*** Needs some error checking for the float case ***/
static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (const char *buf, int len, int parsed_float, YYSTYPE *putithere)
{
/* FIXME: Shouldn't these be unsigned? We don't deal with negative values
here, and we do kind of silly things like cast to unsigned. */
@@ -1721,6 +1726,10 @@ parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
ULONGEST high_bit;
struct type *signed_type;
struct type *unsigned_type;
+ char *p;
+
+ p = alloca (len);
+ memcpy (p, buf, len);
if (parsed_float)
{
@@ -1941,9 +1950,9 @@ static int tempbuf_init;
character was emitted, 0 otherwise. */
int
-c_parse_escape (char **ptr, struct obstack *output)
+c_parse_escape (const char **ptr, struct obstack *output)
{
- char *tokptr = *ptr;
+ const char *tokptr = *ptr;
int result = 1;
/* Some escape sequences undergo character set conversion. Those we
@@ -2102,8 +2111,8 @@ c_parse_escape (char **ptr, struct obstack *output)
CHAR, depending on what was parsed. *HOST_CHARS is set to the
number of host characters in the literal. */
static int
-parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
- int *host_chars)
+parse_string_or_char (const char *tokptr, const char **outptr,
+ struct typed_stoken *value, int *host_chars)
{
int quote;
enum c_string_type type;
@@ -2321,7 +2330,7 @@ static const struct token ident_tokens[] =
we evaluate ADDRESS in the scope of the current frame, but we
evaluate CONDITION in the scope of the breakpoint's location. So
it's simply wrong to try to macro-expand the whole thing at once. */
-static char *macro_original_text;
+static const char *macro_original_text;
/* We save all intermediate macro expansions on this obstack for the
duration of a single parse. The expansion text may sometimes have
@@ -2411,7 +2420,7 @@ lex_one_token (void)
int c;
int namelen;
unsigned int i;
- char *tokstart;
+ const char *tokstart;
int saw_structop = last_was_structop;
char *copy;
@@ -2538,7 +2547,7 @@ lex_one_token (void)
{
/* It's a number. */
int got_dot = 0, got_e = 0, toktype;
- char *p = tokstart;
+ const char *p = tokstart;
int hex = input_radix > 10;
if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
@@ -2590,7 +2599,7 @@ lex_one_token (void)
case '@':
{
- char *p = &tokstart[1];
+ const char *p = &tokstart[1];
size_t len = strlen ("entry");
if (parse_language->la_language == language_objc)
@@ -2692,7 +2701,8 @@ lex_one_token (void)
characters; for comparison expressions, e.g. "a < b > c",
there must be spaces before the '<', etc. */
- char * p = find_template_name_end (tokstart + namelen);
+ const char *p = find_template_name_end (tokstart + namelen);
+
if (p)
namelen = p - tokstart;
}
@@ -2723,7 +2733,8 @@ lex_one_token (void)
&& (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')
&& ! scanning_macro_expansion ())
{
- char *p = tokstart + namelen + 1;
+ const char *p = tokstart + namelen + 1;
+
while (*p == ' ' || *p == '\t')
p++;
if (*p >= '0' && *p <= '9')
diff --git a/gdb/c-lang.h b/gdb/c-lang.h
index 6bf6591..9f8f50d 100644
--- a/gdb/c-lang.h
+++ b/gdb/c-lang.h
@@ -61,7 +61,7 @@ extern int c_parse (void);
extern void c_error (char *);
-extern int c_parse_escape (char **, struct obstack *);
+extern int c_parse_escape (const char **, struct obstack *);
/* Defined in c-typeprint.c */
extern void c_print_type (struct type *, const char *,
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 4317ea3..886ba7a 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -666,7 +666,7 @@ source_command (char *args, int from_tty)
static void
echo_command (char *text, int from_tty)
{
- char *p = text;
+ const char *p = text;
int c;
if (text)
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index 3e41fd4..45df6f6 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -160,7 +160,7 @@ do_set_command (char *arg, int from_tty, struct cmd_list_element *c)
case var_string:
{
char *new;
- char *p;
+ const char *p;
char *q;
int ch;
diff --git a/gdb/completer.c b/gdb/completer.c
index e132651..91bf812 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -911,11 +911,12 @@ line_completion_function (const char *text, int matches,
QUOTECHARS or BREAKCHARS is NULL, use the same values used by the
completer. */
-char *
-skip_quoted_chars (char *str, char *quotechars, char *breakchars)
+const char *
+skip_quoted_chars (const char *str, const char *quotechars,
+ const char *breakchars)
{
char quote_char = '\0';
- char *scan;
+ const char *scan;
if (quotechars == NULL)
quotechars = gdb_completer_quote_characters;
@@ -953,8 +954,8 @@ skip_quoted_chars (char *str, char *quotechars, char *breakchars)
characters and word break characters used by the completer).
Returns pointer to the location after the "word". */
-char *
-skip_quoted (char *str)
+const char *
+skip_quoted (const char *str)
{
return skip_quoted_chars (str, NULL, NULL);
}
diff --git a/gdb/completer.h b/gdb/completer.h
index d6090f4..97eb9dd 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -50,8 +50,9 @@ extern char *gdb_completion_word_break_characters (void);
/* Exported to linespec.c */
-extern char *skip_quoted_chars (char *, char *, char *);
+extern const char *skip_quoted_chars (const char *, const char *,
+ const char *);
-extern char *skip_quoted (char *);
+extern const char *skip_quoted (const char *);
#endif /* defined (COMPLETER_H) */
diff --git a/gdb/defs.h b/gdb/defs.h
index 45555e0..b1caaad 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -311,8 +311,6 @@ extern void print_transfer_performance (struct ui_file *stream,
typedef void initialize_file_ftype (void);
-extern char *skip_quoted (char *);
-
extern char *gdb_readline (char *);
extern char *gdb_readline_wrapper (char *);
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 296a7fe..59c5e6c 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -157,7 +157,7 @@ static int match_string_literal (void);
%{
/* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (const char *, int, int, YYSTYPE *);
%}
%type <voidval> exp type_exp start variable
@@ -669,7 +669,7 @@ name_not_typename : NAME
/*** Needs some error checking for the float case ***/
static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere)
{
LONGEST n = 0;
LONGEST prevn = 0;
@@ -920,7 +920,7 @@ growbuf_by_size (int count)
static int
match_string_literal (void)
{
- char *tokptr = lexptr;
+ const char *tokptr = lexptr;
for (tempbufindex = 0, tokptr++; *tokptr != '\0'; tokptr++)
{
@@ -955,7 +955,7 @@ yylex (void)
int c;
int namelen;
unsigned int i,token;
- char *tokstart;
+ const char *tokstart;
retry:
@@ -1054,7 +1054,7 @@ yylex (void)
{
/* It's a number. */
int got_dot = 0, got_e = 0, got_d = 0, toktype;
- char *p = tokstart;
+ const char *p = tokstart;
int hex = input_radix > 10;
if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index ea5ca21..6c809a4 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1353,7 +1353,7 @@ lookup_template_type (char *name, struct type *type,
If NAME is the name of a baseclass type, return that type. */
struct type *
-lookup_struct_elt_type (struct type *type, char *name, int noerr)
+lookup_struct_elt_type (struct type *type, const char *name, int noerr)
{
int i;
char *typename;
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 0ca7a87..5e8d1e7 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1508,7 +1508,7 @@ extern const char *type_name_no_tag (const struct type *);
extern const char *type_name_no_tag_or_error (struct type *type);
-extern struct type *lookup_struct_elt_type (struct type *, char *, int);
+extern struct type *lookup_struct_elt_type (struct type *, const char *, int);
extern struct type *make_pointer_type (struct type *, struct type **);
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 2ccb394..01c382a 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -158,7 +158,7 @@ void yyerror (char *);
%{
/* YYSTYPE gets defined by %union. */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (const char *, int, int, YYSTYPE *);
static int parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
DOUBLEST *d, struct type **t);
%}
@@ -704,7 +704,7 @@ parse_go_float (struct gdbarch *gdbarch, const char *p, int len,
as our YYSTYPE is different than c-exp.y's */
static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere)
{
/* FIXME: Shouldn't these be unsigned? We don't deal with negative values
here, and we do kind of silly things like cast to unsigned. */
@@ -908,8 +908,8 @@ static int tempbuf_init;
number of host characters in the literal. */
static int
-parse_string_or_char (char *tokptr, char **outptr, struct typed_stoken *value,
- int *host_chars)
+parse_string_or_char (const char *tokptr, const char **outptr,
+ struct typed_stoken *value, int *host_chars)
{
int quote;
@@ -1049,7 +1049,7 @@ lex_one_token (void)
int c;
int namelen;
unsigned int i;
- char *tokstart;
+ const char *tokstart;
int saw_structop = last_was_structop;
char *copy;
@@ -1143,7 +1143,7 @@ lex_one_token (void)
{
/* It's a number. */
int got_dot = 0, got_e = 0, toktype;
- char *p = tokstart;
+ const char *p = tokstart;
int hex = input_radix > 10;
if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
@@ -1190,7 +1190,7 @@ lex_one_token (void)
case '@':
{
- char *p = &tokstart[1];
+ const char *p = &tokstart[1];
size_t len = strlen ("entry");
while (isspace (*p))
@@ -1283,7 +1283,8 @@ lex_one_token (void)
&& strncmp (tokstart, "thread", namelen) == 0
&& (tokstart[namelen] == ' ' || tokstart[namelen] == '\t'))
{
- char *p = tokstart + namelen + 1;
+ const char *p = tokstart + namelen + 1;
+
while (*p == ' ' || *p == '\t')
p++;
if (*p >= '0' && *p <= '9')
diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y
index a4e1253..2c5154e 100644
--- a/gdb/jv-exp.y
+++ b/gdb/jv-exp.y
@@ -47,6 +47,7 @@
#include "symfile.h" /* Required by objfiles.h. */
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
#include "block.h"
+#include "completer.h"
#define parse_type builtin_type (parse_gdbarch)
#define parse_java_type builtin_java_type (parse_gdbarch)
@@ -154,7 +155,7 @@ static void insert_exp (int, struct expression *);
%{
/* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (const char *, int, int, YYSTYPE *);
%}
%type <lval> rcurly Dims Dims_opt
@@ -345,10 +346,13 @@ QualifiedName:
$$.ptr = $1.ptr; /* Optimization. */
else
{
- $$.ptr = (char *) malloc ($$.length + 1);
- make_cleanup (free, $$.ptr);
- sprintf ($$.ptr, "%.*s.%.*s",
+ char *buf;
+
+ buf = malloc ($$.length + 1);
+ make_cleanup (free, buf);
+ sprintf (buf, "%.*s.%.*s",
$1.length, $1.ptr, $3.length, $3.ptr);
+ $$.ptr = buf;
} }
;
@@ -696,7 +700,7 @@ Expression:
/*** Needs some error checking for the float case ***/
static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere)
{
ULONGEST n = 0;
ULONGEST limit, limit_div_base;
@@ -858,8 +862,8 @@ yylex (void)
int c;
int namelen;
unsigned int i;
- char *tokstart;
- char *tokptr;
+ const char *tokstart;
+ const char *tokptr;
int tempbufindex;
static char *tempbuf;
static int tempbufsize;
@@ -966,7 +970,7 @@ yylex (void)
{
/* It's a number. */
int got_dot = 0, got_e = 0, toktype;
- char *p = tokstart;
+ const char *p = tokstart;
int hex = input_radix > 10;
if (c == '0' && (p[1] == 'x' || p[1] == 'X'))
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 8b7f3bd..9468f26 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -278,10 +278,10 @@ struct ls_parser
struct
{
/* Save head of input stream. */
- char *saved_arg;
+ const char *saved_arg;
/* Head of the input stream. */
- char **stream;
+ const char **stream;
#define PARSER_STREAM(P) (*(P)->lexer.stream)
/* The current token. */
@@ -320,7 +320,7 @@ static CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
static struct symtabs_and_lines decode_objc (struct linespec_state *self,
linespec_p ls,
- char **argptr);
+ const char **argptr);
static VEC (symtab_ptr) *symtabs_from_filename (const char *);
@@ -515,12 +515,12 @@ is_closing_quote_enclosed (const char *p)
This helper function assists with lexing string segments
which might contain valid (non-terminating) commas. */
-static char *
-find_parameter_list_end (char *input)
+static const char *
+find_parameter_list_end (const char *input)
{
char end_char, start_char;
int depth;
- char *p;
+ const char *p;
start_char = *input;
if (start_char == '(')
@@ -557,7 +557,7 @@ static linespec_token
linespec_lexer_lex_string (linespec_parser *parser)
{
linespec_token token;
- char *start = PARSER_STREAM (parser);
+ const char *start = PARSER_STREAM (parser);
token.type = LSTOKEN_STRING;
@@ -607,7 +607,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
}
else
{
- char *p;
+ const char *p;
/* Otherwise, only identifier characters are permitted.
Spaces are the exception. In general, we keep spaces,
@@ -621,7 +621,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
{
if (isspace (*PARSER_STREAM (parser)))
{
- p = skip_spaces (PARSER_STREAM (parser));
+ p = skip_spaces_const (PARSER_STREAM (parser));
/* When we get here we know we've found something followed by
a space (we skip over parens and templates below).
So if we find a keyword now, we know it is a keyword and not,
@@ -681,7 +681,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
else if (*PARSER_STREAM (parser) == '<'
|| *PARSER_STREAM (parser) == '(')
{
- char *p;
+ const char *p;
p = find_parameter_list_end (PARSER_STREAM (parser));
if (p != NULL)
@@ -733,7 +733,7 @@ linespec_lexer_lex_one (linespec_parser *parser)
if (parser->lexer.current.type == LSTOKEN_CONSUMED)
{
/* Skip any whitespace. */
- PARSER_STREAM (parser) = skip_spaces (PARSER_STREAM (parser));
+ PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser));
/* Check for a keyword, they end the linespec. */
keyword = NULL;
@@ -819,7 +819,7 @@ static linespec_token
linespec_lexer_peek_token (linespec_parser *parser)
{
linespec_token next;
- char *saved_stream = PARSER_STREAM (parser);
+ const char *saved_stream = PARSER_STREAM (parser);
linespec_token saved_token = parser->lexer.current;
next = linespec_lexer_consume_token (parser);
@@ -2144,7 +2144,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
/* Parse the linespec in ARGPTR. */
static struct symtabs_and_lines
-parse_linespec (linespec_parser *parser, char **argptr)
+parse_linespec (linespec_parser *parser, const char **argptr)
{
linespec_token token;
struct symtabs_and_lines values;
@@ -2426,6 +2426,7 @@ decode_line_full (char **argptr, int flags,
VEC (const_char_ptr) *filters = NULL;
linespec_parser parser;
struct linespec_state *state;
+ const char *copy, *orig;
gdb_assert (canonical != NULL);
/* The filter only makes sense for 'all'. */
@@ -2441,7 +2442,9 @@ decode_line_full (char **argptr, int flags,
cleanups = make_cleanup (linespec_parser_delete, &parser);
save_current_program_space ();
- result = parse_linespec (&parser, argptr);
+ orig = copy = *argptr;
+ result = parse_linespec (&parser, &copy);
+ *argptr += copy - orig;
state = PARSER_STATE (&parser);
gdb_assert (result.nelts == 1 || canonical->pre_expanded);
@@ -2496,13 +2499,16 @@ decode_line_1 (char **argptr, int flags,
struct symtabs_and_lines result;
linespec_parser parser;
struct cleanup *cleanups;
+ const char *copy, *orig;
linespec_parser_new (&parser, flags, current_language, default_symtab,
default_line, NULL);
cleanups = make_cleanup (linespec_parser_delete, &parser);
save_current_program_space ();
- result = parse_linespec (&parser, argptr);
+ orig = copy = *argptr;
+ result = parse_linespec (&parser, &copy);
+ *argptr += copy - orig;
do_cleanups (cleanups);
return result;
@@ -2602,12 +2608,12 @@ linespec_expression_to_pc (const char **exp_ptr)
the existing C++ code to let the user choose one. */
static struct symtabs_and_lines
-decode_objc (struct linespec_state *self, linespec_p ls, char **argptr)
+decode_objc (struct linespec_state *self, linespec_p ls, const char **argptr)
{
struct collect_info info;
VEC (const_char_ptr) *symbol_names = NULL;
struct symtabs_and_lines values;
- char *new_argptr;
+ const char *new_argptr;
struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
&symbol_names);
@@ -3053,7 +3059,7 @@ find_function_symbols (struct linespec_state *state,
info.file_symtabs = file_symtabs;
/* Try NAME as an Objective-C selector. */
- find_imps ((char *) name, &symbol_names);
+ find_imps (name, &symbol_names);
if (!VEC_empty (const_char_ptr, symbol_names))
add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
else
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index eaa5a23..0002e45 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -662,7 +662,7 @@ type
static int
parse_number (int olen)
{
- char *p = lexptr;
+ const char *p = lexptr;
LONGEST n = 0;
LONGEST prevn = 0;
int c,i,ischar=0;
@@ -814,7 +814,7 @@ yylex (void)
int c;
int namelen;
int i;
- char *tokstart;
+ const char *tokstart;
char quote;
retry:
@@ -927,7 +927,7 @@ yylex (void)
{
/* It's a number. */
int got_dot = 0, got_e = 0;
- char *p = tokstart;
+ const char *p = tokstart;
int toktype;
for (++p ;; ++p)
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index d88dac3..3d98550f 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -360,8 +360,11 @@ get_character_constant (struct macro_buffer *tok, char *p, char *end)
}
else if (*p == '\\')
{
- p++;
- char_count += c_parse_escape (&p, NULL);
+ const char *s, *o;
+
+ s = o = ++p;
+ char_count += c_parse_escape (&s, NULL);
+ p += s - o;
}
else
{
@@ -414,8 +417,11 @@ get_string_literal (struct macro_buffer *tok, char *p, char *end)
"constants."));
else if (*p == '\\')
{
- p++;
- c_parse_escape (&p, NULL);
+ const char *s, *o;
+
+ s = o = ++p;
+ c_parse_escape (&s, NULL);
+ p += s - o;
}
else
p++;
@@ -1434,7 +1440,7 @@ macro_expand_once (const char *source,
char *
-macro_expand_next (char **lexptr,
+macro_expand_next (const char **lexptr,
macro_lookup_ftype *lookup_func,
void *lookup_baton)
{
@@ -1442,7 +1448,7 @@ macro_expand_next (char **lexptr,
struct cleanup *back_to;
/* Set up SRC to refer to the input text, pointed to by *lexptr. */
- init_shared_buffer (&src, *lexptr, strlen (*lexptr));
+ init_shared_buffer (&src, (char *) *lexptr, strlen (*lexptr));
/* Set up DEST to receive the expansion, if there is one. */
init_buffer (&dest, 0);
diff --git a/gdb/macroexp.h b/gdb/macroexp.h
index cbe9629..8bf4b7f 100644
--- a/gdb/macroexp.h
+++ b/gdb/macroexp.h
@@ -80,7 +80,7 @@ char *macro_expand_once (const char *source,
much have to do tokenization to find the end of the string that
needs to be macro-expanded. Our C/C++ tokenizer isn't really
designed to be called by anything but the yacc parser engine. */
-char *macro_expand_next (char **lexptr,
+char *macro_expand_next (const char **lexptr,
macro_lookup_ftype *lookup_func,
void *lookup_baton);
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 734fc5d..bcce435 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -426,7 +426,8 @@ start_msglist(void)
void
add_msglist(struct stoken *str, int addcolon)
{
- char *s, *p;
+ char *s;
+ const char *p;
int len, plen;
if (str == 0) /* Unnamed arg, or... */
@@ -1071,7 +1072,7 @@ uniquify_strings (VEC (const_char_ptr) **strings)
}
/*
- * Function: find_imps (char *selector, struct symbol **sym_arr)
+ * Function: find_imps (const char *selector, struct symbol **sym_arr)
*
* Input: a string representing a selector
* a pointer to an array of symbol pointers
@@ -1100,8 +1101,8 @@ uniquify_strings (VEC (const_char_ptr) **strings)
* be the index of the first non-debuggable one).
*/
-char *
-find_imps (char *method, VEC (const_char_ptr) **symbol_names)
+const char *
+find_imps (const char *method, VEC (const_char_ptr) **symbol_names)
{
char type = '\0';
char *class = NULL;
diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
index 23fac1b..2409363 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -36,7 +36,8 @@ extern char *objc_demangle (const char *mangled, int options);
extern int find_objc_msgcall (CORE_ADDR pc, CORE_ADDR *new_pc);
-extern char *find_imps (char *method, VEC (const_char_ptr) **symbol_names);
+extern const char *
+ find_imps (const char *method, VEC (const_char_ptr) **symbol_names);
extern struct value *value_nsstring (struct gdbarch *gdbarch,
char *ptr, int len);
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index da8d5f7..de14cbb 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -55,6 +55,7 @@
#include "symfile.h" /* Required by objfiles.h. */
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols. */
#include "block.h"
+#include "completer.h"
#define parse_type builtin_type (parse_gdbarch)
@@ -158,7 +159,7 @@ static char * uptok (char *, int);
%{
/* YYSTYPE gets defined by %union */
-static int parse_number (char *, int, int, YYSTYPE *);
+static int parse_number (const char *, int, int, YYSTYPE *);
static struct type *current_type;
static struct internalvar *intvar;
@@ -352,9 +353,12 @@ exp : exp '['
if (arrayfieldindex)
{
struct stoken stringsval;
- stringsval.ptr = alloca (strlen (arrayname) + 1);
+ char *buf;
+
+ buf = alloca (strlen (arrayname) + 1);
+ stringsval.ptr = buf;
stringsval.length = strlen (arrayname);
- strcpy (stringsval.ptr, arrayname);
+ strcpy (buf, arrayname);
current_type = TYPE_FIELD_TYPE (current_type,
arrayfieldindex - 1);
write_exp_elt_opcode (STRUCTOP_STRUCT);
@@ -591,7 +595,8 @@ exp : STRING
the array upper bound is the string length.
There is no such thing in C as a completely empty
string. */
- char *sp = $1.ptr; int count = $1.length;
+ const char *sp = $1.ptr; int count = $1.length;
+
while (count-- > 0)
{
write_exp_elt_opcode (OP_LONG);
@@ -854,7 +859,7 @@ name_not_typename : NAME
/*** Needs some error checking for the float case ***/
static int
-parse_number (char *p, int len, int parsed_float, YYSTYPE *putithere)
+parse_number (const char *p, int len, int parsed_float, YYSTYPE *putithere)
{
/* FIXME: Shouldn't these be unsigned? We don't deal with negative values
here, and we do kind of silly things like cast to unsigned. */
@@ -1141,8 +1146,10 @@ yylex (void)
prev_lexptr = lexptr;
- tokstart = lexptr;
explen = strlen (lexptr);
+ tokstart = alloca (explen + 1);
+ memcpy (tokstart, lexptr, explen + 1);
+
/* See if it is a special token of length 3. */
if (explen > 2)
for (i = 0; i < sizeof (tokentab3) / sizeof (tokentab3[0]); i++)
@@ -1361,13 +1368,18 @@ yylex (void)
/* Do nothing, loop will terminate. */
break;
case '\\':
- tokptr++;
- c = parse_escape (parse_gdbarch, &tokptr);
- if (c == -1)
- {
- continue;
- }
- tempbuf[tempbufindex++] = c;
+ {
+ const char *s, *o;
+
+ o = s = ++tokptr;
+ c = parse_escape (parse_gdbarch, &s);
+ *tokptr += s - o;
+ if (c == -1)
+ {
+ continue;
+ }
+ tempbuf[tempbufindex++] = c;
+ }
break;
default:
tempbuf[tempbufindex++] = *tokptr++;
@@ -1623,8 +1635,8 @@ yylex (void)
distinction) named x, then this code incorrectly thinks we
are dealing with nested types rather than a member function. */
- char *p;
- char *namestart;
+ const char *p;
+ const char *namestart;
struct symbol *best_sym;
/* Look ahead to detect nested types. This probably should be
diff --git a/gdb/parse.c b/gdb/parse.c
index 674342b..07c1765 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -75,8 +75,8 @@ CORE_ADDR expression_context_pc;
const struct block *innermost_block;
int arglist_len;
static struct type_stack type_stack;
-char *lexptr;
-char *prev_lexptr;
+const char *lexptr;
+const char *prev_lexptr;
int paren_depth;
int comma_terminates;
@@ -123,7 +123,7 @@ static int prefixify_subexp (struct expression *, struct expression *, int,
static struct expression *parse_exp_in_context (const char **, CORE_ADDR,
const struct block *, int,
int, int *);
-static struct expression *parse_exp_in_context_1 (char **, CORE_ADDR,
+static struct expression *parse_exp_in_context_1 (const char **, CORE_ADDR,
const struct block *, int,
int, int *);
@@ -733,8 +733,8 @@ handle_register:
}
-char *
-find_template_name_end (char *p)
+const char *
+find_template_name_end (const char *p)
{
int depth = 1;
int just_seen_right = 0;
@@ -1142,16 +1142,8 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
const struct block *block,
int comma, int void_context_p, int *out_subexp)
{
- struct expression *expr;
- char *const_hack = *stringptr ? xstrdup (*stringptr) : NULL;
- char *orig = const_hack;
- struct cleanup *back_to = make_cleanup (xfree, const_hack);
-
- expr = parse_exp_in_context_1 (&const_hack, pc, block, comma,
+ return parse_exp_in_context_1 (stringptr, pc, block, comma,
void_context_p, out_subexp);
- (*stringptr) += const_hack - orig;
- do_cleanups (back_to);
- return expr;
}
/* As for parse_exp_1, except that if VOID_CONTEXT_P, then
@@ -1162,7 +1154,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
is left untouched. */
static struct expression *
-parse_exp_in_context_1 (char **stringptr, CORE_ADDR pc,
+parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
const struct block *block,
int comma, int void_context_p, int *out_subexp)
{
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index 92daca9..ed022ad 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -67,7 +67,7 @@ extern int arglist_len;
struct stoken
{
/* Pointer to first byte of char-string or first bit of bit-string. */
- char *ptr;
+ const char *ptr;
/* Length of string in bytes for char-string or bits for bit-string. */
int length;
};
@@ -201,7 +201,7 @@ extern void write_dollar_variable (struct stoken str);
extern void mark_struct_expression (void);
-extern char *find_template_name_end (char *);
+extern const char *find_template_name_end (const char *);
extern void start_arglist (void);
@@ -264,11 +264,11 @@ extern int parse_c_float (struct gdbarch *gdbarch, const char *p, int len,
/* During parsing of a C expression, the pointer to the next character
is in this variable. */
-extern char *lexptr;
+extern const char *lexptr;
/* After a token has been recognized, this variable points to it.
Currently used only for error reporting. */
-extern char *prev_lexptr;
+extern const char *prev_lexptr;
/* Current depth in parentheses within the expression. */
diff --git a/gdb/utils.c b/gdb/utils.c
index 0652197..26879ec 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -1412,7 +1412,7 @@ host_char_to_target (struct gdbarch *gdbarch, int c, int *target_c)
after the zeros. A value of 0 does not mean end of string. */
int
-parse_escape (struct gdbarch *gdbarch, char **string_ptr)
+parse_escape (struct gdbarch *gdbarch, const char **string_ptr)
{
int target_char = -2; /* Initialize to avoid GCC warnings. */
int c = *(*string_ptr)++;
diff --git a/gdb/utils.h b/gdb/utils.h
index 143cd6b..3492f09 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -64,7 +64,7 @@ struct timeval get_prompt_for_continue_wait_time (void);
extern int parse_pid_to_attach (char *args);
-extern int parse_escape (struct gdbarch *, char **);
+extern int parse_escape (struct gdbarch *, const char **);
char **gdb_buildargv (const char *);