GDB (API)
|
00001 /* MI Command Set - disassemble commands. 00002 Copyright (C) 2000-2013 Free Software Foundation, Inc. 00003 Contributed by Cygnus Solutions (a Red Hat company). 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "arch-utils.h" 00022 #include "target.h" 00023 #include "value.h" 00024 #include "mi-cmds.h" 00025 #include "mi-getopt.h" 00026 #include "gdb_string.h" 00027 #include "ui-out.h" 00028 #include "disasm.h" 00029 00030 /* The arguments to be passed on the command line and parsed here are 00031 either: 00032 00033 START-ADDRESS: address to start the disassembly at. 00034 END-ADDRESS: address to end the disassembly at. 00035 00036 or: 00037 00038 FILENAME: The name of the file where we want disassemble from. 00039 LINE: The line around which we want to disassemble. It will 00040 disassemble the function that contins that line. 00041 HOW_MANY: Number of disassembly lines to display. With source, it 00042 is the number of disassembly lines only, not counting the source 00043 lines. 00044 00045 always required: 00046 00047 MODE: 0 -- disassembly. 00048 1 -- disassembly and source. 00049 2 -- disassembly and opcodes. 00050 3 -- disassembly, source and opcodes. 00051 */ 00052 00053 void 00054 mi_cmd_disassemble (char *command, char **argv, int argc) 00055 { 00056 struct gdbarch *gdbarch = get_current_arch (); 00057 struct ui_out *uiout = current_uiout; 00058 CORE_ADDR start; 00059 00060 int mode, disasm_flags; 00061 struct symtab *s; 00062 00063 /* Which options have we processed ... */ 00064 int file_seen = 0; 00065 int line_seen = 0; 00066 int num_seen = 0; 00067 int start_seen = 0; 00068 int end_seen = 0; 00069 00070 /* ... and their corresponding value. */ 00071 char *file_string = NULL; 00072 int line_num = -1; 00073 int how_many = -1; 00074 CORE_ADDR low = 0; 00075 CORE_ADDR high = 0; 00076 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); 00077 00078 /* Options processing stuff. */ 00079 int oind = 0; 00080 char *oarg; 00081 enum opt 00082 { 00083 FILE_OPT, LINE_OPT, NUM_OPT, START_OPT, END_OPT 00084 }; 00085 static const struct mi_opt opts[] = 00086 { 00087 {"f", FILE_OPT, 1}, 00088 {"l", LINE_OPT, 1}, 00089 {"n", NUM_OPT, 1}, 00090 {"s", START_OPT, 1}, 00091 {"e", END_OPT, 1}, 00092 { 0, 0, 0 } 00093 }; 00094 00095 /* Get the options with their arguments. Keep track of what we 00096 encountered. */ 00097 while (1) 00098 { 00099 int opt = mi_getopt ("-data-disassemble", argc, argv, opts, 00100 &oind, &oarg); 00101 if (opt < 0) 00102 break; 00103 switch ((enum opt) opt) 00104 { 00105 case FILE_OPT: 00106 file_string = xstrdup (oarg); 00107 file_seen = 1; 00108 make_cleanup (xfree, file_string); 00109 break; 00110 case LINE_OPT: 00111 line_num = atoi (oarg); 00112 line_seen = 1; 00113 break; 00114 case NUM_OPT: 00115 how_many = atoi (oarg); 00116 num_seen = 1; 00117 break; 00118 case START_OPT: 00119 low = parse_and_eval_address (oarg); 00120 start_seen = 1; 00121 break; 00122 case END_OPT: 00123 high = parse_and_eval_address (oarg); 00124 end_seen = 1; 00125 break; 00126 } 00127 } 00128 argv += oind; 00129 argc -= oind; 00130 00131 /* Allow only filename + linenum (with how_many which is not 00132 required) OR start_addr + end_addr. */ 00133 00134 if (!((line_seen && file_seen && num_seen && !start_seen && !end_seen) 00135 || (line_seen && file_seen && !num_seen && !start_seen && !end_seen) 00136 || (!line_seen && !file_seen && !num_seen && start_seen && end_seen))) 00137 error (_("-data-disassemble: Usage: ( [-f filename -l linenum [-n " 00138 "howmany]] | [-s startaddr -e endaddr]) [--] mode.")); 00139 00140 if (argc != 1) 00141 error (_("-data-disassemble: Usage: [-f filename -l linenum " 00142 "[-n howmany]] [-s startaddr -e endaddr] [--] mode.")); 00143 00144 mode = atoi (argv[0]); 00145 if (mode < 0 || mode > 3) 00146 error (_("-data-disassemble: Mode argument must be 0, 1, 2, or 3.")); 00147 00148 /* Convert the mode into a set of disassembly flags. */ 00149 00150 disasm_flags = 0; 00151 if (mode & 0x1) 00152 disasm_flags |= DISASSEMBLY_SOURCE; 00153 if (mode & 0x2) 00154 disasm_flags |= DISASSEMBLY_RAW_INSN; 00155 00156 /* We must get the function beginning and end where line_num is 00157 contained. */ 00158 00159 if (line_seen && file_seen) 00160 { 00161 s = lookup_symtab (file_string); 00162 if (s == NULL) 00163 error (_("-data-disassemble: Invalid filename.")); 00164 if (!find_line_pc (s, line_num, &start)) 00165 error (_("-data-disassemble: Invalid line number")); 00166 if (find_pc_partial_function (start, NULL, &low, &high) == 0) 00167 error (_("-data-disassemble: " 00168 "No function contains specified address")); 00169 } 00170 00171 gdb_disassembly (gdbarch, uiout, 00172 file_string, 00173 disasm_flags, 00174 how_many, low, high); 00175 00176 do_cleanups (cleanups); 00177 }