| OLD | NEW |
| 1 /* MI Command Set - disassemble commands. | 1 /* MI Command Set - disassemble commands. |
| 2 Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc. | 2 Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc. |
| 3 Contributed by Cygnus Solutions (a Red Hat company). | 3 Contributed by Cygnus Solutions (a Red Hat company). |
| 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 "arch-utils.h" | 21 #include "arch-utils.h" |
| 22 #include "target.h" | 22 #include "target.h" |
| 23 #include "value.h" | 23 #include "value.h" |
| 24 #include "mi-cmds.h" | 24 #include "mi-cmds.h" |
| 25 #include "mi-getopt.h" | 25 #include "mi-getopt.h" |
| 26 #include "gdb_string.h" | 26 #include "gdb_string.h" |
| 27 #include "ui-out.h" | 27 #include "ui-out.h" |
| 28 #include "disasm.h" | 28 #include "disasm.h" |
| 29 | 29 |
| 30 /* The arguments to be passed on the command line and parsed here are: | 30 /* The arguments to be passed on the command line and parsed here are |
| 31 | |
| 32 either: | 31 either: |
| 33 | 32 |
| 34 START-ADDRESS: address to start the disassembly at. | 33 START-ADDRESS: address to start the disassembly at. |
| 35 END-ADDRESS: address to end the disassembly at. | 34 END-ADDRESS: address to end the disassembly at. |
| 36 | 35 |
| 37 or: | 36 or: |
| 38 | 37 |
| 39 FILENAME: The name of the file where we want disassemble from. | 38 FILENAME: The name of the file where we want disassemble from. |
| 40 LINE: The line around which we want to disassemble. It will | 39 LINE: The line around which we want to disassemble. It will |
| 41 disassemble the function that contins that line. | 40 disassemble the function that contins that line. |
| 42 HOW_MANY: Number of disassembly lines to display. With source, it | 41 HOW_MANY: Number of disassembly lines to display. With source, it |
| 43 is the number of disassembly lines only, not counting the source | 42 is the number of disassembly lines only, not counting the source |
| 44 lines. | 43 lines. |
| 45 | 44 |
| 46 always required: | 45 always required: |
| 47 | 46 |
| 48 MODE: 0 -- disassembly. | 47 MODE: 0 -- disassembly. |
| 49 1 -- disassembly and source. | 48 1 -- disassembly and source. |
| 50 2 -- disassembly and opcodes. | 49 2 -- disassembly and opcodes. |
| 51 3 -- disassembly, source and opcodes. | 50 3 -- disassembly, source and opcodes. |
| 52 */ | 51 */ |
| 52 |
| 53 void | 53 void |
| 54 mi_cmd_disassemble (char *command, char **argv, int argc) | 54 mi_cmd_disassemble (char *command, char **argv, int argc) |
| 55 { | 55 { |
| 56 struct gdbarch *gdbarch = get_current_arch (); | 56 struct gdbarch *gdbarch = get_current_arch (); |
| 57 struct ui_out *uiout = current_uiout; | 57 struct ui_out *uiout = current_uiout; |
| 58 CORE_ADDR start; | 58 CORE_ADDR start; |
| 59 | 59 |
| 60 int mode, disasm_flags; | 60 int mode, disasm_flags; |
| 61 struct symtab *s; | 61 struct symtab *s; |
| 62 | 62 |
| 63 /* Which options have we processed ... */ | 63 /* Which options have we processed ... */ |
| 64 int file_seen = 0; | 64 int file_seen = 0; |
| 65 int line_seen = 0; | 65 int line_seen = 0; |
| 66 int num_seen = 0; | 66 int num_seen = 0; |
| 67 int start_seen = 0; | 67 int start_seen = 0; |
| 68 int end_seen = 0; | 68 int end_seen = 0; |
| 69 | 69 |
| 70 /* ... and their corresponding value. */ | 70 /* ... and their corresponding value. */ |
| 71 char *file_string = NULL; | 71 char *file_string = NULL; |
| 72 int line_num = -1; | 72 int line_num = -1; |
| 73 int how_many = -1; | 73 int how_many = -1; |
| 74 CORE_ADDR low = 0; | 74 CORE_ADDR low = 0; |
| 75 CORE_ADDR high = 0; | 75 CORE_ADDR high = 0; |
| 76 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); | 76 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
| 77 | 77 |
| 78 /* Options processing stuff. */ | 78 /* Options processing stuff. */ |
| 79 int optind = 0; | 79 int oind = 0; |
| 80 char *optarg; | 80 char *oarg; |
| 81 enum opt | 81 enum opt |
| 82 { | 82 { |
| 83 FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT | 83 FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT |
| 84 }; | 84 }; |
| 85 static const struct mi_opt opts[] = { | 85 static const struct mi_opt opts[] = |
| 86 {"f", FILE_OPT, 1}, | 86 { |
| 87 {"l", LINE_OPT, 1}, | 87 {"f", FILE_OPT, 1}, |
| 88 {"n", NUM_OPT, 1}, | 88 {"l", LINE_OPT, 1}, |
| 89 {"s", START_OPT, 1}, | 89 {"n", NUM_OPT, 1}, |
| 90 {"e", END_OPT, 1}, | 90 {"s", START_OPT, 1}, |
| 91 { 0, 0, 0 } | 91 {"e", END_OPT, 1}, |
| 92 }; | 92 { 0, 0, 0 } |
| 93 }; |
| 93 | 94 |
| 94 /* Get the options with their arguments. Keep track of what we | 95 /* Get the options with their arguments. Keep track of what we |
| 95 encountered. */ | 96 encountered. */ |
| 96 while (1) | 97 while (1) |
| 97 { | 98 { |
| 98 int opt = mi_getopt ("-data-disassemble", argc, argv, opts, | 99 int opt = mi_getopt ("-data-disassemble", argc, argv, opts, |
| 99 » » » &optind, &optarg); | 100 » » » &oind, &oarg); |
| 100 if (opt < 0) | 101 if (opt < 0) |
| 101 break; | 102 break; |
| 102 switch ((enum opt) opt) | 103 switch ((enum opt) opt) |
| 103 { | 104 { |
| 104 case FILE_OPT: | 105 case FILE_OPT: |
| 105 » file_string = xstrdup (optarg); | 106 » file_string = xstrdup (oarg); |
| 106 file_seen = 1; | 107 file_seen = 1; |
| 107 make_cleanup (xfree, file_string); | 108 make_cleanup (xfree, file_string); |
| 108 break; | 109 break; |
| 109 case LINE_OPT: | 110 case LINE_OPT: |
| 110 » line_num = atoi (optarg); | 111 » line_num = atoi (oarg); |
| 111 line_seen = 1; | 112 line_seen = 1; |
| 112 break; | 113 break; |
| 113 case NUM_OPT: | 114 case NUM_OPT: |
| 114 » how_many = atoi (optarg); | 115 » how_many = atoi (oarg); |
| 115 num_seen = 1; | 116 num_seen = 1; |
| 116 break; | 117 break; |
| 117 case START_OPT: | 118 case START_OPT: |
| 118 » low = parse_and_eval_address (optarg); | 119 » low = parse_and_eval_address (oarg); |
| 119 start_seen = 1; | 120 start_seen = 1; |
| 120 break; | 121 break; |
| 121 case END_OPT: | 122 case END_OPT: |
| 122 » high = parse_and_eval_address (optarg); | 123 » high = parse_and_eval_address (oarg); |
| 123 end_seen = 1; | 124 end_seen = 1; |
| 124 break; | 125 break; |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 argv += optind; | 128 argv += oind; |
| 128 argc -= optind; | 129 argc -= oind; |
| 129 | 130 |
| 130 /* Allow only filename + linenum (with how_many which is not | 131 /* Allow only filename + linenum (with how_many which is not |
| 131 required) OR start_addr + and_addr */ | 132 required) OR start_addr + end_addr. */ |
| 132 | 133 |
| 133 if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen) | 134 if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen) |
| 134 || (line_seen && file_seen && !num_seen && !start_seen && !end_seen) | 135 || (line_seen && file_seen && !num_seen && !start_seen && !end_seen) |
| 135 || (!line_seen && !file_seen && !num_seen && start_seen && end_seen))) | 136 || (!line_seen && !file_seen && !num_seen && start_seen && end_seen))) |
| 136 error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n " | 137 error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n " |
| 137 "howmany]] | [-s startaddr -e endaddr]) [--] mode.")); | 138 "howmany]] | [-s startaddr -e endaddr]) [--] mode.")); |
| 138 | 139 |
| 139 if (argc != 1) | 140 if (argc != 1) |
| 140 error (_("-data-disassemble: Usage: [-f filename -l linenum " | 141 error (_("-data-disassemble: Usage: [-f filename -l linenum " |
| 141 "[-n howmany]] [-s startaddr -e endaddr] [--] mode.")); | 142 "[-n howmany]] [-s startaddr -e endaddr] [--] mode.")); |
| 142 | 143 |
| 143 mode = atoi (argv[0]); | 144 mode = atoi (argv[0]); |
| 144 if (mode < 0 || mode > 3) | 145 if (mode < 0 || mode > 3) |
| 145 error (_("-data-disassemble: Mode argument must be 0, 1, 2, or 3.")); | 146 error (_("-data-disassemble: Mode argument must be 0, 1, 2, or 3.")); |
| 146 | 147 |
| 147 /* Convert the mode into a set of disassembly flags */ | 148 /* Convert the mode into a set of disassembly flags. */ |
| 148 | 149 |
| 149 disasm_flags = 0; | 150 disasm_flags = 0; |
| 150 if (mode & 0x1) | 151 if (mode & 0x1) |
| 151 disasm_flags |= DISASSEMBLY_SOURCE; | 152 disasm_flags |= DISASSEMBLY_SOURCE; |
| 152 if (mode & 0x2) | 153 if (mode & 0x2) |
| 153 disasm_flags |= DISASSEMBLY_RAW_INSN; | 154 disasm_flags |= DISASSEMBLY_RAW_INSN; |
| 154 | 155 |
| 155 /* We must get the function beginning and end where line_num is | 156 /* We must get the function beginning and end where line_num is |
| 156 contained. */ | 157 contained. */ |
| 157 | 158 |
| 158 if (line_seen && file_seen) | 159 if (line_seen && file_seen) |
| 159 { | 160 { |
| 160 s = lookup_symtab (file_string); | 161 s = lookup_symtab (file_string); |
| 161 if (s == NULL) | 162 if (s == NULL) |
| 162 error (_("-data-disassemble: Invalid filename.")); | 163 error (_("-data-disassemble: Invalid filename.")); |
| 163 if (!find_line_pc (s, line_num, &start)) | 164 if (!find_line_pc (s, line_num, &start)) |
| 164 error (_("-data-disassemble: Invalid line number")); | 165 error (_("-data-disassemble: Invalid line number")); |
| 165 if (find_pc_partial_function (start, NULL, &low, &high) == 0) | 166 if (find_pc_partial_function (start, NULL, &low, &high) == 0) |
| 166 error (_("-data-disassemble: " | 167 error (_("-data-disassemble: " |
| 167 "No function contains specified address")); | 168 "No function contains specified address")); |
| 168 } | 169 } |
| 169 | 170 |
| 170 gdb_disassembly (gdbarch, uiout, | 171 gdb_disassembly (gdbarch, uiout, |
| 171 file_string, | 172 file_string, |
| 172 disasm_flags, | 173 disasm_flags, |
| 173 how_many, low, high); | 174 how_many, low, high); |
| 174 | 175 |
| 175 do_cleanups (cleanups); | 176 do_cleanups (cleanups); |
| 176 } | 177 } |
| OLD | NEW |