blob: ae1612e4cf69b2fe388e35ed6286a329bf49163c [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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 Clayton63094e02010-06-23 01:19:29 +000016#include "lldb/Core/Debugger.h"
Greg Clayton5f54ac32011-02-08 05:05:52 +000017#include "lldb/Host/FileSpec.h"
Greg Clayton63094e02010-06-23 01:19:29 +000018#include "lldb/Core/Module.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/RegularExpression.h"
20#include "lldb/Core/Stream.h"
Greg Clayton63094e02010-06-23 01:19:29 +000021#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 Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Symbol/SymbolFile.h"
29#include "lldb/Symbol/SymbolVendor.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Target/Process.h"
31#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032
33using namespace lldb;
34using namespace lldb_private;
35
36//----------------------------------------------------------------------
37// Static Helper functions
38//----------------------------------------------------------------------
39static void
40DumpModuleArchitecture (Stream &strm, Module *module, uint32_t width)
41{
42 if (module)
43 {
44 if (width)
Greg Clayton940b1032011-02-23 00:35:02 +000045 strm.Printf("%-*s", width, module->GetArchitecture().GetArchitectureName());
Chris Lattner24943d22010-06-08 16:52:24 +000046 else
Greg Clayton940b1032011-02-23 00:35:02 +000047 strm.PutCString(module->GetArchitecture().GetArchitectureName());
Chris Lattner24943d22010-06-08 16:52:24 +000048 }
49}
50
51static void
52DumpModuleUUID (Stream &strm, Module *module)
53{
54 module->GetUUID().Dump (&strm);
55}
56
57static uint32_t
58DumpCompileUnitLineTable
59(
Greg Clayton63094e02010-06-23 01:19:29 +000060 CommandInterpreter &interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +000061 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 Chencff44fd2010-10-29 22:18:43 +000085 strm << "Line table for " << *static_cast<FileSpec*> (sc.comp_unit) << " in `"
Chris Lattner24943d22010-06-08 16:52:24 +000086 << module->GetFileSpec().GetFilename() << "\n";
87 LineTable *line_table = sc.comp_unit->GetLineTable();
88 if (line_table)
Greg Clayton63094e02010-06-23 01:19:29 +000089 line_table->GetDescription (&strm,
Greg Claytonb72d0f02011-04-12 05:54:46 +000090 interpreter.GetExecutionContext().target,
Greg Clayton63094e02010-06-23 01:19:29 +000091 lldb::eDescriptionLevelBrief);
Chris Lattner24943d22010-06-08 16:52:24 +000092 else
93 strm << "No line table";
94 }
95 }
96 }
97 return num_matches;
98}
99
100static void
101DumpFullpath (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
125static void
126DumpDirectory (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
141static void
142DumpBasename (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
158static void
Greg Claytonb3448432011-03-24 21:19:54 +0000159DumpModuleSymtab (CommandInterpreter &interpreter, Stream &strm, Module *module, SortOrder sort_order)
Chris Lattner24943d22010-06-08 16:52:24 +0000160{
161 if (module)
162 {
163 ObjectFile *objfile = module->GetObjectFile ();
164 if (objfile)
165 {
166 Symtab *symtab = objfile->GetSymtab();
167 if (symtab)
Greg Claytonb72d0f02011-04-12 05:54:46 +0000168 symtab->Dump(&strm, interpreter.GetExecutionContext().target, sort_order);
Chris Lattner24943d22010-06-08 16:52:24 +0000169 }
170 }
171}
172
173static void
Greg Clayton63094e02010-06-23 01:19:29 +0000174DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *module)
Chris Lattner24943d22010-06-08 16:52:24 +0000175{
176 if (module)
177 {
178 ObjectFile *objfile = module->GetObjectFile ();
179 if (objfile)
180 {
181 SectionList *section_list = objfile->GetSectionList();
182 if (section_list)
Greg Clayton3fed8b92010-10-08 00:21:05 +0000183 {
184 strm.PutCString ("Sections for '");
185 strm << module->GetFileSpec();
Greg Claytonb72d0f02011-04-12 05:54:46 +0000186 if (module->GetObjectName())
187 strm << '(' << module->GetObjectName() << ')';
Greg Clayton940b1032011-02-23 00:35:02 +0000188 strm.Printf ("' (%s):\n", module->GetArchitecture().GetArchitectureName());
Greg Clayton3fed8b92010-10-08 00:21:05 +0000189 strm.IndentMore();
Greg Claytonb72d0f02011-04-12 05:54:46 +0000190 section_list->Dump(&strm, interpreter.GetExecutionContext().target, true, UINT32_MAX);
Greg Clayton3fed8b92010-10-08 00:21:05 +0000191 strm.IndentLess();
192 }
Chris Lattner24943d22010-06-08 16:52:24 +0000193 }
194 }
195}
196
197static bool
198DumpModuleSymbolVendor (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
212static bool
Greg Clayton960d6a42010-08-03 00:35:52 +0000213LookupAddressInModule
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 Lattner24943d22010-06-08 16:52:24 +0000223{
224 if (module)
225 {
226 lldb::addr_t addr = raw_addr - offset;
227 Address so_addr;
228 SymbolContext sc;
Greg Claytonb72d0f02011-04-12 05:54:46 +0000229 Target *target = interpreter.GetExecutionContext().target;
Greg Claytoneea26402010-09-14 23:36:40 +0000230 if (target && !target->GetSectionLoadList().IsEmpty())
Chris Lattner24943d22010-06-08 16:52:24 +0000231 {
Greg Claytoneea26402010-09-14 23:36:40 +0000232 if (!target->GetSectionLoadList().ResolveLoadAddress (addr, so_addr))
Chris Lattner24943d22010-06-08 16:52:24 +0000233 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 Clayton7e2f91c2011-01-29 07:10:55 +0000245 strm.Printf("File Address: 0x%llx\n", addr);
Chris Lattner24943d22010-06-08 16:52:24 +0000246
Greg Claytonb72d0f02011-04-12 05:54:46 +0000247 ExecutionContextScope *exe_scope = interpreter.GetExecutionContext().GetBestExecutionContextScope();
Greg Clayton12bec712010-06-28 21:30:43 +0000248 strm.IndentMore();
249 strm.Indent (" Address: ");
250 so_addr.Dump (&strm, exe_scope, Address::DumpStyleSectionNameOffset);
251 strm.EOL();
Greg Clayton70436352010-06-30 23:03:03 +0000252 strm.Indent (" Summary: ");
Greg Clayton3c126042011-02-08 02:40:32 +0000253 const uint32_t save_indent = strm.GetIndentLevel ();
254 strm.SetIndentLevel (save_indent + 11);
Chris Lattner24943d22010-06-08 16:52:24 +0000255 so_addr.Dump (&strm, exe_scope, Address::DumpStyleResolvedDescription);
Greg Clayton3c126042011-02-08 02:40:32 +0000256 strm.SetIndentLevel (save_indent);
Greg Clayton70436352010-06-30 23:03:03 +0000257 strm.EOL();
Greg Clayton960d6a42010-08-03 00:35:52 +0000258 // 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 Clayton12bec712010-06-28 21:30:43 +0000264 strm.IndentLess();
Chris Lattner24943d22010-06-08 16:52:24 +0000265 return true;
266 }
267
268 return false;
269}
270
271static uint32_t
Greg Clayton63094e02010-06-23 01:19:29 +0000272LookupSymbolInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex)
Chris Lattner24943d22010-06-08 16:52:24 +0000273{
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 Clayton7c36fa02010-09-11 03:13:28 +0000291 num_matches = symtab->AppendSymbolIndexesMatchingRegExAndType (name_regexp,
292 eSymbolTypeAny,
Chris Lattner24943d22010-06-08 16:52:24 +0000293 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 Claytonb72d0f02011-04-12 05:54:46 +0000314 symbol->Dump (&strm, interpreter.GetExecutionContext().target, i);
Chris Lattner24943d22010-06-08 16:52:24 +0000315 }
316 strm.IndentLess ();
317 return num_matches;
318 }
319 }
320 }
321 }
322 return 0;
323}
324
325
326static void
Greg Clayton63094e02010-06-23 01:19:29 +0000327DumpSymbolContextList (CommandInterpreter &interpreter, Stream &strm, SymbolContextList &sc_list, bool prepend_addr)
Chris Lattner24943d22010-06-08 16:52:24 +0000328{
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 Claytonb72d0f02011-04-12 05:54:46 +0000343 lldb::addr_t vm_addr = sc.line_entry.range.GetBaseAddress().GetLoadAddress(interpreter.GetExecutionContext().target);
Chris Lattner24943d22010-06-08 16:52:24 +0000344 int addr_size = sizeof (addr_t);
Greg Claytonb72d0f02011-04-12 05:54:46 +0000345 Process *process = interpreter.GetExecutionContext().process;
Chris Lattner24943d22010-06-08 16:52:24 +0000346 if (process)
Greg Clayton395fc332011-02-15 21:59:32 +0000347 addr_size = process->GetTarget().GetArchitecture().GetAddressByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000348 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 Claytonb72d0f02011-04-12 05:54:46 +0000356 sc.DumpStopContext(&strm, interpreter.GetExecutionContext().process, sc.line_entry.range.GetBaseAddress(), true, true, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000357 }
358 }
359 strm.IndentLess ();
360}
361
362static uint32_t
Greg Clayton63094e02010-06-23 01:19:29 +0000363LookupFunctionInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const char *name, bool name_is_regex)
Chris Lattner24943d22010-06-08 16:52:24 +0000364{
365 if (module && name && name[0])
366 {
367 SymbolContextList sc_list;
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000368 const bool include_symbols = false;
369 const bool append = true;
370 uint32_t num_matches = 0;
371 if (name_is_regex)
Chris Lattner24943d22010-06-08 16:52:24 +0000372 {
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000373 RegularExpression function_name_regex (name);
374 num_matches = module->FindFunctions (function_name_regex,
375 include_symbols,
376 append,
377 sc_list);
Chris Lattner24943d22010-06-08 16:52:24 +0000378 }
Greg Clayton28d5fcc2011-01-27 06:44:37 +0000379 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 Lattner24943d22010-06-08 16:52:24 +0000398 }
399 return 0;
400}
401
402static uint32_t
Greg Clayton960d6a42010-08-03 00:35:52 +0000403LookupTypeInModule
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 Clayton04c9c7b2011-02-16 23:00:21 +0000447 type_sp->GetClangFullType ();
Greg Clayton960d6a42010-08-03 00:35:52 +0000448 type_sp->GetDescription (&strm, eDescriptionLevelFull, true);
449 }
450 strm.EOL();
451 }
452 }
453 return num_matches;
454 }
455 }
456 return 0;
457}
458
459static uint32_t
Greg Clayton63094e02010-06-23 01:19:29 +0000460LookupFileAndLineInModule (CommandInterpreter &interpreter, Stream &strm, Module *module, const FileSpec &file_spec, uint32_t line, bool check_inlines)
Chris Lattner24943d22010-06-08 16:52:24 +0000461{
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 Clayton63094e02010-06-23 01:19:29 +0000477 DumpSymbolContextList (interpreter, strm, sc_list, true);
Chris Lattner24943d22010-06-08 16:52:24 +0000478 return num_matches;
479 }
480 }
481 return 0;
482
483}
484
485
486//----------------------------------------------------------------------
487// Image symbol table dumping command
488//----------------------------------------------------------------------
489
490class CommandObjectImageDumpModuleList : public CommandObject
491{
492public:
493
Greg Clayton238c0a12010-09-18 01:14:36 +0000494 CommandObjectImageDumpModuleList (CommandInterpreter &interpreter,
495 const char *name,
Greg Clayton63094e02010-06-23 01:19:29 +0000496 const char *help,
497 const char *syntax) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000498 CommandObject (interpreter, name, help, syntax)
Chris Lattner24943d22010-06-08 16:52:24 +0000499 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000500 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 Lattner24943d22010-06-08 16:52:24 +0000512 }
513
514 virtual
515 ~CommandObjectImageDumpModuleList ()
516 {
517 }
518
519 virtual int
Greg Clayton238c0a12010-09-18 01:14:36 +0000520 HandleArgumentCompletion (Args &input,
Greg Clayton63094e02010-06-23 01:19:29 +0000521 int &cursor_index,
522 int &cursor_char_position,
523 OptionElementVector &opt_element_vector,
524 int match_start_point,
525 int max_return_elements,
Jim Ingham802f8b02010-06-30 05:02:46 +0000526 bool &word_complete,
Greg Clayton63094e02010-06-23 01:19:29 +0000527 StringList &matches)
Chris Lattner24943d22010-06-08 16:52:24 +0000528 {
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 Clayton238c0a12010-09-18 01:14:36 +0000533 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Greg Clayton63094e02010-06-23 01:19:29 +0000534 CommandCompletions::eModuleCompletion,
535 completion_str.c_str(),
536 match_start_point,
537 max_return_elements,
538 NULL,
Jim Ingham802f8b02010-06-30 05:02:46 +0000539 word_complete,
Greg Clayton63094e02010-06-23 01:19:29 +0000540 matches);
Chris Lattner24943d22010-06-08 16:52:24 +0000541 return matches.GetSize();
542 }
543};
544
545class CommandObjectImageDumpSourceFileList : public CommandObject
546{
547public:
548
Greg Clayton238c0a12010-09-18 01:14:36 +0000549 CommandObjectImageDumpSourceFileList (CommandInterpreter &interpreter,
550 const char *name,
Greg Clayton63094e02010-06-23 01:19:29 +0000551 const char *help,
552 const char *syntax) :
Greg Clayton238c0a12010-09-18 01:14:36 +0000553 CommandObject (interpreter, name, help, syntax)
Chris Lattner24943d22010-06-08 16:52:24 +0000554 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000555 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 Lattner24943d22010-06-08 16:52:24 +0000567 }
568
569 virtual
570 ~CommandObjectImageDumpSourceFileList ()
571 {
572 }
573
574 virtual int
Greg Clayton238c0a12010-09-18 01:14:36 +0000575 HandleArgumentCompletion (Args &input,
Greg Clayton63094e02010-06-23 01:19:29 +0000576 int &cursor_index,
577 int &cursor_char_position,
578 OptionElementVector &opt_element_vector,
579 int match_start_point,
580 int max_return_elements,
Greg Clayton54e7afa2010-07-09 20:39:50 +0000581 bool &word_complete,
Greg Clayton63094e02010-06-23 01:19:29 +0000582 StringList &matches)
Chris Lattner24943d22010-06-08 16:52:24 +0000583 {
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 Clayton238c0a12010-09-18 01:14:36 +0000588 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
Greg Clayton63094e02010-06-23 01:19:29 +0000589 CommandCompletions::eSourceFileCompletion,
590 completion_str.c_str(),
591 match_start_point,
592 max_return_elements,
593 NULL,
Jim Ingham802f8b02010-06-30 05:02:46 +0000594 word_complete,
Greg Clayton63094e02010-06-23 01:19:29 +0000595 matches);
Chris Lattner24943d22010-06-08 16:52:24 +0000596 return matches.GetSize();
597 }
598};
599
600
601class CommandObjectImageDumpSymtab : public CommandObjectImageDumpModuleList
602{
603public:
Greg Clayton238c0a12010-09-18 01:14:36 +0000604 CommandObjectImageDumpSymtab (CommandInterpreter &interpreter) :
605 CommandObjectImageDumpModuleList (interpreter,
606 "image dump symtab",
607 "Dump the symbol table from one or more executable images.",
Greg Claytonf15996e2011-04-07 22:46:35 +0000608 NULL),
609 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +0000610 {
611 }
612
613 virtual
614 ~CommandObjectImageDumpSymtab ()
615 {
616 }
617
618 virtual bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000619 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000620 CommandReturnObject &result)
621 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000622 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000623 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 Clayton8d3802d2010-10-08 04:20:14 +0000646 if (num_dumped > 0)
647 {
648 result.GetOutputStream().EOL();
649 result.GetOutputStream().EOL();
650 }
Chris Lattner24943d22010-06-08 16:52:24 +0000651 num_dumped++;
Greg Clayton8d3802d2010-10-08 04:20:14 +0000652 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx), m_options.m_sort_order);
Chris Lattner24943d22010-06-08 16:52:24 +0000653 }
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 Clayton537a7a82010-10-20 20:54:39 +0000668 FileSpec image_file(arg_cstr, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000669 ModuleList matching_modules;
Greg Clayton661825b2010-06-28 23:51:11 +0000670 size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules);
Chris Lattner24943d22010-06-08 16:52:24 +0000671
Greg Clayton661825b2010-06-28 23:51:11 +0000672 // 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 Lattner24943d22010-06-08 16:52:24 +0000682 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 Clayton8d3802d2010-10-08 04:20:14 +0000689 if (num_dumped > 0)
690 {
691 result.GetOutputStream().EOL();
692 result.GetOutputStream().EOL();
693 }
Chris Lattner24943d22010-06-08 16:52:24 +0000694 num_dumped++;
Greg Clayton8d3802d2010-10-08 04:20:14 +0000695 DumpModuleSymtab (m_interpreter, result.GetOutputStream(), image_module, m_options.m_sort_order);
Chris Lattner24943d22010-06-08 16:52:24 +0000696 }
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 Clayton8d3802d2010-10-08 04:20:14 +0000714
715 virtual Options *
716 GetOptions ()
717 {
718 return &m_options;
719 }
720
721 class CommandOptions : public Options
722 {
723 public:
Chris Lattner24943d22010-06-08 16:52:24 +0000724
Greg Claytonf15996e2011-04-07 22:46:35 +0000725 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +0000726 Options(interpreter),
Greg Clayton8d3802d2010-10-08 04:20:14 +0000727 m_sort_order (eSortOrderNone)
728 {
729 }
730
731 virtual
732 ~CommandOptions ()
733 {
734 }
735
736 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +0000737 SetOptionValue (uint32_t option_idx, const char *option_arg)
Greg Clayton8d3802d2010-10-08 04:20:14 +0000738 {
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 Claytonb3448432011-03-24 21:19:54 +0000747 m_sort_order = (SortOrder) Args::StringToOptionEnum (option_arg,
Greg Clayton8d3802d2010-10-08 04:20:14 +0000748 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 Clayton143fcc32011-04-13 00:18:08 +0000767 OptionParsingStarting ()
Greg Clayton8d3802d2010-10-08 04:20:14 +0000768 {
Greg Clayton8d3802d2010-10-08 04:20:14 +0000769 m_sort_order = eSortOrderNone;
770 }
771
Greg Claytonb3448432011-03-24 21:19:54 +0000772 const OptionDefinition*
Greg Clayton8d3802d2010-10-08 04:20:14 +0000773 GetDefinitions ()
774 {
775 return g_option_table;
776 }
777
778 // Options table: Required for subclasses of Options.
Greg Claytonb3448432011-03-24 21:19:54 +0000779 static OptionDefinition g_option_table[];
Greg Clayton8d3802d2010-10-08 04:20:14 +0000780
781 SortOrder m_sort_order;
782 };
783
784protected:
785
786 CommandOptions m_options;
Chris Lattner24943d22010-06-08 16:52:24 +0000787};
788
Greg Claytonb3448432011-03-24 21:19:54 +0000789static OptionEnumValueElement
Greg Clayton8d3802d2010-10-08 04:20:14 +0000790g_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 Claytonb3448432011-03-24 21:19:54 +0000799OptionDefinition
Greg Clayton8d3802d2010-10-08 04:20:14 +0000800CommandObjectImageDumpSymtab::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 Lattner24943d22010-06-08 16:52:24 +0000807//----------------------------------------------------------------------
808// Image section dumping command
809//----------------------------------------------------------------------
810class CommandObjectImageDumpSections : public CommandObjectImageDumpModuleList
811{
812public:
Greg Clayton238c0a12010-09-18 01:14:36 +0000813 CommandObjectImageDumpSections (CommandInterpreter &interpreter) :
814 CommandObjectImageDumpModuleList (interpreter,
815 "image dump sections",
Greg Clayton63094e02010-06-23 01:19:29 +0000816 "Dump the sections from one or more executable images.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000817 //"image dump sections [<file1> ...]")
818 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000819 {
820 }
821
822 virtual
823 ~CommandObjectImageDumpSections ()
824 {
825 }
826
827 virtual bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000828 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000829 CommandReturnObject &result)
830 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000831 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000832 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 Clayton238c0a12010-09-18 01:14:36 +0000856 DumpModuleSections (m_interpreter, result.GetOutputStream(), target->GetImages().GetModulePointerAtIndex(image_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000857 }
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 Clayton537a7a82010-10-20 20:54:39 +0000872 FileSpec image_file(arg_cstr, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000873 ModuleList matching_modules;
Greg Clayton661825b2010-06-28 23:51:11 +0000874 size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules);
Chris Lattner24943d22010-06-08 16:52:24 +0000875
Greg Clayton661825b2010-06-28 23:51:11 +0000876 // 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 Lattner24943d22010-06-08 16:52:24 +0000886 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 Clayton238c0a12010-09-18 01:14:36 +0000894 DumpModuleSections (m_interpreter, result.GetOutputStream(), image_module);
Chris Lattner24943d22010-06-08 16:52:24 +0000895 }
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//----------------------------------------------------------------------
918class CommandObjectImageDumpSymfile : public CommandObjectImageDumpModuleList
919{
920public:
Greg Clayton238c0a12010-09-18 01:14:36 +0000921 CommandObjectImageDumpSymfile (CommandInterpreter &interpreter) :
922 CommandObjectImageDumpModuleList (interpreter,
923 "image dump symfile",
924 "Dump the debug symbol file for one or more executable images.",
Caroline Tice43b014a2010-10-04 22:28:36 +0000925 //"image dump symfile [<file1> ...]")
926 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000927 {
928 }
929
930 virtual
931 ~CommandObjectImageDumpSymfile ()
932 {
933 }
934
935 virtual bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000936 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +0000937 CommandReturnObject &result)
938 {
Greg Clayton238c0a12010-09-18 01:14:36 +0000939 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +0000940 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 Clayton537a7a82010-10-20 20:54:39 +0000980 FileSpec image_file(arg_cstr, false);
Chris Lattner24943d22010-06-08 16:52:24 +0000981 ModuleList matching_modules;
Greg Clayton661825b2010-06-28 23:51:11 +0000982 size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules);
Chris Lattner24943d22010-06-08 16:52:24 +0000983
Greg Clayton661825b2010-06-28 23:51:11 +0000984 // 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 Lattner24943d22010-06-08 16:52:24 +0000994 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//----------------------------------------------------------------------
1026class CommandObjectImageDumpLineTable : public CommandObjectImageDumpSourceFileList
1027{
1028public:
Greg Clayton238c0a12010-09-18 01:14:36 +00001029 CommandObjectImageDumpLineTable (CommandInterpreter &interpreter) :
1030 CommandObjectImageDumpSourceFileList (interpreter,
1031 "image dump line-table",
1032 "Dump the debug symbol file for one or more executable images.",
Caroline Tice43b014a2010-10-04 22:28:36 +00001033 NULL)
Chris Lattner24943d22010-06-08 16:52:24 +00001034 {
1035 }
1036
1037 virtual
1038 ~CommandObjectImageDumpLineTable ()
1039 {
1040 }
1041
1042 virtual bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001043 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001044 CommandReturnObject &result)
1045 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001046 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001047 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 Claytonb72d0f02011-04-12 05:54:46 +00001055 ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
Chris Lattner24943d22010-06-08 16:52:24 +00001056 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 Clayton537a7a82010-10-20 20:54:39 +00001073 FileSpec file_spec(arg_cstr, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001074 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 Clayton238c0a12010-09-18 01:14:36 +00001080 if (DumpCompileUnitLineTable (m_interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +00001081 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//----------------------------------------------------------------------
1110class CommandObjectImageDump : public CommandObjectMultiword
1111{
1112public:
1113
1114 //------------------------------------------------------------------
1115 // Constructors and Destructors
1116 //------------------------------------------------------------------
Greg Clayton63094e02010-06-23 01:19:29 +00001117 CommandObjectImageDump(CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001118 CommandObjectMultiword (interpreter,
1119 "image dump",
Caroline Ticeabb507a2010-09-08 21:06:11 +00001120 "A set of commands for dumping information about one or more executable images; 'line-table' expects a source file name",
Greg Clayton63094e02010-06-23 01:19:29 +00001121 "image dump [symtab|sections|symfile|line-table] [<file1> <file2> ...]")
Chris Lattner24943d22010-06-08 16:52:24 +00001122 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001123 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 Lattner24943d22010-06-08 16:52:24 +00001127 }
1128
1129 virtual
1130 ~CommandObjectImageDump()
1131 {
1132 }
1133};
1134
1135//----------------------------------------------------------------------
1136// List images with associated information
1137//----------------------------------------------------------------------
1138class CommandObjectImageList : public CommandObject
1139{
1140public:
1141
1142 class CommandOptions : public Options
1143 {
1144 public:
1145
Greg Claytonf15996e2011-04-07 22:46:35 +00001146 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +00001147 Options(interpreter),
Chris Lattner24943d22010-06-08 16:52:24 +00001148 m_format_array()
1149 {
1150 }
1151
1152 virtual
1153 ~CommandOptions ()
1154 {
1155 }
1156
1157 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001158 SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +00001159 {
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 Clayton143fcc32011-04-13 00:18:08 +00001170 OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +00001171 {
Chris Lattner24943d22010-06-08 16:52:24 +00001172 m_format_array.clear();
1173 }
1174
Greg Claytonb3448432011-03-24 21:19:54 +00001175 const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +00001176 GetDefinitions ()
1177 {
1178 return g_option_table;
1179 }
1180
1181 // Options table: Required for subclasses of Options.
1182
Greg Claytonb3448432011-03-24 21:19:54 +00001183 static OptionDefinition g_option_table[];
Chris Lattner24943d22010-06-08 16:52:24 +00001184
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 Clayton238c0a12010-09-18 01:14:36 +00001190 CommandObjectImageList (CommandInterpreter &interpreter) :
1191 CommandObject (interpreter,
1192 "image list",
1193 "List current executable and dependent shared library images.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001194 "image list [<cmd-options>]"),
1195 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +00001196 {
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 Clayton238c0a12010-09-18 01:14:36 +00001212 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001213 CommandReturnObject &result)
1214 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001215 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001216 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 Claytonb72d0f02011-04-12 05:54:46 +00001238 bool dump_object_name = false;
Chris Lattner24943d22010-06-08 16:52:24 +00001239 if (m_options.m_format_array.empty())
1240 {
1241 DumpFullpath(strm, &module->GetFileSpec(), 0);
Greg Claytonb72d0f02011-04-12 05:54:46 +00001242 dump_object_name = true;
Chris Lattner24943d22010-06-08 16:52:24 +00001243 }
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 Claytonb72d0f02011-04-12 05:54:46 +00001261 dump_object_name = true;
Chris Lattner24943d22010-06-08 16:52:24 +00001262 break;
1263
1264 case 'd':
1265 DumpDirectory (strm, &module->GetFileSpec(), width);
1266 break;
1267
1268 case 'b':
1269 DumpBasename (strm, &module->GetFileSpec(), width);
Greg Claytonb72d0f02011-04-12 05:54:46 +00001270 dump_object_name = true;
Chris Lattner24943d22010-06-08 16:52:24 +00001271 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 Claytonb72d0f02011-04-12 05:54:46 +00001286 dump_object_name = true;
Chris Lattner24943d22010-06-08 16:52:24 +00001287 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 Claytonb72d0f02011-04-12 05:54:46 +00001301
Chris Lattner24943d22010-06-08 16:52:24 +00001302 }
1303 }
Greg Claytonb72d0f02011-04-12 05:54:46 +00001304 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 Lattner24943d22010-06-08 16:52:24 +00001310 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 }
1323protected:
1324
1325 CommandOptions m_options;
1326};
1327
Greg Claytonb3448432011-03-24 21:19:54 +00001328OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +00001329CommandObjectImageList::CommandOptions::g_option_table[] =
1330{
Caroline Tice4d6675c2010-10-01 19:59:14 +00001331{ LLDB_OPT_SET_1, false, "arch", 'a', optional_argument, NULL, 0, eArgTypeWidth, "Display the architecture when listing images."},
Greg Clayton0467c782011-02-04 18:53:10 +00001332{ LLDB_OPT_SET_1, false, "uuid", 'u', no_argument, NULL, 0, eArgTypeNone, "Display the UUID when listing images."},
Caroline Tice4d6675c2010-10-01 19:59:14 +00001333{ 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 Lattner24943d22010-06-08 16:52:24 +00001339};
1340
1341
1342
1343//----------------------------------------------------------------------
1344// Lookup information in images
1345//----------------------------------------------------------------------
1346class CommandObjectImageLookup : public CommandObject
1347{
1348public:
1349
1350 enum
1351 {
1352 eLookupTypeInvalid = -1,
1353 eLookupTypeAddress = 0,
1354 eLookupTypeSymbol,
1355 eLookupTypeFileLine, // Line is optional
1356 eLookupTypeFunction,
Greg Clayton960d6a42010-08-03 00:35:52 +00001357 eLookupTypeType,
Chris Lattner24943d22010-06-08 16:52:24 +00001358 kNumLookupTypes
1359 };
1360
1361 class CommandOptions : public Options
1362 {
1363 public:
1364
Greg Claytonf15996e2011-04-07 22:46:35 +00001365 CommandOptions (CommandInterpreter &interpreter) :
Johnny Chen93356432011-04-08 22:39:17 +00001366 Options(interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +00001367 {
Greg Clayton143fcc32011-04-13 00:18:08 +00001368 OptionParsingStarting();
Chris Lattner24943d22010-06-08 16:52:24 +00001369 }
1370
1371 virtual
1372 ~CommandOptions ()
1373 {
1374 }
1375
1376 virtual Error
Greg Clayton143fcc32011-04-13 00:18:08 +00001377 SetOptionValue (uint32_t option_idx, const char *option_arg)
Chris Lattner24943d22010-06-08 16:52:24 +00001378 {
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 Clayton537a7a82010-10-20 20:54:39 +00001404 m_file.SetFile (option_arg, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001405 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 Clayton960d6a42010-08-03 00:35:52 +00001426 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 Lattner24943d22010-06-08 16:52:24 +00001435 case 'r':
1436 m_use_regex = true;
1437 break;
1438 }
1439
1440 return error;
1441 }
1442
1443 void
Greg Clayton143fcc32011-04-13 00:18:08 +00001444 OptionParsingStarting ()
Chris Lattner24943d22010-06-08 16:52:24 +00001445 {
Chris Lattner24943d22010-06-08 16:52:24 +00001446 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 Clayton960d6a42010-08-03 00:35:52 +00001454 m_verbose = false;
Chris Lattner24943d22010-06-08 16:52:24 +00001455 }
1456
Greg Claytonb3448432011-03-24 21:19:54 +00001457 const OptionDefinition*
Chris Lattner24943d22010-06-08 16:52:24 +00001458 GetDefinitions ()
1459 {
1460 return g_option_table;
1461 }
1462
1463 // Options table: Required for subclasses of Options.
1464
Greg Claytonb3448432011-03-24 21:19:54 +00001465 static OptionDefinition g_option_table[];
Chris Lattner24943d22010-06-08 16:52:24 +00001466 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 Clayton960d6a42010-08-03 00:35:52 +00001474 bool m_verbose; // Enable verbose lookup info
1475
Chris Lattner24943d22010-06-08 16:52:24 +00001476 };
1477
Greg Clayton238c0a12010-09-18 01:14:36 +00001478 CommandObjectImageLookup (CommandInterpreter &interpreter) :
1479 CommandObject (interpreter,
1480 "image lookup",
1481 "Look up information within executable and dependent shared library images.",
Greg Claytonf15996e2011-04-07 22:46:35 +00001482 NULL),
1483 m_options (interpreter)
Chris Lattner24943d22010-06-08 16:52:24 +00001484 {
Caroline Tice43b014a2010-10-04 22:28:36 +00001485 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 Lattner24943d22010-06-08 16:52:24 +00001497 }
1498
1499 virtual
1500 ~CommandObjectImageLookup ()
1501 {
1502 }
1503
Greg Clayton8d3802d2010-10-08 04:20:14 +00001504 virtual Options *
Chris Lattner24943d22010-06-08 16:52:24 +00001505 GetOptions ()
1506 {
1507 return &m_options;
1508 }
1509
1510
1511 bool
Greg Clayton63094e02010-06-23 01:19:29 +00001512 LookupInModule (CommandInterpreter &interpreter, Module *module, CommandReturnObject &result, bool &syntax_error)
Chris Lattner24943d22010-06-08 16:52:24 +00001513 {
1514 switch (m_options.m_type)
1515 {
1516 case eLookupTypeAddress:
1517 if (m_options.m_addr != LLDB_INVALID_ADDRESS)
1518 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001519 if (LookupAddressInModule (m_interpreter,
Greg Clayton960d6a42010-08-03 00:35:52 +00001520 result.GetOutputStream(),
1521 module,
1522 eSymbolContextEverything,
1523 m_options.m_addr,
1524 m_options.m_offset,
1525 m_options.m_verbose))
Chris Lattner24943d22010-06-08 16:52:24 +00001526 {
1527 result.SetStatus(eReturnStatusSuccessFinishResult);
1528 return true;
1529 }
1530 }
1531 break;
1532
1533 case eLookupTypeSymbol:
1534 if (!m_options.m_str.empty())
1535 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001536 if (LookupSymbolInModule (m_interpreter, result.GetOutputStream(), module, m_options.m_str.c_str(), m_options.m_use_regex))
Chris Lattner24943d22010-06-08 16:52:24 +00001537 {
1538 result.SetStatus(eReturnStatusSuccessFinishResult);
1539 return true;
1540 }
1541 }
1542 break;
1543
1544 case eLookupTypeFileLine:
1545 if (m_options.m_file)
1546 {
1547
Greg Clayton238c0a12010-09-18 01:14:36 +00001548 if (LookupFileAndLineInModule (m_interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +00001549 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 Clayton238c0a12010-09-18 01:14:36 +00001564 if (LookupFunctionInModule (m_interpreter,
Chris Lattner24943d22010-06-08 16:52:24 +00001565 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 Clayton960d6a42010-08-03 00:35:52 +00001576 case eLookupTypeType:
1577 if (!m_options.m_str.empty())
1578 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001579 if (LookupTypeInModule (m_interpreter,
Greg Clayton960d6a42010-08-03 00:35:52 +00001580 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 Lattner24943d22010-06-08 16:52:24 +00001591 default:
Greg Claytonf15996e2011-04-07 22:46:35 +00001592 m_options.GenerateOptionUsage (result.GetErrorStream(), this);
Chris Lattner24943d22010-06-08 16:52:24 +00001593 syntax_error = true;
1594 break;
1595 }
1596
1597 result.SetStatus (eReturnStatusFailed);
1598 return false;
1599 }
1600
1601 virtual bool
Greg Clayton238c0a12010-09-18 01:14:36 +00001602 Execute (Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +00001603 CommandReturnObject &result)
1604 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001605 Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
Chris Lattner24943d22010-06-08 16:52:24 +00001606 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 Clayton238c0a12010-09-18 01:14:36 +00001630 if (LookupInModule (m_interpreter, target->GetImages().GetModulePointerAtIndex(i), result, syntax_error))
Chris Lattner24943d22010-06-08 16:52:24 +00001631 {
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 Clayton537a7a82010-10-20 20:54:39 +00001650 FileSpec image_file(arg_cstr, false);
Chris Lattner24943d22010-06-08 16:52:24 +00001651 ModuleList matching_modules;
Greg Clayton661825b2010-06-28 23:51:11 +00001652 size_t num_matching_modules = target->GetImages().FindModules(&image_file, NULL, NULL, NULL, matching_modules);
Chris Lattner24943d22010-06-08 16:52:24 +00001653
Greg Clayton661825b2010-06-28 23:51:11 +00001654 // 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 Lattner24943d22010-06-08 16:52:24 +00001664 if (num_matching_modules > 0)
1665 {
Greg Claytonbef15832010-07-14 00:18:15 +00001666 for (size_t j=0; j<num_matching_modules; ++j)
Chris Lattner24943d22010-06-08 16:52:24 +00001667 {
Greg Claytonbef15832010-07-14 00:18:15 +00001668 Module * image_module = matching_modules.GetModulePointerAtIndex(j);
Chris Lattner24943d22010-06-08 16:52:24 +00001669 if (image_module)
1670 {
Greg Clayton238c0a12010-09-18 01:14:36 +00001671 if (LookupInModule (m_interpreter, image_module, result, syntax_error))
Chris Lattner24943d22010-06-08 16:52:24 +00001672 {
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 }
1691protected:
1692
1693 CommandOptions m_options;
1694};
1695
Greg Claytonb3448432011-03-24 21:19:54 +00001696OptionDefinition
Chris Lattner24943d22010-06-08 16:52:24 +00001697CommandObjectImageLookup::CommandOptions::g_option_table[] =
1698{
Greg Claytonb72d0f02011-04-12 05:54:46 +00001699{ 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 Tice4d6675c2010-10-01 19:59:14 +00001709{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
Chris Lattner24943d22010-06-08 16:52:24 +00001710};
1711
1712
1713
1714
1715
1716//----------------------------------------------------------------------
1717// CommandObjectImage constructor
1718//----------------------------------------------------------------------
Greg Clayton63094e02010-06-23 01:19:29 +00001719CommandObjectImage::CommandObjectImage(CommandInterpreter &interpreter) :
Greg Clayton238c0a12010-09-18 01:14:36 +00001720 CommandObjectMultiword (interpreter,
1721 "image",
Caroline Ticec1ad82e2010-09-07 22:38:08 +00001722 "A set of commands for accessing information for one or more executable images.",
1723 "image <sub-command> ...")
Chris Lattner24943d22010-06-08 16:52:24 +00001724{
Greg Clayton238c0a12010-09-18 01:14:36 +00001725 LoadSubCommand ("dump", CommandObjectSP (new CommandObjectImageDump (interpreter)));
1726 LoadSubCommand ("list", CommandObjectSP (new CommandObjectImageList (interpreter)));
1727 LoadSubCommand ("lookup", CommandObjectSP (new CommandObjectImageLookup (interpreter)));
Chris Lattner24943d22010-06-08 16:52:24 +00001728}
1729
1730//----------------------------------------------------------------------
1731// Destructor
1732//----------------------------------------------------------------------
1733CommandObjectImage::~CommandObjectImage()
1734{
1735}
1736