1 /* Disassemble support for GDB.
3 Copyright (C) 2000-2016 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/>. */
30 /* Disassemble functions.
31 FIXME: We should get rid of all the duplicate code in gdb that does
32 the same thing: disassemble_command() and the gdbtk variation. */
34 /* This structure is used to store line number information for the
36 We need a different sort of line table from the normal one cuz we can't
37 depend upon implicit line-end pc's for lines to do the
38 reordering in this function. */
40 struct deprecated_dis_line_entry
47 /* This Structure is used to store line number information.
48 We need a different sort of line table from the normal one cuz we can't
49 depend upon implicit line-end pc's for lines to do the
50 reordering in this function. */
54 struct symtab *symtab;
58 /* Hash function for dis_line_entry. */
61 hash_dis_line_entry (const void *item)
63 const struct dis_line_entry *dle = (const struct dis_line_entry *) item;
65 return htab_hash_pointer (dle->symtab) + dle->line;
68 /* Equal function for dis_line_entry. */
71 eq_dis_line_entry (const void *item_lhs, const void *item_rhs)
73 const struct dis_line_entry *lhs = (const struct dis_line_entry *) item_lhs;
74 const struct dis_line_entry *rhs = (const struct dis_line_entry *) item_rhs;
76 return (lhs->symtab == rhs->symtab
77 && lhs->line == rhs->line);
80 /* Create the table to manage lines for mixed source/disassembly. */
83 allocate_dis_line_table (void)
85 return htab_create_alloc (41,
86 hash_dis_line_entry, eq_dis_line_entry,
87 xfree, xcalloc, xfree);
90 /* Add a new dis_line_entry containing SYMTAB and LINE to TABLE. */
93 add_dis_line_entry (htab_t table, struct symtab *symtab, int line)
96 struct dis_line_entry dle, *dlep;
100 slot = htab_find_slot (table, &dle, INSERT);
103 dlep = XNEW (struct dis_line_entry);
104 dlep->symtab = symtab;
110 /* Return non-zero if SYMTAB, LINE are in TABLE. */
113 line_has_code_p (htab_t table, struct symtab *symtab, int line)
115 struct dis_line_entry dle;
119 return htab_find (table, &dle) != NULL;
122 /* Like target_read_memory, but slightly different parameters. */
124 dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len,
125 struct disassemble_info *info)
127 return target_read_code (memaddr, myaddr, len);
130 /* Like memory_error with slightly different parameters. */
132 dis_asm_memory_error (int err, bfd_vma memaddr,
133 struct disassemble_info *info)
135 memory_error (TARGET_XFER_E_IO, memaddr);
138 /* Like print_address with slightly different parameters. */
140 dis_asm_print_address (bfd_vma addr, struct disassemble_info *info)
142 struct gdbarch *gdbarch = (struct gdbarch *) info->application_data;
144 print_address (gdbarch, addr, (struct ui_file *) info->stream);
148 compare_lines (const void *mle1p, const void *mle2p)
150 struct deprecated_dis_line_entry *mle1, *mle2;
153 mle1 = (struct deprecated_dis_line_entry *) mle1p;
154 mle2 = (struct deprecated_dis_line_entry *) mle2p;
156 /* End of sequence markers have a line number of 0 but don't want to
157 be sorted to the head of the list, instead sort by PC. */
158 if (mle1->line == 0 || mle2->line == 0)
160 val = mle1->start_pc - mle2->start_pc;
162 val = mle1->line - mle2->line;
166 val = mle1->line - mle2->line;
168 val = mle1->start_pc - mle2->start_pc;
176 gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout,
177 struct disassemble_info * di,
178 const struct disasm_insn *insn, int flags,
181 /* parts of the symbolic representation of the address */
186 struct cleanup *ui_out_chain;
187 char *filename = NULL;
191 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
194 if (insn->number != 0)
196 ui_out_field_fmt (uiout, "insn-number", "%u", insn->number);
197 ui_out_text (uiout, "\t");
200 if ((flags & DISASSEMBLY_SPECULATIVE) != 0)
202 if (insn->is_speculative)
204 ui_out_field_string (uiout, "is-speculative", "?");
206 /* The speculative execution indication overwrites the first
207 character of the PC prefix.
208 We assume a PC prefix length of 3 characters. */
209 if ((flags & DISASSEMBLY_OMIT_PC) == 0)
210 ui_out_text (uiout, pc_prefix (pc) + 1);
212 ui_out_text (uiout, " ");
214 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
215 ui_out_text (uiout, pc_prefix (pc));
217 ui_out_text (uiout, " ");
219 else if ((flags & DISASSEMBLY_OMIT_PC) == 0)
220 ui_out_text (uiout, pc_prefix (pc));
221 ui_out_field_core_addr (uiout, "address", gdbarch, pc);
223 if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename,
226 /* We don't care now about line, filename and unmapped. But we might in
228 ui_out_text (uiout, " <");
229 if ((flags & DISASSEMBLY_OMIT_FNAME) == 0)
230 ui_out_field_string (uiout, "func-name", name);
231 ui_out_text (uiout, "+");
232 ui_out_field_int (uiout, "offset", offset);
233 ui_out_text (uiout, ">:\t");
236 ui_out_text (uiout, ":\t");
238 if (filename != NULL)
243 ui_file_rewind (stb);
244 if (flags & DISASSEMBLY_RAW_INSN)
249 const char *spacer = "";
251 /* Build the opcodes using a temporary stream so we can
252 write them out in a single go for the MI. */
253 struct ui_file *opcode_stream = mem_fileopen ();
254 struct cleanup *cleanups =
255 make_cleanup_ui_file_delete (opcode_stream);
257 size = gdbarch_print_insn (gdbarch, pc, di);
260 for (;pc < end_pc; ++pc)
262 err = (*di->read_memory_func) (pc, &data, 1, di);
264 (*di->memory_error_func) (err, pc, di);
265 fprintf_filtered (opcode_stream, "%s%02x",
266 spacer, (unsigned) data);
270 ui_out_field_stream (uiout, "opcodes", opcode_stream);
271 ui_out_text (uiout, "\t");
273 do_cleanups (cleanups);
276 size = gdbarch_print_insn (gdbarch, pc, di);
278 ui_out_field_stream (uiout, "inst", stb);
279 ui_file_rewind (stb);
280 do_cleanups (ui_out_chain);
281 ui_out_text (uiout, "\n");
287 dump_insns (struct gdbarch *gdbarch, struct ui_out *uiout,
288 struct disassemble_info * di,
289 CORE_ADDR low, CORE_ADDR high,
290 int how_many, int flags, struct ui_file *stb,
293 struct disasm_insn insn;
294 int num_displayed = 0;
296 memset (&insn, 0, sizeof (insn));
299 while (insn.addr < high && (how_many < 0 || num_displayed < how_many))
303 size = gdb_pretty_print_insn (gdbarch, uiout, di, &insn, flags, stb);
310 /* Allow user to bail out with ^C. */
317 return num_displayed;
320 /* The idea here is to present a source-O-centric view of a
321 function to the user. This means that things are presented
322 in source order, with (possibly) out of order assembly
323 immediately following.
325 N.B. This view is deprecated. */
328 do_mixed_source_and_assembly_deprecated
329 (struct gdbarch *gdbarch, struct ui_out *uiout,
330 struct disassemble_info *di, struct symtab *symtab,
331 CORE_ADDR low, CORE_ADDR high,
332 int how_many, int flags, struct ui_file *stb)
336 struct linetable_entry *le;
337 struct deprecated_dis_line_entry *mle;
338 struct symtab_and_line sal;
340 int out_of_order = 0;
342 int num_displayed = 0;
343 print_source_lines_flags psl_flags = 0;
344 struct cleanup *ui_out_chain;
345 struct cleanup *ui_out_tuple_chain = make_cleanup (null_cleanup, 0);
346 struct cleanup *ui_out_list_chain = make_cleanup (null_cleanup, 0);
348 gdb_assert (symtab != NULL && SYMTAB_LINETABLE (symtab) != NULL);
350 nlines = SYMTAB_LINETABLE (symtab)->nitems;
351 le = SYMTAB_LINETABLE (symtab)->item;
353 if (flags & DISASSEMBLY_FILENAME)
354 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
356 mle = (struct deprecated_dis_line_entry *)
357 alloca (nlines * sizeof (struct deprecated_dis_line_entry));
359 /* Copy linetable entries for this function into our data
360 structure, creating end_pc's and setting out_of_order as
363 /* First, skip all the preceding functions. */
365 for (i = 0; i < nlines - 1 && le[i].pc < low; i++);
367 /* Now, copy all entries before the end of this function. */
369 for (; i < nlines - 1 && le[i].pc < high; i++)
371 if (le[i].line == le[i + 1].line && le[i].pc == le[i + 1].pc)
372 continue; /* Ignore duplicates. */
374 /* Skip any end-of-function markers. */
378 mle[newlines].line = le[i].line;
379 if (le[i].line > le[i + 1].line)
381 mle[newlines].start_pc = le[i].pc;
382 mle[newlines].end_pc = le[i + 1].pc;
386 /* If we're on the last line, and it's part of the function,
387 then we need to get the end pc in a special way. */
389 if (i == nlines - 1 && le[i].pc < high)
391 mle[newlines].line = le[i].line;
392 mle[newlines].start_pc = le[i].pc;
393 sal = find_pc_line (le[i].pc, 0);
394 mle[newlines].end_pc = sal.end;
398 /* Now, sort mle by line #s (and, then by addresses within lines). */
401 qsort (mle, newlines, sizeof (struct deprecated_dis_line_entry),
404 /* Now, for each line entry, emit the specified lines (unless
405 they have been emitted before), followed by the assembly code
408 ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
410 for (i = 0; i < newlines; i++)
412 /* Print out everything from next_line to the current line. */
413 if (mle[i].line >= next_line)
417 /* Just one line to print. */
418 if (next_line == mle[i].line)
421 = make_cleanup_ui_out_tuple_begin_end (uiout,
423 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
427 /* Several source lines w/o asm instructions associated. */
428 for (; next_line < mle[i].line; next_line++)
430 struct cleanup *ui_out_list_chain_line;
431 struct cleanup *ui_out_tuple_chain_line;
433 ui_out_tuple_chain_line
434 = make_cleanup_ui_out_tuple_begin_end (uiout,
436 print_source_lines (symtab, next_line, next_line + 1,
438 ui_out_list_chain_line
439 = make_cleanup_ui_out_list_begin_end (uiout,
441 do_cleanups (ui_out_list_chain_line);
442 do_cleanups (ui_out_tuple_chain_line);
444 /* Print the last line and leave list open for
445 asm instructions to be added. */
447 = make_cleanup_ui_out_tuple_begin_end (uiout,
449 print_source_lines (symtab, next_line, mle[i].line + 1, psl_flags);
455 = make_cleanup_ui_out_tuple_begin_end (uiout,
457 print_source_lines (symtab, mle[i].line, mle[i].line + 1, psl_flags);
460 next_line = mle[i].line + 1;
462 = make_cleanup_ui_out_list_begin_end (uiout, "line_asm_insn");
465 num_displayed += dump_insns (gdbarch, uiout, di,
466 mle[i].start_pc, mle[i].end_pc,
467 how_many, flags, stb, NULL);
469 /* When we've reached the end of the mle array, or we've seen the last
470 assembly range for this source line, close out the list/tuple. */
471 if (i == (newlines - 1) || mle[i + 1].line > mle[i].line)
473 do_cleanups (ui_out_list_chain);
474 do_cleanups (ui_out_tuple_chain);
475 ui_out_tuple_chain = make_cleanup (null_cleanup, 0);
476 ui_out_list_chain = make_cleanup (null_cleanup, 0);
477 ui_out_text (uiout, "\n");
479 if (how_many >= 0 && num_displayed >= how_many)
482 do_cleanups (ui_out_chain);
485 /* The idea here is to present a source-O-centric view of a
486 function to the user. This means that things are presented
487 in source order, with (possibly) out of order assembly
488 immediately following. */
491 do_mixed_source_and_assembly (struct gdbarch *gdbarch, struct ui_out *uiout,
492 struct disassemble_info *di,
493 struct symtab *main_symtab,
494 CORE_ADDR low, CORE_ADDR high,
495 int how_many, int flags, struct ui_file *stb)
497 const struct linetable_entry *le, *first_le;
499 int num_displayed = 0;
500 print_source_lines_flags psl_flags = 0;
501 struct cleanup *cleanups;
502 struct cleanup *ui_out_chain;
503 struct cleanup *ui_out_tuple_chain;
504 struct cleanup *ui_out_list_chain;
506 struct symtab *last_symtab;
508 htab_t dis_line_table;
510 gdb_assert (main_symtab != NULL && SYMTAB_LINETABLE (main_symtab) != NULL);
512 /* First pass: collect the list of all source files and lines.
513 We do this so that we can only print lines containing code once.
514 We try to print the source text leading up to the next instruction,
515 but if that text is for code that will be disassembled later, then
516 we'll want to defer printing it until later with its associated code. */
518 dis_line_table = allocate_dis_line_table ();
519 cleanups = make_cleanup_htab_delete (dis_line_table);
523 /* The prologue may be empty, but there may still be a line number entry
524 for the opening brace which is distinct from the first line of code.
525 If the prologue has been eliminated find_pc_line may return the source
526 line after the opening brace. We still want to print this opening brace.
527 first_le is used to implement this. */
529 nlines = SYMTAB_LINETABLE (main_symtab)->nitems;
530 le = SYMTAB_LINETABLE (main_symtab)->item;
533 /* Skip all the preceding functions. */
534 for (i = 0; i < nlines && le[i].pc < low; i++)
537 if (i < nlines && le[i].pc < high)
540 /* Add lines for every pc value. */
543 struct symtab_and_line sal;
546 sal = find_pc_line (pc, 0);
547 length = gdb_insn_length (gdbarch, pc);
550 if (sal.symtab != NULL)
551 add_dis_line_entry (dis_line_table, sal.symtab, sal.line);
554 /* Second pass: print the disassembly.
556 Output format, from an MI perspective:
557 The result is a ui_out list, field name "asm_insns", where elements have
558 name "src_and_asm_line".
559 Each element is a tuple of source line specs (field names line, file,
560 fullname), and field "line_asm_insn" which contains the disassembly.
561 Field "line_asm_insn" is a list of tuples: address, func-name, offset,
564 CLI output works on top of this because MI ignores ui_out_text output,
565 which is where we put file name and source line contents output.
569 For things created at the beginning of this function and need to be
570 kept until the end of this function.
572 Handles the outer "asm_insns" list.
574 The tuples for each group of consecutive disassemblies.
576 List of consecutive source lines or disassembled insns. */
578 if (flags & DISASSEMBLY_FILENAME)
579 psl_flags |= PRINT_SOURCE_LINES_FILENAME;
581 ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
583 ui_out_tuple_chain = NULL;
584 ui_out_list_chain = NULL;
592 struct symtab_and_line sal;
594 int start_preceding_line_to_display = 0;
595 int end_preceding_line_to_display = 0;
596 int new_source_line = 0;
598 sal = find_pc_line (pc, 0);
600 if (sal.symtab != last_symtab)
602 /* New source file. */
605 /* If this is the first line of output, check for any preceding
609 && first_le->line < sal.line)
611 start_preceding_line_to_display = first_le->line;
612 end_preceding_line_to_display = sal.line;
617 /* Same source file as last time. */
618 if (sal.symtab != NULL)
620 if (sal.line > last_line + 1 && last_line != 0)
624 /* Several preceding source lines. Print the trailing ones
625 not associated with code that we'll print later. */
626 for (l = sal.line - 1; l > last_line; --l)
628 if (line_has_code_p (dis_line_table, sal.symtab, l))
631 if (l < sal.line - 1)
633 start_preceding_line_to_display = l + 1;
634 end_preceding_line_to_display = sal.line;
637 if (sal.line != last_line)
641 /* Same source line as last time. This can happen, depending
642 on the debug info. */
649 /* Skip the newline if this is the first instruction. */
651 ui_out_text (uiout, "\n");
652 if (ui_out_tuple_chain != NULL)
654 gdb_assert (ui_out_list_chain != NULL);
655 do_cleanups (ui_out_list_chain);
656 do_cleanups (ui_out_tuple_chain);
658 if (sal.symtab != last_symtab
659 && !(flags & DISASSEMBLY_FILENAME))
661 /* Remember MI ignores ui_out_text.
662 We don't have to do anything here for MI because MI
663 output includes the source specs for each line. */
664 if (sal.symtab != NULL)
667 symtab_to_filename_for_display (sal.symtab));
670 ui_out_text (uiout, "unknown");
671 ui_out_text (uiout, ":\n");
673 if (start_preceding_line_to_display > 0)
675 /* Several source lines w/o asm instructions associated.
676 We need to preserve the structure of the output, so output
677 a bunch of line tuples with no asm entries. */
679 struct cleanup *ui_out_list_chain_line;
680 struct cleanup *ui_out_tuple_chain_line;
682 gdb_assert (sal.symtab != NULL);
683 for (l = start_preceding_line_to_display;
684 l < end_preceding_line_to_display;
687 ui_out_tuple_chain_line
688 = make_cleanup_ui_out_tuple_begin_end (uiout,
690 print_source_lines (sal.symtab, l, l + 1, psl_flags);
691 ui_out_list_chain_line
692 = make_cleanup_ui_out_list_begin_end (uiout,
694 do_cleanups (ui_out_list_chain_line);
695 do_cleanups (ui_out_tuple_chain_line);
699 = make_cleanup_ui_out_tuple_begin_end (uiout, "src_and_asm_line");
700 if (sal.symtab != NULL)
701 print_source_lines (sal.symtab, sal.line, sal.line + 1, psl_flags);
703 ui_out_text (uiout, _("--- no source info for this pc ---\n"));
705 = make_cleanup_ui_out_list_begin_end (uiout, "line_asm_insn");
709 /* Here we're appending instructions to an existing line.
710 By construction the very first insn will have a symtab
711 and follow the new_source_line path above. */
712 gdb_assert (ui_out_tuple_chain != NULL);
713 gdb_assert (ui_out_list_chain != NULL);
717 end_pc = std::min (sal.end, high);
720 num_displayed += dump_insns (gdbarch, uiout, di, pc, end_pc,
721 how_many, flags, stb, &end_pc);
724 if (how_many >= 0 && num_displayed >= how_many)
727 last_symtab = sal.symtab;
728 last_line = sal.line;
731 do_cleanups (ui_out_chain);
732 do_cleanups (cleanups);
736 do_assembly_only (struct gdbarch *gdbarch, struct ui_out *uiout,
737 struct disassemble_info * di,
738 CORE_ADDR low, CORE_ADDR high,
739 int how_many, int flags, struct ui_file *stb)
741 struct cleanup *ui_out_chain;
743 ui_out_chain = make_cleanup_ui_out_list_begin_end (uiout, "asm_insns");
745 dump_insns (gdbarch, uiout, di, low, high, how_many, flags, stb, NULL);
747 do_cleanups (ui_out_chain);
750 /* Initialize the disassemble info struct ready for the specified
753 static int ATTRIBUTE_PRINTF (2, 3)
754 fprintf_disasm (void *stream, const char *format, ...)
758 va_start (args, format);
759 vfprintf_filtered ((struct ui_file *) stream, format, args);
761 /* Something non -ve. */
765 struct disassemble_info
766 gdb_disassemble_info (struct gdbarch *gdbarch, struct ui_file *file)
768 struct disassemble_info di;
770 init_disassemble_info (&di, file, fprintf_disasm);
771 di.flavour = bfd_target_unknown_flavour;
772 di.memory_error_func = dis_asm_memory_error;
773 di.print_address_func = dis_asm_print_address;
774 /* NOTE: cagney/2003-04-28: The original code, from the old Insight
775 disassembler had a local optomization here. By default it would
776 access the executable file, instead of the target memory (there
777 was a growing list of exceptions though). Unfortunately, the
778 heuristic was flawed. Commands like "disassemble &variable"
779 didn't work as they relied on the access going to the target.
780 Further, it has been supperseeded by trust-read-only-sections
781 (although that should be superseeded by target_trust..._p()). */
782 di.read_memory_func = dis_asm_read_memory;
783 di.arch = gdbarch_bfd_arch_info (gdbarch)->arch;
784 di.mach = gdbarch_bfd_arch_info (gdbarch)->mach;
785 di.endian = gdbarch_byte_order (gdbarch);
786 di.endian_code = gdbarch_byte_order_for_code (gdbarch);
787 di.application_data = gdbarch;
788 disassemble_init_for_target (&di);
793 gdb_disassembly (struct gdbarch *gdbarch, struct ui_out *uiout,
794 char *file_string, int flags, int how_many,
795 CORE_ADDR low, CORE_ADDR high)
797 struct ui_file *stb = mem_fileopen ();
798 struct cleanup *cleanups = make_cleanup_ui_file_delete (stb);
799 struct disassemble_info di = gdb_disassemble_info (gdbarch, stb);
800 struct symtab *symtab;
803 /* Assume symtab is valid for whole PC range. */
804 symtab = find_pc_line_symtab (low);
806 if (symtab != NULL && SYMTAB_LINETABLE (symtab) != NULL)
807 nlines = SYMTAB_LINETABLE (symtab)->nitems;
809 if (!(flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
811 do_assembly_only (gdbarch, uiout, &di, low, high, how_many, flags, stb);
813 else if (flags & DISASSEMBLY_SOURCE)
814 do_mixed_source_and_assembly (gdbarch, uiout, &di, symtab, low, high,
815 how_many, flags, stb);
817 else if (flags & DISASSEMBLY_SOURCE_DEPRECATED)
818 do_mixed_source_and_assembly_deprecated (gdbarch, uiout, &di, symtab,
819 low, high, how_many, flags, stb);
821 do_cleanups (cleanups);
822 gdb_flush (gdb_stdout);
825 /* Print the instruction at address MEMADDR in debugged memory,
826 on STREAM. Returns the length of the instruction, in bytes,
827 and, if requested, the number of branch delay slot instructions. */
830 gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr,
831 struct ui_file *stream, int *branch_delay_insns)
833 struct disassemble_info di;
836 di = gdb_disassemble_info (gdbarch, stream);
837 length = gdbarch_print_insn (gdbarch, memaddr, &di);
838 if (branch_delay_insns)
840 if (di.insn_info_valid)
841 *branch_delay_insns = di.branch_delay_insns;
843 *branch_delay_insns = 0;
849 do_ui_file_delete (void *arg)
851 ui_file_delete ((struct ui_file *) arg);
854 /* Return the length in bytes of the instruction at address MEMADDR in
858 gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr)
860 static struct ui_file *null_stream = NULL;
862 /* Dummy file descriptor for the disassembler. */
865 null_stream = ui_file_new ();
866 make_final_cleanup (do_ui_file_delete, null_stream);
869 return gdb_print_insn (gdbarch, addr, null_stream, NULL);
872 /* fprintf-function for gdb_buffered_insn_length. This function is a
873 nop, we don't want to print anything, we just want to compute the
874 length of the insn. */
876 static int ATTRIBUTE_PRINTF (2, 3)
877 gdb_buffered_insn_length_fprintf (void *stream, const char *format, ...)
882 /* Initialize a struct disassemble_info for gdb_buffered_insn_length. */
885 gdb_buffered_insn_length_init_dis (struct gdbarch *gdbarch,
886 struct disassemble_info *di,
887 const gdb_byte *insn, int max_len,
890 init_disassemble_info (di, NULL, gdb_buffered_insn_length_fprintf);
892 /* init_disassemble_info installs buffer_read_memory, etc.
893 so we don't need to do that here.
894 The cast is necessary until disassemble_info is const-ified. */
895 di->buffer = (gdb_byte *) insn;
896 di->buffer_length = max_len;
897 di->buffer_vma = addr;
899 di->arch = gdbarch_bfd_arch_info (gdbarch)->arch;
900 di->mach = gdbarch_bfd_arch_info (gdbarch)->mach;
901 di->endian = gdbarch_byte_order (gdbarch);
902 di->endian_code = gdbarch_byte_order_for_code (gdbarch);
904 disassemble_init_for_target (di);
907 /* Return the length in bytes of INSN. MAX_LEN is the size of the
908 buffer containing INSN. */
911 gdb_buffered_insn_length (struct gdbarch *gdbarch,
912 const gdb_byte *insn, int max_len, CORE_ADDR addr)
914 struct disassemble_info di;
916 gdb_buffered_insn_length_init_dis (gdbarch, &di, insn, max_len, addr);
918 return gdbarch_print_insn (gdbarch, addr, &di);