| OLD | NEW |
| 1 /* Disassemble support for GDB. | 1 /* Disassemble support for GDB. |
| 2 | 2 |
| 3 Copyright (C) 2000-2005, 2007-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2000-2013 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GDB. | 5 This file is part of GDB. |
| 6 | 6 |
| 7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| 11 | 11 |
| 12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU General Public License | 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/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | 19 |
| 20 #include "defs.h" | 20 #include "defs.h" |
| 21 #include "target.h" | 21 #include "target.h" |
| 22 #include "value.h" | 22 #include "value.h" |
| 23 #include "ui-out.h" | 23 #include "ui-out.h" |
| 24 #include "gdb_string.h" | 24 #include <string.h> |
| 25 #include "disasm.h" | 25 #include "disasm.h" |
| 26 #include "gdbcore.h" | 26 #include "gdbcore.h" |
| 27 #include "dis-asm.h" | 27 #include "dis-asm.h" |
| 28 | 28 |
| 29 /* Disassemble functions. | 29 /* Disassemble functions. |
| 30 FIXME: We should get rid of all the duplicate code in gdb that does | 30 FIXME: We should get rid of all the duplicate code in gdb that does |
| 31 the same thing: disassemble_command() and the gdbtk variation. */ | 31 the same thing: disassemble_command() and the gdbtk variation. */ |
| 32 | 32 |
| 33 /* This Structure is used to store line number information. | 33 /* This Structure is used to store line number information. |
| 34 We need a different sort of line table from the normal one cuz we can't | 34 We need a different sort of line table from the normal one cuz we can't |
| 35 depend upon implicit line-end pc's for lines to do the | 35 depend upon implicit line-end pc's for lines to do the |
| 36 reordering in this function. */ | 36 reordering in this function. */ |
| 37 | 37 |
| 38 struct dis_line_entry | 38 struct dis_line_entry |
| 39 { | 39 { |
| 40 int line; | 40 int line; |
| 41 CORE_ADDR start_pc; | 41 CORE_ADDR start_pc; |
| 42 CORE_ADDR end_pc; | 42 CORE_ADDR end_pc; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 /* Like target_read_memory, but slightly different parameters. */ | 45 /* Like target_read_memory, but slightly different parameters. */ |
| 46 static int | 46 static int |
| 47 dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len, | 47 dis_asm_read_memory (bfd_vma memaddr, gdb_byte *myaddr, unsigned int len, |
| 48 struct disassemble_info *info) | 48 struct disassemble_info *info) |
| 49 { | 49 { |
| 50 return target_read_memory (memaddr, myaddr, len); | 50 return target_read_code (memaddr, myaddr, len); |
| 51 } | 51 } |
| 52 | 52 |
| 53 /* Like memory_error with slightly different parameters. */ | 53 /* Like memory_error with slightly different parameters. */ |
| 54 static void | 54 static void |
| 55 dis_asm_memory_error (int status, bfd_vma memaddr, | 55 dis_asm_memory_error (int status, bfd_vma memaddr, |
| 56 struct disassemble_info *info) | 56 struct disassemble_info *info) |
| 57 { | 57 { |
| 58 memory_error (status, memaddr); | 58 memory_error (status, memaddr); |
| 59 } | 59 } |
| 60 | 60 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 QUIT; | 116 QUIT; |
| 117 if (how_many >= 0) | 117 if (how_many >= 0) |
| 118 { | 118 { |
| 119 if (num_displayed >= how_many) | 119 if (num_displayed >= how_many) |
| 120 break; | 120 break; |
| 121 else | 121 else |
| 122 num_displayed++; | 122 num_displayed++; |
| 123 } | 123 } |
| 124 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | 124 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, NULL); |
| 125 ui_out_text (uiout, pc_prefix (pc)); | 125 |
| 126 if ((flags & DISASSEMBLY_OMIT_PC) == 0) |
| 127 » ui_out_text (uiout, pc_prefix (pc)); |
| 126 ui_out_field_core_addr (uiout, "address", gdbarch, pc); | 128 ui_out_field_core_addr (uiout, "address", gdbarch, pc); |
| 127 | 129 |
| 128 if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename, | 130 if (!build_address_symbolic (gdbarch, pc, 0, &name, &offset, &filename, |
| 129 &line, &unmapped)) | 131 &line, &unmapped)) |
| 130 { | 132 { |
| 131 /* We don't care now about line, filename and | 133 /* We don't care now about line, filename and |
| 132 unmapped. But we might in the future. */ | 134 unmapped. But we might in the future. */ |
| 133 ui_out_text (uiout, " <"); | 135 ui_out_text (uiout, " <"); |
| 134 if ((flags & DISASSEMBLY_OMIT_FNAME) == 0) | 136 if ((flags & DISASSEMBLY_OMIT_FNAME) == 0) |
| 135 ui_out_field_string (uiout, "func-name", name); | 137 ui_out_field_string (uiout, "func-name", name); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 struct symtab *symtab, | 199 struct symtab *symtab, |
| 198 int how_many, int flags, struct ui_file *stb) | 200 int how_many, int flags, struct ui_file *stb) |
| 199 { | 201 { |
| 200 int newlines = 0; | 202 int newlines = 0; |
| 201 struct dis_line_entry *mle; | 203 struct dis_line_entry *mle; |
| 202 struct symtab_and_line sal; | 204 struct symtab_and_line sal; |
| 203 int i; | 205 int i; |
| 204 int out_of_order = 0; | 206 int out_of_order = 0; |
| 205 int next_line = 0; | 207 int next_line = 0; |
| 206 int num_displayed = 0; | 208 int num_displayed = 0; |
| 209 enum print_source_lines_flags psl_flags = 0; |
| 207 struct cleanup *ui_out_chain; | 210 struct cleanup *ui_out_chain; |
| 208 struct cleanup *ui_out_tuple_chain = make_cleanup (null_cleanup, 0); | 211 struct cleanup *ui_out_tuple_chain = make_cleanup (null_cleanup, 0); |
| 209 struct cleanup *ui_out_list_chain = make_cleanup (null_cleanup, 0); | 212 struct cleanup *ui_out_list_chain = make_cleanup (null_cleanup, 0); |
| 210 | 213 |
| 214 if (flags & DISASSEMBLY_FILENAME) |
| 215 psl_flags |= PRINT_SOURCE_LINES_FILENAME; |
| 216 |
| 211 mle = (struct dis_line_entry *) alloca (nlines | 217 mle = (struct dis_line_entry *) alloca (nlines |
| 212 * sizeof (struct dis_line_entry)); | 218 * sizeof (struct dis_line_entry)); |
| 213 | 219 |
| 214 /* Copy linetable entries for this function into our data | 220 /* Copy linetable entries for this function into our data |
| 215 structure, creating end_pc's and setting out_of_order as | 221 structure, creating end_pc's and setting out_of_order as |
| 216 appropriate. */ | 222 appropriate. */ |
| 217 | 223 |
| 218 /* First, skip all the preceding functions. */ | 224 /* First, skip all the preceding functions. */ |
| 219 | 225 |
| 220 for (i = 0; i < nlines - 1 && le[i].pc < low; i++); | 226 for (i = 0; i < nlines - 1 && le[i].pc < low; i++); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 if (mle[i].line >= next_line) | 274 if (mle[i].line >= next_line) |
| 269 { | 275 { |
| 270 if (next_line != 0) | 276 if (next_line != 0) |
| 271 { | 277 { |
| 272 /* Just one line to print. */ | 278 /* Just one line to print. */ |
| 273 if (next_line == mle[i].line) | 279 if (next_line == mle[i].line) |
| 274 { | 280 { |
| 275 ui_out_tuple_chain | 281 ui_out_tuple_chain |
| 276 = make_cleanup_ui_out_tuple_begin_end (uiout, | 282 = make_cleanup_ui_out_tuple_begin_end (uiout, |
| 277 "src_and_asm_line"); | 283 "src_and_asm_line"); |
| 278 » » print_source_lines (symtab, next_line, mle[i].line + 1, 0); | 284 » » print_source_lines (symtab, next_line, mle[i].line + 1, psl_fl
ags); |
| 279 } | 285 } |
| 280 else | 286 else |
| 281 { | 287 { |
| 282 /* Several source lines w/o asm instructions associated. */ | 288 /* Several source lines w/o asm instructions associated. */ |
| 283 for (; next_line < mle[i].line; next_line++) | 289 for (; next_line < mle[i].line; next_line++) |
| 284 { | 290 { |
| 285 struct cleanup *ui_out_list_chain_line; | 291 struct cleanup *ui_out_list_chain_line; |
| 286 struct cleanup *ui_out_tuple_chain_line; | 292 struct cleanup *ui_out_tuple_chain_line; |
| 287 | 293 |
| 288 ui_out_tuple_chain_line | 294 ui_out_tuple_chain_line |
| 289 = make_cleanup_ui_out_tuple_begin_end (uiout, | 295 = make_cleanup_ui_out_tuple_begin_end (uiout, |
| 290 "src_and_asm_line
"); | 296 "src_and_asm_line
"); |
| 291 print_source_lines (symtab, next_line, next_line + 1, | 297 print_source_lines (symtab, next_line, next_line + 1, |
| 292 » » » » » 0); | 298 » » » » » psl_flags); |
| 293 ui_out_list_chain_line | 299 ui_out_list_chain_line |
| 294 = make_cleanup_ui_out_list_begin_end (uiout, | 300 = make_cleanup_ui_out_list_begin_end (uiout, |
| 295 "line_asm_insn"); | 301 "line_asm_insn"); |
| 296 do_cleanups (ui_out_list_chain_line); | 302 do_cleanups (ui_out_list_chain_line); |
| 297 do_cleanups (ui_out_tuple_chain_line); | 303 do_cleanups (ui_out_tuple_chain_line); |
| 298 } | 304 } |
| 299 /* Print the last line and leave list open for | 305 /* Print the last line and leave list open for |
| 300 asm instructions to be added. */ | 306 asm instructions to be added. */ |
| 301 ui_out_tuple_chain | 307 ui_out_tuple_chain |
| 302 = make_cleanup_ui_out_tuple_begin_end (uiout, | 308 = make_cleanup_ui_out_tuple_begin_end (uiout, |
| 303 "src_and_asm_line"); | 309 "src_and_asm_line"); |
| 304 » » print_source_lines (symtab, next_line, mle[i].line + 1, 0); | 310 » » print_source_lines (symtab, next_line, mle[i].line + 1, psl_fl
ags); |
| 305 } | 311 } |
| 306 } | 312 } |
| 307 else | 313 else |
| 308 { | 314 { |
| 309 ui_out_tuple_chain | 315 ui_out_tuple_chain |
| 310 = make_cleanup_ui_out_tuple_begin_end (uiout, | 316 = make_cleanup_ui_out_tuple_begin_end (uiout, |
| 311 "src_and_asm_line"); | 317 "src_and_asm_line"); |
| 312 » print_source_lines (symtab, mle[i].line, mle[i].line + 1, 0); | 318 » print_source_lines (symtab, mle[i].line, mle[i].line + 1, psl_flag
s); |
| 313 } | 319 } |
| 314 | 320 |
| 315 next_line = mle[i].line + 1; | 321 next_line = mle[i].line + 1; |
| 316 ui_out_list_chain | 322 ui_out_list_chain |
| 317 = make_cleanup_ui_out_list_begin_end (uiout, "line_asm_insn"); | 323 = make_cleanup_ui_out_list_begin_end (uiout, "line_asm_insn"); |
| 318 } | 324 } |
| 319 | 325 |
| 320 num_displayed += dump_insns (gdbarch, uiout, di, | 326 num_displayed += dump_insns (gdbarch, uiout, di, |
| 321 mle[i].start_pc, mle[i].end_pc, | 327 mle[i].start_pc, mle[i].end_pc, |
| 322 how_many, flags, stb); | 328 how_many, flags, stb); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 int | 526 int |
| 521 gdb_buffered_insn_length (struct gdbarch *gdbarch, | 527 gdb_buffered_insn_length (struct gdbarch *gdbarch, |
| 522 const gdb_byte *insn, int max_len, CORE_ADDR addr) | 528 const gdb_byte *insn, int max_len, CORE_ADDR addr) |
| 523 { | 529 { |
| 524 struct disassemble_info di; | 530 struct disassemble_info di; |
| 525 | 531 |
| 526 gdb_buffered_insn_length_init_dis (gdbarch, &di, insn, max_len, addr); | 532 gdb_buffered_insn_length_init_dis (gdbarch, &di, insn, max_len, addr); |
| 527 | 533 |
| 528 return gdbarch_print_insn (gdbarch, addr, &di); | 534 return gdbarch_print_insn (gdbarch, addr, &di); |
| 529 } | 535 } |
| OLD | NEW |