RISC-V: Don't report warnings when linking different privileged spec objects.
[binutils-gdb.git] / gdb / disasm.c
blob541293ac4fcd021dd2b22879f6572cef0f79d99c
1 /* Disassemble support for GDB.
3 Copyright (C) 2000-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "arch-utils.h"
21 #include "event-top.h"
22 #include "target.h"
23 #include "value.h"
24 #include "ui-out.h"
25 #include "disasm.h"
26 #include "gdbcore.h"
27 #include "cli/cli-cmds.h"
28 #include "dis-asm.h"
29 #include "source.h"
30 #include "gdbsupport/gdb-safe-ctype.h"
31 #include <algorithm>
32 #include <optional>
33 #include "valprint.h"
34 #include "cli/cli-style.h"
35 #include "objfiles.h"
36 #include "inferior.h"
38 /* Disassemble functions.
39 FIXME: We should get rid of all the duplicate code in gdb that does
40 the same thing: disassemble_command() and the gdbtk variation. */
42 /* This variable is used to hold the prospective disassembler_options value
43 which is set by the "set disassembler_options" command. */
44 static std::string prospective_options;
46 /* When this is true we will try to use libopcodes to provide styling to
47 the disassembler output. */
49 static bool use_libopcodes_styling = true;
51 /* To support the set_use_libopcodes_styling function we have a second
52 variable which is connected to the actual set/show option. */
54 static bool use_libopcodes_styling_option = use_libopcodes_styling;
56 /* The "maint show libopcodes-styling enabled" command. */
58 static void
59 show_use_libopcodes_styling (struct ui_file *file, int from_tty,
60 struct cmd_list_element *c,
61 const char *value)
63 gdbarch *arch = current_inferior ()->arch ();
64 gdb_non_printing_memory_disassembler dis (arch);
65 bool supported = dis.disasm_info ()->created_styled_output;
67 if (supported || !use_libopcodes_styling)
68 gdb_printf (file, _("Use of libopcodes styling support is \"%s\".\n"),
69 value);
70 else
72 /* Use of libopcodes styling is not supported, and the user has this
73 turned on! */
74 gdb_printf (file, _("Use of libopcodes styling support is \"off\""
75 " (not supported on architecture \"%s\")\n"),
76 gdbarch_bfd_arch_info (arch)->printable_name);
80 /* The "maint set libopcodes-styling enabled" command. */
82 static void
83 set_use_libopcodes_styling (const char *args, int from_tty,
84 struct cmd_list_element *c)
86 gdbarch *arch = current_inferior ()->arch ();
87 gdb_non_printing_memory_disassembler dis (arch);
88 bool supported = dis.disasm_info ()->created_styled_output;
90 /* If the current architecture doesn't support libopcodes styling then we
91 give an error here, but leave the underlying setting enabled. This
92 means that if the user switches to an architecture that does support
93 libopcodes styling the setting will be enabled. */
95 if (use_libopcodes_styling_option && !supported)
97 use_libopcodes_styling_option = use_libopcodes_styling;
98 error (_("Use of libopcodes styling not supported on architecture \"%s\"."),
99 gdbarch_bfd_arch_info (arch)->printable_name);
101 else
102 use_libopcodes_styling = use_libopcodes_styling_option;
105 /* This structure is used to store line number information for the
106 deprecated /m option.
107 We need a different sort of line table from the normal one cuz we can't
108 depend upon implicit line-end pc's for lines to do the
109 reordering in this function. */
111 struct deprecated_dis_line_entry
113 int line;
114 CORE_ADDR start_pc;
115 CORE_ADDR end_pc;
118 /* This Structure is used to store line number information.
119 We need a different sort of line table from the normal one cuz we can't
120 depend upon implicit line-end pc's for lines to do the
121 reordering in this function. */
123 struct dis_line_entry
125 struct symtab *symtab;
126 int line;
129 /* Hash function for dis_line_entry. */
131 static hashval_t
132 hash_dis_line_entry (const void *item)
134 const struct dis_line_entry *dle = (const struct dis_line_entry *) item;
136 return htab_hash_pointer (dle->symtab) + dle->line;
139 /* Equal function for dis_line_entry. */
141 static int
142 eq_dis_line_entry (const void *item_lhs, const void *item_rhs)
144 const struct dis_line_entry *lhs = (const struct dis_line_entry *) item_lhs;
145 const struct dis_line_entry *rhs = (const struct dis_line_entry *) item_rhs;
147 return (lhs->symtab == rhs->symtab
148 && lhs->line == rhs->line);
151 /* Create the table to manage lines for mixed source/disassembly. */
153 static htab_t
154 allocate_dis_line_table (void)
156 return htab_create_alloc (41,
157 hash_dis_line_entry, eq_dis_line_entry,
158 xfree, xcalloc, xfree);
161 /* Add a new dis_line_entry containing SYMTAB and LINE to TABLE. */
163 static void
164 add_dis_line_entry (htab_t table, struct symtab *symtab, int line)
166 void **slot;
167 struct dis_line_entry dle, *dlep;
169 dle.symtab = symtab;
170 dle.line = line;
171 slot = htab_find_slot (table, &dle, INSERT);
172 if (*slot == NULL)
174 dlep = XNEW (struct dis_line_entry);
175 dlep->symtab = symtab;
176 dlep->line = line;
177 *slot = dlep;
181 /* Return non-zero if SYMTAB, LINE are in TABLE. */
183 static int
184 line_has_code_p (htab_t table, struct symtab *symtab, int line)
186 struct dis_line_entry dle;
188 dle.symtab = symtab;
189 dle.line = line;
190 return htab_find (table, &dle) != NULL;
193 /* Wrapper of target_read_code. */
196 gdb_disassembler_memory_reader::dis_asm_read_memory
197 (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
198 struct disassemble_info *info) noexcept
200 auto res = catch_exceptions<int, -1> ([&]
202 return target_read_code (memaddr, myaddr, len);
205 return res;
208 /* Wrapper of memory_error. */
210 void
211 gdb_disassembler::dis_asm_memory_error
212 (int err, bfd_vma memaddr, struct disassemble_info *info) noexcept
214 gdb_disassembler *self
215 = static_cast<gdb_disassembler *>(info->application_data);
217 self->m_err_memaddr.emplace (memaddr);
220 /* Wrapper of print_address. */
222 void
223 gdb_disassembler::dis_asm_print_address
224 (bfd_vma addr, struct disassemble_info *info) noexcept
226 gdb_disassembler *self
227 = static_cast<gdb_disassembler *>(info->application_data);
229 if (self->in_comment_p ())
231 /* Calling 'print_address' might add styling to the output (based on
232 the properties of the stream we're writing too). This is usually
233 fine, but if we are in an assembler comment then we'd prefer to
234 have the comment style, rather than the default address style.
236 Print the address into a temporary buffer which doesn't support
237 styling, then reprint this unstyled address with the default text
238 style.
240 As we are inside a comment right now, the standard print routine
241 will ensure that the comment is printed to the user with a
242 suitable comment style. */
243 string_file tmp;
244 print_address (self->arch (), addr, &tmp);
245 self->fprintf_styled_func (self, dis_style_text, "%s", tmp.c_str ());
247 else
248 print_address (self->arch (), addr, self->stream ());
251 /* See disasm.h. */
253 ui_file *
254 gdb_printing_disassembler::stream_from_gdb_disassemble_info (void *dis_info)
256 gdb_disassemble_info *di = (gdb_disassemble_info *) dis_info;
257 gdb_printing_disassembler *dis
258 = gdb::checked_static_cast<gdb_printing_disassembler *> (di);
259 ui_file *stream = dis->stream ();
260 gdb_assert (stream != nullptr);
261 return stream;
264 /* Format disassembler output to STREAM. */
267 gdb_printing_disassembler::fprintf_func (void *dis_info,
268 const char *format, ...) noexcept
270 ui_file *stream = stream_from_gdb_disassemble_info (dis_info);
272 va_list args;
273 va_start (args, format);
274 gdb_vprintf (stream, format, args);
275 va_end (args);
277 /* Something non -ve. */
278 return 0;
281 /* See disasm.h. */
284 gdb_printing_disassembler::fprintf_styled_func
285 (void *dis_info, enum disassembler_style style,
286 const char *format, ...) noexcept
288 ui_file *stream = stream_from_gdb_disassemble_info (dis_info);
289 gdb_printing_disassembler *dis = (gdb_printing_disassembler *) dis_info;
291 va_list args;
292 va_start (args, format);
293 std::string content = string_vprintf (format, args);
294 va_end (args);
296 /* Once in a comment then everything should be styled as a comment. */
297 if (style == dis_style_comment_start)
298 dis->set_in_comment (true);
299 if (dis->in_comment_p ())
300 style = dis_style_comment_start;
302 /* Now print the content with the correct style. */
303 const char *txt = content.c_str ();
304 switch (style)
306 case dis_style_mnemonic:
307 case dis_style_sub_mnemonic:
308 case dis_style_assembler_directive:
309 fputs_styled (txt, disasm_mnemonic_style.style (), stream);
310 break;
312 case dis_style_register:
313 fputs_styled (txt, disasm_register_style.style (), stream);
314 break;
316 case dis_style_immediate:
317 case dis_style_address_offset:
318 fputs_styled (txt, disasm_immediate_style.style (), stream);
319 break;
321 case dis_style_address:
322 fputs_styled (txt, address_style.style (), stream);
323 break;
325 case dis_style_symbol:
326 fputs_styled (txt, function_name_style.style (), stream);
327 break;
329 case dis_style_comment_start:
330 fputs_styled (txt, disasm_comment_style.style (), stream);
331 break;
333 case dis_style_text:
334 gdb_puts (txt, stream);
335 break;
338 /* Something non -ve. */
339 return 0;
342 static bool
343 line_is_less_than (const deprecated_dis_line_entry &mle1,
344 const deprecated_dis_line_entry &mle2)
346 bool val;
348 /* End of sequence markers have a line number of 0 but don't want to
349 be sorted to the head of the list, instead sort by PC. */
350 if (mle1.line == 0 || mle2.line == 0)
352 if (mle1.start_pc != mle2.start_pc)
353 val = mle1.start_pc < mle2.start_pc;
354 else
355 val = mle1.line < mle2.line;
357 else
359 if (mle1.line != mle2.line)
360 val = mle1.line < mle2.line;
361 else
362 val = mle1.start_pc < mle2.start_pc;
364 return val;
367 /* See disasm.h. */
370 gdb_pretty_print_disassembler::pretty_print_insn (const struct disasm_insn *insn,
371 gdb_disassembly_flags flags)
373 /* parts of the symbolic representation of the address */
374 int unmapped;
375 int offset;
376 int line;
377 int size;
378 CORE_ADDR pc;
379 struct gdbarch *gdbarch = arch ();
382 ui_out_emit_tuple tuple_emitter (m_uiout, NULL);
383 pc = insn->addr;
385 if (insn->number != 0)
387 m_uiout->field_unsigned ("insn-number", insn->number);
388 m_uiout->text ("\t");
391 if ((flags & DISASSEMBLY_SPECULATIVE) != 0)
393 if (insn->is_speculative)
395 m_uiout->field_string ("is-speculative", "?");
397 /* The speculative execution indication overwrites the first
398 character of the PC prefix.
399 We assume a PC prefix length of 3 characters. */
400 if ((flags & DISASSEMBLY_OMIT_PC) == 0)
401 m_uiout->text (pc_prefix (pc) + 1);
402 else
403 m_uiout->text (" ");
405 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
406 m_uiout->text (pc_prefix (pc));
407 else
408 m_uiout->text (" ");
410 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
411 m_uiout->text (pc_prefix (pc));
412 m_uiout->field_core_addr ("address", gdbarch, pc);
414 std::string name, filename;
415 bool omit_fname = ((flags & DISASSEMBLY_OMIT_FNAME) != 0);
416 if (!build_address_symbolic (gdbarch, pc, false, omit_fname, &name,
417 &offset, &filename, &line, &unmapped))
419 /* We don't care now about line, filename and unmapped. But we might in
420 the future. */
421 m_uiout->text (" <");
422 if (!omit_fname)
423 m_uiout->field_string ("func-name", name,
424 function_name_style.style ());
425 /* For negative offsets, avoid displaying them as +-N; the sign of
426 the offset takes the place of the "+" here. */
427 if (offset >= 0)
428 m_uiout->text ("+");
429 m_uiout->field_signed ("offset", offset);
430 m_uiout->text (">:\t");
432 else
433 m_uiout->text (":\t");
435 /* Clear the buffer into which we will disassemble the instruction. */
436 m_insn_stb.clear ();
438 /* A helper function to write the M_INSN_STB buffer, followed by a
439 newline. This can be called in a couple of situations. */
440 auto write_out_insn_buffer = [&] ()
442 m_uiout->field_stream ("inst", m_insn_stb);
443 m_uiout->text ("\n");
448 /* Now we can disassemble the instruction. If the disassembler
449 returns a negative value this indicates an error and is handled
450 within the print_insn call, resulting in an exception being
451 thrown. Returning zero makes no sense, as this indicates we
452 disassembled something successfully, but it was something of no
453 size? */
454 size = m_di.print_insn (pc);
455 gdb_assert (size > 0);
457 catch (const gdb_exception &)
459 /* An exception was thrown while disassembling the instruction.
460 However, the disassembler might still have written something
461 out, so ensure that we flush the instruction buffer before
462 rethrowing the exception. We can't perform this write from an
463 object destructor as the write itself might throw an exception
464 if the pager kicks in, and the user selects quit. */
465 write_out_insn_buffer ();
466 throw;
469 if ((flags & (DISASSEMBLY_RAW_INSN | DISASSEMBLY_RAW_BYTES)) != 0)
471 /* Build the opcodes using a temporary stream so we can
472 write them out in a single go for the MI. */
473 m_opcode_stb.clear ();
475 /* Read the instruction opcode data. */
476 m_opcode_data.resize (size);
477 read_code (pc, m_opcode_data.data (), size);
479 /* The disassembler provides information about the best way to
480 display the instruction bytes to the user. We provide some sane
481 defaults in case the disassembler gets it wrong. */
482 const struct disassemble_info *di = m_di.disasm_info ();
483 int bytes_per_line = std::max (di->bytes_per_line, size);
484 int bytes_per_chunk = std::max (di->bytes_per_chunk, 1);
486 /* If the user has requested the instruction bytes be displayed
487 byte at a time, then handle that here. Also, if the instruction
488 is not a multiple of the chunk size (which probably indicates a
489 disassembler problem) then avoid that causing display problems
490 by switching to byte at a time mode. */
491 if ((flags & DISASSEMBLY_RAW_BYTES) != 0
492 || (size % bytes_per_chunk) != 0)
493 bytes_per_chunk = 1;
495 /* Print the instruction opcodes bytes, grouped into chunks. */
496 for (int i = 0; i < size; i += bytes_per_chunk)
498 if (i > 0)
499 m_opcode_stb.puts (" ");
501 if (di->display_endian == BFD_ENDIAN_LITTLE)
503 for (int k = bytes_per_chunk; k-- != 0; )
504 m_opcode_stb.printf ("%02x", (unsigned) m_opcode_data[i + k]);
506 else
508 for (int k = 0; k < bytes_per_chunk; k++)
509 m_opcode_stb.printf ("%02x", (unsigned) m_opcode_data[i + k]);
513 /* Calculate required padding. */
514 int nspaces = 0;
515 for (int i = size; i < bytes_per_line; i += bytes_per_chunk)
517 if (i > size)
518 nspaces++;
519 nspaces += bytes_per_chunk * 2;
522 m_uiout->field_stream ("opcodes", m_opcode_stb);
523 m_uiout->spaces (nspaces);
524 m_uiout->text ("\t");
527 /* Disassembly was a success, write out the instruction buffer. */
528 write_out_insn_buffer ();
531 return size;
534 static int
535 dump_insns (struct gdbarch *gdbarch,
536 struct ui_out *uiout, CORE_ADDR low, CORE_ADDR high,
537 int how_many, gdb_disassembly_flags flags, CORE_ADDR *end_pc)
539 struct disasm_insn insn;
540 int num_displayed = 0;
542 memset (&insn, 0, sizeof (insn));
543 insn.addr = low;
545 gdb_pretty_print_disassembler disasm (gdbarch, uiout);
547 while (insn.addr < high && (how_many < 0 || num_displayed < how_many))
549 int size;
551 size = disasm.pretty_print_insn (&insn, flags);
552 if (size <= 0)
553 break;
555 ++num_displayed;
556 insn.addr += size;
558 /* Allow user to bail out with ^C. */
559 QUIT;
562 if (end_pc != NULL)
563 *end_pc = insn.addr;
565 return num_displayed;
568 /* The idea here is to present a source-O-centric view of a
569 function to the user. This means that things are presented
570 in source order, with (possibly) out of order assembly
571 immediately following.
573 N.B. This view is deprecated. */
575 static void
576 do_mixed_source_and_assembly_deprecated
577 (struct gdbarch *gdbarch, struct ui_out *uiout,
578 struct symtab *symtab,
579 CORE_ADDR low, CORE_ADDR high,
580 int how_many, gdb_disassembly_flags flags)
582 int newlines = 0;
583 int nlines;
584 const struct linetable_entry *le;
585 struct deprecated_dis_line_entry *mle;
586 struct symtab_and_line sal;
587 int i;
588 int out_of_order = 0;
589 int next_line = 0;
590 int num_displayed = 0;
591 print_source_lines_flags psl_flags = 0;
593 gdb_assert (symtab != nullptr && symtab->linetable () != nullptr);
595 nlines = symtab->linetable ()->nitems;
596 le = symtab->linetable ()->item;
598 if (flags & DISASSEMBLY_FILENAME)
599 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
601 mle = (struct deprecated_dis_line_entry *)
602 alloca (nlines * sizeof (struct deprecated_dis_line_entry));
604 struct objfile *objfile = symtab->compunit ()->objfile ();
606 unrelocated_addr unrel_low
607 = unrelocated_addr (low - objfile->text_section_offset ());
608 unrelocated_addr unrel_high
609 = unrelocated_addr (high - objfile->text_section_offset ());
611 /* Copy linetable entries for this function into our data
612 structure, creating end_pc's and setting out_of_order as
613 appropriate. */
615 /* First, skip all the preceding functions. */
617 for (i = 0; i < nlines - 1 && le[i].unrelocated_pc () < unrel_low; i++);
619 /* Now, copy all entries before the end of this function. */
621 for (; i < nlines - 1 && le[i].unrelocated_pc () < unrel_high; i++)
623 if (le[i] == le[i + 1])
624 continue; /* Ignore duplicates. */
626 /* Skip any end-of-function markers. */
627 if (le[i].line == 0)
628 continue;
630 mle[newlines].line = le[i].line;
631 if (le[i].line > le[i + 1].line)
632 out_of_order = 1;
633 mle[newlines].start_pc = le[i].pc (objfile);
634 mle[newlines].end_pc = le[i + 1].pc (objfile);
635 newlines++;
638 /* If we're on the last line, and it's part of the function,
639 then we need to get the end pc in a special way. */
641 if (i == nlines - 1 && le[i].unrelocated_pc () < unrel_high)
643 mle[newlines].line = le[i].line;
644 mle[newlines].start_pc = le[i].pc (objfile);
645 sal = find_pc_line (le[i].pc (objfile), 0);
646 mle[newlines].end_pc = sal.end;
647 newlines++;
650 /* Now, sort mle by line #s (and, then by addresses within lines). */
652 if (out_of_order)
653 std::sort (mle, mle + newlines, line_is_less_than);
655 /* Now, for each line entry, emit the specified lines (unless
656 they have been emitted before), followed by the assembly code
657 for that line. */
659 ui_out_emit_list asm_insns_list (uiout, "asm_insns");
661 std::optional<ui_out_emit_tuple> outer_tuple_emitter;
662 std::optional<ui_out_emit_list> inner_list_emitter;
664 for (i = 0; i < newlines; i++)
666 /* Print out everything from next_line to the current line. */
667 if (mle[i].line >= next_line)
669 if (next_line != 0)
671 /* Just one line to print. */
672 if (next_line == mle[i].line)
674 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
675 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
677 else
679 /* Several source lines w/o asm instructions associated. */
680 for (; next_line < mle[i].line; next_line++)
682 ui_out_emit_tuple tuple_emitter (uiout,
683 "src_and_asm_line");
684 print_source_lines (symtab, next_line, next_line + 1,
685 psl_flags);
686 ui_out_emit_list temp_list_emitter (uiout,
687 "line_asm_insn");
689 /* Print the last line and leave list open for
690 asm instructions to be added. */
691 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
692 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
695 else
697 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
698 print_source_lines (symtab, mle[i].line, mle[i].line + 1, psl_flags);
701 next_line = mle[i].line + 1;
702 inner_list_emitter.emplace (uiout, "line_asm_insn");
705 num_displayed += dump_insns (gdbarch, uiout,
706 mle[i].start_pc, mle[i].end_pc,
707 how_many, flags, NULL);
709 /* When we've reached the end of the mle array, or we've seen the last
710 assembly range for this source line, close out the list/tuple. */
711 if (i == (newlines - 1) || mle[i + 1].line > mle[i].line)
713 inner_list_emitter.reset ();
714 outer_tuple_emitter.reset ();
715 uiout->text ("\n");
717 if (how_many >= 0 && num_displayed >= how_many)
718 break;
722 /* The idea here is to present a source-O-centric view of a
723 function to the user. This means that things are presented
724 in source order, with (possibly) out of order assembly
725 immediately following. */
727 static void
728 do_mixed_source_and_assembly (struct gdbarch *gdbarch,
729 struct ui_out *uiout,
730 struct symtab *main_symtab,
731 CORE_ADDR low, CORE_ADDR high,
732 int how_many, gdb_disassembly_flags flags)
734 const struct linetable_entry *le, *first_le;
735 int i, nlines;
736 int num_displayed = 0;
737 print_source_lines_flags psl_flags = 0;
738 CORE_ADDR pc;
739 struct symtab *last_symtab;
740 int last_line;
742 gdb_assert (main_symtab != NULL && main_symtab->linetable () != NULL);
744 /* First pass: collect the list of all source files and lines.
745 We do this so that we can only print lines containing code once.
746 We try to print the source text leading up to the next instruction,
747 but if that text is for code that will be disassembled later, then
748 we'll want to defer printing it until later with its associated code. */
750 htab_up dis_line_table (allocate_dis_line_table ());
752 struct objfile *objfile = main_symtab->compunit ()->objfile ();
754 unrelocated_addr unrel_low
755 = unrelocated_addr (low - objfile->text_section_offset ());
756 unrelocated_addr unrel_high
757 = unrelocated_addr (high - objfile->text_section_offset ());
759 pc = low;
761 /* The prologue may be empty, but there may still be a line number entry
762 for the opening brace which is distinct from the first line of code.
763 If the prologue has been eliminated find_pc_line may return the source
764 line after the opening brace. We still want to print this opening brace.
765 first_le is used to implement this. */
767 nlines = main_symtab->linetable ()->nitems;
768 le = main_symtab->linetable ()->item;
769 first_le = NULL;
771 /* Skip all the preceding functions. */
772 for (i = 0; i < nlines && le[i].unrelocated_pc () < unrel_low; i++)
773 continue;
775 if (i < nlines && le[i].unrelocated_pc () < unrel_high)
776 first_le = &le[i];
778 /* Add lines for every pc value. */
779 while (pc < high)
781 struct symtab_and_line sal;
782 int length;
784 sal = find_pc_line (pc, 0);
785 length = gdb_insn_length (gdbarch, pc);
786 pc += length;
788 if (sal.symtab != NULL)
789 add_dis_line_entry (dis_line_table.get (), sal.symtab, sal.line);
792 /* Second pass: print the disassembly.
794 Output format, from an MI perspective:
795 The result is a ui_out list, field name "asm_insns", where elements have
796 name "src_and_asm_line".
797 Each element is a tuple of source line specs (field names line, file,
798 fullname), and field "line_asm_insn" which contains the disassembly.
799 Field "line_asm_insn" is a list of tuples: address, func-name, offset,
800 opcodes, inst.
802 CLI output works on top of this because MI ignores ui_out_text output,
803 which is where we put file name and source line contents output.
805 Emitter usage:
806 asm_insns_emitter
807 Handles the outer "asm_insns" list.
808 tuple_emitter
809 The tuples for each group of consecutive disassemblies.
810 list_emitter
811 List of consecutive source lines or disassembled insns. */
813 if (flags & DISASSEMBLY_FILENAME)
814 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
816 ui_out_emit_list asm_insns_emitter (uiout, "asm_insns");
818 std::optional<ui_out_emit_tuple> tuple_emitter;
819 std::optional<ui_out_emit_list> list_emitter;
821 last_symtab = NULL;
822 last_line = 0;
823 pc = low;
825 while (pc < high)
827 struct symtab_and_line sal;
828 CORE_ADDR end_pc;
829 int start_preceding_line_to_display = 0;
830 int end_preceding_line_to_display = 0;
831 int new_source_line = 0;
833 sal = find_pc_line (pc, 0);
835 if (sal.symtab != last_symtab)
837 /* New source file. */
838 new_source_line = 1;
840 /* If this is the first line of output, check for any preceding
841 lines. */
842 if (last_line == 0
843 && first_le != NULL
844 && first_le->line < sal.line)
846 start_preceding_line_to_display = first_le->line;
847 end_preceding_line_to_display = sal.line;
850 else
852 /* Same source file as last time. */
853 if (sal.symtab != NULL)
855 if (sal.line > last_line + 1 && last_line != 0)
857 int l;
859 /* Several preceding source lines. Print the trailing ones
860 not associated with code that we'll print later. */
861 for (l = sal.line - 1; l > last_line; --l)
863 if (line_has_code_p (dis_line_table.get (),
864 sal.symtab, l))
865 break;
867 if (l < sal.line - 1)
869 start_preceding_line_to_display = l + 1;
870 end_preceding_line_to_display = sal.line;
873 if (sal.line != last_line)
874 new_source_line = 1;
875 else
877 /* Same source line as last time. This can happen, depending
878 on the debug info. */
883 if (new_source_line)
885 /* Skip the newline if this is the first instruction. */
886 if (pc > low)
887 uiout->text ("\n");
888 if (tuple_emitter.has_value ())
890 gdb_assert (list_emitter.has_value ());
891 list_emitter.reset ();
892 tuple_emitter.reset ();
894 if (sal.symtab != last_symtab
895 && !(flags & DISASSEMBLY_FILENAME))
897 /* Remember MI ignores ui_out_text.
898 We don't have to do anything here for MI because MI
899 output includes the source specs for each line. */
900 if (sal.symtab != NULL)
902 auto filename = symtab_to_filename_for_display (sal.symtab);
903 uiout->message ("%ps",
904 styled_string (file_name_style.style (),
905 filename));
907 else
908 uiout->text ("unknown");
909 uiout->text (":\n");
911 if (start_preceding_line_to_display > 0)
913 /* Several source lines w/o asm instructions associated.
914 We need to preserve the structure of the output, so output
915 a bunch of line tuples with no asm entries. */
916 int l;
918 gdb_assert (sal.symtab != NULL);
919 for (l = start_preceding_line_to_display;
920 l < end_preceding_line_to_display;
921 ++l)
923 ui_out_emit_tuple line_tuple_emitter (uiout,
924 "src_and_asm_line");
925 print_source_lines (sal.symtab, l, l + 1, psl_flags);
926 ui_out_emit_list chain_line_emitter (uiout, "line_asm_insn");
929 tuple_emitter.emplace (uiout, "src_and_asm_line");
930 if (sal.symtab != NULL)
931 print_source_lines (sal.symtab, sal.line, sal.line + 1, psl_flags);
932 else
933 uiout->text (_("--- no source info for this pc ---\n"));
934 list_emitter.emplace (uiout, "line_asm_insn");
936 else
938 /* Here we're appending instructions to an existing line.
939 By construction the very first insn will have a symtab
940 and follow the new_source_line path above. */
941 gdb_assert (tuple_emitter.has_value ());
942 gdb_assert (list_emitter.has_value ());
945 if (sal.end != 0)
946 end_pc = std::min (sal.end, high);
947 else
948 end_pc = pc + 1;
949 num_displayed += dump_insns (gdbarch, uiout, pc, end_pc,
950 how_many, flags, &end_pc);
951 pc = end_pc;
953 if (how_many >= 0 && num_displayed >= how_many)
954 break;
956 last_symtab = sal.symtab;
957 last_line = sal.line;
961 static void
962 do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
963 CORE_ADDR low, CORE_ADDR high,
964 int how_many, gdb_disassembly_flags flags)
966 ui_out_emit_list list_emitter (uiout, "asm_insns");
968 dump_insns (gdbarch, uiout, low, high, how_many, flags, NULL);
971 /* Combine implicit and user disassembler options and return them
972 in a newly-created string. */
974 static std::string
975 get_all_disassembler_options (struct gdbarch *gdbarch)
977 const char *implicit = gdbarch_disassembler_options_implicit (gdbarch);
978 const char *options = get_disassembler_options (gdbarch);
979 const char *comma = ",";
981 if (implicit == nullptr)
983 implicit = "";
984 comma = "";
987 if (options == nullptr)
989 options = "";
990 comma = "";
993 return string_printf ("%s%s%s", implicit, comma, options);
996 gdb_disassembler::gdb_disassembler (struct gdbarch *gdbarch,
997 struct ui_file *file,
998 read_memory_ftype func)
999 : gdb_printing_disassembler (gdbarch, &m_buffer, func,
1000 dis_asm_memory_error, dis_asm_print_address),
1001 m_dest (file),
1002 m_buffer (!use_ext_lang_for_styling () && use_libopcodes_for_styling ())
1003 { /* Nothing. */ }
1005 /* See disasm.h. */
1007 bool
1008 gdb_disassembler::use_ext_lang_for_styling () const
1010 /* The use of m_di.created_styled_output here is a bit of a cheat, but
1011 it works fine for now.
1013 This function is called in situations after m_di has been initialized,
1014 but before the instruction has been disassembled.
1016 Currently, every target that supports libopcodes styling sets the
1017 created_styled_output field in disassemble_init_for_target, which was
1018 called as part of the initialization of gdb_printing_disassembler.
1020 This means that we are OK to check the created_styled_output field
1021 here.
1023 If, in the future, there's ever a target that only sets the
1024 created_styled_output field during the actual instruction disassembly
1025 phase, then we will need to update this code. */
1026 return (disassembler_styling
1027 && (!m_di.created_styled_output || !use_libopcodes_styling)
1028 && use_ext_lang_colorization_p
1029 && m_dest->can_emit_style_escape ());
1032 /* See disasm.h. */
1034 bool
1035 gdb_disassembler::use_libopcodes_for_styling () const
1037 /* See the comment on the use of m_di.created_styled_output in the
1038 gdb_disassembler::use_ext_lang_for_styling function. */
1039 return (disassembler_styling
1040 && m_di.created_styled_output
1041 && use_libopcodes_styling
1042 && m_dest->can_emit_style_escape ());
1045 /* See disasm.h. */
1047 gdb_disassemble_info::gdb_disassemble_info
1048 (struct gdbarch *gdbarch,
1049 read_memory_ftype read_memory_func, memory_error_ftype memory_error_func,
1050 print_address_ftype print_address_func, fprintf_ftype fprintf_func,
1051 fprintf_styled_ftype fprintf_styled_func)
1052 : m_gdbarch (gdbarch)
1054 gdb_assert (fprintf_func != nullptr);
1055 gdb_assert (fprintf_styled_func != nullptr);
1056 init_disassemble_info (&m_di, (void *) this, fprintf_func,
1057 fprintf_styled_func);
1058 m_di.flavour = bfd_target_unknown_flavour;
1060 /* The memory_error_func, print_address_func, and read_memory_func are
1061 all initialized to a default (non-nullptr) value by the call to
1062 init_disassemble_info above. If the user is overriding these fields
1063 (by passing non-nullptr values) then do that now, otherwise, leave
1064 these fields as the defaults. */
1065 if (memory_error_func != nullptr)
1066 m_di.memory_error_func = memory_error_func;
1067 if (print_address_func != nullptr)
1068 m_di.print_address_func = print_address_func;
1069 if (read_memory_func != nullptr)
1070 m_di.read_memory_func = read_memory_func;
1072 m_di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1073 m_di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
1074 m_di.endian = gdbarch_byte_order (gdbarch);
1075 m_di.endian_code = gdbarch_byte_order_for_code (gdbarch);
1076 m_di.application_data = this;
1077 m_disassembler_options_holder = get_all_disassembler_options (gdbarch);
1078 if (!m_disassembler_options_holder.empty ())
1079 m_di.disassembler_options = m_disassembler_options_holder.c_str ();
1080 disassemble_init_for_target (&m_di);
1083 /* See disasm.h. */
1085 gdb_disassemble_info::~gdb_disassemble_info ()
1087 disassemble_free_target (&m_di);
1090 /* Wrapper around calling gdbarch_print_insn. This function takes care of
1091 first calling the extension language hooks for print_insn, and, if none
1092 of the extension languages can print this instruction, calls
1093 gdbarch_print_insn to do the work.
1095 GDBARCH is the architecture to disassemble in, VMA is the address of the
1096 instruction being disassembled, and INFO is the libopcodes disassembler
1097 related information. */
1099 static int
1100 gdb_print_insn_1 (struct gdbarch *gdbarch, CORE_ADDR vma,
1101 struct disassemble_info *info)
1103 /* Call into the extension languages to do the disassembly. */
1104 std::optional<int> length = ext_lang_print_insn (gdbarch, vma, info);
1105 if (length.has_value ())
1106 return *length;
1108 /* No extension language wanted to do the disassembly, so do it
1109 manually. */
1110 return gdbarch_print_insn (gdbarch, vma, info);
1113 /* See disasm.h. */
1115 bool gdb_disassembler::use_ext_lang_colorization_p = true;
1117 /* See disasm.h. */
1120 gdb_disassembler::print_insn (CORE_ADDR memaddr,
1121 int *branch_delay_insns)
1123 m_err_memaddr.reset ();
1124 m_buffer.clear ();
1125 this->set_in_comment (false);
1127 int length = gdb_print_insn_1 (arch (), memaddr, &m_di);
1129 /* If we have successfully disassembled an instruction, disassembler
1130 styling using the extension language is on, and libopcodes hasn't
1131 already styled the output for us, and, if the destination can support
1132 styling, then lets call into the extension languages in order to style
1133 this output. */
1134 if (length > 0 && use_ext_lang_for_styling ())
1136 std::optional<std::string> ext_contents;
1137 ext_contents = ext_lang_colorize_disasm (m_buffer.string (), arch ());
1138 if (ext_contents.has_value ())
1139 m_buffer = std::move (*ext_contents);
1140 else
1142 /* The extension language failed to add styling to the
1143 disassembly output. Set the static flag so that next time we
1144 disassemble we don't even bother attempting to use the
1145 extension language for styling. */
1146 use_ext_lang_colorization_p = false;
1148 /* We're about to disassemble this instruction again, reset the
1149 in-comment state. */
1150 this->set_in_comment (false);
1152 /* The instruction we just disassembled, and the extension
1153 languages failed to style, might have otherwise had some
1154 minimal styling applied by GDB. To regain that styling we
1155 need to recreate m_buffer, but this time with styling support.
1157 To do this we perform an in-place new, but this time turn on
1158 the styling support, then we can re-disassembly the
1159 instruction, and gain any minimal styling GDB might add. */
1160 static_assert ((std::is_same<decltype (m_buffer),
1161 string_file>::value));
1162 gdb_assert (!m_buffer.term_out ());
1163 m_buffer.~string_file ();
1164 new (&m_buffer) string_file (use_libopcodes_for_styling ());
1165 length = gdb_print_insn_1 (arch (), memaddr, &m_di);
1166 gdb_assert (length > 0);
1170 /* Push any disassemble output to the real destination stream. We do
1171 this even if the disassembler reported failure (-1) as the
1172 disassembler may have printed something to its output stream. */
1173 gdb_printf (m_dest, "%s", m_buffer.c_str ());
1175 /* If the disassembler failed then report an appropriate error. */
1176 if (length < 0)
1178 if (m_err_memaddr.has_value ())
1179 memory_error (TARGET_XFER_E_IO, *m_err_memaddr);
1180 else
1181 error (_("unknown disassembler error (error = %d)"), length);
1184 if (branch_delay_insns != NULL)
1186 if (m_di.insn_info_valid)
1187 *branch_delay_insns = m_di.branch_delay_insns;
1188 else
1189 *branch_delay_insns = 0;
1191 return length;
1194 void
1195 gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
1196 gdb_disassembly_flags flags, int how_many,
1197 CORE_ADDR low, CORE_ADDR high)
1199 struct symtab *symtab;
1200 int nlines = -1;
1202 /* Assume symtab is valid for whole PC range. */
1203 symtab = find_pc_line_symtab (low);
1205 if (symtab != NULL && symtab->linetable () != NULL)
1206 nlines = symtab->linetable ()->nitems;
1208 if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
1209 || nlines <= 0)
1210 do_assembly_only (gdbarch, uiout, low, high, how_many, flags);
1212 else if (flags & DISASSEMBLY_SOURCE)
1213 do_mixed_source_and_assembly (gdbarch, uiout, symtab, low, high,
1214 how_many, flags);
1216 else if (flags & DISASSEMBLY_SOURCE_DEPRECATED)
1217 do_mixed_source_and_assembly_deprecated (gdbarch, uiout, symtab,
1218 low, high, how_many, flags);
1220 gdb_flush (gdb_stdout);
1223 /* Print the instruction at address MEMADDR in debugged memory,
1224 on STREAM. Returns the length of the instruction, in bytes,
1225 and, if requested, the number of branch delay slot instructions. */
1228 gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
1229 struct ui_file *stream, int *branch_delay_insns)
1232 gdb_disassembler di (gdbarch, stream);
1234 return di.print_insn (memaddr, branch_delay_insns);
1237 /* Return the length in bytes of the instruction at address MEMADDR in
1238 debugged memory. */
1241 gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr)
1243 return gdb_print_insn (gdbarch, addr, &null_stream, NULL);
1246 /* See disasm.h. */
1249 gdb_non_printing_disassembler::null_fprintf_func
1250 (void *stream, const char *format, ...) noexcept
1252 return 0;
1255 /* See disasm.h. */
1258 gdb_non_printing_disassembler::null_fprintf_styled_func
1259 (void *stream, enum disassembler_style style,
1260 const char *format, ...) noexcept
1262 return 0;
1265 /* A non-printing disassemble_info management class. The disassemble_info
1266 setup by this class will not print anything to the output stream (there
1267 is no output stream), and the instruction to be disassembled will be
1268 read from a buffer passed to the constructor. */
1270 struct gdb_non_printing_buffer_disassembler
1271 : public gdb_non_printing_disassembler
1273 /* Constructor. GDBARCH is the architecture to disassemble for, BUFFER
1274 contains the instruction to disassemble, and INSN_ADDRESS is the
1275 address (in target memory) of the instruction to disassemble. */
1276 gdb_non_printing_buffer_disassembler (struct gdbarch *gdbarch,
1277 gdb::array_view<const gdb_byte> buffer,
1278 CORE_ADDR insn_address)
1279 : gdb_non_printing_disassembler (gdbarch, nullptr)
1281 /* The cast is necessary until disassemble_info is const-ified. */
1282 m_di.buffer = (gdb_byte *) buffer.data ();
1283 m_di.buffer_length = buffer.size ();
1284 m_di.buffer_vma = insn_address;
1288 /* Return the length in bytes of INSN. MAX_LEN is the size of the
1289 buffer containing INSN. */
1292 gdb_buffered_insn_length (struct gdbarch *gdbarch,
1293 const gdb_byte *insn, int max_len, CORE_ADDR addr)
1295 gdb::array_view<const gdb_byte> buffer
1296 = gdb::make_array_view (insn, max_len);
1297 gdb_non_printing_buffer_disassembler dis (gdbarch, buffer, addr);
1298 int result = gdb_print_insn_1 (gdbarch, addr, dis.disasm_info ());
1299 return result;
1302 const char *
1303 get_disassembler_options (struct gdbarch *gdbarch)
1305 std::string *disassembler_options = gdbarch_disassembler_options (gdbarch);
1306 if (disassembler_options == nullptr || disassembler_options->empty ())
1307 return nullptr;
1308 return disassembler_options->c_str ();
1311 void
1312 set_disassembler_options (const char *prospective_options)
1314 struct gdbarch *gdbarch = get_current_arch ();
1315 std::string *disassembler_options = gdbarch_disassembler_options (gdbarch);
1316 const disasm_options_and_args_t *valid_options_and_args;
1317 const disasm_options_t *valid_options;
1318 gdb::unique_xmalloc_ptr<char> prospective_options_local
1319 = make_unique_xstrdup (prospective_options);
1320 char *options = remove_whitespace_and_extra_commas
1321 (prospective_options_local.get ());
1322 const char *opt;
1324 /* Allow all architectures, even ones that do not support 'set disassembler',
1325 to reset their disassembler options to NULL. */
1326 if (options == NULL)
1328 if (disassembler_options != nullptr)
1329 disassembler_options->clear ();
1330 return;
1333 valid_options_and_args = gdbarch_valid_disassembler_options (gdbarch);
1334 if (valid_options_and_args == NULL)
1336 gdb_printf (gdb_stderr, _("\
1337 'set disassembler-options ...' is not supported on this architecture.\n"));
1338 return;
1341 valid_options = &valid_options_and_args->options;
1343 /* Verify we have valid disassembler options. */
1344 FOR_EACH_DISASSEMBLER_OPTION (opt, options)
1346 size_t i;
1347 for (i = 0; valid_options->name[i] != NULL; i++)
1348 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1350 size_t len = strlen (valid_options->name[i]);
1351 bool found = false;
1352 const char *arg;
1353 size_t j;
1355 if (memcmp (opt, valid_options->name[i], len) != 0)
1356 continue;
1357 arg = opt + len;
1358 if (valid_options->arg[i]->values == NULL)
1359 break;
1360 for (j = 0; valid_options->arg[i]->values[j] != NULL; j++)
1361 if (disassembler_options_cmp
1362 (arg, valid_options->arg[i]->values[j]) == 0)
1364 found = true;
1365 break;
1367 if (found)
1368 break;
1370 else if (disassembler_options_cmp (opt, valid_options->name[i]) == 0)
1371 break;
1372 if (valid_options->name[i] == NULL)
1374 gdb_printf (gdb_stderr,
1375 _("Invalid disassembler option value: '%s'.\n"),
1376 opt);
1377 return;
1381 *disassembler_options = options;
1384 static void
1385 set_disassembler_options_sfunc (const char *args, int from_tty,
1386 struct cmd_list_element *c)
1388 set_disassembler_options (prospective_options.c_str ());
1391 static void
1392 show_disassembler_options_sfunc (struct ui_file *file, int from_tty,
1393 struct cmd_list_element *c, const char *value)
1395 struct gdbarch *gdbarch = get_current_arch ();
1396 const disasm_options_and_args_t *valid_options_and_args;
1397 const disasm_option_arg_t *valid_args;
1398 const disasm_options_t *valid_options;
1400 const char *options = get_disassembler_options (gdbarch);
1401 if (options == NULL)
1402 options = "";
1404 gdb_printf (file, _("The current disassembler options are '%s'\n\n"),
1405 options);
1407 valid_options_and_args = gdbarch_valid_disassembler_options (gdbarch);
1409 if (valid_options_and_args == NULL)
1411 gdb_puts (_("There are no disassembler options available "
1412 "for this architecture.\n"),
1413 file);
1414 return;
1417 valid_options = &valid_options_and_args->options;
1419 gdb_printf (file, _("\
1420 The following disassembler options are supported for use with the\n\
1421 'set disassembler-options OPTION [,OPTION]...' command:\n"));
1423 if (valid_options->description != NULL)
1425 size_t i, max_len = 0;
1427 gdb_printf (file, "\n");
1429 /* Compute the length of the longest option name. */
1430 for (i = 0; valid_options->name[i] != NULL; i++)
1432 size_t len = strlen (valid_options->name[i]);
1434 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1435 len += strlen (valid_options->arg[i]->name);
1436 if (max_len < len)
1437 max_len = len;
1440 for (i = 0, max_len++; valid_options->name[i] != NULL; i++)
1442 gdb_printf (file, " %s", valid_options->name[i]);
1443 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1444 gdb_printf (file, "%s", valid_options->arg[i]->name);
1445 if (valid_options->description[i] != NULL)
1447 size_t len = strlen (valid_options->name[i]);
1449 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1450 len += strlen (valid_options->arg[i]->name);
1451 gdb_printf (file, "%*c %s", (int) (max_len - len), ' ',
1452 valid_options->description[i]);
1454 gdb_printf (file, "\n");
1457 else
1459 size_t i;
1460 gdb_printf (file, " ");
1461 for (i = 0; valid_options->name[i] != NULL; i++)
1463 gdb_printf (file, "%s", valid_options->name[i]);
1464 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1465 gdb_printf (file, "%s", valid_options->arg[i]->name);
1466 if (valid_options->name[i + 1] != NULL)
1467 gdb_printf (file, ", ");
1468 file->wrap_here (2);
1470 gdb_printf (file, "\n");
1473 valid_args = valid_options_and_args->args;
1474 if (valid_args != NULL)
1476 size_t i, j;
1478 for (i = 0; valid_args[i].name != NULL; i++)
1480 if (valid_args[i].values == NULL)
1481 continue;
1482 gdb_printf (file, _("\n\
1483 For the options above, the following values are supported for \"%s\":\n "),
1484 valid_args[i].name);
1485 for (j = 0; valid_args[i].values[j] != NULL; j++)
1487 gdb_printf (file, " %s", valid_args[i].values[j]);
1488 file->wrap_here (3);
1490 gdb_printf (file, "\n");
1495 /* A completion function for "set disassembler". */
1497 static void
1498 disassembler_options_completer (struct cmd_list_element *ignore,
1499 completion_tracker &tracker,
1500 const char *text, const char *word)
1502 struct gdbarch *gdbarch = get_current_arch ();
1503 const disasm_options_and_args_t *opts_and_args
1504 = gdbarch_valid_disassembler_options (gdbarch);
1506 if (opts_and_args != NULL)
1508 const disasm_options_t *opts = &opts_and_args->options;
1510 /* Only attempt to complete on the last option text. */
1511 const char *separator = strrchr (text, ',');
1512 if (separator != NULL)
1513 text = separator + 1;
1514 text = skip_spaces (text);
1515 complete_on_enum (tracker, opts->name, text, word);
1520 /* Initialization code. */
1522 void _initialize_disasm ();
1523 void
1524 _initialize_disasm ()
1526 /* Add the command that controls the disassembler options. */
1527 set_show_commands set_show_disas_opts
1528 = add_setshow_string_noescape_cmd ("disassembler-options", no_class,
1529 &prospective_options, _("\
1530 Set the disassembler options.\n\
1531 Usage: set disassembler-options OPTION [,OPTION]...\n\n\
1532 See: 'show disassembler-options' for valid option values."), _("\
1533 Show the disassembler options."), NULL,
1534 set_disassembler_options_sfunc,
1535 show_disassembler_options_sfunc,
1536 &setlist, &showlist);
1537 set_cmd_completer (set_show_disas_opts.set, disassembler_options_completer);
1540 /* All the 'maint set|show libopcodes-styling' sub-commands. */
1541 static struct cmd_list_element *maint_set_libopcodes_styling_cmdlist;
1542 static struct cmd_list_element *maint_show_libopcodes_styling_cmdlist;
1544 /* Adds 'maint set|show libopcodes-styling'. */
1545 add_setshow_prefix_cmd ("libopcodes-styling", class_maintenance,
1546 _("Set libopcodes-styling specific variables."),
1547 _("Show libopcodes-styling specific variables."),
1548 &maint_set_libopcodes_styling_cmdlist,
1549 &maint_show_libopcodes_styling_cmdlist,
1550 &maintenance_set_cmdlist,
1551 &maintenance_show_cmdlist);
1553 /* Adds 'maint set|show gnu-source-highlight enabled'. */
1554 add_setshow_boolean_cmd ("enabled", class_maintenance,
1555 &use_libopcodes_styling_option, _("\
1556 Set whether the libopcodes styling support should be used."), _("\
1557 Show whether the libopcodes styling support should be used."),_("\
1558 When enabled, GDB will try to make use of the builtin libopcodes styling\n\
1559 support, to style the disassembler output. Not every architecture has\n\
1560 styling support within libopcodes, so enabling this is not a guarantee\n\
1561 that libopcodes styling will be available.\n\
1563 When this option is disabled, GDB will make use of the Python Pygments\n\
1564 package (if available) to style the disassembler output.\n\
1566 All disassembler styling can be disabled with:\n\
1568 set style disassembler enabled off"),
1569 set_use_libopcodes_styling,
1570 show_use_libopcodes_styling,
1571 &maint_set_libopcodes_styling_cmdlist,
1572 &maint_show_libopcodes_styling_cmdlist);