From: Tom Tromey Date: Fri, 12 Dec 2025 18:45:42 +0000 (-0700) Subject: Use skip_spaces in more places X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60a614d2a56dff3c70bde93a93121ea52338b678;p=thirdparty%2Fbinutils-gdb.git Use skip_spaces in more places I looked through gdb for instance of: while (*p == ' ' || *p == '\t') p++; ... and replaced these with a call to skip_spaces. In some cases this might slightly change the semantics, as now other whitespace (like \r or \f) will be considered. However I don't think this matters. Regression tested on x86-64 Fedora 41. Approved-By: Simon Marchi --- diff --git a/gdb/c-exp.y b/gdb/c-exp.y index d321e815ca4..271f823ca8d 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -3038,10 +3038,7 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t') && ! scanning_macro_expansion ()) { - const char *p = tokstart + namelen + 1; - - while (*p == ' ' || *p == '\t') - p++; + const char *p = skip_spaces (tokstart + namelen + 1); if (*p >= '0' && *p <= '9') return 0; } diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index cf5571c5419..362f239f896 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1402,8 +1402,7 @@ list_command (const char *arg, int from_tty) const char *beg = arg; size_t beg_len = arg1 - beg; - while (*arg1 == ' ' || *arg1 == '\t') - arg1++; + arg1 = skip_spaces (arg1); if (*arg1 == ',') { no_end = 0; @@ -1415,8 +1414,7 @@ list_command (const char *arg, int from_tty) return; } arg1++; - while (*arg1 == ' ' || *arg1 == '\t') - arg1++; + arg1 = skip_spaces (arg1); if (*arg1 == 0) dummy_end = 1; else diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 6a7d07ae29c..62f2a8b2142 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -2267,8 +2267,7 @@ lookup_cmd_1 (const char **text, struct cmd_list_element *clist, bool found_alias = false; const char *line = *text; - while (**text == ' ' || **text == '\t') - (*text)++; + *text = skip_spaces (*text); /* Identify the name of the command. */ len = find_command_name_length (*text); @@ -2499,8 +2498,7 @@ lookup_cmd (const char **line, struct cmd_list_element *list, /* We've got something. It may still not be what the caller wants (if this command *needs* a subcommand). */ - while (**line == ' ' || **line == '\t') - (*line)++; + *line = skip_spaces (*line); if (c->is_prefix () && **line && !c->allow_unknown) undef_cmd_error (c->prefixname ().c_str (), *line); diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 31be1141871..9fa5ec29569 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -776,8 +776,7 @@ user_args::user_args (const char *command_line) int bsquote = 0; /* Strip whitespace. */ - while (*p == ' ' || *p == '\t') - p++; + p = skip_spaces (p); /* P now points to an argument. */ start_arg = p; diff --git a/gdb/completer.c b/gdb/completer.c index 677b9d15650..194ab8a21a1 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -1698,10 +1698,7 @@ complete_line_internal_1 (completion_tracker &tracker, true); /* Move p up to the next interesting thing. */ - while (*p == ' ' || *p == '\t') - { - p++; - } + p = skip_spaces (p); tracker.advance_custom_word_point_by (p - tmp_command); diff --git a/gdb/d-exp.y b/gdb/d-exp.y index f6b56296b22..15a55e33eb5 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -1247,10 +1247,7 @@ lex_one_token (struct parser_state *par_state) || strncmp (tokstart, "task", namelen) == 0) && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')) { - const char *p = tokstart + namelen + 1; - - while (*p == ' ' || *p == '\t') - p++; + const char *p = skip_spaces (tokstart + namelen + 1); if (*p >= '0' && *p <= '9') return 0; } diff --git a/gdb/event-top.c b/gdb/event-top.c index 3138e8c8886..23c2f1c0379 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -598,7 +598,6 @@ void command_handler (const char *command) { struct ui *ui = current_ui; - const char *c; if (ui->instream == ui->stdin_stream) reinitialize_more_filter (); @@ -606,8 +605,7 @@ command_handler (const char *command) scoped_command_stats stat_reporter (true); /* Do not execute commented lines. */ - for (c = command; *c == ' ' || *c == '\t'; c++) - ; + const char *c = skip_spaces (command); if (c[0] != '#') { execute_command (command, ui->instream == ui->stdin_stream); @@ -717,9 +715,7 @@ handle_line_of_input (std::string &cmd_line_buffer, /* If we just got an empty line, and that is supposed to repeat the previous command, return the previously saved command. */ - const char *p1; - for (p1 = cmd_line_buffer.c_str (); *p1 == ' ' || *p1 == '\t'; p1++) - ; + const char *p1 = skip_spaces (cmd_line_buffer.c_str ()); if (repeat && *p1 == '\0') return get_saved_command_line (); diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 5da8cefd64b..fe95fad0a9e 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -1202,10 +1202,7 @@ lex_one_token (struct parser_state *par_state) && strncmp (tokstart, "thread", namelen) == 0 && (tokstart[namelen] == ' ' || tokstart[namelen] == '\t')) { - const char *p = tokstart + namelen + 1; - - while (*p == ' ' || *p == '\t') - p++; + const char *p = skip_spaces (tokstart + namelen + 1); if (*p >= '0' && *p <= '9') return 0; } diff --git a/gdb/infcmd.c b/gdb/infcmd.c index ed1fa74dc37..246dadffcd9 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -2097,9 +2097,7 @@ set_var_in_environment (gdb_environ *env, const char *arg) else { /* Not setting variable value to null. */ - val = p + 1; - while (*val == ' ' || *val == '\t') - val++; + val = skip_spaces (p + 1); } while (p != arg && (p[-1] == ' ' || p[-1] == '\t')) diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 9804f2c3963..3b05607f3be 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -569,8 +569,7 @@ info_selectors_command (const char *regexp, int from_tty) if (*regexp == '+' || *regexp == '-') { /* User wants only class methods or only instance methods. */ plusminus = *regexp++; - while (*regexp == ' ' || *regexp == '\t') - regexp++; + regexp = skip_spaces (regexp); } if (*regexp == '\0') strcpy(myregexp, ".*]"); diff --git a/gdb/p-exp.y b/gdb/p-exp.y index ff84e7726ec..f9885052368 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -1559,15 +1559,13 @@ yylex (void) while (1) { /* Skip whitespace. */ - while (*p == ' ' || *p == '\t' || *p == '\n') - ++p; + p = skip_spaces (p); if (*p == ':' && p[1] == ':') { /* Skip the `::'. */ p += 2; /* Skip whitespace. */ - while (*p == ' ' || *p == '\t' || *p == '\n') - ++p; + p = skip_spaces (p); namestart = p; while (*p == '_' || *p == '$' || (*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'z') diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index b740d5a7b16..2256cf89aa4 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -761,10 +761,8 @@ rust_parser::lex_string () static bool space_then_number (const char *string) { - const char *p = string; + const char *p = skip_spaces (string); - while (p[0] == ' ' || p[0] == '\t') - ++p; if (p == string) return false; @@ -1072,11 +1070,7 @@ int rust_parser::lex_one_token (bool decimal_only) { /* Skip all leading whitespace. */ - while (pstate->lexptr[0] == ' ' - || pstate->lexptr[0] == '\t' - || pstate->lexptr[0] == '\r' - || pstate->lexptr[0] == '\n') - ++pstate->lexptr; + pstate->lexptr = skip_spaces (pstate->lexptr); /* If we hit EOF and we're completing, then return COMPLETE -- maybe we're completing an empty string at the end of a field_expr. diff --git a/gdb/symtab.c b/gdb/symtab.c index 5754d944b6c..2eda0da532d 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4117,8 +4117,7 @@ operator_chars (const char *p, const char **end) return *end; /* Allow some whitespace between `operator' and the operator symbol. */ - while (*p == ' ' || *p == '\t') - p++; + p = skip_spaces (p); /* Recognize 'operator TYPENAME'. */ diff --git a/gdb/top.c b/gdb/top.c index 1214101ad18..4f689255907 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -467,8 +467,7 @@ execute_command (const char *p, int from_tty) target_log_command (p); - while (*p == ' ' || *p == '\t') - p++; + p = skip_spaces (p); if (*p) { const char *cmd = p; diff --git a/gdb/utils.c b/gdb/utils.c index ffe0d639e3a..d06ebc0014b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1473,10 +1473,8 @@ pager_file::prompt_for_continue () if (ignore != NULL) { - char *p = ignore.get (); + char *p = skip_spaces (ignore.get ()); - while (*p == ' ' || *p == '\t') - ++p; if (p[0] == 'q') /* Do not call quit here; there is no possibility of SIGINT. */ throw_quit ("Quit");