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