Add extra files found in etc/ sub-directory to ETC_SUPPORT in src-release.sh
[binutils-gdb.git] / gdb / disasm.c
blob16736e549977b97d9c8ccc9586ea96663fa65100
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 return target_read_code (memaddr, myaddr, len);
203 /* Wrapper of memory_error. */
205 void
206 gdb_disassembler::dis_asm_memory_error
207 (int err, bfd_vma memaddr, struct disassemble_info *info) noexcept
209 gdb_disassembler *self
210 = static_cast<gdb_disassembler *>(info->application_data);
212 self->m_err_memaddr.emplace (memaddr);
215 /* Wrapper of print_address. */
217 void
218 gdb_disassembler::dis_asm_print_address
219 (bfd_vma addr, struct disassemble_info *info) noexcept
221 gdb_disassembler *self
222 = static_cast<gdb_disassembler *>(info->application_data);
224 if (self->in_comment_p ())
226 /* Calling 'print_address' might add styling to the output (based on
227 the properties of the stream we're writing too). This is usually
228 fine, but if we are in an assembler comment then we'd prefer to
229 have the comment style, rather than the default address style.
231 Print the address into a temporary buffer which doesn't support
232 styling, then reprint this unstyled address with the default text
233 style.
235 As we are inside a comment right now, the standard print routine
236 will ensure that the comment is printed to the user with a
237 suitable comment style. */
238 string_file tmp;
239 print_address (self->arch (), addr, &tmp);
240 self->fprintf_styled_func (self, dis_style_text, "%s", tmp.c_str ());
242 else
243 print_address (self->arch (), addr, self->stream ());
246 /* See disasm.h. */
248 ui_file *
249 gdb_printing_disassembler::stream_from_gdb_disassemble_info (void *dis_info)
251 gdb_disassemble_info *di = (gdb_disassemble_info *) dis_info;
252 gdb_printing_disassembler *dis
253 = gdb::checked_static_cast<gdb_printing_disassembler *> (di);
254 ui_file *stream = dis->stream ();
255 gdb_assert (stream != nullptr);
256 return stream;
259 /* Format disassembler output to STREAM. */
262 gdb_printing_disassembler::fprintf_func (void *dis_info,
263 const char *format, ...) noexcept
265 ui_file *stream = stream_from_gdb_disassemble_info (dis_info);
267 va_list args;
268 va_start (args, format);
269 gdb_vprintf (stream, format, args);
270 va_end (args);
272 /* Something non -ve. */
273 return 0;
276 /* See disasm.h. */
279 gdb_printing_disassembler::fprintf_styled_func
280 (void *dis_info, enum disassembler_style style,
281 const char *format, ...) noexcept
283 ui_file *stream = stream_from_gdb_disassemble_info (dis_info);
284 gdb_printing_disassembler *dis = (gdb_printing_disassembler *) dis_info;
286 va_list args;
287 va_start (args, format);
288 std::string content = string_vprintf (format, args);
289 va_end (args);
291 /* Once in a comment then everything should be styled as a comment. */
292 if (style == dis_style_comment_start)
293 dis->set_in_comment (true);
294 if (dis->in_comment_p ())
295 style = dis_style_comment_start;
297 /* Now print the content with the correct style. */
298 const char *txt = content.c_str ();
299 switch (style)
301 case dis_style_mnemonic:
302 case dis_style_sub_mnemonic:
303 case dis_style_assembler_directive:
304 fputs_styled (txt, disasm_mnemonic_style.style (), stream);
305 break;
307 case dis_style_register:
308 fputs_styled (txt, disasm_register_style.style (), stream);
309 break;
311 case dis_style_immediate:
312 case dis_style_address_offset:
313 fputs_styled (txt, disasm_immediate_style.style (), stream);
314 break;
316 case dis_style_address:
317 fputs_styled (txt, address_style.style (), stream);
318 break;
320 case dis_style_symbol:
321 fputs_styled (txt, function_name_style.style (), stream);
322 break;
324 case dis_style_comment_start:
325 fputs_styled (txt, disasm_comment_style.style (), stream);
326 break;
328 case dis_style_text:
329 gdb_puts (txt, stream);
330 break;
333 /* Something non -ve. */
334 return 0;
337 static bool
338 line_is_less_than (const deprecated_dis_line_entry &mle1,
339 const deprecated_dis_line_entry &mle2)
341 bool val;
343 /* End of sequence markers have a line number of 0 but don't want to
344 be sorted to the head of the list, instead sort by PC. */
345 if (mle1.line == 0 || mle2.line == 0)
347 if (mle1.start_pc != mle2.start_pc)
348 val = mle1.start_pc < mle2.start_pc;
349 else
350 val = mle1.line < mle2.line;
352 else
354 if (mle1.line != mle2.line)
355 val = mle1.line < mle2.line;
356 else
357 val = mle1.start_pc < mle2.start_pc;
359 return val;
362 /* See disasm.h. */
365 gdb_pretty_print_disassembler::pretty_print_insn (const struct disasm_insn *insn,
366 gdb_disassembly_flags flags)
368 /* parts of the symbolic representation of the address */
369 int unmapped;
370 int offset;
371 int line;
372 int size;
373 CORE_ADDR pc;
374 struct gdbarch *gdbarch = arch ();
377 ui_out_emit_tuple tuple_emitter (m_uiout, NULL);
378 pc = insn->addr;
380 if (insn->number != 0)
382 m_uiout->field_unsigned ("insn-number", insn->number);
383 m_uiout->text ("\t");
386 if ((flags & DISASSEMBLY_SPECULATIVE) != 0)
388 if (insn->is_speculative)
390 m_uiout->field_string ("is-speculative", "?");
392 /* The speculative execution indication overwrites the first
393 character of the PC prefix.
394 We assume a PC prefix length of 3 characters. */
395 if ((flags & DISASSEMBLY_OMIT_PC) == 0)
396 m_uiout->text (pc_prefix (pc) + 1);
397 else
398 m_uiout->text (" ");
400 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
401 m_uiout->text (pc_prefix (pc));
402 else
403 m_uiout->text (" ");
405 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
406 m_uiout->text (pc_prefix (pc));
407 m_uiout->field_core_addr ("address", gdbarch, pc);
409 std::string name, filename;
410 bool omit_fname = ((flags & DISASSEMBLY_OMIT_FNAME) != 0);
411 if (!build_address_symbolic (gdbarch, pc, false, omit_fname, &name,
412 &offset, &filename, &line, &unmapped))
414 /* We don't care now about line, filename and unmapped. But we might in
415 the future. */
416 m_uiout->text (" <");
417 if (!omit_fname)
418 m_uiout->field_string ("func-name", name,
419 function_name_style.style ());
420 /* For negative offsets, avoid displaying them as +-N; the sign of
421 the offset takes the place of the "+" here. */
422 if (offset >= 0)
423 m_uiout->text ("+");
424 m_uiout->field_signed ("offset", offset);
425 m_uiout->text (">:\t");
427 else
428 m_uiout->text (":\t");
430 /* Clear the buffer into which we will disassemble the instruction. */
431 m_insn_stb.clear ();
433 /* A helper function to write the M_INSN_STB buffer, followed by a
434 newline. This can be called in a couple of situations. */
435 auto write_out_insn_buffer = [&] ()
437 m_uiout->field_stream ("inst", m_insn_stb);
438 m_uiout->text ("\n");
443 /* Now we can disassemble the instruction. If the disassembler
444 returns a negative value this indicates an error and is handled
445 within the print_insn call, resulting in an exception being
446 thrown. Returning zero makes no sense, as this indicates we
447 disassembled something successfully, but it was something of no
448 size? */
449 size = m_di.print_insn (pc);
450 gdb_assert (size > 0);
452 catch (const gdb_exception &)
454 /* An exception was thrown while disassembling the instruction.
455 However, the disassembler might still have written something
456 out, so ensure that we flush the instruction buffer before
457 rethrowing the exception. We can't perform this write from an
458 object destructor as the write itself might throw an exception
459 if the pager kicks in, and the user selects quit. */
460 write_out_insn_buffer ();
461 throw;
464 if ((flags & (DISASSEMBLY_RAW_INSN | DISASSEMBLY_RAW_BYTES)) != 0)
466 /* Build the opcodes using a temporary stream so we can
467 write them out in a single go for the MI. */
468 m_opcode_stb.clear ();
470 /* Read the instruction opcode data. */
471 m_opcode_data.resize (size);
472 read_code (pc, m_opcode_data.data (), size);
474 /* The disassembler provides information about the best way to
475 display the instruction bytes to the user. We provide some sane
476 defaults in case the disassembler gets it wrong. */
477 const struct disassemble_info *di = m_di.disasm_info ();
478 int bytes_per_line = std::max (di->bytes_per_line, size);
479 int bytes_per_chunk = std::max (di->bytes_per_chunk, 1);
481 /* If the user has requested the instruction bytes be displayed
482 byte at a time, then handle that here. Also, if the instruction
483 is not a multiple of the chunk size (which probably indicates a
484 disassembler problem) then avoid that causing display problems
485 by switching to byte at a time mode. */
486 if ((flags & DISASSEMBLY_RAW_BYTES) != 0
487 || (size % bytes_per_chunk) != 0)
488 bytes_per_chunk = 1;
490 /* Print the instruction opcodes bytes, grouped into chunks. */
491 for (int i = 0; i < size; i += bytes_per_chunk)
493 if (i > 0)
494 m_opcode_stb.puts (" ");
496 if (di->display_endian == BFD_ENDIAN_LITTLE)
498 for (int k = bytes_per_chunk; k-- != 0; )
499 m_opcode_stb.printf ("%02x", (unsigned) m_opcode_data[i + k]);
501 else
503 for (int k = 0; k < bytes_per_chunk; k++)
504 m_opcode_stb.printf ("%02x", (unsigned) m_opcode_data[i + k]);
508 /* Calculate required padding. */
509 int nspaces = 0;
510 for (int i = size; i < bytes_per_line; i += bytes_per_chunk)
512 if (i > size)
513 nspaces++;
514 nspaces += bytes_per_chunk * 2;
517 m_uiout->field_stream ("opcodes", m_opcode_stb);
518 m_uiout->spaces (nspaces);
519 m_uiout->text ("\t");
522 /* Disassembly was a success, write out the instruction buffer. */
523 write_out_insn_buffer ();
526 return size;
529 static int
530 dump_insns (struct gdbarch *gdbarch,
531 struct ui_out *uiout, CORE_ADDR low, CORE_ADDR high,
532 int how_many, gdb_disassembly_flags flags, CORE_ADDR *end_pc)
534 struct disasm_insn insn;
535 int num_displayed = 0;
537 memset (&insn, 0, sizeof (insn));
538 insn.addr = low;
540 gdb_pretty_print_disassembler disasm (gdbarch, uiout);
542 while (insn.addr < high && (how_many < 0 || num_displayed < how_many))
544 int size;
546 size = disasm.pretty_print_insn (&insn, flags);
547 if (size <= 0)
548 break;
550 ++num_displayed;
551 insn.addr += size;
553 /* Allow user to bail out with ^C. */
554 QUIT;
557 if (end_pc != NULL)
558 *end_pc = insn.addr;
560 return num_displayed;
563 /* The idea here is to present a source-O-centric view of a
564 function to the user. This means that things are presented
565 in source order, with (possibly) out of order assembly
566 immediately following.
568 N.B. This view is deprecated. */
570 static void
571 do_mixed_source_and_assembly_deprecated
572 (struct gdbarch *gdbarch, struct ui_out *uiout,
573 struct symtab *symtab,
574 CORE_ADDR low, CORE_ADDR high,
575 int how_many, gdb_disassembly_flags flags)
577 int newlines = 0;
578 int nlines;
579 const struct linetable_entry *le;
580 struct deprecated_dis_line_entry *mle;
581 struct symtab_and_line sal;
582 int i;
583 int out_of_order = 0;
584 int next_line = 0;
585 int num_displayed = 0;
586 print_source_lines_flags psl_flags = 0;
588 gdb_assert (symtab != nullptr && symtab->linetable () != nullptr);
590 nlines = symtab->linetable ()->nitems;
591 le = symtab->linetable ()->item;
593 if (flags & DISASSEMBLY_FILENAME)
594 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
596 mle = (struct deprecated_dis_line_entry *)
597 alloca (nlines * sizeof (struct deprecated_dis_line_entry));
599 struct objfile *objfile = symtab->compunit ()->objfile ();
601 unrelocated_addr unrel_low
602 = unrelocated_addr (low - objfile->text_section_offset ());
603 unrelocated_addr unrel_high
604 = unrelocated_addr (high - objfile->text_section_offset ());
606 /* Copy linetable entries for this function into our data
607 structure, creating end_pc's and setting out_of_order as
608 appropriate. */
610 /* First, skip all the preceding functions. */
612 for (i = 0; i < nlines - 1 && le[i].unrelocated_pc () < unrel_low; i++);
614 /* Now, copy all entries before the end of this function. */
616 for (; i < nlines - 1 && le[i].unrelocated_pc () < unrel_high; i++)
618 if (le[i] == le[i + 1])
619 continue; /* Ignore duplicates. */
621 /* Skip any end-of-function markers. */
622 if (le[i].line == 0)
623 continue;
625 mle[newlines].line = le[i].line;
626 if (le[i].line > le[i + 1].line)
627 out_of_order = 1;
628 mle[newlines].start_pc = le[i].pc (objfile);
629 mle[newlines].end_pc = le[i + 1].pc (objfile);
630 newlines++;
633 /* If we're on the last line, and it's part of the function,
634 then we need to get the end pc in a special way. */
636 if (i == nlines - 1 && le[i].unrelocated_pc () < unrel_high)
638 mle[newlines].line = le[i].line;
639 mle[newlines].start_pc = le[i].pc (objfile);
640 sal = find_pc_line (le[i].pc (objfile), 0);
641 mle[newlines].end_pc = sal.end;
642 newlines++;
645 /* Now, sort mle by line #s (and, then by addresses within lines). */
647 if (out_of_order)
648 std::sort (mle, mle + newlines, line_is_less_than);
650 /* Now, for each line entry, emit the specified lines (unless
651 they have been emitted before), followed by the assembly code
652 for that line. */
654 ui_out_emit_list asm_insns_list (uiout, "asm_insns");
656 std::optional<ui_out_emit_tuple> outer_tuple_emitter;
657 std::optional<ui_out_emit_list> inner_list_emitter;
659 for (i = 0; i < newlines; i++)
661 /* Print out everything from next_line to the current line. */
662 if (mle[i].line >= next_line)
664 if (next_line != 0)
666 /* Just one line to print. */
667 if (next_line == mle[i].line)
669 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
670 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
672 else
674 /* Several source lines w/o asm instructions associated. */
675 for (; next_line < mle[i].line; next_line++)
677 ui_out_emit_tuple tuple_emitter (uiout,
678 "src_and_asm_line");
679 print_source_lines (symtab, next_line, next_line + 1,
680 psl_flags);
681 ui_out_emit_list temp_list_emitter (uiout,
682 "line_asm_insn");
684 /* Print the last line and leave list open for
685 asm instructions to be added. */
686 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
687 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
690 else
692 outer_tuple_emitter.emplace (uiout, "src_and_asm_line");
693 print_source_lines (symtab, mle[i].line, mle[i].line + 1, psl_flags);
696 next_line = mle[i].line + 1;
697 inner_list_emitter.emplace (uiout, "line_asm_insn");
700 num_displayed += dump_insns (gdbarch, uiout,
701 mle[i].start_pc, mle[i].end_pc,
702 how_many, flags, NULL);
704 /* When we've reached the end of the mle array, or we've seen the last
705 assembly range for this source line, close out the list/tuple. */
706 if (i == (newlines - 1) || mle[i + 1].line > mle[i].line)
708 inner_list_emitter.reset ();
709 outer_tuple_emitter.reset ();
710 uiout->text ("\n");
712 if (how_many >= 0 && num_displayed >= how_many)
713 break;
717 /* The idea here is to present a source-O-centric view of a
718 function to the user. This means that things are presented
719 in source order, with (possibly) out of order assembly
720 immediately following. */
722 static void
723 do_mixed_source_and_assembly (struct gdbarch *gdbarch,
724 struct ui_out *uiout,
725 struct symtab *main_symtab,
726 CORE_ADDR low, CORE_ADDR high,
727 int how_many, gdb_disassembly_flags flags)
729 const struct linetable_entry *le, *first_le;
730 int i, nlines;
731 int num_displayed = 0;
732 print_source_lines_flags psl_flags = 0;
733 CORE_ADDR pc;
734 struct symtab *last_symtab;
735 int last_line;
737 gdb_assert (main_symtab != NULL && main_symtab->linetable () != NULL);
739 /* First pass: collect the list of all source files and lines.
740 We do this so that we can only print lines containing code once.
741 We try to print the source text leading up to the next instruction,
742 but if that text is for code that will be disassembled later, then
743 we'll want to defer printing it until later with its associated code. */
745 htab_up dis_line_table (allocate_dis_line_table ());
747 struct objfile *objfile = main_symtab->compunit ()->objfile ();
749 unrelocated_addr unrel_low
750 = unrelocated_addr (low - objfile->text_section_offset ());
751 unrelocated_addr unrel_high
752 = unrelocated_addr (high - objfile->text_section_offset ());
754 pc = low;
756 /* The prologue may be empty, but there may still be a line number entry
757 for the opening brace which is distinct from the first line of code.
758 If the prologue has been eliminated find_pc_line may return the source
759 line after the opening brace. We still want to print this opening brace.
760 first_le is used to implement this. */
762 nlines = main_symtab->linetable ()->nitems;
763 le = main_symtab->linetable ()->item;
764 first_le = NULL;
766 /* Skip all the preceding functions. */
767 for (i = 0; i < nlines && le[i].unrelocated_pc () < unrel_low; i++)
768 continue;
770 if (i < nlines && le[i].unrelocated_pc () < unrel_high)
771 first_le = &le[i];
773 /* Add lines for every pc value. */
774 while (pc < high)
776 struct symtab_and_line sal;
777 int length;
779 sal = find_pc_line (pc, 0);
780 length = gdb_insn_length (gdbarch, pc);
781 pc += length;
783 if (sal.symtab != NULL)
784 add_dis_line_entry (dis_line_table.get (), sal.symtab, sal.line);
787 /* Second pass: print the disassembly.
789 Output format, from an MI perspective:
790 The result is a ui_out list, field name "asm_insns", where elements have
791 name "src_and_asm_line".
792 Each element is a tuple of source line specs (field names line, file,
793 fullname), and field "line_asm_insn" which contains the disassembly.
794 Field "line_asm_insn" is a list of tuples: address, func-name, offset,
795 opcodes, inst.
797 CLI output works on top of this because MI ignores ui_out_text output,
798 which is where we put file name and source line contents output.
800 Emitter usage:
801 asm_insns_emitter
802 Handles the outer "asm_insns" list.
803 tuple_emitter
804 The tuples for each group of consecutive disassemblies.
805 list_emitter
806 List of consecutive source lines or disassembled insns. */
808 if (flags & DISASSEMBLY_FILENAME)
809 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
811 ui_out_emit_list asm_insns_emitter (uiout, "asm_insns");
813 std::optional<ui_out_emit_tuple> tuple_emitter;
814 std::optional<ui_out_emit_list> list_emitter;
816 last_symtab = NULL;
817 last_line = 0;
818 pc = low;
820 while (pc < high)
822 struct symtab_and_line sal;
823 CORE_ADDR end_pc;
824 int start_preceding_line_to_display = 0;
825 int end_preceding_line_to_display = 0;
826 int new_source_line = 0;
828 sal = find_pc_line (pc, 0);
830 if (sal.symtab != last_symtab)
832 /* New source file. */
833 new_source_line = 1;
835 /* If this is the first line of output, check for any preceding
836 lines. */
837 if (last_line == 0
838 && first_le != NULL
839 && first_le->line < sal.line)
841 start_preceding_line_to_display = first_le->line;
842 end_preceding_line_to_display = sal.line;
845 else
847 /* Same source file as last time. */
848 if (sal.symtab != NULL)
850 if (sal.line > last_line + 1 && last_line != 0)
852 int l;
854 /* Several preceding source lines. Print the trailing ones
855 not associated with code that we'll print later. */
856 for (l = sal.line - 1; l > last_line; --l)
858 if (line_has_code_p (dis_line_table.get (),
859 sal.symtab, l))
860 break;
862 if (l < sal.line - 1)
864 start_preceding_line_to_display = l + 1;
865 end_preceding_line_to_display = sal.line;
868 if (sal.line != last_line)
869 new_source_line = 1;
870 else
872 /* Same source line as last time. This can happen, depending
873 on the debug info. */
878 if (new_source_line)
880 /* Skip the newline if this is the first instruction. */
881 if (pc > low)
882 uiout->text ("\n");
883 if (tuple_emitter.has_value ())
885 gdb_assert (list_emitter.has_value ());
886 list_emitter.reset ();
887 tuple_emitter.reset ();
889 if (sal.symtab != last_symtab
890 && !(flags & DISASSEMBLY_FILENAME))
892 /* Remember MI ignores ui_out_text.
893 We don't have to do anything here for MI because MI
894 output includes the source specs for each line. */
895 if (sal.symtab != NULL)
897 uiout->text (symtab_to_filename_for_display (sal.symtab));
899 else
900 uiout->text ("unknown");
901 uiout->text (":\n");
903 if (start_preceding_line_to_display > 0)
905 /* Several source lines w/o asm instructions associated.
906 We need to preserve the structure of the output, so output
907 a bunch of line tuples with no asm entries. */
908 int l;
910 gdb_assert (sal.symtab != NULL);
911 for (l = start_preceding_line_to_display;
912 l < end_preceding_line_to_display;
913 ++l)
915 ui_out_emit_tuple line_tuple_emitter (uiout,
916 "src_and_asm_line");
917 print_source_lines (sal.symtab, l, l + 1, psl_flags);
918 ui_out_emit_list chain_line_emitter (uiout, "line_asm_insn");
921 tuple_emitter.emplace (uiout, "src_and_asm_line");
922 if (sal.symtab != NULL)
923 print_source_lines (sal.symtab, sal.line, sal.line + 1, psl_flags);
924 else
925 uiout->text (_("--- no source info for this pc ---\n"));
926 list_emitter.emplace (uiout, "line_asm_insn");
928 else
930 /* Here we're appending instructions to an existing line.
931 By construction the very first insn will have a symtab
932 and follow the new_source_line path above. */
933 gdb_assert (tuple_emitter.has_value ());
934 gdb_assert (list_emitter.has_value ());
937 if (sal.end != 0)
938 end_pc = std::min (sal.end, high);
939 else
940 end_pc = pc + 1;
941 num_displayed += dump_insns (gdbarch, uiout, pc, end_pc,
942 how_many, flags, &end_pc);
943 pc = end_pc;
945 if (how_many >= 0 && num_displayed >= how_many)
946 break;
948 last_symtab = sal.symtab;
949 last_line = sal.line;
953 static void
954 do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
955 CORE_ADDR low, CORE_ADDR high,
956 int how_many, gdb_disassembly_flags flags)
958 ui_out_emit_list list_emitter (uiout, "asm_insns");
960 dump_insns (gdbarch, uiout, low, high, how_many, flags, NULL);
963 /* Combine implicit and user disassembler options and return them
964 in a newly-created string. */
966 static std::string
967 get_all_disassembler_options (struct gdbarch *gdbarch)
969 const char *implicit = gdbarch_disassembler_options_implicit (gdbarch);
970 const char *options = get_disassembler_options (gdbarch);
971 const char *comma = ",";
973 if (implicit == nullptr)
975 implicit = "";
976 comma = "";
979 if (options == nullptr)
981 options = "";
982 comma = "";
985 return string_printf ("%s%s%s", implicit, comma, options);
988 gdb_disassembler::gdb_disassembler (struct gdbarch *gdbarch,
989 struct ui_file *file,
990 read_memory_ftype func)
991 : gdb_printing_disassembler (gdbarch, &m_buffer, func,
992 dis_asm_memory_error, dis_asm_print_address),
993 m_dest (file),
994 m_buffer (!use_ext_lang_for_styling () && use_libopcodes_for_styling ())
995 { /* Nothing. */ }
997 /* See disasm.h. */
999 bool
1000 gdb_disassembler::use_ext_lang_for_styling () const
1002 /* The use of m_di.created_styled_output here is a bit of a cheat, but
1003 it works fine for now.
1005 This function is called in situations after m_di has been initialized,
1006 but before the instruction has been disassembled.
1008 Currently, every target that supports libopcodes styling sets the
1009 created_styled_output field in disassemble_init_for_target, which was
1010 called as part of the initialization of gdb_printing_disassembler.
1012 This means that we are OK to check the created_styled_output field
1013 here.
1015 If, in the future, there's ever a target that only sets the
1016 created_styled_output field during the actual instruction disassembly
1017 phase, then we will need to update this code. */
1018 return (disassembler_styling
1019 && (!m_di.created_styled_output || !use_libopcodes_styling)
1020 && use_ext_lang_colorization_p
1021 && m_dest->can_emit_style_escape ());
1024 /* See disasm.h. */
1026 bool
1027 gdb_disassembler::use_libopcodes_for_styling () const
1029 /* See the comment on the use of m_di.created_styled_output in the
1030 gdb_disassembler::use_ext_lang_for_styling function. */
1031 return (disassembler_styling
1032 && m_di.created_styled_output
1033 && use_libopcodes_styling
1034 && m_dest->can_emit_style_escape ());
1037 /* See disasm.h. */
1039 gdb_disassemble_info::gdb_disassemble_info
1040 (struct gdbarch *gdbarch,
1041 read_memory_ftype read_memory_func, memory_error_ftype memory_error_func,
1042 print_address_ftype print_address_func, fprintf_ftype fprintf_func,
1043 fprintf_styled_ftype fprintf_styled_func)
1044 : m_gdbarch (gdbarch)
1046 gdb_assert (fprintf_func != nullptr);
1047 gdb_assert (fprintf_styled_func != nullptr);
1048 init_disassemble_info (&m_di, (void *) this, fprintf_func,
1049 fprintf_styled_func);
1050 m_di.flavour = bfd_target_unknown_flavour;
1052 /* The memory_error_func, print_address_func, and read_memory_func are
1053 all initialized to a default (non-nullptr) value by the call to
1054 init_disassemble_info above. If the user is overriding these fields
1055 (by passing non-nullptr values) then do that now, otherwise, leave
1056 these fields as the defaults. */
1057 if (memory_error_func != nullptr)
1058 m_di.memory_error_func = memory_error_func;
1059 if (print_address_func != nullptr)
1060 m_di.print_address_func = print_address_func;
1061 if (read_memory_func != nullptr)
1062 m_di.read_memory_func = read_memory_func;
1064 m_di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1065 m_di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
1066 m_di.endian = gdbarch_byte_order (gdbarch);
1067 m_di.endian_code = gdbarch_byte_order_for_code (gdbarch);
1068 m_di.application_data = this;
1069 m_disassembler_options_holder = get_all_disassembler_options (gdbarch);
1070 if (!m_disassembler_options_holder.empty ())
1071 m_di.disassembler_options = m_disassembler_options_holder.c_str ();
1072 disassemble_init_for_target (&m_di);
1075 /* See disasm.h. */
1077 gdb_disassemble_info::~gdb_disassemble_info ()
1079 disassemble_free_target (&m_di);
1082 /* Wrapper around calling gdbarch_print_insn. This function takes care of
1083 first calling the extension language hooks for print_insn, and, if none
1084 of the extension languages can print this instruction, calls
1085 gdbarch_print_insn to do the work.
1087 GDBARCH is the architecture to disassemble in, VMA is the address of the
1088 instruction being disassembled, and INFO is the libopcodes disassembler
1089 related information. */
1091 static int
1092 gdb_print_insn_1 (struct gdbarch *gdbarch, CORE_ADDR vma,
1093 struct disassemble_info *info)
1095 /* Call into the extension languages to do the disassembly. */
1096 std::optional<int> length = ext_lang_print_insn (gdbarch, vma, info);
1097 if (length.has_value ())
1098 return *length;
1100 /* No extension language wanted to do the disassembly, so do it
1101 manually. */
1102 return gdbarch_print_insn (gdbarch, vma, info);
1105 /* See disasm.h. */
1107 bool gdb_disassembler::use_ext_lang_colorization_p = true;
1109 /* See disasm.h. */
1112 gdb_disassembler::print_insn (CORE_ADDR memaddr,
1113 int *branch_delay_insns)
1115 m_err_memaddr.reset ();
1116 m_buffer.clear ();
1117 this->set_in_comment (false);
1119 int length = gdb_print_insn_1 (arch (), memaddr, &m_di);
1121 /* If we have successfully disassembled an instruction, disassembler
1122 styling using the extension language is on, and libopcodes hasn't
1123 already styled the output for us, and, if the destination can support
1124 styling, then lets call into the extension languages in order to style
1125 this output. */
1126 if (length > 0 && use_ext_lang_for_styling ())
1128 std::optional<std::string> ext_contents;
1129 ext_contents = ext_lang_colorize_disasm (m_buffer.string (), arch ());
1130 if (ext_contents.has_value ())
1131 m_buffer = std::move (*ext_contents);
1132 else
1134 /* The extension language failed to add styling to the
1135 disassembly output. Set the static flag so that next time we
1136 disassemble we don't even bother attempting to use the
1137 extension language for styling. */
1138 use_ext_lang_colorization_p = false;
1140 /* We're about to disassemble this instruction again, reset the
1141 in-comment state. */
1142 this->set_in_comment (false);
1144 /* The instruction we just disassembled, and the extension
1145 languages failed to style, might have otherwise had some
1146 minimal styling applied by GDB. To regain that styling we
1147 need to recreate m_buffer, but this time with styling support.
1149 To do this we perform an in-place new, but this time turn on
1150 the styling support, then we can re-disassembly the
1151 instruction, and gain any minimal styling GDB might add. */
1152 static_assert ((std::is_same<decltype (m_buffer),
1153 string_file>::value));
1154 gdb_assert (!m_buffer.term_out ());
1155 m_buffer.~string_file ();
1156 new (&m_buffer) string_file (use_libopcodes_for_styling ());
1157 length = gdb_print_insn_1 (arch (), memaddr, &m_di);
1158 gdb_assert (length > 0);
1162 /* Push any disassemble output to the real destination stream. We do
1163 this even if the disassembler reported failure (-1) as the
1164 disassembler may have printed something to its output stream. */
1165 gdb_printf (m_dest, "%s", m_buffer.c_str ());
1167 /* If the disassembler failed then report an appropriate error. */
1168 if (length < 0)
1170 if (m_err_memaddr.has_value ())
1171 memory_error (TARGET_XFER_E_IO, *m_err_memaddr);
1172 else
1173 error (_("unknown disassembler error (error = %d)"), length);
1176 if (branch_delay_insns != NULL)
1178 if (m_di.insn_info_valid)
1179 *branch_delay_insns = m_di.branch_delay_insns;
1180 else
1181 *branch_delay_insns = 0;
1183 return length;
1186 void
1187 gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
1188 gdb_disassembly_flags flags, int how_many,
1189 CORE_ADDR low, CORE_ADDR high)
1191 struct symtab *symtab;
1192 int nlines = -1;
1194 /* Assume symtab is valid for whole PC range. */
1195 symtab = find_pc_line_symtab (low);
1197 if (symtab != NULL && symtab->linetable () != NULL)
1198 nlines = symtab->linetable ()->nitems;
1200 if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
1201 || nlines <= 0)
1202 do_assembly_only (gdbarch, uiout, low, high, how_many, flags);
1204 else if (flags & DISASSEMBLY_SOURCE)
1205 do_mixed_source_and_assembly (gdbarch, uiout, symtab, low, high,
1206 how_many, flags);
1208 else if (flags & DISASSEMBLY_SOURCE_DEPRECATED)
1209 do_mixed_source_and_assembly_deprecated (gdbarch, uiout, symtab,
1210 low, high, how_many, flags);
1212 gdb_flush (gdb_stdout);
1215 /* Print the instruction at address MEMADDR in debugged memory,
1216 on STREAM. Returns the length of the instruction, in bytes,
1217 and, if requested, the number of branch delay slot instructions. */
1220 gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
1221 struct ui_file *stream, int *branch_delay_insns)
1224 gdb_disassembler di (gdbarch, stream);
1226 return di.print_insn (memaddr, branch_delay_insns);
1229 /* Return the length in bytes of the instruction at address MEMADDR in
1230 debugged memory. */
1233 gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr)
1235 return gdb_print_insn (gdbarch, addr, &null_stream, NULL);
1238 /* See disasm.h. */
1241 gdb_non_printing_disassembler::null_fprintf_func
1242 (void *stream, const char *format, ...) noexcept
1244 return 0;
1247 /* See disasm.h. */
1250 gdb_non_printing_disassembler::null_fprintf_styled_func
1251 (void *stream, enum disassembler_style style,
1252 const char *format, ...) noexcept
1254 return 0;
1257 /* A non-printing disassemble_info management class. The disassemble_info
1258 setup by this class will not print anything to the output stream (there
1259 is no output stream), and the instruction to be disassembled will be
1260 read from a buffer passed to the constructor. */
1262 struct gdb_non_printing_buffer_disassembler
1263 : public gdb_non_printing_disassembler
1265 /* Constructor. GDBARCH is the architecture to disassemble for, BUFFER
1266 contains the instruction to disassemble, and INSN_ADDRESS is the
1267 address (in target memory) of the instruction to disassemble. */
1268 gdb_non_printing_buffer_disassembler (struct gdbarch *gdbarch,
1269 gdb::array_view<const gdb_byte> buffer,
1270 CORE_ADDR insn_address)
1271 : gdb_non_printing_disassembler (gdbarch, nullptr)
1273 /* The cast is necessary until disassemble_info is const-ified. */
1274 m_di.buffer = (gdb_byte *) buffer.data ();
1275 m_di.buffer_length = buffer.size ();
1276 m_di.buffer_vma = insn_address;
1280 /* Return the length in bytes of INSN. MAX_LEN is the size of the
1281 buffer containing INSN. */
1284 gdb_buffered_insn_length (struct gdbarch *gdbarch,
1285 const gdb_byte *insn, int max_len, CORE_ADDR addr)
1287 gdb::array_view<const gdb_byte> buffer
1288 = gdb::make_array_view (insn, max_len);
1289 gdb_non_printing_buffer_disassembler dis (gdbarch, buffer, addr);
1290 int result = gdb_print_insn_1 (gdbarch, addr, dis.disasm_info ());
1291 return result;
1294 const char *
1295 get_disassembler_options (struct gdbarch *gdbarch)
1297 std::string *disassembler_options = gdbarch_disassembler_options (gdbarch);
1298 if (disassembler_options == nullptr || disassembler_options->empty ())
1299 return nullptr;
1300 return disassembler_options->c_str ();
1303 void
1304 set_disassembler_options (const char *prospective_options)
1306 struct gdbarch *gdbarch = get_current_arch ();
1307 std::string *disassembler_options = gdbarch_disassembler_options (gdbarch);
1308 const disasm_options_and_args_t *valid_options_and_args;
1309 const disasm_options_t *valid_options;
1310 gdb::unique_xmalloc_ptr<char> prospective_options_local
1311 = make_unique_xstrdup (prospective_options);
1312 char *options = remove_whitespace_and_extra_commas
1313 (prospective_options_local.get ());
1314 const char *opt;
1316 /* Allow all architectures, even ones that do not support 'set disassembler',
1317 to reset their disassembler options to NULL. */
1318 if (options == NULL)
1320 if (disassembler_options != nullptr)
1321 disassembler_options->clear ();
1322 return;
1325 valid_options_and_args = gdbarch_valid_disassembler_options (gdbarch);
1326 if (valid_options_and_args == NULL)
1328 gdb_printf (gdb_stderr, _("\
1329 'set disassembler-options ...' is not supported on this architecture.\n"));
1330 return;
1333 valid_options = &valid_options_and_args->options;
1335 /* Verify we have valid disassembler options. */
1336 FOR_EACH_DISASSEMBLER_OPTION (opt, options)
1338 size_t i;
1339 for (i = 0; valid_options->name[i] != NULL; i++)
1340 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1342 size_t len = strlen (valid_options->name[i]);
1343 bool found = false;
1344 const char *arg;
1345 size_t j;
1347 if (memcmp (opt, valid_options->name[i], len) != 0)
1348 continue;
1349 arg = opt + len;
1350 if (valid_options->arg[i]->values == NULL)
1351 break;
1352 for (j = 0; valid_options->arg[i]->values[j] != NULL; j++)
1353 if (disassembler_options_cmp
1354 (arg, valid_options->arg[i]->values[j]) == 0)
1356 found = true;
1357 break;
1359 if (found)
1360 break;
1362 else if (disassembler_options_cmp (opt, valid_options->name[i]) == 0)
1363 break;
1364 if (valid_options->name[i] == NULL)
1366 gdb_printf (gdb_stderr,
1367 _("Invalid disassembler option value: '%s'.\n"),
1368 opt);
1369 return;
1373 *disassembler_options = options;
1376 static void
1377 set_disassembler_options_sfunc (const char *args, int from_tty,
1378 struct cmd_list_element *c)
1380 set_disassembler_options (prospective_options.c_str ());
1383 static void
1384 show_disassembler_options_sfunc (struct ui_file *file, int from_tty,
1385 struct cmd_list_element *c, const char *value)
1387 struct gdbarch *gdbarch = get_current_arch ();
1388 const disasm_options_and_args_t *valid_options_and_args;
1389 const disasm_option_arg_t *valid_args;
1390 const disasm_options_t *valid_options;
1392 const char *options = get_disassembler_options (gdbarch);
1393 if (options == NULL)
1394 options = "";
1396 gdb_printf (file, _("The current disassembler options are '%s'\n\n"),
1397 options);
1399 valid_options_and_args = gdbarch_valid_disassembler_options (gdbarch);
1401 if (valid_options_and_args == NULL)
1403 gdb_puts (_("There are no disassembler options available "
1404 "for this architecture.\n"),
1405 file);
1406 return;
1409 valid_options = &valid_options_and_args->options;
1411 gdb_printf (file, _("\
1412 The following disassembler options are supported for use with the\n\
1413 'set disassembler-options OPTION [,OPTION]...' command:\n"));
1415 if (valid_options->description != NULL)
1417 size_t i, max_len = 0;
1419 gdb_printf (file, "\n");
1421 /* Compute the length of the longest option name. */
1422 for (i = 0; valid_options->name[i] != NULL; i++)
1424 size_t len = strlen (valid_options->name[i]);
1426 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1427 len += strlen (valid_options->arg[i]->name);
1428 if (max_len < len)
1429 max_len = len;
1432 for (i = 0, max_len++; valid_options->name[i] != NULL; i++)
1434 gdb_printf (file, " %s", valid_options->name[i]);
1435 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1436 gdb_printf (file, "%s", valid_options->arg[i]->name);
1437 if (valid_options->description[i] != NULL)
1439 size_t len = strlen (valid_options->name[i]);
1441 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1442 len += strlen (valid_options->arg[i]->name);
1443 gdb_printf (file, "%*c %s", (int) (max_len - len), ' ',
1444 valid_options->description[i]);
1446 gdb_printf (file, "\n");
1449 else
1451 size_t i;
1452 gdb_printf (file, " ");
1453 for (i = 0; valid_options->name[i] != NULL; i++)
1455 gdb_printf (file, "%s", valid_options->name[i]);
1456 if (valid_options->arg != NULL && valid_options->arg[i] != NULL)
1457 gdb_printf (file, "%s", valid_options->arg[i]->name);
1458 if (valid_options->name[i + 1] != NULL)
1459 gdb_printf (file, ", ");
1460 file->wrap_here (2);
1462 gdb_printf (file, "\n");
1465 valid_args = valid_options_and_args->args;
1466 if (valid_args != NULL)
1468 size_t i, j;
1470 for (i = 0; valid_args[i].name != NULL; i++)
1472 if (valid_args[i].values == NULL)
1473 continue;
1474 gdb_printf (file, _("\n\
1475 For the options above, the following values are supported for \"%s\":\n "),
1476 valid_args[i].name);
1477 for (j = 0; valid_args[i].values[j] != NULL; j++)
1479 gdb_printf (file, " %s", valid_args[i].values[j]);
1480 file->wrap_here (3);
1482 gdb_printf (file, "\n");
1487 /* A completion function for "set disassembler". */
1489 static void
1490 disassembler_options_completer (struct cmd_list_element *ignore,
1491 completion_tracker &tracker,
1492 const char *text, const char *word)
1494 struct gdbarch *gdbarch = get_current_arch ();
1495 const disasm_options_and_args_t *opts_and_args
1496 = gdbarch_valid_disassembler_options (gdbarch);
1498 if (opts_and_args != NULL)
1500 const disasm_options_t *opts = &opts_and_args->options;
1502 /* Only attempt to complete on the last option text. */
1503 const char *separator = strrchr (text, ',');
1504 if (separator != NULL)
1505 text = separator + 1;
1506 text = skip_spaces (text);
1507 complete_on_enum (tracker, opts->name, text, word);
1512 /* Initialization code. */
1514 void _initialize_disasm ();
1515 void
1516 _initialize_disasm ()
1518 /* Add the command that controls the disassembler options. */
1519 set_show_commands set_show_disas_opts
1520 = add_setshow_string_noescape_cmd ("disassembler-options", no_class,
1521 &prospective_options, _("\
1522 Set the disassembler options.\n\
1523 Usage: set disassembler-options OPTION [,OPTION]...\n\n\
1524 See: 'show disassembler-options' for valid option values."), _("\
1525 Show the disassembler options."), NULL,
1526 set_disassembler_options_sfunc,
1527 show_disassembler_options_sfunc,
1528 &setlist, &showlist);
1529 set_cmd_completer (set_show_disas_opts.set, disassembler_options_completer);
1532 /* All the 'maint set|show libopcodes-styling' sub-commands. */
1533 static struct cmd_list_element *maint_set_libopcodes_styling_cmdlist;
1534 static struct cmd_list_element *maint_show_libopcodes_styling_cmdlist;
1536 /* Adds 'maint set|show libopcodes-styling'. */
1537 add_setshow_prefix_cmd ("libopcodes-styling", class_maintenance,
1538 _("Set libopcodes-styling specific variables."),
1539 _("Show libopcodes-styling specific variables."),
1540 &maint_set_libopcodes_styling_cmdlist,
1541 &maint_show_libopcodes_styling_cmdlist,
1542 &maintenance_set_cmdlist,
1543 &maintenance_show_cmdlist);
1545 /* Adds 'maint set|show gnu-source-highlight enabled'. */
1546 add_setshow_boolean_cmd ("enabled", class_maintenance,
1547 &use_libopcodes_styling_option, _("\
1548 Set whether the libopcodes styling support should be used."), _("\
1549 Show whether the libopcodes styling support should be used."),_("\
1550 When enabled, GDB will try to make use of the builtin libopcodes styling\n\
1551 support, to style the disassembler output. Not every architecture has\n\
1552 styling support within libopcodes, so enabling this is not a guarantee\n\
1553 that libopcodes styling will be available.\n\
1555 When this option is disabled, GDB will make use of the Python Pygments\n\
1556 package (if available) to style the disassembler output.\n\
1558 All disassembler styling can be disabled with:\n\
1560 set style disassembler enabled off"),
1561 set_use_libopcodes_styling,
1562 show_use_libopcodes_styling,
1563 &maint_set_libopcodes_styling_cmdlist,
1564 &maint_show_libopcodes_styling_cmdlist);