Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectImage.cpp ----------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CommandObjectImage.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 16 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 5f54ac3 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 17 | #include "lldb/Host/FileSpec.h" |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Module.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/RegularExpression.h" |
| 20 | #include "lldb/Core/Stream.h" |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 21 | #include "lldb/Interpreter/Args.h" |
| 22 | #include "lldb/Interpreter/Options.h" |
| 23 | #include "lldb/Interpreter/CommandCompletions.h" |
| 24 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 25 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 26 | #include "lldb/Symbol/LineTable.h" |
| 27 | #include "lldb/Symbol/ObjectFile.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/Symbol/SymbolFile.h" |
| 29 | #include "lldb/Symbol/SymbolVendor.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Process.h" |
| 31 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
| 36 | //---------------------------------------------------------------------- |
| 37 | // Static Helper functions |
| 38 | //---------------------------------------------------------------------- |
| 39 | static void |
| 40 | DumpModuleArchitecture (Stream &strm, Module *module, uint32_t width) |
| 41 | { |
| 42 | if (module) |
| 43 | { |
| 44 | if (width) |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 45 | strm.Printf("%-*s", width, module->GetArchitecture().GetArchitectureName()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | else |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 47 | strm.PutCString(module->GetArchitecture().GetArchitectureName()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | static void |
| 52 | DumpModuleUUID (Stream &strm, Module *module) |
| 53 | { |
| 54 | module->GetUUID().Dump (&strm); |
| 55 | } |
| 56 | |
| 57 | static uint32_t |
| 58 | DumpCompileUnitLineTable |
| 59 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 60 | CommandInterpreter &interpreter, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | Stream &strm, |
| 62 | Module *module, |
| 63 | const FileSpec &file_spec, |
| 64 | bool load_addresses |
| 65 | ) |
| 66 | { |
| 67 | uint32_t num_matches = 0; |
| 68 | if (module) |
| 69 | { |
| 70 | SymbolContextList sc_list; |
| 71 | num_matches = module->ResolveSymbolContextsForFileSpec (file_spec, |
| 72 | 0, |
| 73 | false, |
| 74 | eSymbolContextCompUnit, |
| 75 | sc_list); |
| 76 | |
| 77 | for (uint32_t i=0; i<num_matches; ++i) |
| 78 | { |
| 79 | SymbolContext sc; |
| 80 | if (sc_list.GetContextAtIndex(i, sc)) |
| 81 | { |
| 82 | if (i > 0) |
| 83 | strm << "\n\n"; |
| 84 | |
Johnny Chen | cff44fd | 2010-10-29 22:18:43 +0000 | [diff] [blame] | 85 | strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 86 | << module->GetFileSpec().GetFilename() << "\n"; |
| 87 | LineTable *line_table = sc.comp_unit->GetLineTable(); |
| 88 | if (line_table) |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 89 | line_table->GetDescription (&strm, |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 90 | interpreter.GetDebugger().GetExecutionContext().target, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 91 | lldb::eDescriptionLevelBrief); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 92 | else |
| 93 | strm << "No line table"; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | return num_matches; |
| 98 | } |
| 99 | |
| 100 | static void |
| 101 | DumpFullpath (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width) |
| 102 | { |
| 103 | if (file_spec_ptr) |
| 104 | { |
| 105 | if (width > 0) |
| 106 | { |
| 107 | char fullpath[PATH_MAX]; |
| 108 | if (file_spec_ptr->GetPath(fullpath, sizeof(fullpath))) |
| 109 | { |
| 110 | strm.Printf("%-*s", width, fullpath); |
| 111 | return; |
| 112 | } |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | file_spec_ptr->Dump(&strm); |
| 117 | return; |
| 118 | } |
| 119 | } |
| 120 | // Keep the width spacing correct if things go wrong... |
| 121 | if (width > 0) |
| 122 | strm.Printf("%-*s", width, ""); |
| 123 | } |
| 124 | |
| 125 | static void |
| 126 | DumpDirectory (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width) |
| 127 | { |
| 128 | if (file_spec_ptr) |
| 129 | { |
| 130 | if (width > 0) |
| 131 | strm.Printf("%-*s", width, file_spec_ptr->GetDirectory().AsCString("")); |
| 132 | else |
| 133 | file_spec_ptr->GetDirectory().Dump(&strm); |
| 134 | return; |
| 135 | } |
| 136 | // Keep the width spacing correct if things go wrong... |
| 137 | if (width > 0) |
| 138 | strm.Printf("%-*s", width, ""); |
| 139 | } |
| 140 | |
| 141 | static void |
| 142 | DumpBasename (Stream &strm, const FileSpec *file_spec_ptr, uint32_t width) |
| 143 | { |
| 144 | if (file_spec_ptr) |
| 145 | { |
| 146 | if (width > 0) |
| 147 | strm.Printf("%-*s", width, file_spec_ptr->GetFilename().AsCString("")); |
| 148 | else |
| 149 | file_spec_ptr->GetFilename().Dump(&strm); |
| 150 | return; |
| 151 | } |
| 152 | // Keep the width spacing correct if things go wrong... |
| 153 | if (width > 0) |
| 154 | strm.Printf("%-*s", width, ""); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | static void |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 159 | DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 160 | { |
| 161 | if (module) |
| 162 | { |
| 163 | ObjectFile *objfile = module->GetObjectFile (); |
| 164 | if (objfile) |
| 165 | { |
| 166 | Symtab *symtab = objfile->GetSymtab(); |
| 167 | if (symtab) |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 168 | symtab->Dump(&strm, interpreter.GetDebugger().GetExecutionContext().target, sort_order); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | static void |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 174 | DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 175 | { |
| 176 | if (module) |
| 177 | { |
| 178 | ObjectFile *objfile = module->GetObjectFile (); |
| 179 | if (objfile) |
| 180 | { |
| 181 | SectionList *section_list = objfile->GetSectionList(); |
| 182 | if (section_list) |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 183 | { |
| 184 | strm.PutCString ("Sections for '"); |
| 185 | strm << module->GetFileSpec(); |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 186 | strm.Printf ("' (%s):\n", module->GetArchitecture().GetArchitectureName()); |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 187 | strm.IndentMore(); |
Greg Clayton | 58e844b | 2010-12-08 05:08:21 +0000 | [diff] [blame] | 188 | section_list->Dump(&strm, interpreter.GetDebugger().GetExecutionContext().target, true, UINT32_MAX); |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 189 | strm.IndentLess(); |
| 190 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | static bool |
| 196 | DumpModuleSymbolVendor (Stream &strm, Module *module) |
| 197 | { |
| 198 | if (module) |
| 199 | { |
| 200 | SymbolVendor *symbol_vendor = module->GetSymbolVendor(true); |
| 201 | if (symbol_vendor) |
| 202 | { |
| 203 | symbol_vendor->Dump(&strm); |
| 204 | return true; |
| 205 | } |
| 206 | } |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | static bool |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 211 | LookupAddressInModule |
| 212 | ( |
| 213 | CommandInterpreter &interpreter, |
| 214 | Stream &strm, |
| 215 | Module *module, |
| 216 | uint32_t resolve_mask, |
| 217 | lldb::addr_t raw_addr, |
| 218 | lldb::addr_t offset, |
| 219 | bool verbose |
| 220 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 221 | { |
| 222 | if (module) |
| 223 | { |
| 224 | lldb::addr_t addr = raw_addr - offset; |
| 225 | Address so_addr; |
| 226 | SymbolContext sc; |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 227 | Target *target = interpreter.GetDebugger().GetExecutionContext().target; |
| 228 | if (target && !target->GetSectionLoadList().IsEmpty()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 229 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 230 | if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 231 | return false; |
| 232 | else if (so_addr.GetModule() != module) |
| 233 | return false; |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | if (!module->ResolveFileAddress (addr, so_addr)) |
| 238 | return false; |
| 239 | } |
| 240 | |
| 241 | // If an offset was given, print out the address we ended up looking up |
| 242 | if (offset) |
Greg Clayton | 7e2f91c | 2011-01-29 07:10:55 +0000 | [diff] [blame] | 243 | strm.Printf("File Address: 0x%llx\n", addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 244 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 245 | ExecutionContextScope *exe_scope = interpreter.GetDebugger().GetExecutionContext().GetBestExecutionContextScope(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 246 | strm.IndentMore(); |
| 247 | strm.Indent (" Address: "); |
| 248 | so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset); |
| 249 | strm.EOL(); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 250 | strm.Indent (" Summary: "); |
Greg Clayton | 3c12604 | 2011-02-08 02:40:32 +0000 | [diff] [blame] | 251 | const uint32_t save_indent = strm.GetIndentLevel (); |
| 252 | strm.SetIndentLevel (save_indent + 11); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 253 | so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription); |
Greg Clayton | 3c12604 | 2011-02-08 02:40:32 +0000 | [diff] [blame] | 254 | strm.SetIndentLevel (save_indent); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 255 | strm.EOL(); |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 256 | // Print out detailed address information when verbose is enabled |
| 257 | if (verbose) |
| 258 | { |
| 259 | if (so_addr.Dump (&strm, exe_scope, Address::DumpStyleDetailedSymbolContext)) |
| 260 | strm.EOL(); |
| 261 | } |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 262 | strm.IndentLess(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | return true; |
| 264 | } |
| 265 | |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | static uint32_t |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 270 | LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | { |
| 272 | if (module) |
| 273 | { |
| 274 | SymbolContext sc; |
| 275 | |
| 276 | ObjectFile *objfile = module->GetObjectFile (); |
| 277 | if (objfile) |
| 278 | { |
| 279 | Symtab *symtab = objfile->GetSymtab(); |
| 280 | if (symtab) |
| 281 | { |
| 282 | uint32_t i; |
| 283 | std::vector<uint32_t> match_indexes; |
| 284 | ConstString symbol_name (name); |
| 285 | uint32_t num_matches = 0; |
| 286 | if (name_is_regex) |
| 287 | { |
| 288 | RegularExpression name_regexp(name); |
Greg Clayton | 7c36fa0 | 2010-09-11 03:13:28 +0000 | [diff] [blame] | 289 | num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp, |
| 290 | eSymbolTypeAny, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 291 | match_indexes); |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | num_matches = symtab->AppendSymbolIndexesWithName (symbol_name, match_indexes); |
| 296 | } |
| 297 | |
| 298 | |
| 299 | if (num_matches > 0) |
| 300 | { |
| 301 | strm.Indent (); |
| 302 | strm.Printf("%u symbols match %s'%s' in ", num_matches, |
| 303 | name_is_regex ? "the regular expression " : "", name); |
| 304 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 305 | strm.PutCString(":\n"); |
| 306 | strm.IndentMore (); |
| 307 | Symtab::DumpSymbolHeader (&strm); |
| 308 | for (i=0; i < num_matches; ++i) |
| 309 | { |
| 310 | Symbol *symbol = symtab->SymbolAtIndex(match_indexes[i]); |
| 311 | strm.Indent (); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 312 | symbol->Dump (&strm, interpreter.GetDebugger().GetExecutionContext().target, i); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | } |
| 314 | strm.IndentLess (); |
| 315 | return num_matches; |
| 316 | } |
| 317 | } |
| 318 | } |
| 319 | } |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | |
| 324 | static void |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 325 | DumpSymbolContextList (CommandInterpreter &interpreter, Stream &strm, SymbolContextList &sc_list, bool prepend_addr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 326 | { |
| 327 | strm.IndentMore (); |
| 328 | uint32_t i; |
| 329 | const uint32_t num_matches = sc_list.GetSize(); |
| 330 | |
| 331 | for (i=0; i<num_matches; ++i) |
| 332 | { |
| 333 | SymbolContext sc; |
| 334 | if (sc_list.GetContextAtIndex(i, sc)) |
| 335 | { |
| 336 | strm.Indent(); |
| 337 | if (prepend_addr) |
| 338 | { |
| 339 | if (sc.line_entry.range.GetBaseAddress().IsValid()) |
| 340 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 341 | lldb::addr_t vm_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(interpreter.GetDebugger().GetExecutionContext().target); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 342 | int addr_size = sizeof (addr_t); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 343 | Process *process = interpreter.GetDebugger().GetExecutionContext().process; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 344 | if (process) |
Greg Clayton | 395fc33 | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 345 | addr_size = process->GetTarget().GetArchitecture().GetAddressByteSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | if (vm_addr != LLDB_INVALID_ADDRESS) |
| 347 | strm.Address (vm_addr, addr_size); |
| 348 | else |
| 349 | sc.line_entry.range.GetBaseAddress().Dump (&strm, NULL, Address::DumpStyleSectionNameOffset); |
| 350 | |
| 351 | strm.PutCString(" in "); |
| 352 | } |
| 353 | } |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 354 | sc.DumpStopContext(&strm, interpreter.GetDebugger().GetExecutionContext().process, sc.line_entry.range.GetBaseAddress(), true, true, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | strm.IndentLess (); |
| 358 | } |
| 359 | |
| 360 | static uint32_t |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 361 | LookupFunctionInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 362 | { |
| 363 | if (module && name && name[0]) |
| 364 | { |
| 365 | SymbolContextList sc_list; |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 366 | const bool include_symbols = false; |
| 367 | const bool append = true; |
| 368 | uint32_t num_matches = 0; |
| 369 | if (name_is_regex) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 370 | { |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 371 | RegularExpression function_name_regex (name); |
| 372 | num_matches = module->FindFunctions (function_name_regex, |
| 373 | include_symbols, |
| 374 | append, |
| 375 | sc_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | } |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 377 | else |
| 378 | { |
| 379 | ConstString function_name (name); |
| 380 | num_matches = module->FindFunctions (function_name, |
| 381 | eFunctionNameTypeBase | eFunctionNameTypeFull | eFunctionNameTypeMethod | eFunctionNameTypeSelector, |
| 382 | include_symbols, |
| 383 | append, |
| 384 | sc_list); |
| 385 | } |
| 386 | |
| 387 | if (num_matches) |
| 388 | { |
| 389 | strm.Indent (); |
| 390 | strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : ""); |
| 391 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 392 | strm.PutCString(":\n"); |
| 393 | DumpSymbolContextList (interpreter, strm, sc_list, true); |
| 394 | } |
| 395 | return num_matches; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 396 | } |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | static uint32_t |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 401 | LookupTypeInModule |
| 402 | ( |
| 403 | CommandInterpreter &interpreter, |
| 404 | Stream &strm, |
| 405 | Module *module, |
| 406 | const char *name_cstr, |
| 407 | bool name_is_regex |
| 408 | ) |
| 409 | { |
| 410 | if (module && name_cstr && name_cstr[0]) |
| 411 | { |
| 412 | SymbolContextList sc_list; |
| 413 | |
| 414 | SymbolVendor *symbol_vendor = module->GetSymbolVendor(); |
| 415 | if (symbol_vendor) |
| 416 | { |
| 417 | TypeList type_list; |
| 418 | uint32_t num_matches = 0; |
| 419 | SymbolContext sc; |
| 420 | // if (name_is_regex) |
| 421 | // { |
| 422 | // RegularExpression name_regex (name_cstr); |
| 423 | // num_matches = symbol_vendor->FindFunctions(sc, name_regex, true, UINT32_MAX, type_list); |
| 424 | // } |
| 425 | // else |
| 426 | // { |
| 427 | ConstString name(name_cstr); |
| 428 | num_matches = symbol_vendor->FindTypes(sc, name, true, UINT32_MAX, type_list); |
| 429 | // } |
| 430 | |
| 431 | if (num_matches) |
| 432 | { |
| 433 | strm.Indent (); |
| 434 | strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : ""); |
| 435 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 436 | strm.PutCString(":\n"); |
| 437 | const uint32_t num_types = type_list.GetSize(); |
| 438 | for (uint32_t i=0; i<num_types; ++i) |
| 439 | { |
| 440 | TypeSP type_sp (type_list.GetTypeAtIndex(i)); |
| 441 | if (type_sp) |
| 442 | { |
| 443 | // Resolve the clang type so that any forward references |
| 444 | // to types that haven't yet been parsed will get parsed. |
Greg Clayton | 04c9c7b | 2011-02-16 23:00:21 +0000 | [diff] [blame] | 445 | type_sp->GetClangFullType (); |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 446 | type_sp->GetDescription (&strm, eDescriptionLevelFull, true); |
| 447 | } |
| 448 | strm.EOL(); |
| 449 | } |
| 450 | } |
| 451 | return num_matches; |
| 452 | } |
| 453 | } |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static uint32_t |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 458 | LookupFileAndLineInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const FileSpec &file_spec, uint32_t line, bool check_inlines) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | { |
| 460 | if (module && file_spec) |
| 461 | { |
| 462 | SymbolContextList sc_list; |
| 463 | const uint32_t num_matches = module->ResolveSymbolContextsForFileSpec(file_spec, line, check_inlines, |
| 464 | eSymbolContextEverything, sc_list); |
| 465 | if (num_matches > 0) |
| 466 | { |
| 467 | strm.Indent (); |
| 468 | strm.Printf("%u match%s found in ", num_matches, num_matches > 1 ? "es" : ""); |
| 469 | strm << file_spec; |
| 470 | if (line > 0) |
| 471 | strm.Printf (":%u", line); |
| 472 | strm << " in "; |
| 473 | DumpFullpath (strm, &module->GetFileSpec(), 0); |
| 474 | strm.PutCString(":\n"); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 475 | DumpSymbolContextList (interpreter, strm, sc_list, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 476 | return num_matches; |
| 477 | } |
| 478 | } |
| 479 | return 0; |
| 480 | |
| 481 | } |
| 482 | |
| 483 | |
| 484 | //---------------------------------------------------------------------- |
| 485 | // Image symbol table dumping command |
| 486 | //---------------------------------------------------------------------- |
| 487 | |
| 488 | class CommandObjectImageDumpModuleList : public CommandObject |
| 489 | { |
| 490 | public: |
| 491 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 492 | CommandObjectImageDumpModuleList (CommandInterpreter &interpreter, |
| 493 | const char *name, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 494 | const char *help, |
| 495 | const char *syntax) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 496 | CommandObject (interpreter, name, help, syntax) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 498 | CommandArgumentEntry arg; |
| 499 | CommandArgumentData file_arg; |
| 500 | |
| 501 | // Define the first (and only) variant of this arg. |
| 502 | file_arg.arg_type = eArgTypeFilename; |
| 503 | file_arg.arg_repetition = eArgRepeatStar; |
| 504 | |
| 505 | // There is only one variant this argument could be; put it into the argument entry. |
| 506 | arg.push_back (file_arg); |
| 507 | |
| 508 | // Push the data for the first argument into the m_arguments vector. |
| 509 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | virtual |
| 513 | ~CommandObjectImageDumpModuleList () |
| 514 | { |
| 515 | } |
| 516 | |
| 517 | virtual int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 518 | HandleArgumentCompletion (Args &input, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 519 | int &cursor_index, |
| 520 | int &cursor_char_position, |
| 521 | OptionElementVector &opt_element_vector, |
| 522 | int match_start_point, |
| 523 | int max_return_elements, |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 524 | bool &word_complete, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 525 | StringList &matches) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 526 | { |
| 527 | // Arguments are the standard module completer. |
| 528 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 529 | completion_str.erase (cursor_char_position); |
| 530 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 531 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 532 | CommandCompletions::eModuleCompletion, |
| 533 | completion_str.c_str(), |
| 534 | match_start_point, |
| 535 | max_return_elements, |
| 536 | NULL, |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 537 | word_complete, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 538 | matches); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 539 | return matches.GetSize(); |
| 540 | } |
| 541 | }; |
| 542 | |
| 543 | class CommandObjectImageDumpSourceFileList : public CommandObject |
| 544 | { |
| 545 | public: |
| 546 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 547 | CommandObjectImageDumpSourceFileList (CommandInterpreter &interpreter, |
| 548 | const char *name, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 549 | const char *help, |
| 550 | const char *syntax) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 551 | CommandObject (interpreter, name, help, syntax) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 552 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 553 | CommandArgumentEntry arg; |
| 554 | CommandArgumentData source_file_arg; |
| 555 | |
| 556 | // Define the first (and only) variant of this arg. |
| 557 | source_file_arg.arg_type = eArgTypeSourceFile; |
| 558 | source_file_arg.arg_repetition = eArgRepeatPlus; |
| 559 | |
| 560 | // There is only one variant this argument could be; put it into the argument entry. |
| 561 | arg.push_back (source_file_arg); |
| 562 | |
| 563 | // Push the data for the first argument into the m_arguments vector. |
| 564 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | virtual |
| 568 | ~CommandObjectImageDumpSourceFileList () |
| 569 | { |
| 570 | } |
| 571 | |
| 572 | virtual int |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 573 | HandleArgumentCompletion (Args &input, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 574 | int &cursor_index, |
| 575 | int &cursor_char_position, |
| 576 | OptionElementVector &opt_element_vector, |
| 577 | int match_start_point, |
| 578 | int max_return_elements, |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 579 | bool &word_complete, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 580 | StringList &matches) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 581 | { |
| 582 | // Arguments are the standard source file completer. |
| 583 | std::string completion_str (input.GetArgumentAtIndex(cursor_index)); |
| 584 | completion_str.erase (cursor_char_position); |
| 585 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 586 | CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 587 | CommandCompletions::eSourceFileCompletion, |
| 588 | completion_str.c_str(), |
| 589 | match_start_point, |
| 590 | max_return_elements, |
| 591 | NULL, |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 592 | word_complete, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 593 | matches); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 594 | return matches.GetSize(); |
| 595 | } |
| 596 | }; |
| 597 | |
| 598 | |
| 599 | class CommandObjectImageDumpSymtab : public CommandObjectImageDumpModuleList |
| 600 | { |
| 601 | public: |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 602 | CommandObjectImageDumpSymtab (CommandInterpreter &interpreter) : |
| 603 | CommandObjectImageDumpModuleList (interpreter, |
| 604 | "image dump symtab", |
| 605 | "Dump the symbol table from one or more executable images.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 606 | NULL), |
| 607 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 608 | { |
| 609 | } |
| 610 | |
| 611 | virtual |
| 612 | ~CommandObjectImageDumpSymtab () |
| 613 | { |
| 614 | } |
| 615 | |
| 616 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 617 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 618 | CommandReturnObject &result) |
| 619 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 620 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 621 | if (target == NULL) |
| 622 | { |
| 623 | result.AppendError ("invalid target, set executable file using 'file' command"); |
| 624 | result.SetStatus (eReturnStatusFailed); |
| 625 | return false; |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | uint32_t num_dumped = 0; |
| 630 | |
| 631 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 632 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 633 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 634 | |
| 635 | if (command.GetArgumentCount() == 0) |
| 636 | { |
| 637 | // Dump all sections for all modules images |
| 638 | const uint32_t num_modules = target->GetImages().GetSize(); |
| 639 | if (num_modules > 0) |
| 640 | { |
| 641 | result.GetOutputStream().Printf("Dumping symbol table for %u modules.\n", num_modules); |
| 642 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 643 | { |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 644 | if (num_dumped > 0) |
| 645 | { |
| 646 | result.GetOutputStream().EOL(); |
| 647 | result.GetOutputStream().EOL(); |
| 648 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | num_dumped++; |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 650 | DumpModuleSymtab (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx), m_options.m_sort_order); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | else |
| 654 | { |
| 655 | result.AppendError ("the target has no associated executable images"); |
| 656 | result.SetStatus (eReturnStatusFailed); |
| 657 | return false; |
| 658 | } |
| 659 | } |
| 660 | else |
| 661 | { |
| 662 | // Dump specified images (by basename or fullpath) |
| 663 | const char *arg_cstr; |
| 664 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
| 665 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 666 | FileSpec image_file(arg_cstr, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 667 | ModuleList matching_modules; |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 668 | size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 669 | |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 670 | // Not found in our module list for our target, check the main |
| 671 | // shared module list in case it is a extra file used somewhere |
| 672 | // else |
| 673 | if (num_matching_modules == 0) |
| 674 | num_matching_modules = ModuleList::FindSharedModules (image_file, |
| 675 | target->GetArchitecture(), |
| 676 | NULL, |
| 677 | NULL, |
| 678 | matching_modules); |
| 679 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 680 | if (num_matching_modules > 0) |
| 681 | { |
| 682 | for (size_t i=0; i<num_matching_modules; ++i) |
| 683 | { |
| 684 | Module *image_module = matching_modules.GetModulePointerAtIndex(i); |
| 685 | if (image_module) |
| 686 | { |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 687 | if (num_dumped > 0) |
| 688 | { |
| 689 | result.GetOutputStream().EOL(); |
| 690 | result.GetOutputStream().EOL(); |
| 691 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 692 | num_dumped++; |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 693 | DumpModuleSymtab (m_interpreter, result.GetOutputStream(), image_module, m_options.m_sort_order); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | } |
| 697 | else |
| 698 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | if (num_dumped > 0) |
| 703 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 704 | else |
| 705 | { |
| 706 | result.AppendError ("no matching executable images found"); |
| 707 | result.SetStatus (eReturnStatusFailed); |
| 708 | } |
| 709 | } |
| 710 | return result.Succeeded(); |
| 711 | } |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 712 | |
| 713 | virtual Options * |
| 714 | GetOptions () |
| 715 | { |
| 716 | return &m_options; |
| 717 | } |
| 718 | |
| 719 | class CommandOptions : public Options |
| 720 | { |
| 721 | public: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 722 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 723 | CommandOptions (CommandInterpreter &interpreter) : |
| 724 | Options(m_interpreter), |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 725 | m_sort_order (eSortOrderNone) |
| 726 | { |
| 727 | } |
| 728 | |
| 729 | virtual |
| 730 | ~CommandOptions () |
| 731 | { |
| 732 | } |
| 733 | |
| 734 | virtual Error |
| 735 | SetOptionValue (int option_idx, const char *option_arg) |
| 736 | { |
| 737 | Error error; |
| 738 | char short_option = (char) m_getopt_table[option_idx].val; |
| 739 | |
| 740 | switch (short_option) |
| 741 | { |
| 742 | case 's': |
| 743 | { |
| 744 | bool found_one = false; |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 745 | m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg, |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 746 | g_option_table[option_idx].enum_values, |
| 747 | eSortOrderNone, |
| 748 | &found_one); |
| 749 | if (!found_one) |
| 750 | error.SetErrorStringWithFormat("Invalid enumeration value '%s' for option '%c'.\n", |
| 751 | option_arg, |
| 752 | short_option); |
| 753 | } |
| 754 | break; |
| 755 | |
| 756 | default: |
| 757 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 758 | break; |
| 759 | |
| 760 | } |
| 761 | return error; |
| 762 | } |
| 763 | |
| 764 | void |
| 765 | ResetOptionValues () |
| 766 | { |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 767 | m_sort_order = eSortOrderNone; |
| 768 | } |
| 769 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 770 | const OptionDefinition* |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 771 | GetDefinitions () |
| 772 | { |
| 773 | return g_option_table; |
| 774 | } |
| 775 | |
| 776 | // Options table: Required for subclasses of Options. |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 777 | static OptionDefinition g_option_table[]; |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 778 | |
| 779 | SortOrder m_sort_order; |
| 780 | }; |
| 781 | |
| 782 | protected: |
| 783 | |
| 784 | CommandOptions m_options; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 785 | }; |
| 786 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 787 | static OptionEnumValueElement |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 788 | g_sort_option_enumeration[4] = |
| 789 | { |
| 790 | { eSortOrderNone, "none", "No sorting, use the original symbol table order."}, |
| 791 | { eSortOrderByAddress, "address", "Sort output by symbol address."}, |
| 792 | { eSortOrderByName, "name", "Sort output by symbol name."}, |
| 793 | { 0, NULL, NULL } |
| 794 | }; |
| 795 | |
| 796 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 797 | OptionDefinition |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 798 | CommandObjectImageDumpSymtab::CommandOptions::g_option_table[] = |
| 799 | { |
| 800 | { LLDB_OPT_SET_1, false, "sort", 's', required_argument, g_sort_option_enumeration, 0, eArgTypeSortOrder, "Supply a sort order when dumping the symbol table."}, |
| 801 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
| 802 | }; |
| 803 | |
| 804 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | //---------------------------------------------------------------------- |
| 806 | // Image section dumping command |
| 807 | //---------------------------------------------------------------------- |
| 808 | class CommandObjectImageDumpSections : public CommandObjectImageDumpModuleList |
| 809 | { |
| 810 | public: |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 811 | CommandObjectImageDumpSections (CommandInterpreter &interpreter) : |
| 812 | CommandObjectImageDumpModuleList (interpreter, |
| 813 | "image dump sections", |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 814 | "Dump the sections from one or more executable images.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 815 | //"image dump sections [<file1> ...]") |
| 816 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 817 | { |
| 818 | } |
| 819 | |
| 820 | virtual |
| 821 | ~CommandObjectImageDumpSections () |
| 822 | { |
| 823 | } |
| 824 | |
| 825 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 826 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 827 | CommandReturnObject &result) |
| 828 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 829 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 830 | if (target == NULL) |
| 831 | { |
| 832 | result.AppendError ("invalid target, set executable file using 'file' command"); |
| 833 | result.SetStatus (eReturnStatusFailed); |
| 834 | return false; |
| 835 | } |
| 836 | else |
| 837 | { |
| 838 | uint32_t num_dumped = 0; |
| 839 | |
| 840 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 841 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 842 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 843 | |
| 844 | if (command.GetArgumentCount() == 0) |
| 845 | { |
| 846 | // Dump all sections for all modules images |
| 847 | const uint32_t num_modules = target->GetImages().GetSize(); |
| 848 | if (num_modules > 0) |
| 849 | { |
| 850 | result.GetOutputStream().Printf("Dumping sections for %u modules.\n", num_modules); |
| 851 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 852 | { |
| 853 | num_dumped++; |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 854 | DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 855 | } |
| 856 | } |
| 857 | else |
| 858 | { |
| 859 | result.AppendError ("the target has no associated executable images"); |
| 860 | result.SetStatus (eReturnStatusFailed); |
| 861 | return false; |
| 862 | } |
| 863 | } |
| 864 | else |
| 865 | { |
| 866 | // Dump specified images (by basename or fullpath) |
| 867 | const char *arg_cstr; |
| 868 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
| 869 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 870 | FileSpec image_file(arg_cstr, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 871 | ModuleList matching_modules; |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 872 | size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 874 | // Not found in our module list for our target, check the main |
| 875 | // shared module list in case it is a extra file used somewhere |
| 876 | // else |
| 877 | if (num_matching_modules == 0) |
| 878 | num_matching_modules = ModuleList::FindSharedModules (image_file, |
| 879 | target->GetArchitecture(), |
| 880 | NULL, |
| 881 | NULL, |
| 882 | matching_modules); |
| 883 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | if (num_matching_modules > 0) |
| 885 | { |
| 886 | for (size_t i=0; i<num_matching_modules; ++i) |
| 887 | { |
| 888 | Module * image_module = matching_modules.GetModulePointerAtIndex(i); |
| 889 | if (image_module) |
| 890 | { |
| 891 | num_dumped++; |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 892 | DumpModuleSections (m_interpreter, result.GetOutputStream(), image_module); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | } |
| 896 | else |
| 897 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | if (num_dumped > 0) |
| 902 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 903 | else |
| 904 | { |
| 905 | result.AppendError ("no matching executable images found"); |
| 906 | result.SetStatus (eReturnStatusFailed); |
| 907 | } |
| 908 | } |
| 909 | return result.Succeeded(); |
| 910 | } |
| 911 | }; |
| 912 | |
| 913 | //---------------------------------------------------------------------- |
| 914 | // Image debug symbol dumping command |
| 915 | //---------------------------------------------------------------------- |
| 916 | class CommandObjectImageDumpSymfile : public CommandObjectImageDumpModuleList |
| 917 | { |
| 918 | public: |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 919 | CommandObjectImageDumpSymfile (CommandInterpreter &interpreter) : |
| 920 | CommandObjectImageDumpModuleList (interpreter, |
| 921 | "image dump symfile", |
| 922 | "Dump the debug symbol file for one or more executable images.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 923 | //"image dump symfile [<file1> ...]") |
| 924 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 925 | { |
| 926 | } |
| 927 | |
| 928 | virtual |
| 929 | ~CommandObjectImageDumpSymfile () |
| 930 | { |
| 931 | } |
| 932 | |
| 933 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 934 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 935 | CommandReturnObject &result) |
| 936 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 937 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 938 | if (target == NULL) |
| 939 | { |
| 940 | result.AppendError ("invalid target, set executable file using 'file' command"); |
| 941 | result.SetStatus (eReturnStatusFailed); |
| 942 | return false; |
| 943 | } |
| 944 | else |
| 945 | { |
| 946 | uint32_t num_dumped = 0; |
| 947 | |
| 948 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 949 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 950 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 951 | |
| 952 | if (command.GetArgumentCount() == 0) |
| 953 | { |
| 954 | // Dump all sections for all modules images |
| 955 | const uint32_t num_modules = target->GetImages().GetSize(); |
| 956 | if (num_modules > 0) |
| 957 | { |
| 958 | result.GetOutputStream().Printf("Dumping debug symbols for %u modules.\n", num_modules); |
| 959 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 960 | { |
| 961 | if (DumpModuleSymbolVendor (result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx))) |
| 962 | num_dumped++; |
| 963 | } |
| 964 | } |
| 965 | else |
| 966 | { |
| 967 | result.AppendError ("the target has no associated executable images"); |
| 968 | result.SetStatus (eReturnStatusFailed); |
| 969 | return false; |
| 970 | } |
| 971 | } |
| 972 | else |
| 973 | { |
| 974 | // Dump specified images (by basename or fullpath) |
| 975 | const char *arg_cstr; |
| 976 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
| 977 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 978 | FileSpec image_file(arg_cstr, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 979 | ModuleList matching_modules; |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 980 | size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 981 | |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 982 | // Not found in our module list for our target, check the main |
| 983 | // shared module list in case it is a extra file used somewhere |
| 984 | // else |
| 985 | if (num_matching_modules == 0) |
| 986 | num_matching_modules = ModuleList::FindSharedModules (image_file, |
| 987 | target->GetArchitecture(), |
| 988 | NULL, |
| 989 | NULL, |
| 990 | matching_modules); |
| 991 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 992 | if (num_matching_modules > 0) |
| 993 | { |
| 994 | for (size_t i=0; i<num_matching_modules; ++i) |
| 995 | { |
| 996 | Module * image_module = matching_modules.GetModulePointerAtIndex(i); |
| 997 | if (image_module) |
| 998 | { |
| 999 | if (DumpModuleSymbolVendor (result.GetOutputStream(), image_module)) |
| 1000 | num_dumped++; |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | else |
| 1005 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | if (num_dumped > 0) |
| 1010 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1011 | else |
| 1012 | { |
| 1013 | result.AppendError ("no matching executable images found"); |
| 1014 | result.SetStatus (eReturnStatusFailed); |
| 1015 | } |
| 1016 | } |
| 1017 | return result.Succeeded(); |
| 1018 | } |
| 1019 | }; |
| 1020 | |
| 1021 | //---------------------------------------------------------------------- |
| 1022 | // Image debug symbol dumping command |
| 1023 | //---------------------------------------------------------------------- |
| 1024 | class CommandObjectImageDumpLineTable : public CommandObjectImageDumpSourceFileList |
| 1025 | { |
| 1026 | public: |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1027 | CommandObjectImageDumpLineTable (CommandInterpreter &interpreter) : |
| 1028 | CommandObjectImageDumpSourceFileList (interpreter, |
| 1029 | "image dump line-table", |
| 1030 | "Dump the debug symbol file for one or more executable images.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1031 | NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1032 | { |
| 1033 | } |
| 1034 | |
| 1035 | virtual |
| 1036 | ~CommandObjectImageDumpLineTable () |
| 1037 | { |
| 1038 | } |
| 1039 | |
| 1040 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1041 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1042 | CommandReturnObject &result) |
| 1043 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1044 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1045 | if (target == NULL) |
| 1046 | { |
| 1047 | result.AppendError ("invalid target, set executable file using 'file' command"); |
| 1048 | result.SetStatus (eReturnStatusFailed); |
| 1049 | return false; |
| 1050 | } |
| 1051 | else |
| 1052 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1053 | ExecutionContext exe_ctx(m_interpreter.GetDebugger().GetExecutionContext()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1054 | uint32_t total_num_dumped = 0; |
| 1055 | |
| 1056 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 1057 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 1058 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 1059 | |
| 1060 | if (command.GetArgumentCount() == 0) |
| 1061 | { |
| 1062 | result.AppendErrorWithFormat ("\nSyntax: %s\n", m_cmd_syntax.c_str()); |
| 1063 | result.SetStatus (eReturnStatusFailed); |
| 1064 | } |
| 1065 | else |
| 1066 | { |
| 1067 | // Dump specified images (by basename or fullpath) |
| 1068 | const char *arg_cstr; |
| 1069 | for (int arg_idx = 0; (arg_cstr = command.GetArgumentAtIndex(arg_idx)) != NULL; ++arg_idx) |
| 1070 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 1071 | FileSpec file_spec(arg_cstr, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1072 | const uint32_t num_modules = target->GetImages().GetSize(); |
| 1073 | if (num_modules > 0) |
| 1074 | { |
| 1075 | uint32_t num_dumped = 0; |
| 1076 | for (uint32_t i = 0; i<num_modules; ++i) |
| 1077 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1078 | if (DumpCompileUnitLineTable (m_interpreter, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1079 | result.GetOutputStream(), |
| 1080 | target->GetImages().GetModulePointerAtIndex(i), |
| 1081 | file_spec, |
| 1082 | exe_ctx.process != NULL && exe_ctx.process->IsAlive())) |
| 1083 | num_dumped++; |
| 1084 | } |
| 1085 | if (num_dumped == 0) |
| 1086 | result.AppendWarningWithFormat ("No source filenames matched '%s'.\n", arg_cstr); |
| 1087 | else |
| 1088 | total_num_dumped += num_dumped; |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | if (total_num_dumped > 0) |
| 1094 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1095 | else |
| 1096 | { |
| 1097 | result.AppendError ("no source filenames matched any command arguments"); |
| 1098 | result.SetStatus (eReturnStatusFailed); |
| 1099 | } |
| 1100 | } |
| 1101 | return result.Succeeded(); |
| 1102 | } |
| 1103 | }; |
| 1104 | |
| 1105 | //---------------------------------------------------------------------- |
| 1106 | // Dump multi-word command |
| 1107 | //---------------------------------------------------------------------- |
| 1108 | class CommandObjectImageDump : public CommandObjectMultiword |
| 1109 | { |
| 1110 | public: |
| 1111 | |
| 1112 | //------------------------------------------------------------------ |
| 1113 | // Constructors and Destructors |
| 1114 | //------------------------------------------------------------------ |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1115 | CommandObjectImageDump(CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1116 | CommandObjectMultiword (interpreter, |
| 1117 | "image dump", |
Caroline Tice | abb507a | 2010-09-08 21:06:11 +0000 | [diff] [blame] | 1118 | "A set of commands for dumping information about one or more executable images; 'line-table' expects a source file name", |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1119 | "image dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1120 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1121 | LoadSubCommand ("symtab", CommandObjectSP (new CommandObjectImageDumpSymtab (interpreter))); |
| 1122 | LoadSubCommand ("sections", CommandObjectSP (new CommandObjectImageDumpSections (interpreter))); |
| 1123 | LoadSubCommand ("symfile", CommandObjectSP (new CommandObjectImageDumpSymfile (interpreter))); |
| 1124 | LoadSubCommand ("line-table", CommandObjectSP (new CommandObjectImageDumpLineTable (interpreter))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | virtual |
| 1128 | ~CommandObjectImageDump() |
| 1129 | { |
| 1130 | } |
| 1131 | }; |
| 1132 | |
| 1133 | //---------------------------------------------------------------------- |
| 1134 | // List images with associated information |
| 1135 | //---------------------------------------------------------------------- |
| 1136 | class CommandObjectImageList : public CommandObject |
| 1137 | { |
| 1138 | public: |
| 1139 | |
| 1140 | class CommandOptions : public Options |
| 1141 | { |
| 1142 | public: |
| 1143 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1144 | CommandOptions (CommandInterpreter &interpreter) : |
| 1145 | Options(m_interpreter), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1146 | m_format_array() |
| 1147 | { |
| 1148 | } |
| 1149 | |
| 1150 | virtual |
| 1151 | ~CommandOptions () |
| 1152 | { |
| 1153 | } |
| 1154 | |
| 1155 | virtual Error |
| 1156 | SetOptionValue (int option_idx, const char *option_arg) |
| 1157 | { |
| 1158 | char short_option = (char) m_getopt_table[option_idx].val; |
| 1159 | uint32_t width = 0; |
| 1160 | if (option_arg) |
| 1161 | width = strtoul (option_arg, NULL, 0); |
| 1162 | m_format_array.push_back(std::make_pair(short_option, width)); |
| 1163 | Error error; |
| 1164 | return error; |
| 1165 | } |
| 1166 | |
| 1167 | void |
| 1168 | ResetOptionValues () |
| 1169 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1170 | m_format_array.clear(); |
| 1171 | } |
| 1172 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1173 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1174 | GetDefinitions () |
| 1175 | { |
| 1176 | return g_option_table; |
| 1177 | } |
| 1178 | |
| 1179 | // Options table: Required for subclasses of Options. |
| 1180 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1181 | static OptionDefinition g_option_table[]; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1182 | |
| 1183 | // Instance variables to hold the values for command options. |
| 1184 | typedef std::vector< std::pair<char, uint32_t> > FormatWidthCollection; |
| 1185 | FormatWidthCollection m_format_array; |
| 1186 | }; |
| 1187 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1188 | CommandObjectImageList (CommandInterpreter &interpreter) : |
| 1189 | CommandObject (interpreter, |
| 1190 | "image list", |
| 1191 | "List current executable and dependent shared library images.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1192 | "image list [<cmd-options>]"), |
| 1193 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1194 | { |
| 1195 | } |
| 1196 | |
| 1197 | virtual |
| 1198 | ~CommandObjectImageList () |
| 1199 | { |
| 1200 | } |
| 1201 | |
| 1202 | virtual |
| 1203 | Options * |
| 1204 | GetOptions () |
| 1205 | { |
| 1206 | return &m_options; |
| 1207 | } |
| 1208 | |
| 1209 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1210 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1211 | CommandReturnObject &result) |
| 1212 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1213 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1214 | if (target == NULL) |
| 1215 | { |
| 1216 | result.AppendError ("invalid target, set executable file using 'file' command"); |
| 1217 | result.SetStatus (eReturnStatusFailed); |
| 1218 | return false; |
| 1219 | } |
| 1220 | else |
| 1221 | { |
| 1222 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 1223 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 1224 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 1225 | // Dump all sections for all modules images |
| 1226 | const uint32_t num_modules = target->GetImages().GetSize(); |
| 1227 | if (num_modules > 0) |
| 1228 | { |
| 1229 | Stream &strm = result.GetOutputStream(); |
| 1230 | |
| 1231 | for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx) |
| 1232 | { |
| 1233 | Module *module = target->GetImages().GetModulePointerAtIndex(image_idx); |
| 1234 | strm.Printf("[%3u] ", image_idx); |
| 1235 | |
| 1236 | if (m_options.m_format_array.empty()) |
| 1237 | { |
| 1238 | DumpFullpath(strm, &module->GetFileSpec(), 0); |
| 1239 | } |
| 1240 | else |
| 1241 | { |
| 1242 | const size_t num_entries = m_options.m_format_array.size(); |
| 1243 | for (size_t i=0; i<num_entries; ++i) |
| 1244 | { |
| 1245 | if (i > 0) |
| 1246 | strm.PutChar(' '); |
| 1247 | char format_char = m_options.m_format_array[i].first; |
| 1248 | uint32_t width = m_options.m_format_array[i].second; |
| 1249 | switch (format_char) |
| 1250 | { |
| 1251 | case 'a': |
| 1252 | DumpModuleArchitecture (strm, module, width); |
| 1253 | break; |
| 1254 | |
| 1255 | case 'f': |
| 1256 | DumpFullpath (strm, &module->GetFileSpec(), width); |
| 1257 | break; |
| 1258 | |
| 1259 | case 'd': |
| 1260 | DumpDirectory (strm, &module->GetFileSpec(), width); |
| 1261 | break; |
| 1262 | |
| 1263 | case 'b': |
| 1264 | DumpBasename (strm, &module->GetFileSpec(), width); |
| 1265 | break; |
| 1266 | |
| 1267 | case 's': |
| 1268 | case 'S': |
| 1269 | { |
| 1270 | SymbolVendor *symbol_vendor = module->GetSymbolVendor(); |
| 1271 | if (symbol_vendor) |
| 1272 | { |
| 1273 | SymbolFile *symbol_file = symbol_vendor->GetSymbolFile(); |
| 1274 | if (symbol_file) |
| 1275 | { |
| 1276 | if (format_char == 'S') |
| 1277 | DumpBasename(strm, &symbol_file->GetObjectFile()->GetFileSpec(), width); |
| 1278 | else |
| 1279 | DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width); |
| 1280 | break; |
| 1281 | } |
| 1282 | } |
| 1283 | strm.Printf("%.*s", width, "<NONE>"); |
| 1284 | } |
| 1285 | break; |
| 1286 | |
| 1287 | case 'u': |
| 1288 | DumpModuleUUID(strm, module); |
| 1289 | break; |
| 1290 | |
| 1291 | default: |
| 1292 | break; |
| 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | strm.EOL(); |
| 1297 | } |
| 1298 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1299 | } |
| 1300 | else |
| 1301 | { |
| 1302 | result.AppendError ("the target has no associated executable images"); |
| 1303 | result.SetStatus (eReturnStatusFailed); |
| 1304 | return false; |
| 1305 | } |
| 1306 | } |
| 1307 | return result.Succeeded(); |
| 1308 | } |
| 1309 | protected: |
| 1310 | |
| 1311 | CommandOptions m_options; |
| 1312 | }; |
| 1313 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1314 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1315 | CommandObjectImageList::CommandOptions::g_option_table[] = |
| 1316 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 1317 | { LLDB_OPT_SET_1, false, "arch", 'a', optional_argument, NULL, 0, eArgTypeWidth, "Display the architecture when listing images."}, |
Greg Clayton | 0467c78 | 2011-02-04 18:53:10 +0000 | [diff] [blame] | 1318 | { LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."}, |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 1319 | { LLDB_OPT_SET_1, false, "fullpath", 'f', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image object file."}, |
| 1320 | { LLDB_OPT_SET_1, false, "directory", 'd', optional_argument, NULL, 0, eArgTypeWidth, "Display the directory with optional width for the image object file."}, |
| 1321 | { LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."}, |
| 1322 | { LLDB_OPT_SET_1, false, "symfile", 's', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."}, |
| 1323 | { LLDB_OPT_SET_1, false, "symfile-basename", 'S', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename to the image symbol file with optional width."}, |
| 1324 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1325 | }; |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | //---------------------------------------------------------------------- |
| 1330 | // Lookup information in images |
| 1331 | //---------------------------------------------------------------------- |
| 1332 | class CommandObjectImageLookup : public CommandObject |
| 1333 | { |
| 1334 | public: |
| 1335 | |
| 1336 | enum |
| 1337 | { |
| 1338 | eLookupTypeInvalid = -1, |
| 1339 | eLookupTypeAddress = 0, |
| 1340 | eLookupTypeSymbol, |
| 1341 | eLookupTypeFileLine, // Line is optional |
| 1342 | eLookupTypeFunction, |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1343 | eLookupTypeType, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1344 | kNumLookupTypes |
| 1345 | }; |
| 1346 | |
| 1347 | class CommandOptions : public Options |
| 1348 | { |
| 1349 | public: |
| 1350 | |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1351 | CommandOptions (CommandInterpreter &interpreter) : |
| 1352 | Options(m_interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1353 | { |
| 1354 | ResetOptionValues(); |
| 1355 | } |
| 1356 | |
| 1357 | virtual |
| 1358 | ~CommandOptions () |
| 1359 | { |
| 1360 | } |
| 1361 | |
| 1362 | virtual Error |
| 1363 | SetOptionValue (int option_idx, const char *option_arg) |
| 1364 | { |
| 1365 | Error error; |
| 1366 | |
| 1367 | char short_option = (char) m_getopt_table[option_idx].val; |
| 1368 | |
| 1369 | switch (short_option) |
| 1370 | { |
| 1371 | case 'a': |
| 1372 | m_type = eLookupTypeAddress; |
| 1373 | m_addr = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS); |
| 1374 | if (m_addr == LLDB_INVALID_ADDRESS) |
| 1375 | error.SetErrorStringWithFormat ("Invalid address string '%s'.\n", option_arg); |
| 1376 | break; |
| 1377 | |
| 1378 | case 'o': |
| 1379 | m_offset = Args::StringToUInt64(option_arg, LLDB_INVALID_ADDRESS); |
| 1380 | if (m_offset == LLDB_INVALID_ADDRESS) |
| 1381 | error.SetErrorStringWithFormat ("Invalid offset string '%s'.\n", option_arg); |
| 1382 | break; |
| 1383 | |
| 1384 | case 's': |
| 1385 | m_str = option_arg; |
| 1386 | m_type = eLookupTypeSymbol; |
| 1387 | break; |
| 1388 | |
| 1389 | case 'f': |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 1390 | m_file.SetFile (option_arg, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1391 | m_type = eLookupTypeFileLine; |
| 1392 | break; |
| 1393 | |
| 1394 | case 'i': |
| 1395 | m_check_inlines = false; |
| 1396 | break; |
| 1397 | |
| 1398 | case 'l': |
| 1399 | m_line_number = Args::StringToUInt32(option_arg, UINT32_MAX); |
| 1400 | if (m_line_number == UINT32_MAX) |
| 1401 | error.SetErrorStringWithFormat ("Invalid line number string '%s'.\n", option_arg); |
| 1402 | else if (m_line_number == 0) |
| 1403 | error.SetErrorString ("Zero is an invalid line number."); |
| 1404 | m_type = eLookupTypeFileLine; |
| 1405 | break; |
| 1406 | |
| 1407 | case 'n': |
| 1408 | m_str = option_arg; |
| 1409 | m_type = eLookupTypeFunction; |
| 1410 | break; |
| 1411 | |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1412 | case 't': |
| 1413 | m_str = option_arg; |
| 1414 | m_type = eLookupTypeType; |
| 1415 | break; |
| 1416 | |
| 1417 | case 'v': |
| 1418 | m_verbose = 1; |
| 1419 | break; |
| 1420 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1421 | case 'r': |
| 1422 | m_use_regex = true; |
| 1423 | break; |
| 1424 | } |
| 1425 | |
| 1426 | return error; |
| 1427 | } |
| 1428 | |
| 1429 | void |
| 1430 | ResetOptionValues () |
| 1431 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1432 | m_type = eLookupTypeInvalid; |
| 1433 | m_str.clear(); |
| 1434 | m_file.Clear(); |
| 1435 | m_addr = LLDB_INVALID_ADDRESS; |
| 1436 | m_offset = 0; |
| 1437 | m_line_number = 0; |
| 1438 | m_use_regex = false; |
| 1439 | m_check_inlines = true; |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1440 | m_verbose = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1443 | const OptionDefinition* |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1444 | GetDefinitions () |
| 1445 | { |
| 1446 | return g_option_table; |
| 1447 | } |
| 1448 | |
| 1449 | // Options table: Required for subclasses of Options. |
| 1450 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1451 | static OptionDefinition g_option_table[]; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1452 | int m_type; // Should be a eLookupTypeXXX enum after parsing options |
| 1453 | std::string m_str; // Holds name lookup |
| 1454 | FileSpec m_file; // Files for file lookups |
| 1455 | lldb::addr_t m_addr; // Holds the address to lookup |
| 1456 | lldb::addr_t m_offset; // Subtract this offset from m_addr before doing lookups. |
| 1457 | uint32_t m_line_number; // Line number for file+line lookups |
| 1458 | bool m_use_regex; // Name lookups in m_str are regular expressions. |
| 1459 | bool m_check_inlines;// Check for inline entries when looking up by file/line. |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1460 | bool m_verbose; // Enable verbose lookup info |
| 1461 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1462 | }; |
| 1463 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1464 | CommandObjectImageLookup (CommandInterpreter &interpreter) : |
| 1465 | CommandObject (interpreter, |
| 1466 | "image lookup", |
| 1467 | "Look up information within executable and dependent shared library images.", |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1468 | NULL), |
| 1469 | m_options (interpreter) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1470 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 1471 | CommandArgumentEntry arg; |
| 1472 | CommandArgumentData file_arg; |
| 1473 | |
| 1474 | // Define the first (and only) variant of this arg. |
| 1475 | file_arg.arg_type = eArgTypeFilename; |
| 1476 | file_arg.arg_repetition = eArgRepeatStar; |
| 1477 | |
| 1478 | // There is only one variant this argument could be; put it into the argument entry. |
| 1479 | arg.push_back (file_arg); |
| 1480 | |
| 1481 | // Push the data for the first argument into the m_arguments vector. |
| 1482 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | virtual |
| 1486 | ~CommandObjectImageLookup () |
| 1487 | { |
| 1488 | } |
| 1489 | |
Greg Clayton | 8d3802d | 2010-10-08 04:20:14 +0000 | [diff] [blame] | 1490 | virtual Options * |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1491 | GetOptions () |
| 1492 | { |
| 1493 | return &m_options; |
| 1494 | } |
| 1495 | |
| 1496 | |
| 1497 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1498 | LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1499 | { |
| 1500 | switch (m_options.m_type) |
| 1501 | { |
| 1502 | case eLookupTypeAddress: |
| 1503 | if (m_options.m_addr != LLDB_INVALID_ADDRESS) |
| 1504 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1505 | if (LookupAddressInModule (m_interpreter, |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1506 | result.GetOutputStream(), |
| 1507 | module, |
| 1508 | eSymbolContextEverything, |
| 1509 | m_options.m_addr, |
| 1510 | m_options.m_offset, |
| 1511 | m_options.m_verbose)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1512 | { |
| 1513 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1514 | return true; |
| 1515 | } |
| 1516 | } |
| 1517 | break; |
| 1518 | |
| 1519 | case eLookupTypeSymbol: |
| 1520 | if (!m_options.m_str.empty()) |
| 1521 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1522 | if (LookupSymbolInModule (m_interpreter, result.GetOutputStream(), module, m_options.m_str.c_str(), m_options.m_use_regex)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1523 | { |
| 1524 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1525 | return true; |
| 1526 | } |
| 1527 | } |
| 1528 | break; |
| 1529 | |
| 1530 | case eLookupTypeFileLine: |
| 1531 | if (m_options.m_file) |
| 1532 | { |
| 1533 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1534 | if (LookupFileAndLineInModule (m_interpreter, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1535 | result.GetOutputStream(), |
| 1536 | module, |
| 1537 | m_options.m_file, |
| 1538 | m_options.m_line_number, |
| 1539 | m_options.m_check_inlines)) |
| 1540 | { |
| 1541 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1542 | return true; |
| 1543 | } |
| 1544 | } |
| 1545 | break; |
| 1546 | |
| 1547 | case eLookupTypeFunction: |
| 1548 | if (!m_options.m_str.empty()) |
| 1549 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1550 | if (LookupFunctionInModule (m_interpreter, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1551 | result.GetOutputStream(), |
| 1552 | module, |
| 1553 | m_options.m_str.c_str(), |
| 1554 | m_options.m_use_regex)) |
| 1555 | { |
| 1556 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1557 | return true; |
| 1558 | } |
| 1559 | } |
| 1560 | break; |
| 1561 | |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1562 | case eLookupTypeType: |
| 1563 | if (!m_options.m_str.empty()) |
| 1564 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1565 | if (LookupTypeInModule (m_interpreter, |
Greg Clayton | 960d6a4 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 1566 | result.GetOutputStream(), |
| 1567 | module, |
| 1568 | m_options.m_str.c_str(), |
| 1569 | m_options.m_use_regex)) |
| 1570 | { |
| 1571 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1572 | return true; |
| 1573 | } |
| 1574 | } |
| 1575 | break; |
| 1576 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1577 | default: |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 1578 | m_options.GenerateOptionUsage (result.GetErrorStream(), this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1579 | syntax_error = true; |
| 1580 | break; |
| 1581 | } |
| 1582 | |
| 1583 | result.SetStatus (eReturnStatusFailed); |
| 1584 | return false; |
| 1585 | } |
| 1586 | |
| 1587 | virtual bool |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1588 | Execute (Args& command, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1589 | CommandReturnObject &result) |
| 1590 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1591 | Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1592 | if (target == NULL) |
| 1593 | { |
| 1594 | result.AppendError ("invalid target, set executable file using 'file' command"); |
| 1595 | result.SetStatus (eReturnStatusFailed); |
| 1596 | return false; |
| 1597 | } |
| 1598 | else |
| 1599 | { |
| 1600 | bool syntax_error = false; |
| 1601 | uint32_t i; |
| 1602 | uint32_t num_successful_lookups = 0; |
| 1603 | uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize(); |
| 1604 | result.GetOutputStream().SetAddressByteSize(addr_byte_size); |
| 1605 | result.GetErrorStream().SetAddressByteSize(addr_byte_size); |
| 1606 | // Dump all sections for all modules images |
| 1607 | |
| 1608 | if (command.GetArgumentCount() == 0) |
| 1609 | { |
| 1610 | // Dump all sections for all modules images |
| 1611 | const uint32_t num_modules = target->GetImages().GetSize(); |
| 1612 | if (num_modules > 0) |
| 1613 | { |
| 1614 | for (i = 0; i<num_modules && syntax_error == false; ++i) |
| 1615 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1616 | if (LookupInModule (m_interpreter, target->GetImages().GetModulePointerAtIndex(i), result, syntax_error)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1617 | { |
| 1618 | result.GetOutputStream().EOL(); |
| 1619 | num_successful_lookups++; |
| 1620 | } |
| 1621 | } |
| 1622 | } |
| 1623 | else |
| 1624 | { |
| 1625 | result.AppendError ("the target has no associated executable images"); |
| 1626 | result.SetStatus (eReturnStatusFailed); |
| 1627 | return false; |
| 1628 | } |
| 1629 | } |
| 1630 | else |
| 1631 | { |
| 1632 | // Dump specified images (by basename or fullpath) |
| 1633 | const char *arg_cstr; |
| 1634 | for (i = 0; (arg_cstr = command.GetArgumentAtIndex(i)) != NULL && syntax_error == false; ++i) |
| 1635 | { |
Greg Clayton | 537a7a8 | 2010-10-20 20:54:39 +0000 | [diff] [blame] | 1636 | FileSpec image_file(arg_cstr, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1637 | ModuleList matching_modules; |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 1638 | size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1639 | |
Greg Clayton | 661825b | 2010-06-28 23:51:11 +0000 | [diff] [blame] | 1640 | // Not found in our module list for our target, check the main |
| 1641 | // shared module list in case it is a extra file used somewhere |
| 1642 | // else |
| 1643 | if (num_matching_modules == 0) |
| 1644 | num_matching_modules = ModuleList::FindSharedModules (image_file, |
| 1645 | target->GetArchitecture(), |
| 1646 | NULL, |
| 1647 | NULL, |
| 1648 | matching_modules); |
| 1649 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1650 | if (num_matching_modules > 0) |
| 1651 | { |
Greg Clayton | bef1583 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 1652 | for (size_t j=0; j<num_matching_modules; ++j) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1653 | { |
Greg Clayton | bef1583 | 2010-07-14 00:18:15 +0000 | [diff] [blame] | 1654 | Module * image_module = matching_modules.GetModulePointerAtIndex(j); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1655 | if (image_module) |
| 1656 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1657 | if (LookupInModule (m_interpreter, image_module, result, syntax_error)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1658 | { |
| 1659 | result.GetOutputStream().EOL(); |
| 1660 | num_successful_lookups++; |
| 1661 | } |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | else |
| 1666 | result.AppendWarningWithFormat("Unable to find an image that matches '%s'.\n", arg_cstr); |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | if (num_successful_lookups > 0) |
| 1671 | result.SetStatus (eReturnStatusSuccessFinishResult); |
| 1672 | else |
| 1673 | result.SetStatus (eReturnStatusFailed); |
| 1674 | } |
| 1675 | return result.Succeeded(); |
| 1676 | } |
| 1677 | protected: |
| 1678 | |
| 1679 | CommandOptions m_options; |
| 1680 | }; |
| 1681 | |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 1682 | OptionDefinition |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1683 | CommandObjectImageLookup::CommandOptions::g_option_table[] = |
| 1684 | { |
Caroline Tice | 4d6675c | 2010-10-01 19:59:14 +0000 | [diff] [blame] | 1685 | { LLDB_OPT_SET_1, true, "address", 'a', required_argument, NULL, 0, eArgTypeAddress, "Lookup an address in one or more executable images."}, |
| 1686 | { LLDB_OPT_SET_1, false, "offset", 'o', required_argument, NULL, 0, eArgTypeOffset, "When looking up an address subtract <offset> from any addresses before doing the lookup."}, |
| 1687 | { LLDB_OPT_SET_2, true, "symbol", 's', required_argument, NULL, 0, eArgTypeSymbol, "Lookup a symbol by name in the symbol tables in one or more executable images."}, |
| 1688 | { LLDB_OPT_SET_2, false, "regex", 'r', no_argument, NULL, 0, eArgTypeNone, "The <name> argument for name lookups are regular expressions."}, |
| 1689 | { LLDB_OPT_SET_3, true, "file", 'f', required_argument, NULL, 0, eArgTypeFilename, "Lookup a file by fullpath or basename in one or more executable images."}, |
| 1690 | { LLDB_OPT_SET_3, false, "line", 'l', required_argument, NULL, 0, eArgTypeLineNum, "Lookup a line number in a file (must be used in conjunction with --file)."}, |
| 1691 | { LLDB_OPT_SET_3, false, "no-inlines", 'i', no_argument, NULL, 0, eArgTypeNone, "Check inline line entries (must be used in conjunction with --file)."}, |
| 1692 | { LLDB_OPT_SET_4, true, "function", 'n', required_argument, NULL, 0, eArgTypeFunctionName, "Lookup a function by name in the debug symbols in one or more executable images."}, |
| 1693 | { LLDB_OPT_SET_5, true, "type", 't', required_argument, NULL, 0, eArgTypeName, "Lookup a type by name in the debug symbols in one or more executable images."}, |
| 1694 | { LLDB_OPT_SET_ALL, false, "verbose", 'v', no_argument, NULL, 0, eArgTypeNone, "Enable verbose lookup information."}, |
| 1695 | { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1696 | }; |
| 1697 | |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | //---------------------------------------------------------------------- |
| 1703 | // CommandObjectImage constructor |
| 1704 | //---------------------------------------------------------------------- |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1705 | CommandObjectImage::CommandObjectImage(CommandInterpreter &interpreter) : |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1706 | CommandObjectMultiword (interpreter, |
| 1707 | "image", |
Caroline Tice | c1ad82e | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 1708 | "A set of commands for accessing information for one or more executable images.", |
| 1709 | "image <sub-command> ...") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1710 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1711 | LoadSubCommand ("dump", CommandObjectSP (new CommandObjectImageDump (interpreter))); |
| 1712 | LoadSubCommand ("list", CommandObjectSP (new CommandObjectImageList (interpreter))); |
| 1713 | LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectImageLookup (interpreter))); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | //---------------------------------------------------------------------- |
| 1717 | // Destructor |
| 1718 | //---------------------------------------------------------------------- |
| 1719 | CommandObjectImage::~CommandObjectImage() |
| 1720 | { |
| 1721 | } |
| 1722 | |