gdb/cli/cli-utils.h - gdb

Data types defined

Macros defined

Source code

  1. /* CLI utilities.

  2.    Copyright (C) 2011-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #ifndef CLI_UTILS_H
  15. #define CLI_UTILS_H

  16. /* *PP is a string denoting a number.  Get the number of the.  Advance
  17.    *PP after the string and any trailing whitespace.

  18.    Currently the string can either be a number,  or "$" followed by the
  19.    name of a convenience variable, or ("$" or "$$") followed by digits.  */

  20. extern int get_number_const (const char **);

  21. /* Like get_number_const, but takes a non-const "char **".  */

  22. extern int get_number (char **);

  23. /* An object of this type is passed to get_number_or_range.  It must
  24.    be initialized by calling init_number_or_range.  This type is
  25.    defined here so that it can be stack-allocated, but all members
  26.    other than `finished' and `string' should be treated as opaque.  */

  27. struct get_number_or_range_state
  28. {
  29.   /* Non-zero if parsing has completed.  */
  30.   int finished;

  31.   /* The string being parsed.  When parsing has finished, this points
  32.      past the last parsed token.  */
  33.   const char *string;

  34.   /* Last value returned.  */
  35.   int last_retval;

  36.   /* When parsing a range, the final value in the range.  */
  37.   int end_value;

  38.   /* When parsing a range, a pointer past the final token in the
  39.      range.  */
  40.   const char *end_ptr;

  41.   /* Non-zero when parsing a range.  */
  42.   int in_range;
  43. };

  44. /* Initialize a get_number_or_range_state for use with
  45.    get_number_or_range_stateSTRING is the string to be parsed.  */

  46. extern void init_number_or_range (struct get_number_or_range_state *state,
  47.                                   const char *string);

  48. /* Parse a number or a range.
  49.    A number will be of the form handled by get_number.
  50.    A range will be of the form <number1> - <number2>, and
  51.    will represent all the integers between number1 and number2,
  52.    inclusive.

  53.    While processing a range, this fuction is called iteratively;
  54.    At each call it will return the next value in the range.

  55.    At the beginning of parsing a range, the char pointer STATE->string will
  56.    be advanced past <number1> and left pointing at the '-' token.
  57.    Subsequent calls will not advance the pointer until the range
  58.    is completed.  The call that completes the range will advance
  59.    the pointer past <number2>.  */

  60. extern int get_number_or_range (struct get_number_or_range_state *state);

  61. /* Accept a number and a string-form list of numbers such as is
  62.    accepted by get_number_or_range.  Return TRUE if the number is
  63.    in the list.

  64.    By definition, an empty list includes all numbers.  This is to
  65.    be interpreted as typing a command such as "delete break" with
  66.    no arguments.  */

  67. extern int number_is_in_list (const char *list, int number);

  68. /* Skip leading whitespace characters in INP, returning an updated
  69.    pointer.  If INP is NULL, return NULL.  */

  70. extern char *skip_spaces (char *inp);

  71. /* A const-correct version of the above.  */

  72. extern const char *skip_spaces_const (const char *inp);

  73. /* Skip leading non-whitespace characters in INP, returning an updated
  74.    pointer.  If INP is NULL, return NULL.  */

  75. #define skip_to_space(INP) ((char *) skip_to_space_const (INP))

  76. /* A const-correct version of the above.  */

  77. extern const char *skip_to_space_const (const char *inp);

  78. /* Reverse S to the last non-whitespace character without skipping past
  79.    START.  */

  80. extern char *remove_trailing_whitespace (const char *start, char *s);

  81. /* A helper function to extract an argument from *ARG.  An argument is
  82.    delimited by whitespace.  The return value is either NULL if no
  83.    argument was found, or an xmalloc'd string.  */

  84. extern char *extract_arg (char **arg);

  85. /* A const-correct version of "extract_arg".

  86.    Since the returned value is xmalloc'd, it eventually needs to be
  87.    xfree'ed, which prevents us from making it const as well.  */

  88. extern char *extract_arg_const (const char **arg);

  89. /* A helper function that looks for an argument at the start of a
  90.    string.  The argument must also either be at the end of the string,
  91.    or be followed by whitespace.  Returns 1 if it finds the argument,
  92.    0 otherwise.  If the argument is found, it updates *STR.  */
  93. extern int check_for_argument (char **str, char *arg, int arg_len);

  94. #endif /* CLI_UTILS_H */