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