]>
Commit | Line | Data |
---|---|---|
494cca16 AC |
1 | /* Definitions for frame unwinder, for GDB, the GNU debugger. |
2 | ||
d01e8234 | 3 | Copyright (C) 2003-2025 Free Software Foundation, Inc. |
494cca16 AC |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
494cca16 AC |
10 | (at your option) any later version. |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
494cca16 | 19 | |
ec452525 | 20 | #include "extract-store-integer.h" |
d55e5aa6 | 21 | #include "frame.h" |
4de283e4 TT |
22 | #include "frame-unwind.h" |
23 | #include "dummy-frame.h" | |
edb3359d | 24 | #include "inline-frame.h" |
4de283e4 | 25 | #include "value.h" |
669fac23 | 26 | #include "regcache.h" |
bf31fd38 | 27 | #include "gdbsupport/gdb_obstack.h" |
ea001bdc | 28 | #include "target.h" |
0d12e84c | 29 | #include "gdbarch.h" |
1009d92f | 30 | #include "dwarf2/frame-tailcall.h" |
be016879 | 31 | #include "cli/cli-cmds.h" |
b49f56d0 | 32 | #include "cli/cli-option.h" |
99d9c3b9 | 33 | #include "inferior.h" |
494cca16 | 34 | |
ce36ef63 GL |
35 | /* Conversion list between the enum for frame_unwind_class and |
36 | string. */ | |
37 | static const char * unwind_class_conversion[] = | |
38 | { | |
39 | "GDB", | |
40 | "EXTENSION", | |
41 | "DEBUGINFO", | |
42 | "ARCH", | |
b49f56d0 | 43 | nullptr |
ce36ef63 GL |
44 | }; |
45 | ||
3919cf8a GL |
46 | /* Default sniffers, that must always be the first in the unwinder list, |
47 | no matter the architecture. */ | |
48 | static constexpr std::initializer_list<const frame_unwind *> | |
49 | standard_unwinders = | |
494cca16 | 50 | { |
3919cf8a | 51 | &dummy_frame_unwind, |
4b42385c | 52 | #if defined(DWARF_FORMAT_AVAILABLE) |
3919cf8a GL |
53 | /* The DWARF tailcall sniffer must come before the inline sniffer. |
54 | Otherwise, we can end up in a situation where a DWARF frame finds | |
55 | tailcall information, but then the inline sniffer claims a frame | |
56 | before the tailcall sniffer, resulting in confusion. This is | |
57 | safe to do always because the tailcall sniffer can only ever be | |
58 | activated if the newer frame was created using the DWARF | |
59 | unwinder, and it also found tailcall information. */ | |
60 | &dwarf2_tailcall_frame_unwind, | |
4b42385c | 61 | #endif |
3919cf8a | 62 | &inline_frame_unwind, |
494cca16 AC |
63 | }; |
64 | ||
3919cf8a GL |
65 | /* If an unwinder should be prepended to the list, this is the |
66 | index in which it should be inserted. */ | |
67 | static constexpr int prepend_unwinder_index = standard_unwinders.size (); | |
494cca16 | 68 | |
3919cf8a | 69 | static const registry<gdbarch>::key<std::vector<const frame_unwind *>> |
cb275538 TT |
70 | frame_unwind_data; |
71 | ||
3919cf8a GL |
72 | /* Retrieve the list of frame unwinders available in GDBARCH. |
73 | If this list is empty, it is initialized before being returned. */ | |
74 | static std::vector<const frame_unwind *> & | |
cb275538 | 75 | get_frame_unwind_table (struct gdbarch *gdbarch) |
494cca16 | 76 | { |
3919cf8a | 77 | std::vector<const frame_unwind *> *table = frame_unwind_data.get (gdbarch); |
d8c4a58b TT |
78 | if (table == nullptr) |
79 | table = frame_unwind_data.emplace (gdbarch, | |
80 | standard_unwinders.begin (), | |
81 | standard_unwinders.end ()); | |
3919cf8a | 82 | return *table; |
494cca16 AC |
83 | } |
84 | ||
ce36ef63 GL |
85 | static const char * |
86 | frame_unwinder_class_str (frame_unwind_class uclass) | |
87 | { | |
88 | gdb_assert (uclass < UNWIND_CLASS_NUMBER); | |
89 | return unwind_class_conversion[uclass]; | |
90 | } | |
91 | ||
b49f56d0 GL |
92 | /* Case insensitive search for a frame_unwind_class based on the given |
93 | string. */ | |
94 | static enum frame_unwind_class | |
95 | str_to_frame_unwind_class (const char *class_str) | |
96 | { | |
97 | for (int i = 0; i < UNWIND_CLASS_NUMBER; i++) | |
98 | { | |
99 | if (strcasecmp (unwind_class_conversion[i], class_str) == 0) | |
100 | return (frame_unwind_class) i; | |
101 | } | |
102 | ||
103 | error (_("Unknown frame unwind class: %s"), class_str); | |
104 | } | |
105 | ||
82417da5 | 106 | void |
fb2be677 | 107 | frame_unwind_prepend_unwinder (struct gdbarch *gdbarch, |
82417da5 AC |
108 | const struct frame_unwind *unwinder) |
109 | { | |
3919cf8a GL |
110 | std::vector<const frame_unwind *> &table = get_frame_unwind_table (gdbarch); |
111 | ||
112 | table.insert (table.begin () + prepend_unwinder_index, unwinder); | |
82417da5 AC |
113 | } |
114 | ||
669fac23 DJ |
115 | void |
116 | frame_unwind_append_unwinder (struct gdbarch *gdbarch, | |
117 | const struct frame_unwind *unwinder) | |
118 | { | |
3919cf8a | 119 | get_frame_unwind_table (gdbarch).push_back (unwinder); |
669fac23 DJ |
120 | } |
121 | ||
ea001bdc | 122 | /* Call SNIFFER from UNWINDER. If it succeeded set UNWINDER for |
a227513b GL |
123 | THIS_FRAME and return true. Otherwise the function keeps THIS_FRAME |
124 | unchanged and returns false. */ | |
ea001bdc | 125 | |
a227513b | 126 | static bool |
8480a37e | 127 | frame_unwind_try_unwinder (const frame_info_ptr &this_frame, void **this_cache, |
dda83cd7 | 128 | const struct frame_unwind *unwinder) |
ea001bdc | 129 | { |
ea001bdc MM |
130 | int res = 0; |
131 | ||
e7bc9db8 PA |
132 | unsigned int entry_generation = get_frame_cache_generation (); |
133 | ||
30a9c02f | 134 | frame_prepare_for_sniffer (this_frame, unwinder); |
ea001bdc | 135 | |
a70b8144 | 136 | try |
ea001bdc | 137 | { |
1239e7cf GL |
138 | frame_debug_printf ("trying unwinder \"%s\"", unwinder->name ()); |
139 | res = unwinder->sniff (this_frame, this_cache); | |
ea001bdc | 140 | } |
230d2906 | 141 | catch (const gdb_exception &ex) |
ea001bdc | 142 | { |
a154d838 SM |
143 | frame_debug_printf ("caught exception: %s", ex.message->c_str ()); |
144 | ||
be7d3cd5 | 145 | /* Catch all exceptions, caused by either interrupt or error. |
e7bc9db8 PA |
146 | Reset *THIS_CACHE, unless something reinitialized the frame |
147 | cache meanwhile, in which case THIS_FRAME/THIS_CACHE are now | |
148 | dangling. */ | |
149 | if (get_frame_cache_generation () == entry_generation) | |
150 | { | |
151 | *this_cache = NULL; | |
152 | frame_cleanup_after_sniffer (this_frame); | |
153 | } | |
980548fd | 154 | |
7556d4a4 PA |
155 | if (ex.error == NOT_AVAILABLE_ERROR) |
156 | { | |
157 | /* This usually means that not even the PC is available, | |
158 | thus most unwinders aren't able to determine if they're | |
159 | the best fit. Keep trying. Fallback prologue unwinders | |
160 | should always accept the frame. */ | |
a227513b | 161 | return false; |
7556d4a4 | 162 | } |
eedc3f4f | 163 | throw; |
ea001bdc | 164 | } |
7556d4a4 PA |
165 | |
166 | if (res) | |
a154d838 SM |
167 | { |
168 | frame_debug_printf ("yes"); | |
a227513b | 169 | return true; |
a154d838 | 170 | } |
ea001bdc MM |
171 | else |
172 | { | |
a154d838 | 173 | frame_debug_printf ("no"); |
be7d3cd5 YQ |
174 | /* Don't set *THIS_CACHE to NULL here, because sniffer has to do |
175 | so. */ | |
30a9c02f | 176 | frame_cleanup_after_sniffer (this_frame); |
a227513b | 177 | return false; |
ea001bdc MM |
178 | } |
179 | gdb_assert_not_reached ("frame_unwind_try_unwinder"); | |
180 | } | |
181 | ||
9f9a8002 JK |
182 | /* Iterate through sniffers for THIS_FRAME frame until one returns with an |
183 | unwinder implementation. THIS_FRAME->UNWIND must be NULL, it will get set | |
184 | by this function. Possibly initialize THIS_CACHE. */ | |
185 | ||
186 | void | |
8480a37e | 187 | frame_unwind_find_by_frame (const frame_info_ptr &this_frame, void **this_cache) |
e8a89fe2 | 188 | { |
fe67a58f | 189 | FRAME_SCOPED_DEBUG_ENTER_EXIT; |
a154d838 SM |
190 | frame_debug_printf ("this_frame=%d", frame_relative_level (this_frame)); |
191 | ||
b49f56d0 GL |
192 | /* If we see a disabled unwinder, we assume some test is being run on |
193 | GDB, and we don't want to internal_error at the end of this function. */ | |
194 | bool seen_disabled_unwinder = false; | |
195 | /* Lambda to factor out the logic of checking if an unwinder is enabled, | |
196 | testing it and otherwise recording if we saw a disable unwinder. */ | |
197 | auto test_unwinder = [&] (const struct frame_unwind *unwinder) | |
198 | { | |
199 | if (unwinder == nullptr) | |
200 | return false; | |
ea001bdc | 201 | |
b49f56d0 GL |
202 | if (!unwinder->enabled ()) |
203 | { | |
204 | seen_disabled_unwinder = true; | |
205 | return false; | |
206 | } | |
207 | ||
208 | return frame_unwind_try_unwinder (this_frame, | |
209 | this_cache, | |
210 | unwinder); | |
211 | }; | |
212 | ||
213 | if (test_unwinder (target_get_unwinder ())) | |
ea001bdc MM |
214 | return; |
215 | ||
b49f56d0 | 216 | if (test_unwinder (target_get_tailcall_unwinder ())) |
ea001bdc | 217 | return; |
1c5465ac | 218 | |
3919cf8a GL |
219 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
220 | std::vector<const frame_unwind *> &table = get_frame_unwind_table (gdbarch); | |
221 | for (const auto &unwinder : table) | |
b49f56d0 GL |
222 | { |
223 | if (test_unwinder (unwinder)) | |
224 | return; | |
225 | } | |
8fbca658 | 226 | |
b49f56d0 GL |
227 | if (seen_disabled_unwinder) |
228 | error (_("Required frame unwinder may have been disabled" | |
229 | ", see 'maint info frame-unwinders'")); | |
230 | else | |
231 | internal_error (_("frame_unwind_find_by_frame failed")); | |
494cca16 AC |
232 | } |
233 | ||
669fac23 DJ |
234 | /* A default frame sniffer which always accepts the frame. Used by |
235 | fallback prologue unwinders. */ | |
236 | ||
237 | int | |
238 | default_frame_sniffer (const struct frame_unwind *self, | |
8480a37e | 239 | const frame_info_ptr &this_frame, |
669fac23 DJ |
240 | void **this_prologue_cache) |
241 | { | |
242 | return 1; | |
243 | } | |
244 | ||
50fd528a | 245 | /* The default frame unwinder stop_reason callback. */ |
8fbca658 PA |
246 | |
247 | enum unwind_stop_reason | |
8480a37e | 248 | default_frame_unwind_stop_reason (const frame_info_ptr &this_frame, |
8fbca658 PA |
249 | void **this_cache) |
250 | { | |
50fd528a PA |
251 | struct frame_id this_id = get_frame_id (this_frame); |
252 | ||
a0cbd650 | 253 | if (this_id == outer_frame_id) |
50fd528a PA |
254 | return UNWIND_OUTERMOST; |
255 | else | |
256 | return UNWIND_NO_REASON; | |
8fbca658 PA |
257 | } |
258 | ||
8bcb5208 AB |
259 | /* See frame-unwind.h. */ |
260 | ||
261 | CORE_ADDR | |
8480a37e | 262 | default_unwind_pc (struct gdbarch *gdbarch, const frame_info_ptr &next_frame) |
8bcb5208 AB |
263 | { |
264 | int pc_regnum = gdbarch_pc_regnum (gdbarch); | |
265 | CORE_ADDR pc = frame_unwind_register_unsigned (next_frame, pc_regnum); | |
266 | pc = gdbarch_addr_bits_remove (gdbarch, pc); | |
267 | return pc; | |
268 | } | |
269 | ||
270 | /* See frame-unwind.h. */ | |
271 | ||
272 | CORE_ADDR | |
8480a37e | 273 | default_unwind_sp (struct gdbarch *gdbarch, const frame_info_ptr &next_frame) |
8bcb5208 AB |
274 | { |
275 | int sp_regnum = gdbarch_sp_regnum (gdbarch); | |
276 | return frame_unwind_register_unsigned (next_frame, sp_regnum); | |
277 | } | |
278 | ||
669fac23 DJ |
279 | /* Helper functions for value-based register unwinding. These return |
280 | a (possibly lazy) value of the appropriate type. */ | |
281 | ||
282 | /* Return a value which indicates that FRAME did not save REGNUM. */ | |
283 | ||
284 | struct value * | |
8480a37e | 285 | frame_unwind_got_optimized (const frame_info_ptr &frame, int regnum) |
669fac23 | 286 | { |
908fa2aa PA |
287 | struct gdbarch *gdbarch = frame_unwind_arch (frame); |
288 | struct type *type = register_type (gdbarch, regnum); | |
8efaf6b3 | 289 | |
b27556e3 | 290 | return value::allocate_optimized_out (type); |
669fac23 DJ |
291 | } |
292 | ||
293 | /* Return a value which indicates that FRAME copied REGNUM into | |
294 | register NEW_REGNUM. */ | |
295 | ||
296 | struct value * | |
8480a37e | 297 | frame_unwind_got_register (const frame_info_ptr &frame, |
3e43a32a | 298 | int regnum, int new_regnum) |
669fac23 | 299 | { |
a7952927 SM |
300 | return value_of_register_lazy (get_next_frame_sentinel_okay (frame), |
301 | new_regnum); | |
669fac23 DJ |
302 | } |
303 | ||
304 | /* Return a value which indicates that FRAME saved REGNUM in memory at | |
305 | ADDR. */ | |
306 | ||
307 | struct value * | |
8480a37e | 308 | frame_unwind_got_memory (const frame_info_ptr &frame, int regnum, CORE_ADDR addr) |
669fac23 | 309 | { |
36f15f55 | 310 | struct gdbarch *gdbarch = frame_unwind_arch (frame); |
4e5d721f | 311 | struct value *v = value_at_lazy (register_type (gdbarch, regnum), addr); |
669fac23 | 312 | |
42c13555 | 313 | v->set_stack (true); |
4e5d721f | 314 | return v; |
669fac23 DJ |
315 | } |
316 | ||
317 | /* Return a value which indicates that FRAME's saved version of | |
318 | REGNUM has a known constant (computed) value of VAL. */ | |
319 | ||
320 | struct value * | |
8480a37e | 321 | frame_unwind_got_constant (const frame_info_ptr &frame, int regnum, |
669fac23 DJ |
322 | ULONGEST val) |
323 | { | |
36f15f55 | 324 | struct gdbarch *gdbarch = frame_unwind_arch (frame); |
e17a4113 | 325 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
669fac23 DJ |
326 | struct value *reg_val; |
327 | ||
ee7bb294 | 328 | reg_val = value::zero (register_type (gdbarch, regnum), not_lval); |
bbe912ba | 329 | store_unsigned_integer (reg_val->contents_writeable ().data (), |
e17a4113 | 330 | register_size (gdbarch, regnum), byte_order, val); |
669fac23 DJ |
331 | return reg_val; |
332 | } | |
333 | ||
15c1e57f | 334 | struct value * |
ad592596 TJB |
335 | frame_unwind_got_bytes (const frame_info_ptr &frame, int regnum, |
336 | gdb::array_view<const gdb_byte> buf) | |
15c1e57f | 337 | { |
36f15f55 | 338 | struct gdbarch *gdbarch = frame_unwind_arch (frame); |
15c1e57f JB |
339 | struct value *reg_val; |
340 | ||
ee7bb294 | 341 | reg_val = value::zero (register_type (gdbarch, regnum), not_lval); |
ad592596 TJB |
342 | gdb::array_view<gdb_byte> val_contents = reg_val->contents_raw (); |
343 | ||
344 | /* The value's contents buffer is zeroed on allocation so if buf is | |
345 | smaller, the remaining space will be filled with zero. | |
346 | ||
347 | This can happen when unwinding through signal frames. For example, if | |
348 | an AArch64 program doesn't use SVE, then the Linux kernel will only | |
349 | save in the signal frame the first 128 bits of the vector registers, | |
350 | which is their minimum size, even if the vector length says they're | |
351 | bigger. */ | |
352 | gdb_assert (buf.size () <= val_contents.size ()); | |
353 | ||
354 | memcpy (val_contents.data (), buf.data (), buf.size ()); | |
15c1e57f JB |
355 | return reg_val; |
356 | } | |
357 | ||
669fac23 DJ |
358 | /* Return a value which indicates that FRAME's saved version of REGNUM |
359 | has a known constant (computed) value of ADDR. Convert the | |
360 | CORE_ADDR to a target address if necessary. */ | |
361 | ||
362 | struct value * | |
8480a37e | 363 | frame_unwind_got_address (const frame_info_ptr &frame, int regnum, |
669fac23 DJ |
364 | CORE_ADDR addr) |
365 | { | |
36f15f55 | 366 | struct gdbarch *gdbarch = frame_unwind_arch (frame); |
669fac23 DJ |
367 | struct value *reg_val; |
368 | ||
ee7bb294 | 369 | reg_val = value::zero (register_type (gdbarch, regnum), not_lval); |
bbe912ba | 370 | pack_long (reg_val->contents_writeable ().data (), |
669fac23 DJ |
371 | register_type (gdbarch, regnum), addr); |
372 | return reg_val; | |
373 | } | |
be016879 | 374 | |
1239e7cf GL |
375 | /* See frame-unwind.h. */ |
376 | ||
377 | enum unwind_stop_reason | |
378 | frame_unwind_legacy::stop_reason (const frame_info_ptr &this_frame, | |
379 | void **this_prologue_cache) const | |
380 | { | |
381 | return m_stop_reason (this_frame, this_prologue_cache); | |
382 | } | |
383 | ||
384 | /* See frame-unwind.h. */ | |
385 | ||
386 | void | |
387 | frame_unwind_legacy::this_id (const frame_info_ptr &this_frame, | |
388 | void **this_prologue_cache, | |
389 | struct frame_id *id) const | |
390 | { | |
391 | return m_this_id (this_frame, this_prologue_cache, id); | |
392 | } | |
393 | ||
394 | /* See frame-unwind.h. */ | |
395 | ||
396 | struct value * | |
397 | frame_unwind_legacy::prev_register (const frame_info_ptr &this_frame, | |
398 | void **this_prologue_cache, | |
399 | int regnum) const | |
400 | { | |
401 | return m_prev_register (this_frame, this_prologue_cache, regnum); | |
402 | } | |
403 | ||
404 | /* See frame-unwind.h. */ | |
405 | ||
406 | int | |
407 | frame_unwind_legacy::sniff (const frame_info_ptr &this_frame, | |
408 | void **this_prologue_cache) const | |
409 | { | |
410 | return m_sniffer (this, this_frame, this_prologue_cache); | |
411 | } | |
412 | ||
413 | /* See frame-unwind.h. */ | |
414 | ||
415 | void | |
416 | frame_unwind_legacy::dealloc_cache (frame_info *self, void *this_cache) const | |
417 | { | |
418 | if (m_dealloc_cache != nullptr) | |
419 | m_dealloc_cache (self, this_cache); | |
420 | } | |
421 | ||
422 | /* See frame-unwind.h. */ | |
423 | ||
424 | struct gdbarch * | |
425 | frame_unwind_legacy::prev_arch (const frame_info_ptr &this_frame, | |
426 | void **this_prologue_cache) const | |
427 | { | |
428 | if (m_prev_arch == nullptr) | |
429 | return frame_unwind::prev_arch (this_frame, this_prologue_cache); | |
430 | return m_prev_arch (this_frame, this_prologue_cache); | |
431 | } | |
432 | ||
be016879 TV |
433 | /* Implement "maintenance info frame-unwinders" command. */ |
434 | ||
435 | static void | |
436 | maintenance_info_frame_unwinders (const char *args, int from_tty) | |
437 | { | |
99d9c3b9 | 438 | gdbarch *gdbarch = current_inferior ()->arch (); |
3919cf8a | 439 | std::vector<const frame_unwind *> &table = get_frame_unwind_table (gdbarch); |
be016879 | 440 | |
b4614d10 | 441 | ui_out *uiout = current_uiout; |
b49f56d0 | 442 | ui_out_emit_table table_emitter (uiout, 4, -1, "FrameUnwinders"); |
b4614d10 TT |
443 | uiout->table_header (27, ui_left, "name", "Name"); |
444 | uiout->table_header (25, ui_left, "type", "Type"); | |
ce36ef63 | 445 | uiout->table_header (9, ui_left, "class", "Class"); |
b49f56d0 | 446 | uiout->table_header (8, ui_left, "enabled", "Enabled"); |
b4614d10 TT |
447 | uiout->table_body (); |
448 | ||
3919cf8a | 449 | for (const auto &unwinder : table) |
be016879 | 450 | { |
b4614d10 | 451 | ui_out_emit_list tuple_emitter (uiout, nullptr); |
1239e7cf GL |
452 | uiout->field_string ("name", unwinder->name ()); |
453 | uiout->field_string ("type", frame_type_str (unwinder->type ())); | |
ce36ef63 | 454 | uiout->field_string ("class", frame_unwinder_class_str ( |
1239e7cf | 455 | unwinder->unwinder_class ())); |
b49f56d0 | 456 | uiout->field_string ("enabled", unwinder->enabled () ? "Y" : "N"); |
b4614d10 | 457 | uiout->text ("\n"); |
be016879 TV |
458 | } |
459 | } | |
460 | ||
b49f56d0 GL |
461 | /* Options for disabling frame unwinders. */ |
462 | struct maint_frame_unwind_options | |
463 | { | |
464 | std::string unwinder_name; | |
465 | const char *unwinder_class = nullptr; | |
466 | bool all = false; | |
467 | }; | |
468 | ||
469 | static const gdb::option::option_def maint_frame_unwind_opt_defs[] = { | |
470 | ||
471 | gdb::option::flag_option_def<maint_frame_unwind_options> { | |
472 | "all", | |
473 | [] (maint_frame_unwind_options *opt) { return &opt->all; }, | |
474 | N_("Change the state of all unwinders") | |
475 | }, | |
476 | gdb::option::string_option_def<maint_frame_unwind_options> { | |
477 | "name", | |
478 | [] (maint_frame_unwind_options *opt) { return &opt->unwinder_name; }, | |
479 | nullptr, | |
480 | N_("The name of the unwinder to have its state changed") | |
481 | }, | |
482 | gdb::option::enum_option_def<maint_frame_unwind_options> { | |
483 | "class", | |
484 | unwind_class_conversion, | |
485 | [] (maint_frame_unwind_options *opt) { return &opt->unwinder_class; }, | |
486 | nullptr, | |
487 | N_("The class of unwinders to have their states changed") | |
488 | } | |
489 | }; | |
490 | ||
491 | static inline gdb::option::option_def_group | |
492 | make_frame_unwind_enable_disable_options (maint_frame_unwind_options *opts) | |
493 | { | |
494 | return {{maint_frame_unwind_opt_defs}, opts}; | |
495 | } | |
496 | ||
497 | /* Helper function to both enable and disable frame unwinders. | |
498 | If ENABLE is true, this call will be enabling unwinders, | |
499 | otherwise the unwinders will be disabled. */ | |
500 | static void | |
501 | enable_disable_frame_unwinders (const char *args, int from_tty, bool enable) | |
502 | { | |
503 | if (args == nullptr) | |
504 | { | |
505 | if (enable) | |
506 | error (_("Specify which frame unwinder(s) should be enabled")); | |
507 | else | |
508 | error (_("Specify which frame unwinder(s) should be disabled")); | |
509 | } | |
510 | ||
511 | struct gdbarch* gdbarch = current_inferior ()->arch (); | |
512 | std::vector<const frame_unwind *> unwinder_list | |
513 | = get_frame_unwind_table (gdbarch); | |
514 | ||
515 | maint_frame_unwind_options opts; | |
516 | gdb::option::process_options | |
517 | (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, | |
518 | make_frame_unwind_enable_disable_options (&opts)); | |
519 | ||
520 | if ((opts.all && !opts.unwinder_name.empty ()) | |
521 | || (opts.all && opts.unwinder_class != nullptr) | |
522 | || (!opts.unwinder_name.empty () && opts.unwinder_class != nullptr)) | |
523 | error (_("Options are mutually exclusive")); | |
524 | ||
525 | /* First see if the user wants to change all unwinders. */ | |
526 | if (opts.all) | |
527 | { | |
528 | for (const frame_unwind *u : unwinder_list) | |
529 | u->set_enabled (enable); | |
530 | ||
531 | reinit_frame_cache (); | |
532 | return; | |
533 | } | |
534 | ||
535 | /* If user entered a specific unwinder name, handle it here. If the | |
536 | unwinder is already at the expected state, error out. */ | |
537 | if (!opts.unwinder_name.empty ()) | |
538 | { | |
539 | bool did_something = false; | |
540 | for (const frame_unwind *unwinder : unwinder_list) | |
541 | { | |
542 | if (strcasecmp (unwinder->name (), | |
543 | opts.unwinder_name.c_str ()) == 0) | |
544 | { | |
545 | if (unwinder->enabled () == enable) | |
546 | { | |
547 | if (unwinder->enabled ()) | |
548 | error (_("unwinder %s is already enabled"), | |
549 | unwinder->name ()); | |
550 | else | |
551 | error (_("unwinder %s is already disabled"), | |
552 | unwinder->name ()); | |
553 | } | |
554 | unwinder->set_enabled (enable); | |
555 | ||
556 | did_something = true; | |
557 | break; | |
558 | } | |
559 | } | |
560 | if (!did_something) | |
561 | error (_("couldn't find unwinder named %s"), | |
562 | opts.unwinder_name.c_str ()); | |
563 | } | |
564 | else | |
565 | { | |
566 | if (opts.unwinder_class == nullptr) | |
567 | opts.unwinder_class = args; | |
568 | enum frame_unwind_class dclass = str_to_frame_unwind_class | |
569 | (opts.unwinder_class); | |
570 | for (const frame_unwind *unwinder: unwinder_list) | |
571 | { | |
572 | if (unwinder->unwinder_class () == dclass) | |
573 | unwinder->set_enabled (enable); | |
574 | } | |
575 | } | |
576 | ||
577 | reinit_frame_cache (); | |
578 | } | |
579 | ||
580 | /* Completer for the "maint frame-unwinder enable|disable" commands. */ | |
581 | ||
582 | static void | |
583 | enable_disable_frame_unwinders_completer (struct cmd_list_element *ignore, | |
584 | completion_tracker &tracker, | |
585 | const char *text, | |
586 | const char * /*word*/) | |
587 | { | |
588 | maint_frame_unwind_options opts; | |
589 | const auto group = make_frame_unwind_enable_disable_options (&opts); | |
590 | ||
591 | const char *start = text; | |
592 | if (gdb::option::complete_options | |
593 | (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group)) | |
594 | return; | |
595 | ||
596 | /* Only complete a class name as a stand-alone operand when no options | |
597 | are given. */ | |
598 | if (start == text) | |
599 | complete_on_enum (tracker, unwind_class_conversion, text, text); | |
600 | return; | |
601 | } | |
602 | ||
603 | /* Implement "maint frame-unwinder disable" command. */ | |
604 | static void | |
605 | maintenance_disable_frame_unwinders (const char *args, int from_tty) | |
606 | { | |
607 | enable_disable_frame_unwinders (args, from_tty, false); | |
608 | } | |
609 | ||
610 | /* Implement "maint frame-unwinder enable" command. */ | |
611 | static void | |
612 | maintenance_enable_frame_unwinders (const char *args, int from_tty) | |
613 | { | |
614 | enable_disable_frame_unwinders (args, from_tty, true); | |
615 | } | |
616 | ||
5fe70629 | 617 | INIT_GDB_FILE (frame_unwind) |
be016879 TV |
618 | { |
619 | /* Add "maint info frame-unwinders". */ | |
620 | add_cmd ("frame-unwinders", | |
621 | class_maintenance, | |
622 | maintenance_info_frame_unwinders, | |
fc55e99a TT |
623 | _("\ |
624 | List the frame unwinders currently in effect.\n\ | |
625 | Unwinders are listed starting with the highest priority."), | |
be016879 | 626 | &maintenanceinfolist); |
b49f56d0 GL |
627 | |
628 | /* Add "maint frame-unwinder disable/enable". */ | |
629 | static struct cmd_list_element *maint_frame_unwinder; | |
630 | ||
631 | add_basic_prefix_cmd ("frame-unwinder", class_maintenance, | |
632 | _("Commands handling frame unwinders."), | |
633 | &maint_frame_unwinder, 0, &maintenancelist); | |
634 | ||
635 | cmd_list_element *c | |
636 | = add_cmd ("disable", class_maintenance, maintenance_disable_frame_unwinders, | |
637 | _("\ | |
638 | Disable one or more frame unwinder(s).\n\ | |
639 | Usage: maint frame-unwinder disable [-all | -name NAME | [-class] CLASS]\n\ | |
640 | \n\ | |
641 | These are the meanings of the options:\n\ | |
642 | \t-all - All available unwinders will be disabled\n\ | |
643 | \t-name - NAME is the exact name of the frame unwinder to be disabled\n\ | |
644 | \t-class - CLASS is the class of unwinders to be disabled. Valid classes are:\n\ | |
645 | \t\tGDB - Unwinders added by GDB core;\n\ | |
646 | \t\tEXTENSION - Unwinders added by extension languages;\n\ | |
647 | \t\tDEBUGINFO - Unwinders that handle debug information;\n\ | |
648 | \t\tARCH - Unwinders that use architecture-specific information;\n\ | |
649 | \n\ | |
650 | UNWINDER and NAME are case insensitive."), | |
651 | &maint_frame_unwinder); | |
652 | set_cmd_completer_handle_brkchars (c, | |
653 | enable_disable_frame_unwinders_completer); | |
654 | ||
655 | c = | |
656 | add_cmd ("enable", class_maintenance, maintenance_enable_frame_unwinders, | |
657 | _("\ | |
658 | Enable one or more frame unwinder(s).\n\ | |
659 | Usage: maint frame-unwinder enable [-all | -name NAME | [-class] CLASS]\n\ | |
660 | \n\ | |
661 | These are the meanings of the options:\n\ | |
662 | \t-all - All available unwinders will be enabled\n\ | |
663 | \t-name - NAME is the exact name of the frame unwinder to be enabled\n\ | |
664 | \t-class - CLASS is the class of unwinders to be enabled. Valid classes are:\n\ | |
665 | \t\tGDB - Unwinders added by GDB core;\n\ | |
666 | \t\tEXTENSION - Unwinders added by extension languages;\n\ | |
667 | \t\tDEBUGINFO - Unwinders that handle debug information;\n\ | |
668 | \t\tARCH - Unwinders that use architecture-specific information;\n\ | |
669 | \n\ | |
670 | UNWINDER and NAME are case insensitive."), | |
671 | &maint_frame_unwinder); | |
672 | set_cmd_completer_handle_brkchars (c, | |
673 | enable_disable_frame_unwinders_completer); | |
be016879 | 674 | } |