GDB (xrefs)

/tmp/gdb-8.1/gdb/location.h
Go to the documentation of this file.
1 /* Data structures and API for event locations in GDB.
2 Copyright (C) 2013-2018 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19 #ifndef LOCATIONS_H
20 #define LOCATIONS_H 1
21
22 struct language_defn;
23 struct event_location;
24
25 /* An enumeration of possible signs for a line offset. */
26
27 enum offset_relative_sign
28 {
29 /* No sign */
30 LINE_OFFSET_NONE,
31
32 /* A plus sign ("+") */
33 LINE_OFFSET_PLUS,
34
35 /* A minus sign ("-") */
36 LINE_OFFSET_MINUS,
37
38 /* A special "sign" for unspecified offset. */
39 LINE_OFFSET_UNKNOWN
40 };
41
42 /* A line offset in a location. */
43
44 struct line_offset
45 {
46 /* Line offset and any specified sign. */
47 int offset;
48 enum offset_relative_sign sign;
49 };
50
51 /* An enumeration of the various ways to specify a stop event
52 location (used with create_breakpoint). */
53
54 enum event_location_type
55 {
56 /* A traditional linespec. */
57 LINESPEC_LOCATION,
58
59 /* An address in the inferior. */
60 ADDRESS_LOCATION,
61
62 /* An explicit location. */
63 EXPLICIT_LOCATION,
64
65 /* A probe location. */
66 PROBE_LOCATION
67 };
68
69 /* A traditional linespec. */
70
71 struct linespec_location
72 {
73 /* Whether the function name is fully-qualified or not. */
74 symbol_name_match_type match_type;
75
76 /* The linespec. */
77 char *spec_string;
78 };
79
80 /* An explicit location. This structure is used to bypass the
81 parsing done on linespecs. It still has the same requirements
82 as linespecs, though. For example, source_filename requires
83 at least one other field. */
84
85 struct explicit_location
86 {
87 /* The source filename. Malloc'd. */
88 char *source_filename;
89
90 /* The function name. Malloc'd. */
91 char *function_name;
92
93 /* Whether the function name is fully-qualified or not. */
94 symbol_name_match_type func_name_match_type;
95
96 /* The name of a label. Malloc'd. */
97 char *label_name;
98
99 /* A line offset relative to the start of the symbol
100 identified by the above fields or the current symtab
101 if the other fields are NULL. */
102 struct line_offset line_offset;
103 };
104
105 /* Return the type of the given event location. */
106
107 extern enum event_location_type
108 event_location_type (const struct event_location *);
109
110 /* Return a malloc'd explicit string representation of the given
111 explicit location. The location must already be canonicalized/valid. */
112
113 extern char *
114 explicit_location_to_string (const struct explicit_location *explicit_loc);
115
116 /* Return a malloc'd linespec string representation of the given
117 explicit location. The location must already be canonicalized/valid. */
118
119 extern char *
120 explicit_location_to_linespec (const struct explicit_location *explicit_loc);
121
122 /* Return a string representation of the LOCATION.
123 This function may return NULL for unspecified linespecs,
124 e.g, LINESPEC_LOCATION and spec_string is NULL.
125
126 The result is cached in LOCATION. */
127
128 extern const char *
129 event_location_to_string (struct event_location *location);
130
131 /* A deleter for a struct event_location. */
132
133 struct event_location_deleter
134 {
135 void operator() (event_location *location) const;
136 };
137
138 /* A unique pointer for event_location. */
139 typedef std::unique_ptr<event_location, event_location_deleter>
140 event_location_up;
141
142 /* Create a new linespec location. */
143
144 extern event_location_up new_linespec_location
145 (const char **linespec, symbol_name_match_type match_type);
146
147 /* Return the linespec location of the given event_location (which
148 must be of type LINESPEC_LOCATION). */
149
150 extern const linespec_location *
151 get_linespec_location (const struct event_location *location);
152
153 /* Create a new address location.
154 ADDR is the address corresponding to this event_location.
155 ADDR_STRING, a string of ADDR_STRING_LEN characters, is
156 the expression that was parsed to determine the address ADDR. */
157
158 extern event_location_up new_address_location (CORE_ADDR addr,
159 const char *addr_string,
160 int addr_string_len);
161
162 /* Return the address location (a CORE_ADDR) of the given event_location
163 (which must be of type ADDRESS_LOCATION). */
164
165 extern CORE_ADDR
166 get_address_location (const struct event_location *location);
167
168 /* Return the expression (a string) that was used to compute the address
169 of the given event_location (which must be of type ADDRESS_LOCATION). */
170
171 extern const char *
172 get_address_string_location (const struct event_location *location);
173
174 /* Create a new probe location. */
175
176 extern event_location_up new_probe_location (const char *probe);
177
178 /* Return the probe location (a string) of the given event_location
179 (which must be of type PROBE_LOCATION). */
180
181 extern const char *
182 get_probe_location (const struct event_location *location);
183
184 /* Initialize the given explicit location. */
185
186 extern void
187 initialize_explicit_location (struct explicit_location *explicit_loc);
188
189 /* Create a new explicit location. If not NULL, EXPLICIT is checked for
190 validity. If invalid, an exception is thrown. */
191
192 extern event_location_up
193 new_explicit_location (const struct explicit_location *explicit_loc);
194
195 /* Return the explicit location of the given event_location
196 (which must be of type EXPLICIT_LOCATION). */
197
198 extern struct explicit_location *
199 get_explicit_location (struct event_location *location);
200
201 /* A const version of the above. */
202
203 extern const struct explicit_location *
204 get_explicit_location_const (const struct event_location *location);
205
206 /* Return a copy of the given SRC location. */
207
208 extern event_location_up
209 copy_event_location (const struct event_location *src);
210
211 /* Attempt to convert the input string in *ARGP into an event_location.
212 ARGP is advanced past any processed input. Returns an event_location
213 (malloc'd) if an event location was successfully found in *ARGP,
214 NULL otherwise.
215
216 This function may call error() if *ARGP looks like properly formed,
217 but invalid, input, e.g., if it is called with missing argument parameters
218 or invalid options.
219
220 This function is intended to be used by CLI commands and will parse
221 explicit locations in a CLI-centric way. Other interfaces should use
222 string_to_event_location_basic if they want to maintain support for
223 legacy specifications of probe, address, and linespec locations.
224
225 MATCH_TYPE should be either WILD or FULL. If -q/--qualified is specified
226 in the input string, it will take precedence over this parameter. */
227
228 extern event_location_up string_to_event_location
229 (const char **argp, const struct language_defn *langauge,
230 symbol_name_match_type match_type = symbol_name_match_type::WILD);
231
232 /* Like string_to_event_location, but does not attempt to parse
233 explicit locations. MATCH_TYPE indicates how function names should
234 be matched. */
235
236 extern event_location_up
237 string_to_event_location_basic (const char **argp,
238 const struct language_defn *language,
239 symbol_name_match_type match_type);
240
241 /* Structure filled in by string_to_explicit_location to aid the
242 completer. */
243 struct explicit_completion_info
244 {
245 /* Pointer to the last option found. E.g., in "b -sou src.c -fun
246 func", LAST_OPTION is left pointing at "-fun func". */
247 const char *last_option = NULL;
248
249 /* These point to the start and end of a quoted argument, iff the
250 last argument was quoted. If parsing finds an incomplete quoted
251 string (e.g., "break -function 'fun"), then QUOTED_ARG_START is
252 set to point to the opening \', and QUOTED_ARG_END is left NULL.
253 If the last option is not quoted, then both are set to NULL. */
254 const char *quoted_arg_start = NULL;
255 const char *quoted_arg_end = NULL;
256
257 /* True if we saw an explicit location option, as opposed to only
258 flags that affect both explicit locations and linespecs, like
259 "-qualified". */
260 bool saw_explicit_location_option = false;
261 };
262
263 /* Attempt to convert the input string in *ARGP into an explicit location.
264 ARGP is advanced past any processed input. Returns an event_location
265 (malloc'd) if an explicit location was successfully found in *ARGP,
266 NULL otherwise.
267
268 If COMPLETION_INFO is NULL, this function may call error() if *ARGP
269 looks like improperly formed input, e.g., if it is called with
270 missing argument parameters or invalid options. If COMPLETION_INFO
271 is not NULL, this function will not throw any exceptions. */
272
273 extern event_location_up
274 string_to_explicit_location (const char **argp,
275 const struct language_defn *language,
276 explicit_completion_info *completion_info);
277
278 /* A convenience function for testing for unset locations. */
279
280 extern int event_location_empty_p (const struct event_location *location);
281
282 /* Set the location's string representation. If STRING is NULL, clear
283 the string representation. */
284
285 extern void
286 set_event_location_string (struct event_location *location,
287 const char *string);
288 #endif /* LOCATIONS_H */
probe
Definition: probe.h:112
LINE_OFFSET_PLUS
Definition: location.h:33
new_explicit_location
event_location_up new_explicit_location(const struct explicit_location *explicit_loc)
Definition: location.c:178
event_location_to_string
const char * event_location_to_string(struct event_location *location)
Definition: location.c:397
CORE_ADDR
bfd_vma CORE_ADDR
Definition: common-types.h:41
ADDRESS_LOCATION
Definition: location.h:60
EXPLICIT_LOCATION
Definition: location.h:63
LINE_OFFSET_MINUS
Definition: location.h:36
LINE_OFFSET_NONE
Definition: location.h:30
linespec_location::spec_string
char * spec_string
Definition: location.h:77
LINESPEC_LOCATION
Definition: location.h:57
event_location_empty_p
int event_location_empty_p(const struct event_location *location)
Definition: location.c:951
new_linespec_location
event_location_up new_linespec_location(const char **linespec, symbol_name_match_type match_type)
Definition: location.c:88
set_event_location_string
void set_event_location_string(struct event_location *location, const char *string)
Definition: location.c:981
linespec_location::match_type
symbol_name_match_type match_type
Definition: location.h:74
language_defn
Definition: language.h:132
line_offset::sign
enum offset_relative_sign sign
Definition: location.h:48
string_to_event_location
event_location_up string_to_event_location(const char **argp, const struct language_defn *langauge, symbol_name_match_type match_type=symbol_name_match_type::WILD)
Definition: location.c:917
initialize_explicit_location
void initialize_explicit_location(struct explicit_location *explicit_loc)
Definition: location.c:78
offset_relative_sign
offset_relative_sign
Definition: location.h:27
explicit_completion_info::quoted_arg_start
const char * quoted_arg_start
Definition: location.h:254
get_explicit_location
struct explicit_location * get_explicit_location(struct event_location *location)
Definition: location.c:213
line_offset
Definition: location.h:44
explicit_location_to_string
char * explicit_location_to_string(const struct explicit_location *explicit_loc)
Definition: location.c:291
explicit_completion_info::last_option
const char * last_option
Definition: location.h:247
event_location_deleter::operator()
void operator()(event_location *location) const
Definition: location.c:360
copy_event_location
event_location_up copy_event_location(const struct event_location *src)
Definition: location.c:307
event_location
Definition: location.c:36
get_address_string_location
const char * get_address_string_location(const struct event_location *location)
Definition: location.c:146
explicit_location
Definition: location.h:85
event_location_up
std::unique_ptr< event_location, event_location_deleter > event_location_up
Definition: location.h:140
string_to_explicit_location
event_location_up string_to_explicit_location(const char **argp, const struct language_defn *language, explicit_completion_info *completion_info)
Definition: location.c:719
LINE_OFFSET_UNKNOWN
Definition: location.h:39
line_offset::offset
int offset
Definition: location.h:47
get_address_location
CORE_ADDR get_address_location(const struct event_location *location)
Definition: location.c:137
event_location_deleter
Definition: location.h:133
linespec
Definition: linespec.c:103
get_probe_location
const char * get_probe_location(const struct event_location *location)
Definition: location.c:169
event_location_type
event_location_type
Definition: location.h:54
explicit_location::function_name
char * function_name
Definition: location.h:91
explicit_location::func_name_match_type
symbol_name_match_type func_name_match_type
Definition: location.h:94
get_explicit_location_const
const struct explicit_location * get_explicit_location_const(const struct event_location *location)
Definition: location.c:222
PROBE_LOCATION
Definition: location.h:66
explicit_completion_info::quoted_arg_end
const char * quoted_arg_end
Definition: location.h:255
explicit_location_to_linespec
char * explicit_location_to_linespec(const struct explicit_location *explicit_loc)
Definition: location.c:299
string_to_event_location_basic
event_location_up string_to_event_location_basic(const char **argp, const struct language_defn *language, symbol_name_match_type match_type)
Definition: location.c:877
linespec_location
Definition: location.h:71
language
language
Definition: defs.h:203
explicit_location::source_filename
char * source_filename
Definition: location.h:88
explicit_location::label_name
char * label_name
Definition: location.h:97
new_address_location
event_location_up new_address_location(CORE_ADDR addr, const char *addr_string, int addr_string_len)
Definition: location.c:121
new_probe_location
event_location_up new_probe_location(const char *probe)
Definition: location.c:155
get_linespec_location
const linespec_location * get_linespec_location(const struct event_location *location)
Definition: location.c:112
symbol_name_match_type::WILD
explicit_completion_info
Definition: location.h:243
explicit_completion_info::saw_explicit_location_option
bool saw_explicit_location_option
Definition: location.h:260
symbol_name_match_type
symbol_name_match_type
Definition: symtab.h:52