gdb: introduce symtab_create_debug_printf
[binutils-gdb.git] / gdb / disasm.c
1 /* Disassemble support for GDB.
2
3 Copyright (C) 2000-2022 Free Software Foundation, Inc.
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
9 the Free Software Foundation; either version 3 of the License, or
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
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "target.h"
23 #include "value.h"
24 #include "ui-out.h"
25 #include "disasm.h"
26 #include "gdbcore.h"
27 #include "gdbcmd.h"
28 #include "dis-asm.h"
29 #include "source.h"
30 #include "safe-ctype.h"
31 #include <algorithm>
32 #include "gdbsupport/gdb_optional.h"
33 #include "valprint.h"
34 #include "cli/cli-style.h"
35
36 /* Disassemble functions.
37 FIXME: We should get rid of all the duplicate code in gdb that does
38 the same thing: disassemble_command() and the gdbtk variation. */
39
40 /* This variable is used to hold the prospective disassembler_options value
41 which is set by the "set disassembler_options" command. */
42 static std::string prospective_options;
43
44 /* When this is true we will try to use libopcodes to provide styling to
45 the disassembler output. */
46
47 static bool use_libopcodes_styling = true;
48
49 /* To support the set_use_libopcodes_styling function we have a second
50 variable which is connected to the actual set/show option. */
51
52 static bool use_libopcodes_styling_option = use_libopcodes_styling;
53
54 /* The "maint show libopcodes-styling enabled" command. */
55
56 static void
57 show_use_libopcodes_styling (struct ui_file *file, int from_tty,
58 struct cmd_list_element *c,
59 const char *value)
60 {
61 gdb_non_printing_memory_disassembler dis (target_gdbarch ());
62 bool supported = dis.disasm_info ()->created_styled_output;
63
64 if (supported || !use_libopcodes_styling)
65 gdb_printf (file, _("Use of libopcodes styling support is \"%s\".\n"),
66 value);
67 else
68 {
69 /* Use of libopcodes styling is not supported, and the user has this
70 turned on! */
71 gdb_printf (file, _("Use of libopcodes styling support is \"off\""
72 " (not supported on architecture \"%s\")\n"),
73 gdbarch_bfd_arch_info (target_gdbarch ())->printable_name);
74 }
75 }
76
77 /* The "maint set libopcodes-styling enabled" command. */
78
79 static void
80 set_use_libopcodes_styling (const char *args, int from_tty,
81 struct cmd_list_element *c)
82 {
83 gdb_non_printing_memory_disassembler dis (target_gdbarch ());
84 bool supported = dis.disasm_info ()->created_styled_output;
85
86 /* If the current architecture doesn't support libopcodes styling then we
87 give an error here, but leave the underlying setting enabled. This
88 means that if the user switches to an architecture that does support
89 libopcodes styling the setting will be enabled. */
90
91 if (use_libopcodes_styling_option && !supported)
92 {
93 use_libopcodes_styling_option = use_libopcodes_styling;
94 error (_("Use of libopcodes styling not supported on architecture \"%s\"."),
95 gdbarch_bfd_arch_info (target_gdbarch ())->printable_name);
96 }
97 else
98 use_libopcodes_styling = use_libopcodes_styling_option;
99 }
100
101 /* This structure is used to store line number information for the
102 deprecated /m option.
103 We need a different sort of line table from the normal one cuz we can't
104 depend upon implicit line-end pc's for lines to do the
105 reordering in this function. */
106
107 struct deprecated_dis_line_entry
108 {
109 int line;
110 CORE_ADDR start_pc;
111 CORE_ADDR end_pc;
112 };
113
114 /* This Structure is used to store line number information.
115 We need a different sort of line table from the normal one cuz we can't
116 depend upon implicit line-end pc's for lines to do the
117 reordering in this function. */
118
119 struct dis_line_entry
120 {
121 struct symtab *symtab;
122 int line;
123 };
124
125 /* Hash function for dis_line_entry. */
126
127 static hashval_t
128 hash_dis_line_entry (const void *item)
129 {
130 const struct dis_line_entry *dle = (const struct dis_line_entry *) item;
131
132 return htab_hash_pointer (dle->symtab) + dle->line;
133 }
134
135 /* Equal function for dis_line_entry. */
136
137 static int
138 eq_dis_line_entry (const void *item_lhs, const void *item_rhs)
139 {
140 const struct dis_line_entry *lhs = (const struct dis_line_entry *) item_lhs;
141 const struct dis_line_entry *rhs = (const struct dis_line_entry *) item_rhs;
142
143 return (lhs->symtab == rhs->symtab
144 && lhs->line == rhs->line);
145 }
146
147 /* Create the table to manage lines for mixed source/disassembly. */
148
149 static htab_t
150 allocate_dis_line_table (void)
151 {
152 return htab_create_alloc (41,
153 hash_dis_line_entry, eq_dis_line_entry,
154 xfree, xcalloc, xfree);
155 }
156
157 /* Add a new dis_line_entry containing SYMTAB and LINE to TABLE. */
158
159 static void
160 add_dis_line_entry (htab_t table, struct symtab *symtab, int line)
161 {
162 void **slot;
163 struct dis_line_entry dle, *dlep;
164
165 dle.symtab = symtab;
166 dle.line = line;
167 slot = htab_find_slot (table, &dle, INSERT);
168 if (*slot == NULL)
169 {
170 dlep = XNEW (struct dis_line_entry);
171 dlep->symtab = symtab;
172 dlep->line = line;
173 *slot = dlep;
174 }
175 }
176
177 /* Return non-zero if SYMTAB, LINE are in TABLE. */
178
179 static int
180 line_has_code_p (htab_t table, struct symtab *symtab, int line)
181 {
182 struct dis_line_entry dle;
183
184 dle.symtab = symtab;
185 dle.line = line;
186 return htab_find (table, &dle) != NULL;
187 }
188
189 /* Wrapper of target_read_code. */
190
191 int
192 gdb_disassembler_memory_reader::dis_asm_read_memory
193 (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
194 struct disassemble_info *info)
195 {
196 return target_read_code (memaddr, myaddr, len);
197 }
198
199 /* Wrapper of memory_error. */
200
201 void
202 gdb_disassembler::dis_asm_memory_error (int err, bfd_vma memaddr,
203 struct disassemble_info *info)
204 {
205 gdb_disassembler *self
206 = static_cast<gdb_disassembler *>(info->application_data);
207
208 self->m_err_memaddr.emplace (memaddr);
209 }
210
211 /* Wrapper of print_address. */
212
213 void
214 gdb_disassembler::dis_asm_print_address (bfd_vma addr,
215 struct disassemble_info *info)
216 {
217 gdb_disassembler *self
218 = static_cast<gdb_disassembler *>(info->application_data);
219
220 if (self->in_comment_p ())
221 {
222 /* Calling 'print_address' might add styling to the output (based on
223 the properties of the stream we're writing too). This is usually
224 fine, but if we are in an assembler comment then we'd prefer to
225 have the comment style, rather than the default address style.
226
227 Print the address into a temporary buffer which doesn't support
228 styling, then reprint this unstyled address with the default text
229 style.
230
231 As we are inside a comment right now, the standard print routine
232 will ensure that the comment is printed to the user with a
233 suitable comment style. */
234 string_file tmp;
235 print_address (self->arch (), addr, &tmp);
236 self->fprintf_styled_func (self, dis_style_text, "%s", tmp.c_str ());
237 }
238 else
239 print_address (self->arch (), addr, self->stream ());
240 }
241
242 /* See disasm.h. */
243
244 ui_file *
245 gdb_printing_disassembler::stream_from_gdb_disassemble_info (void *dis_info)
246 {
247 gdb_disassemble_info *di = (gdb_disassemble_info *) dis_info;
248 gdb_printing_disassembler *dis
249 = dynamic_cast<gdb_printing_disassembler *> (di);
250 gdb_assert (dis != nullptr);
251 ui_file *stream = dis->stream ();
252 gdb_assert (stream != nullptr);
253 return stream;
254 }
255
256 /* Format disassembler output to STREAM. */
257
258 int
259 gdb_printing_disassembler::fprintf_func (void *dis_info,
260 const char *format, ...)
261 {
262 ui_file *stream = stream_from_gdb_disassemble_info (dis_info);
263
264 va_list args;
265 va_start (args, format);
266 gdb_vprintf (stream, format, args);
267 va_end (args);
268
269 /* Something non -ve. */
270 return 0;
271 }
272
273 /* See disasm.h. */
274
275 int
276 gdb_printing_disassembler::fprintf_styled_func (void *dis_info,
277 enum disassembler_style style,
278 const char *format, ...)
279 {
280 ui_file *stream = stream_from_gdb_disassemble_info (dis_info);
281 gdb_printing_disassembler *dis = (gdb_printing_disassembler *) dis_info;
282
283 va_list args;
284 va_start (args, format);
285 std::string content = string_vprintf (format, args);
286 va_end (args);
287
288 /* Once in a comment then everything should be styled as a comment. */
289 if (style == dis_style_comment_start)
290 dis->set_in_comment (true);
291 if (dis->in_comment_p ())
292 style = dis_style_comment_start;
293
294 /* Now print the content with the correct style. */
295 const char *txt = content.c_str ();
296 switch (style)
297 {
298 case dis_style_mnemonic:
299 case dis_style_sub_mnemonic:
300 case dis_style_assembler_directive:
301 fputs_styled (txt, disasm_mnemonic_style.style (), stream);
302 break;
303
304 case dis_style_register:
305 fputs_styled (txt, disasm_register_style.style (), stream);
306 break;
307
308 case dis_style_immediate:
309 case dis_style_address_offset:
310 fputs_styled (txt, disasm_immediate_style.style (), stream);
311 break;
312
313 case dis_style_address:
314 fputs_styled (txt, address_style.style (), stream);
315 break;
316
317 case dis_style_symbol:
318 fputs_styled (txt, function_name_style.style (), stream);
319 break;
320
321 case dis_style_comment_start:
322 fputs_styled (txt, disasm_comment_style.style (), stream);
323 break;
324
325 case dis_style_text:
326 gdb_puts (txt, stream);
327 break;
328 }
329
330 /* Something non -ve. */
331 return 0;
332 }
333
334 static bool
335 line_is_less_than (const deprecated_dis_line_entry &mle1,
336 const deprecated_dis_line_entry &mle2)
337 {
338 bool val;
339
340 /* End of sequence markers have a line number of 0 but don't want to
341 be sorted to the head of the list, instead sort by PC. */
342 if (mle1.line == 0 || mle2.line == 0)
343 {
344 if (mle1.start_pc != mle2.start_pc)
345 val = mle1.start_pc < mle2.start_pc;
346 else
347 val = mle1.line < mle2.line;
348 }
349 else
350 {
351 if (mle1.line != mle2.line)
352 val = mle1.line < mle2.line;
353 else
354 val = mle1.start_pc < mle2.start_pc;
355 }
356 return val;
357 }
358
359 /* See disasm.h. */
360
361 int
362 gdb_pretty_print_disassembler::pretty_print_insn (const struct disasm_insn *insn,
363 gdb_disassembly_flags flags)
364 {
365 /* parts of the symbolic representation of the address */
366 int unmapped;
367 int offset;
368 int line;
369 int size;
370 CORE_ADDR pc;
371 struct gdbarch *gdbarch = arch ();
372
373 {
374 ui_out_emit_tuple tuple_emitter (m_uiout, NULL);
375 pc = insn->addr;
376
377 if (insn->number != 0)
378 {
379 m_uiout->field_unsigned ("insn-number", insn->number);
380 m_uiout->text ("\t");
381 }
382
383 if ((flags & DISASSEMBLY_SPECULATIVE) != 0)
384 {
385 if (insn->is_speculative)
386 {
387 m_uiout->field_string ("is-speculative", "?");
388
389 /* The speculative execution indication overwrites the first
390 character of the PC prefix.
391 We assume a PC prefix length of 3 characters. */
392 if ((flags & DISASSEMBLY_OMIT_PC) == 0)
393 m_uiout->text (pc_prefix (pc) + 1);
394 else
395 m_uiout->text (" ");
396 }
397 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
398 m_uiout->text (pc_prefix (pc));
399 else
400 m_uiout->text (" ");
401 }
402 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
403 m_uiout->text (pc_prefix (pc));
404 m_uiout->field_core_addr ("address", gdbarch, pc);
405
406 std::string name, filename;
407 bool omit_fname = ((flags & DISASSEMBLY_OMIT_FNAME) != 0);
408 if (!build_address_symbolic (gdbarch, pc, false, omit_fname, &name,
409 &offset, &filename, &line, &unmapped))
410 {
411 /* We don't care now about line, filename and unmapped. But we might in
412 the future. */
413 m_uiout->text (" <");
414 if (!omit_fname)
415 m_uiout->field_string ("func-name", name,
416 function_name_style.style ());
417 /* For negative offsets, avoid displaying them as +-N; the sign of
418 the offset takes the place of the "+" here. */
419 if (offset >= 0)
420 m_uiout->text ("+");
421 m_uiout->field_signed ("offset", offset);
422 m_uiout->text (">:\t");
423 }
424 else
425 m_uiout->text (":\t");
426
427 /* Clear the buffer into which we will disassemble the instruction. */
428 m_insn_stb.clear ();
429
430 /* A helper function to write the M_INSN_STB buffer, followed by a
431 newline. This can be called in a couple of situations. */
432 auto write_out_insn_buffer = [&] ()
433 {
434 m_uiout->field_stream ("inst", m_insn_stb);
435 m_uiout->text ("\n");
436 };
437
438 try
439 {
440 /* Now we can disassemble the instruction. If the disassembler
441 returns a negative value this indicates an error and is handled
442 within the print_insn call, resulting in an exception being
443 thrown. Returning zero makes no sense, as this indicates we
444 disassembled something successfully, but it was something of no
445 size? */
446 size = m_di.print_insn (pc);
447 gdb_assert (size > 0);
448 }
449 catch (const gdb_exception &ex)
450 {
451 /* An exception was thrown while disassembling the instruction.
452 However, the disassembler might still have written something
453 out, so ensure that we flush the instruction buffer before
454 rethrowing the exception. We can't perform this write from an
455 object destructor as the write itself might throw an exception
456 if the pager kicks in, and the user selects quit. */
457 write_out_insn_buffer ();
458 throw ex;
459 }
460
461 if (flags & DISASSEMBLY_RAW_INSN)
462 {
463 CORE_ADDR end_pc;
464 bfd_byte data;
465 const char *spacer = "";
466
467 /* Build the opcodes using a temporary stream so we can
468 write them out in a single go for the MI. */
469 m_opcode_stb.clear ();
470
471 end_pc = pc + size;
472
473 for (;pc < end_pc; ++pc)
474 {
475 read_code (pc, &data, 1);
476 m_opcode_stb.printf ("%s%02x", spacer, (unsigned) data);
477 spacer = " ";
478 }
479
480 m_uiout->field_stream ("opcodes", m_opcode_stb);
481 m_uiout->text ("\t");
482 }
483
484 /* Disassembly was a success, write out the instruction buffer. */
485 write_out_insn_buffer ();
486 }
487
488 return size;
489 }
490
491 static int
492 dump_insns (struct gdbarch *gdbarch,
493 struct ui_out *uiout, CORE_ADDR low, CORE_ADDR high,
494 int how_many, gdb_disassembly_flags flags, CORE_ADDR *end_pc)
495 {
496 struct disasm_insn insn;
497 int num_displayed = 0;
498
499 memset (&insn, 0, sizeof (insn));
500 insn.addr = low;
501
502 gdb_pretty_print_disassembler disasm (gdbarch, uiout);
503
504 while (insn.addr < high && (how_many < 0 || num_displayed < how_many))
505 {
506 int size;
507
508 size = disasm.pretty_print_insn (&insn, flags);
509 if (size <= 0)
510 break;
511
512 ++num_displayed;
513 insn.addr += size;
514
515 /* Allow user to bail out with ^C. */
516 QUIT;
517 }
518
519 if (end_pc != NULL)
520 *end_pc = insn.addr;
521
522 return num_displayed;
523 }
524
525 /* The idea here is to present a source-O-centric view of a
526 function to the user. This means that things are presented
527 in source order, with (possibly) out of order assembly
528 immediately following.
529
530 N.B. This view is deprecated. */
531
532 static void
533 do_mixed_source_and_assembly_deprecated
534 (struct gdbarch *gdbarch, struct ui_out *uiout,
535 struct symtab *symtab,
536 CORE_ADDR low, CORE_ADDR high,
537 int how_many, gdb_disassembly_flags flags)
538 {
539 int newlines = 0;
540 int nlines;
541 struct linetable_entry *le;
542 struct deprecated_dis_line_entry *mle;
543 struct symtab_and_line sal;
544 int i;
545 int out_of_order = 0;
546 int next_line = 0;
547 int num_displayed = 0;
548 print_source_lines_flags psl_flags = 0;
549
550 gdb_assert (symtab != nullptr && symtab->linetable () != nullptr);
551
552 nlines = symtab->linetable ()->nitems;
553 le = symtab->linetable ()->item;
554
555 if (flags & DISASSEMBLY_FILENAME)
556 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
557
558 mle = (struct deprecated_dis_line_entry *)
559 alloca (nlines * sizeof (struct deprecated_dis_line_entry));
560
561 /* Copy linetable entries for this function into our data
562 structure, creating end_pc's and setting out_of_order as
563 appropriate. */
564
565 /* First, skip all the preceding functions. */
566
567 for (i = 0; i < nlines - 1 && le[i].pc < low; i++);
568
569 /* Now, copy all entries before the end of this function. */
570
571 for (; i < nlines - 1 && le[i].pc < high; i++)
572 {
573 if (le[i].line == le[i + 1].line && le[i].pc == le[i + 1].pc)
574 continue; /* Ignore duplicates. */
575
576 /* Skip any end-of-function markers. */
577 if (le[i].line == 0)
578 continue;
579
580 mle[newlines].line = le[i].line;
581 if (le[i].line > le[i + 1].line)
582 out_of_order = 1;
583 mle[newlines].start_pc = le[i].pc;
584 mle[newlines].end_pc = le[i + 1].pc;
585 newlines++;
586 }
587
588 /* If we're on the last line, and it's part of the function,
589 then we need to get the end pc in a special way. */
590
591 if (i == nlines - 1 && le[i].pc < high)
592 {
593 mle[newlines].line = le[i].line;
594 mle[newlines].start_pc = le[i].pc;
595 sal = find_pc_line (le[i].pc, 0);
596 mle[newlines].end_pc = sal.end;
597 newlines++;
598 }
599
600 /* Now, sort mle by line #s (and, then by addresses within lines). */
601
602 if (out_of_order)
603 std::sort (mle, mle + newlines, line_is_less_than);
604
605 /* Now, for each line entry, emit the specified lines (unless
606 they have been emitted before), followed by the assembly code
607 for that line. */
608
609 ui_out_emit_list asm_insns_list (uiout, "asm_insns");
610
611 gdb::optional<ui_out_emit_tuple> outer_tuple_emitter;
612 gdb::optional<ui_out_emit_list> inner_list_emitter;
613
614 for (i = 0; i < newlines; i++)
615 {
616 /* Print out everything from next_line to the current line. */
617 if (mle[i].line >= next_line)
618 {
619 if (next_line != 0)
620 {
621 /* Just one line to print. */
622 if (next_line == mle[i].line)
623 {
624 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
625 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
626 }
627 else
628 {
629 /* Several source lines w/o asm instructions associated. */
630 for (; next_line < mle[i].line; next_line++)
631 {
632 ui_out_emit_tuple tuple_emitter (uiout,
633 "src_and_asm_line");
634 print_source_lines (symtab, next_line, next_line + 1,
635 psl_flags);
636 ui_out_emit_list temp_list_emitter (uiout,
637 "line_asm_insn");
638 }
639 /* Print the last line and leave list open for
640 asm instructions to be added. */
641 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
642 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
643 }
644 }
645 else
646 {
647 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
648 print_source_lines (symtab, mle[i].line, mle[i].line + 1, psl_flags);
649 }
650
651 next_line = mle[i].line + 1;
652 inner_list_emitter.emplace (uiout, "line_asm_insn");
653 }
654
655 num_displayed += dump_insns (gdbarch, uiout,
656 mle[i].start_pc, mle[i].end_pc,
657 how_many, flags, NULL);
658
659 /* When we've reached the end of the mle array, or we've seen the last
660 assembly range for this source line, close out the list/tuple. */
661 if (i == (newlines - 1) || mle[i + 1].line > mle[i].line)
662 {
663 inner_list_emitter.reset ();
664 outer_tuple_emitter.reset ();
665 uiout->text ("\n");
666 }
667 if (how_many >= 0 && num_displayed >= how_many)
668 break;
669 }
670 }
671
672 /* The idea here is to present a source-O-centric view of a
673 function to the user. This means that things are presented
674 in source order, with (possibly) out of order assembly
675 immediately following. */
676
677 static void
678 do_mixed_source_and_assembly (struct gdbarch *gdbarch,
679 struct ui_out *uiout,
680 struct symtab *main_symtab,
681 CORE_ADDR low, CORE_ADDR high,
682 int how_many, gdb_disassembly_flags flags)
683 {
684 const struct linetable_entry *le, *first_le;
685 int i, nlines;
686 int num_displayed = 0;
687 print_source_lines_flags psl_flags = 0;
688 CORE_ADDR pc;
689 struct symtab *last_symtab;
690 int last_line;
691
692 gdb_assert (main_symtab != NULL && main_symtab->linetable () != NULL);
693
694 /* First pass: collect the list of all source files and lines.
695 We do this so that we can only print lines containing code once.
696 We try to print the source text leading up to the next instruction,
697 but if that text is for code that will be disassembled later, then
698 we'll want to defer printing it until later with its associated code. */
699
700 htab_up dis_line_table (allocate_dis_line_table ());
701
702 pc = low;
703
704 /* The prologue may be empty, but there may still be a line number entry
705 for the opening brace which is distinct from the first line of code.
706 If the prologue has been eliminated find_pc_line may return the source
707 line after the opening brace. We still want to print this opening brace.
708 first_le is used to implement this. */
709
710 nlines = main_symtab->linetable ()->nitems;
711 le = main_symtab->linetable ()->item;
712 first_le = NULL;
713
714 /* Skip all the preceding functions. */
715 for (i = 0; i < nlines && le[i].pc < low; i++)
716 continue;
717
718 if (i < nlines && le[i].pc < high)
719 first_le = &le[i];
720
721 /* Add lines for every pc value. */
722 while (pc < high)
723 {
724 struct symtab_and_line sal;
725 int length;
726
727 sal = find_pc_line (pc, 0);
728 length = gdb_insn_length (gdbarch, pc);
729 pc += length;
730
731 if (sal.symtab != NULL)
732 add_dis_line_entry (dis_line_table.get (), sal.symtab, sal.line);
733 }
734
735 /* Second pass: print the disassembly.
736
737 Output format, from an MI perspective:
738 The result is a ui_out list, field name "asm_insns", where elements have
739 name "src_and_asm_line".
740 Each element is a tuple of source line specs (field names line, file,
741 fullname), and field "line_asm_insn" which contains the disassembly.
742 Field "line_asm_insn" is a list of tuples: address, func-name, offset,
743 opcodes, inst.
744
745 CLI output works on top of this because MI ignores ui_out_text output,
746 which is where we put file name and source line contents output.
747
748 Emitter usage:
749 asm_insns_emitter
750 Handles the outer "asm_insns" list.
751 tuple_emitter
752 The tuples for each group of consecutive disassemblies.
753 list_emitter
754 List of consecutive source lines or disassembled insns. */
755
756 if (flags & DISASSEMBLY_FILENAME)
757 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
758
759 ui_out_emit_list asm_insns_emitter (uiout, "asm_insns");
760
761 gdb::optional<ui_out_emit_tuple> tuple_emitter;
762 gdb::optional<ui_out_emit_list> list_emitter;
763
764 last_symtab = NULL;
765 last_line = 0;
766 pc = low;
767
768 while (pc < high)
769 {
770 struct symtab_and_line sal;
771 CORE_ADDR end_pc;
772 int start_preceding_line_to_display = 0;
773 int end_preceding_line_to_display = 0;
774 int new_source_line = 0;
775
776 sal = find_pc_line (pc, 0);
777
778 if (sal.symtab != last_symtab)
779 {
780 /* New source file. */
781 new_source_line = 1;
782
783 /* If this is the first line of output, check for any preceding
784 lines. */
785 if (last_line == 0
786 && first_le != NULL
787 && first_le->line < sal.line)
788 {
789 start_preceding_line_to_display = first_le->line;
790 end_preceding_line_to_display = sal.line;
791 }
792 }
793 else
794 {
795 /* Same source file as last time. */
796 if (sal.symtab != NULL)
797 {
798 if (sal.line > last_line + 1 && last_line != 0)
799 {
800 int l;
801
802 /* Several preceding source lines. Print the trailing ones
803 not associated with code that we'll print later. */
804 for (l = sal.line - 1; l > last_line; --l)
805 {
806 if (line_has_code_p (dis_line_table.get (),
807 sal.symtab, l))
808 break;
809 }
810 if (l < sal.line - 1)
811 {
812 start_preceding_line_to_display = l + 1;
813 end_preceding_line_to_display = sal.line;
814 }
815 }
816 if (sal.line != last_line)
817 new_source_line = 1;
818 else
819 {
820 /* Same source line as last time. This can happen, depending
821 on the debug info. */
822 }
823 }
824 }
825
826 if (new_source_line)
827 {
828 /* Skip the newline if this is the first instruction. */
829 if (pc > low)
830 uiout->text ("\n");
831 if (tuple_emitter.has_value ())
832 {
833 gdb_assert (list_emitter.has_value ());
834 list_emitter.reset ();
835 tuple_emitter.reset ();
836 }
837 if (sal.symtab != last_symtab
838 && !(flags & DISASSEMBLY_FILENAME))
839 {
840 /* Remember MI ignores ui_out_text.
841 We don't have to do anything here for MI because MI
842 output includes the source specs for each line. */
843 if (sal.symtab != NULL)
844 {
845 uiout->text (symtab_to_filename_for_display (sal.symtab));
846 }
847 else
848 uiout->text ("unknown");
849 uiout->text (":\n");
850 }
851 if (start_preceding_line_to_display > 0)
852 {
853 /* Several source lines w/o asm instructions associated.
854 We need to preserve the structure of the output, so output
855 a bunch of line tuples with no asm entries. */
856 int l;
857
858 gdb_assert (sal.symtab != NULL);
859 for (l = start_preceding_line_to_display;
860 l < end_preceding_line_to_display;
861 ++l)
862 {
863 ui_out_emit_tuple line_tuple_emitter (uiout,
864 "src_and_asm_line");
865 print_source_lines (sal.symtab, l, l + 1, psl_flags);
866 ui_out_emit_list chain_line_emitter (uiout, "line_asm_insn");
867 }
868 }
869 tuple_emitter.emplace (uiout, "src_and_asm_line");
870 if (sal.symtab != NULL)
871 print_source_lines (sal.symtab, sal.line, sal.line + 1, psl_flags);
872 else
873 uiout->text (_("--- no source info for this pc ---\n"));
874 list_emitter.emplace (uiout, "line_asm_insn");
875 }
876 else
877 {
878 /* Here we're appending instructions to an existing line.
879 By construction the very first insn will have a symtab
880 and follow the new_source_line path above. */
881 gdb_assert (tuple_emitter.has_value ());
882 gdb_assert (list_emitter.has_value ());
883 }
884
885 if (sal.end != 0)
886 end_pc = std::min (sal.end, high);
887 else
888 end_pc = pc + 1;
889 num_displayed += dump_insns (gdbarch, uiout, pc, end_pc,
890 how_many, flags, &end_pc);
891 pc = end_pc;
892
893 if (how_many >= 0 && num_displayed >= how_many)
894 break;
895
896 last_symtab = sal.symtab;
897 last_line = sal.line;
898 }
899 }
900
901 static void
902 do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
903 CORE_ADDR low, CORE_ADDR high,
904 int how_many, gdb_disassembly_flags flags)
905 {
906 ui_out_emit_list list_emitter (uiout, "asm_insns");
907
908 dump_insns (gdbarch, uiout, low, high, how_many, flags, NULL);
909 }
910
911 /* Combine implicit and user disassembler options and return them
912 in a newly-created string. */
913
914 static std::string
915 get_all_disassembler_options (struct gdbarch *gdbarch)
916 {
917 const char *implicit = gdbarch_disassembler_options_implicit (gdbarch);
918 const char *options = get_disassembler_options (gdbarch);
919 const char *comma = ",";
920
921 if (implicit == nullptr)
922 {
923 implicit = "";
924 comma = "";
925 }
926
927 if (options == nullptr)
928 {
929 options = "";
930 comma = "";
931 }
932
933 return string_printf ("%s%s%s", implicit, comma, options);
934 }
935
936 gdb_disassembler::gdb_disassembler (struct gdbarch *gdbarch,
937 struct ui_file *file,
938 read_memory_ftype func)
939 : gdb_printing_disassembler (gdbarch, &m_buffer, func,
940 dis_asm_memory_error, dis_asm_print_address),
941 /* The use of m_di.created_styled_output here is a bit of a cheat, but
942 it works fine for now. Currently, for all targets that support
943 libopcodes styling, this field is set during the call to
944 disassemble_init_for_target, which was called as part of the
945 initialization of gdb_printing_disassembler. And so, we are able to
946 spot if a target supports libopcodes styling, and create m_buffer in
947 the correct styling mode.
948
949 If there's ever a target that only sets created_styled_output during
950 the actual disassemble phase, then the logic here will have to
951 change. */
952 m_buffer ((!use_ext_lang_colorization_p
953 || (use_libopcodes_styling && m_di.created_styled_output))
954 && disassembler_styling
955 && file->can_emit_style_escape ()),
956 m_dest (file)
957 { /* Nothing. */ }
958
959 /* See disasm.h. */
960
961 gdb_disassemble_info::gdb_disassemble_info
962 (struct gdbarch *gdbarch,
963 read_memory_ftype read_memory_func, memory_error_ftype memory_error_func,
964 print_address_ftype print_address_func, fprintf_ftype fprintf_func,
965 fprintf_styled_ftype fprintf_styled_func)
966 : m_gdbarch (gdbarch)
967 {
968 gdb_assert (fprintf_func != nullptr);
969 gdb_assert (fprintf_styled_func != nullptr);
970 init_disassemble_info (&m_di, (void *) this, fprintf_func,
971 fprintf_styled_func);
972 m_di.flavour = bfd_target_unknown_flavour;
973
974 /* The memory_error_func, print_address_func, and read_memory_func are
975 all initialized to a default (non-nullptr) value by the call to
976 init_disassemble_info above. If the user is overriding these fields
977 (by passing non-nullptr values) then do that now, otherwise, leave
978 these fields as the defaults. */
979 if (memory_error_func != nullptr)
980 m_di.memory_error_func = memory_error_func;
981 if (print_address_func != nullptr)
982 m_di.print_address_func = print_address_func;
983 if (read_memory_func != nullptr)
984 m_di.read_memory_func = read_memory_func;
985
986 m_di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
987 m_di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
988 m_di.endian = gdbarch_byte_order (gdbarch);
989 m_di.endian_code = gdbarch_byte_order_for_code (gdbarch);
990 m_di.application_data = this;
991 m_disassembler_options_holder = get_all_disassembler_options (gdbarch);
992 if (!m_disassembler_options_holder.empty ())
993 m_di.disassembler_options = m_disassembler_options_holder.c_str ();
994 disassemble_init_for_target (&m_di);
995 }
996
997 /* See disasm.h. */
998
999 gdb_disassemble_info::~gdb_disassemble_info ()
1000 {
1001 disassemble_free_target (&m_di);
1002 }
1003
1004 /* Wrapper around calling gdbarch_print_insn. This function takes care of
1005 first calling the extension language hooks for print_insn, and, if none
1006 of the extension languages can print this instruction, calls
1007 gdbarch_print_insn to do the work.
1008
1009 GDBARCH is the architecture to disassemble in, VMA is the address of the
1010 instruction being disassembled, and INFO is the libopcodes disassembler
1011 related information. */
1012
1013 static int
1014 gdb_print_insn_1 (struct gdbarch *gdbarch, CORE_ADDR vma,
1015 struct disassemble_info *info)
1016 {
1017 /* Call into the extension languages to do the disassembly. */
1018 gdb::optional<int> length = ext_lang_print_insn (gdbarch, vma, info);
1019 if (length.has_value ())
1020 return *length;
1021
1022 /* No extension language wanted to do the disassembly, so do it
1023 manually. */
1024 return gdbarch_print_insn (gdbarch, vma, info);
1025 }
1026
1027 /* See disasm.h. */
1028
1029 bool gdb_disassembler::use_ext_lang_colorization_p = true;
1030
1031 /* See disasm.h. */
1032
1033 int
1034 gdb_disassembler::print_insn (CORE_ADDR memaddr,
1035 int *branch_delay_insns)
1036 {
1037 m_err_memaddr.reset ();
1038 m_buffer.clear ();
1039 this->set_in_comment (false);
1040
1041 int length = gdb_print_insn_1 (arch (), memaddr, &m_di);
1042
1043 /* If we have successfully disassembled an instruction, disassembler
1044 styling using the extension language is on, and libopcodes hasn't
1045 already styled the output for us, and, if the destination can support
1046 styling, then lets call into the extension languages in order to style
1047 this output. */
1048 if (length > 0 && disassembler_styling
1049 && (!m_di.created_styled_output || !use_libopcodes_styling)
1050 && use_ext_lang_colorization_p
1051 && m_dest->can_emit_style_escape ())
1052 {
1053 gdb::optional<std::string> ext_contents;
1054 ext_contents = ext_lang_colorize_disasm (m_buffer.string (), arch ());
1055 if (ext_contents.has_value ())
1056 m_buffer = std::move (*ext_contents);
1057 else
1058 {
1059 /* The extension language failed to add styling to the
1060 disassembly output. Set the static flag so that next time we
1061 disassemble we don't even bother attempting to use the
1062 extension language for styling. */
1063 use_ext_lang_colorization_p = false;
1064
1065 /* The instruction we just disassembled, and the extension
1066 languages failed to style, might have otherwise had some
1067 minimal styling applied by GDB. To regain that styling we
1068 need to recreate m_buffer, but this time with styling support.
1069
1070 To do this we perform an in-place new, but this time turn on
1071 the styling support, then we can re-disassembly the
1072 instruction, and gain any minimal styling GDB might add. */
1073 gdb_static_assert ((std::is_same<decltype (m_buffer),
1074 string_file>::value));
1075 gdb_assert (!m_buffer.term_out ());
1076 m_buffer.~string_file ();
1077 new (&m_buffer) string_file (true);
1078 length = gdb_print_insn_1 (arch (), memaddr, &m_di);
1079 gdb_assert (length > 0);
1080 }
1081 }
1082
1083 /* Push any disassemble output to the real destination stream. We do
1084 this even if the disassembler reported failure (-1) as the
1085 disassembler may have printed something to its output stream. */
1086 gdb_printf (m_dest, "%s", m_buffer.c_str ());
1087
1088 /* If the disassembler failed then report an appropriate error. */
1089 if (length < 0)
1090 {
1091 if (m_err_memaddr.has_value ())
1092 memory_error (TARGET_XFER_E_IO, *m_err_memaddr);
1093 else
1094 error (_("unknown disassembler error (error = %d)"), length);
1095 }
1096
1097 if (branch_delay_insns != NULL)
1098 {
1099 if (m_di.insn_info_valid)
1100 *branch_delay_insns = m_di.branch_delay_insns;
1101 else
1102 *branch_delay_insns = 0;
1103 }
1104 return length;
1105 }
1106
1107 void
1108 gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
1109 gdb_disassembly_flags flags, int how_many,
1110 CORE_ADDR low, CORE_ADDR high)
1111 {
1112 struct symtab *symtab;
1113 int nlines = -1;
1114
1115 /* Assume symtab is valid for whole PC range. */
1116 symtab = find_pc_line_symtab (low);
1117
1118 if (symtab != NULL && symtab->linetable () != NULL)
1119 nlines = symtab->linetable ()->nitems;
1120
1121 if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
1122 || nlines <= 0)
1123 do_assembly_only (gdbarch, uiout, low, high, how_many, flags);
1124
1125 else if (flags & DISASSEMBLY_SOURCE)
1126 do_mixed_source_and_assembly (gdbarch, uiout, symtab, low, high,
1127 how_many, flags);
1128
1129 else if (flags & DISASSEMBLY_SOURCE_DEPRECATED)
1130 do_mixed_source_and_assembly_deprecated (gdbarch, uiout, symtab,
1131 low, high, how_many, flags);
1132
1133 gdb_flush (gdb_stdout);
1134 }
1135
1136 /* Print the instruction at address MEMADDR in debugged memory,
1137 on STREAM. Returns the length of the instruction, in bytes,
1138 and, if requested, the number of branch delay slot instructions. */
1139
1140 int
1141 gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
1142 struct ui_file *stream, int *branch_delay_insns)
1143 {
1144
1145 gdb_disassembler di (gdbarch, stream);
1146
1147 return di.print_insn (memaddr, branch_delay_insns);
1148 }
1149
1150 /* Return the length in bytes of the instruction at address MEMADDR in
1151 debugged memory. */
1152
1153 int
1154 gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr)
1155 {
1156 return gdb_print_insn (gdbarch, addr, &null_stream, NULL);
1157 }
1158
1159 /* See disasm.h. */
1160
1161 int
1162 gdb_non_printing_disassembler::null_fprintf_func (void *stream,
1163 const char *format, ...)
1164 {
1165 return 0;
1166 }
1167
1168 /* See disasm.h. */
1169
1170 int
1171 gdb_non_printing_disassembler::null_fprintf_styled_func
1172 (void *stream, enum disassembler_style style, const char *format, ...)
1173 {
1174 return 0;
1175 }
1176
1177 /* A non-printing disassemble_info management class. The disassemble_info
1178 setup by this class will not print anything to the output stream (there
1179 is no output stream), and the instruction to be disassembled will be
1180 read from a buffer passed to the constructor. */
1181
1182 struct gdb_non_printing_buffer_disassembler
1183 : public gdb_non_printing_disassembler
1184 {
1185 /* Constructor. GDBARCH is the architecture to disassemble for, BUFFER
1186 contains the instruction to disassemble, and INSN_ADDRESS is the
1187 address (in target memory) of the instruction to disassemble. */
1188 gdb_non_printing_buffer_disassembler (struct gdbarch *gdbarch,
1189 gdb::array_view<const gdb_byte> buffer,
1190 CORE_ADDR insn_address)
1191 : gdb_non_printing_disassembler (gdbarch, nullptr)
1192 {
1193 /* The cast is necessary until disassemble_info is const-ified. */
1194 m_di.buffer = (gdb_byte *) buffer.data ();
1195 m_di.buffer_length = buffer.size ();
1196 m_di.buffer_vma = insn_address;
1197 }
1198 };
1199
1200 /* Return the length in bytes of INSN. MAX_LEN is the size of the
1201 buffer containing INSN. */
1202
1203 int
1204 gdb_buffered_insn_length (struct gdbarch *gdbarch,
1205 const gdb_byte *insn, int max_len, CORE_ADDR addr)
1206 {
1207 gdb::array_view<const gdb_byte> buffer
1208 = gdb::make_array_view (insn, max_len);
1209 gdb_non_printing_buffer_disassembler dis (gdbarch, buffer, addr);
1210 int result = gdb_print_insn_1 (gdbarch, addr, dis.disasm_info ());
1211 return result;
1212 }
1213
1214 char *
1215 get_disassembler_options (struct gdbarch *gdbarch)
1216 {
1217 char **disassembler_options = gdbarch_disassembler_options (gdbarch);
1218 if (disassembler_options == NULL)
1219 return NULL;
1220 return *disassembler_options;
1221 }
1222
1223 void
1224 set_disassembler_options (const char *prospective_options)
1225 {
1226 struct gdbarch *gdbarch = get_current_arch ();
1227 char **disassembler_options = gdbarch_disassembler_options (gdbarch);
1228 const disasm_options_and_args_t *valid_options_and_args;
1229 const disasm_options_t *valid_options;
1230 gdb::unique_xmalloc_ptr<char> prospective_options_local
1231 = make_unique_xstrdup (prospective_options);
1232 char *options = remove_whitespace_and_extra_commas
1233 (prospective_options_local.get ());
1234 const char *opt;
1235
1236 /* Allow all architectures, even ones that do not support 'set disassembler',
1237 to reset their disassembler options to NULL. */
1238 if (options == NULL)
1239 {
1240 if (disassembler_options != NULL)
1241 {
1242 free (*disassembler_options);
1243 *disassembler_options = NULL;
1244 }
1245 return;
1246 }
1247
1248 valid_options_and_args = gdbarch_valid_disassembler_options (gdbarch);
1249 if (valid_options_and_args == NULL)
1250 {
1251 gdb_printf (gdb_stderr, _("\
1252 'set disassembler-options ...' is not supported on this architecture.\n"));
1253 return;
1254 }
1255
1256 valid_options = &valid_options_and_args->options;
1257
1258 /* Verify we have valid disassembler options. */
1259 FOR_EACH_DISASSEMBLER_OPTION (opt, options)
1260 {
1261 size_t i;
1262 for (i = 0; valid_options->name[i] != NULL; i++)
1263 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1264 {
1265 size_t len = strlen (valid_options->name[i]);
1266 bool found = false;
1267 const char *arg;
1268 size_t j;
1269
1270 if (memcmp (opt, valid_options->name[i], len) != 0)
1271 continue;
1272 arg = opt + len;
1273 for (j = 0; valid_options->arg[i]->values[j] != NULL; j++)
1274 if (disassembler_options_cmp
1275 (arg, valid_options->arg[i]->values[j]) == 0)
1276 {
1277 found = true;
1278 break;
1279 }
1280 if (found)
1281 break;
1282 }
1283 else if (disassembler_options_cmp (opt, valid_options->name[i]) == 0)
1284 break;
1285 if (valid_options->name[i] == NULL)
1286 {
1287 gdb_printf (gdb_stderr,
1288 _("Invalid disassembler option value: '%s'.\n"),
1289 opt);
1290 return;
1291 }
1292 }
1293
1294 free (*disassembler_options);
1295 *disassembler_options = xstrdup (options);
1296 }
1297
1298 static void
1299 set_disassembler_options_sfunc (const char *args, int from_tty,
1300 struct cmd_list_element *c)
1301 {
1302 set_disassembler_options (prospective_options.c_str ());
1303 }
1304
1305 static void
1306 show_disassembler_options_sfunc (struct ui_file *file, int from_tty,
1307 struct cmd_list_element *c, const char *value)
1308 {
1309 struct gdbarch *gdbarch = get_current_arch ();
1310 const disasm_options_and_args_t *valid_options_and_args;
1311 const disasm_option_arg_t *valid_args;
1312 const disasm_options_t *valid_options;
1313
1314 const char *options = get_disassembler_options (gdbarch);
1315 if (options == NULL)
1316 options = "";
1317
1318 gdb_printf (file, _("The current disassembler options are '%s'\n\n"),
1319 options);
1320
1321 valid_options_and_args = gdbarch_valid_disassembler_options (gdbarch);
1322
1323 if (valid_options_and_args == NULL)
1324 {
1325 gdb_puts (_("There are no disassembler options available "
1326 "for this architecture.\n"),
1327 file);
1328 return;
1329 }
1330
1331 valid_options = &valid_options_and_args->options;
1332
1333 gdb_printf (file, _("\
1334 The following disassembler options are supported for use with the\n\
1335 'set disassembler-options OPTION [,OPTION]...' command:\n"));
1336
1337 if (valid_options->description != NULL)
1338 {
1339 size_t i, max_len = 0;
1340
1341 gdb_printf (file, "\n");
1342
1343 /* Compute the length of the longest option name. */
1344 for (i = 0; valid_options->name[i] != NULL; i++)
1345 {
1346 size_t len = strlen (valid_options->name[i]);
1347
1348 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1349 len += strlen (valid_options->arg[i]->name);
1350 if (max_len < len)
1351 max_len = len;
1352 }
1353
1354 for (i = 0, max_len++; valid_options->name[i] != NULL; i++)
1355 {
1356 gdb_printf (file, " %s", valid_options->name[i]);
1357 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1358 gdb_printf (file, "%s", valid_options->arg[i]->name);
1359 if (valid_options->description[i] != NULL)
1360 {
1361 size_t len = strlen (valid_options->name[i]);
1362
1363 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1364 len += strlen (valid_options->arg[i]->name);
1365 gdb_printf (file, "%*c %s", (int) (max_len - len), ' ',
1366 valid_options->description[i]);
1367 }
1368 gdb_printf (file, "\n");
1369 }
1370 }
1371 else
1372 {
1373 size_t i;
1374 gdb_printf (file, " ");
1375 for (i = 0; valid_options->name[i] != NULL; i++)
1376 {
1377 gdb_printf (file, "%s", valid_options->name[i]);
1378 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1379 gdb_printf (file, "%s", valid_options->arg[i]->name);
1380 if (valid_options->name[i + 1] != NULL)
1381 gdb_printf (file, ", ");
1382 file->wrap_here (2);
1383 }
1384 gdb_printf (file, "\n");
1385 }
1386
1387 valid_args = valid_options_and_args->args;
1388 if (valid_args != NULL)
1389 {
1390 size_t i, j;
1391
1392 for (i = 0; valid_args[i].name != NULL; i++)
1393 {
1394 gdb_printf (file, _("\n\
1395 For the options above, the following values are supported for \"%s\":\n "),
1396 valid_args[i].name);
1397 for (j = 0; valid_args[i].values[j] != NULL; j++)
1398 {
1399 gdb_printf (file, " %s", valid_args[i].values[j]);
1400 file->wrap_here (3);
1401 }
1402 gdb_printf (file, "\n");
1403 }
1404 }
1405 }
1406
1407 /* A completion function for "set disassembler". */
1408
1409 static void
1410 disassembler_options_completer (struct cmd_list_element *ignore,
1411 completion_tracker &tracker,
1412 const char *text, const char *word)
1413 {
1414 struct gdbarch *gdbarch = get_current_arch ();
1415 const disasm_options_and_args_t *opts_and_args
1416 = gdbarch_valid_disassembler_options (gdbarch);
1417
1418 if (opts_and_args != NULL)
1419 {
1420 const disasm_options_t *opts = &opts_and_args->options;
1421
1422 /* Only attempt to complete on the last option text. */
1423 const char *separator = strrchr (text, ',');
1424 if (separator != NULL)
1425 text = separator + 1;
1426 text = skip_spaces (text);
1427 complete_on_enum (tracker, opts->name, text, word);
1428 }
1429 }
1430
1431
1432 /* Initialization code. */
1433
1434 void _initialize_disasm ();
1435 void
1436 _initialize_disasm ()
1437 {
1438 /* Add the command that controls the disassembler options. */
1439 set_show_commands set_show_disas_opts
1440 = add_setshow_string_noescape_cmd ("disassembler-options", no_class,
1441 &prospective_options, _("\
1442 Set the disassembler options.\n\
1443 Usage: set disassembler-options OPTION [,OPTION]...\n\n\
1444 See: 'show disassembler-options' for valid option values."), _("\
1445 Show the disassembler options."), NULL,
1446 set_disassembler_options_sfunc,
1447 show_disassembler_options_sfunc,
1448 &setlist, &showlist);
1449 set_cmd_completer (set_show_disas_opts.set, disassembler_options_completer);
1450
1451
1452 /* All the 'maint set|show libopcodes-styling' sub-commands. */
1453 static struct cmd_list_element *maint_set_libopcodes_styling_cmdlist;
1454 static struct cmd_list_element *maint_show_libopcodes_styling_cmdlist;
1455
1456 /* Adds 'maint set|show libopcodes-styling'. */
1457 add_setshow_prefix_cmd ("libopcodes-styling", class_maintenance,
1458 _("Set libopcodes-styling specific variables."),
1459 _("Show libopcodes-styling specific variables."),
1460 &maint_set_libopcodes_styling_cmdlist,
1461 &maint_show_libopcodes_styling_cmdlist,
1462 &maintenance_set_cmdlist,
1463 &maintenance_show_cmdlist);
1464
1465 /* Adds 'maint set|show gnu-source-highlight enabled'. */
1466 add_setshow_boolean_cmd ("enabled", class_maintenance,
1467 &use_libopcodes_styling_option, _("\
1468 Set whether the libopcodes styling support should be used."), _("\
1469 Show whether the libopcodes styling support should be used."),_("\
1470 When enabled, GDB will try to make use of the builtin libopcodes styling\n\
1471 support, to style the disassembler output. Not every architecture has\n\
1472 styling support within libopcodes, so enabling this is not a guarantee\n\
1473 that libopcodes styling will be available.\n\
1474 \n\
1475 When this option is disabled, GDB will make use of the Python Pygments\n\
1476 package (if available) to style the disassembler output.\n\
1477 \n\
1478 All disassembler styling can be disabled with:\n\
1479 \n\
1480 set style disassembler enabled off"),
1481 set_use_libopcodes_styling,
1482 show_use_libopcodes_styling,
1483 &maint_set_libopcodes_styling_cmdlist,
1484 &maint_show_libopcodes_styling_cmdlist);
1485 }