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