location.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* Data structures and API for event locations in GDB.
  2. Copyright (C) 2013-2022 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 LOCATION_H
  15. #define LOCATION_H
  16. #include "symtab.h"
  17. struct language_defn;
  18. struct event_location;
  19. /* An enumeration of possible signs for a line offset. */
  20. enum offset_relative_sign
  21. {
  22. /* No sign */
  23. LINE_OFFSET_NONE,
  24. /* A plus sign ("+") */
  25. LINE_OFFSET_PLUS,
  26. /* A minus sign ("-") */
  27. LINE_OFFSET_MINUS,
  28. /* A special "sign" for unspecified offset. */
  29. LINE_OFFSET_UNKNOWN
  30. };
  31. /* A line offset in a location. */
  32. struct line_offset
  33. {
  34. /* Line offset and any specified sign. */
  35. int offset;
  36. enum offset_relative_sign sign;
  37. };
  38. /* An enumeration of the various ways to specify a stop event
  39. location (used with create_breakpoint). */
  40. enum event_location_type
  41. {
  42. /* A traditional linespec. */
  43. LINESPEC_LOCATION,
  44. /* An address in the inferior. */
  45. ADDRESS_LOCATION,
  46. /* An explicit location. */
  47. EXPLICIT_LOCATION,
  48. /* A probe location. */
  49. PROBE_LOCATION
  50. };
  51. /* A traditional linespec. */
  52. struct linespec_location
  53. {
  54. /* Whether the function name is fully-qualified or not. */
  55. symbol_name_match_type match_type;
  56. /* The linespec. */
  57. char *spec_string;
  58. };
  59. /* An explicit location. This structure is used to bypass the
  60. parsing done on linespecs. It still has the same requirements
  61. as linespecs, though. For example, source_filename requires
  62. at least one other field. */
  63. struct explicit_location
  64. {
  65. /* The source filename. Malloc'd. */
  66. char *source_filename;
  67. /* The function name. Malloc'd. */
  68. char *function_name;
  69. /* Whether the function name is fully-qualified or not. */
  70. symbol_name_match_type func_name_match_type;
  71. /* The name of a label. Malloc'd. */
  72. char *label_name;
  73. /* A line offset relative to the start of the symbol
  74. identified by the above fields or the current symtab
  75. if the other fields are NULL. */
  76. struct line_offset line_offset;
  77. };
  78. /* Return the type of the given event location. */
  79. extern enum event_location_type
  80. event_location_type (const struct event_location *);
  81. /* Return a linespec string representation of the given explicit
  82. location. The location must already be canonicalized/valid. */
  83. extern std::string
  84. explicit_location_to_linespec (const struct explicit_location *explicit_loc);
  85. /* Return a string representation of the LOCATION.
  86. This function may return NULL for unspecified linespecs,
  87. e.g, LINESPEC_LOCATION and spec_string is NULL.
  88. The result is cached in LOCATION. */
  89. extern const char *
  90. event_location_to_string (struct event_location *location);
  91. /* A deleter for a struct event_location. */
  92. struct event_location_deleter
  93. {
  94. void operator() (event_location *location) const;
  95. };
  96. /* A unique pointer for event_location. */
  97. typedef std::unique_ptr<event_location, event_location_deleter>
  98. event_location_up;
  99. /* Create a new linespec location. */
  100. extern event_location_up new_linespec_location
  101. (const char **linespec, symbol_name_match_type match_type);
  102. /* Return the linespec location of the given event_location (which
  103. must be of type LINESPEC_LOCATION). */
  104. extern const linespec_location *
  105. get_linespec_location (const struct event_location *location);
  106. /* Create a new address location.
  107. ADDR is the address corresponding to this event_location.
  108. ADDR_STRING, a string of ADDR_STRING_LEN characters, is
  109. the expression that was parsed to determine the address ADDR. */
  110. extern event_location_up new_address_location (CORE_ADDR addr,
  111. const char *addr_string,
  112. int addr_string_len);
  113. /* Return the address location (a CORE_ADDR) of the given event_location
  114. (which must be of type ADDRESS_LOCATION). */
  115. extern CORE_ADDR
  116. get_address_location (const struct event_location *location);
  117. /* Return the expression (a string) that was used to compute the address
  118. of the given event_location (which must be of type ADDRESS_LOCATION). */
  119. extern const char *
  120. get_address_string_location (const struct event_location *location);
  121. /* Create a new probe location. */
  122. extern event_location_up new_probe_location (std::string &&probe);
  123. /* Return the probe location (a string) of the given event_location
  124. (which must be of type PROBE_LOCATION). */
  125. extern const char *
  126. get_probe_location (const struct event_location *location);
  127. /* Initialize the given explicit location. */
  128. extern void
  129. initialize_explicit_location (struct explicit_location *explicit_loc);
  130. /* Create a new explicit location. If not NULL, EXPLICIT is checked for
  131. validity. If invalid, an exception is thrown. */
  132. extern event_location_up
  133. new_explicit_location (const struct explicit_location *explicit_loc);
  134. /* Return the explicit location of the given event_location
  135. (which must be of type EXPLICIT_LOCATION). */
  136. extern struct explicit_location *
  137. get_explicit_location (struct event_location *location);
  138. /* A const version of the above. */
  139. extern const struct explicit_location *
  140. get_explicit_location_const (const struct event_location *location);
  141. /* Return a copy of the given SRC location. */
  142. extern event_location_up
  143. copy_event_location (const struct event_location *src);
  144. /* Attempt to convert the input string in *ARGP into an event_location.
  145. ARGP is advanced past any processed input. Always returns a non-nullptr
  146. event_location unique pointer object.
  147. This function may call error() if *ARGP looks like properly formed, but
  148. invalid, input, e.g., if it is called with missing argument parameters
  149. or invalid options.
  150. This function is intended to be used by CLI commands and will parse
  151. explicit locations in a CLI-centric way. Other interfaces should use
  152. string_to_event_location_basic if they want to maintain support for
  153. legacy specifications of probe, address, and linespec locations.
  154. MATCH_TYPE should be either WILD or FULL. If -q/--qualified is specified
  155. in the input string, it will take precedence over this parameter. */
  156. extern event_location_up string_to_event_location
  157. (const char **argp, const struct language_defn *language,
  158. symbol_name_match_type match_type = symbol_name_match_type::WILD);
  159. /* Like string_to_event_location, but does not attempt to parse
  160. explicit locations. MATCH_TYPE indicates how function names should
  161. be matched. */
  162. extern event_location_up
  163. string_to_event_location_basic (const char **argp,
  164. const struct language_defn *language,
  165. symbol_name_match_type match_type);
  166. /* Structure filled in by string_to_explicit_location to aid the
  167. completer. */
  168. struct explicit_completion_info
  169. {
  170. /* Pointer to the last option found. E.g., in "b -sou src.c -fun
  171. func", LAST_OPTION is left pointing at "-fun func". */
  172. const char *last_option = NULL;
  173. /* These point to the start and end of a quoted argument, iff the
  174. last argument was quoted. If parsing finds an incomplete quoted
  175. string (e.g., "break -function 'fun"), then QUOTED_ARG_START is
  176. set to point to the opening \', and QUOTED_ARG_END is left NULL.
  177. If the last option is not quoted, then both are set to NULL. */
  178. const char *quoted_arg_start = NULL;
  179. const char *quoted_arg_end = NULL;
  180. /* True if we saw an explicit location option, as opposed to only
  181. flags that affect both explicit locations and linespecs, like
  182. "-qualified". */
  183. bool saw_explicit_location_option = false;
  184. };
  185. /* Attempt to convert the input string in *ARGP into an explicit location.
  186. ARGP is advanced past any processed input. Returns an event_location
  187. (malloc'd) if an explicit location was successfully found in *ARGP,
  188. NULL otherwise.
  189. If COMPLETION_INFO is NULL, this function may call error() if *ARGP
  190. looks like improperly formed input, e.g., if it is called with
  191. missing argument parameters or invalid options. If COMPLETION_INFO
  192. is not NULL, this function will not throw any exceptions. */
  193. extern event_location_up
  194. string_to_explicit_location (const char **argp,
  195. const struct language_defn *language,
  196. explicit_completion_info *completion_info);
  197. /* A convenience function for testing for unset locations. */
  198. extern int event_location_empty_p (const struct event_location *location);
  199. /* Set the location's string representation. */
  200. extern void
  201. set_event_location_string (struct event_location *location,
  202. std::string &&string);
  203. #endif /* LOCATION_H */