Module.h revision 36da2aa6dc5ad9994b638ed09eb81c44cc05540b
1//===-- Module.h ------------------------------------------------*- 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#ifndef liblldb_Module_h_
11#define liblldb_Module_h_
12
13#include "lldb/Core/ArchSpec.h"
14#include "lldb/Core/UUID.h"
15#include "lldb/Host/FileSpec.h"
16#include "lldb/Host/Mutex.h"
17#include "lldb/Host/TimeValue.h"
18#include "lldb/Symbol/ClangASTContext.h"
19#include "lldb/Symbol/SymbolContextScope.h"
20#include "lldb/Target/PathMappingList.h"
21
22namespace lldb_private {
23
24//----------------------------------------------------------------------
25/// @class Module Module.h "lldb/Core/Module.h"
26/// @brief A class that describes an executable image and its associated
27///        object and symbol files.
28///
29/// The module is designed to be able to select a single slice of an
30/// executable image as it would appear on disk and during program
31/// execution.
32///
33/// Modules control when and if information is parsed according to which
34/// accessors are called. For example the object file (ObjectFile)
35/// representation will only be parsed if the object file is requested
36/// using the Module::GetObjectFile() is called. The debug symbols
37/// will only be parsed if the symbol vendor (SymbolVendor) is
38/// requested using the Module::GetSymbolVendor() is called.
39///
40/// The module will parse more detailed information as more queries are
41/// made.
42//----------------------------------------------------------------------
43class Module :
44    public STD_ENABLE_SHARED_FROM_THIS(Module),
45    public SymbolContextScope
46{
47public:
48	// Static functions that can track the lifetime of moodule objects.
49	// This is handy because we might have Module objects that are in
50	// shared pointers that aren't in the global module list (from
51	// ModuleList). If this is the case we need to know about it.
52    // The modules in the global list maintained by these functions
53    // can be viewed using the "target modules list" command using the
54    // "--global" (-g for short).
55    static size_t
56    GetNumberAllocatedModules ();
57
58    static Module *
59    GetAllocatedModuleAtIndex (size_t idx);
60
61    static Mutex *
62    GetAllocationModuleCollectionMutex();
63
64    //------------------------------------------------------------------
65    /// Construct with file specification and architecture.
66    ///
67    /// Clients that wish to share modules with other targets should
68    /// use ModuleList::GetSharedModule().
69    ///
70    /// @param[in] file_spec
71    ///     The file specification for the on disk repesentation of
72    ///     this executable image.
73    ///
74    /// @param[in] arch
75    ///     The architecture to set as the current architecture in
76    ///     this module.
77    ///
78    /// @param[in] object_name
79    ///     The name of an object in a module used to extract a module
80    ///     within a module (.a files and modules that contain multiple
81    ///     architectures).
82    ///
83    /// @param[in] object_offset
84    ///     The offset within an existing module used to extract a
85    ///     module within a module (.a files and modules that contain
86    ///     multiple architectures).
87    //------------------------------------------------------------------
88    Module (const FileSpec& file_spec,
89            const ArchSpec& arch,
90            const ConstString *object_name = NULL,
91            off_t object_offset = 0);
92
93    Module (const ModuleSpec &module_spec);
94    //------------------------------------------------------------------
95    /// Destructor.
96    //------------------------------------------------------------------
97    virtual
98    ~Module ();
99
100    bool
101    MatchesModuleSpec (const ModuleSpec &module_ref);
102
103    //------------------------------------------------------------------
104    /// Set the load address for all sections in a module to be the
105    /// file address plus \a slide.
106    ///
107    /// Many times a module will be loaded in a target with a constant
108    /// offset applied to all top level sections. This function can
109    /// set the load address for all top level sections to be the
110    /// section file address + offset.
111    ///
112    /// @param[in] target
113    ///     The target in which to apply the section load addresses.
114    ///
115    /// @param[in] offset
116    ///     The offset to apply to all file addresses for all top
117    ///     level sections in the object file as each section load
118    ///     address is being set.
119    ///
120    /// @param[out] changed
121    ///     If any section load addresses were changed in \a target,
122    ///     then \a changed will be set to \b true. Else \a changed
123    ///     will be set to false. This allows this function to be
124    ///     called multiple times on the same module for the same
125    ///     target. If the module hasn't moved, then \a changed will
126    ///     be false and no module updated notification will need to
127    ///     be sent out.
128    ///
129    /// @return
130    ///     /b True if any sections were successfully loaded in \a target,
131    ///     /b false otherwise.
132    //------------------------------------------------------------------
133    bool
134    SetLoadAddress (Target &target,
135                    lldb::addr_t offset,
136                    bool &changed);
137
138    //------------------------------------------------------------------
139    /// @copydoc SymbolContextScope::CalculateSymbolContext(SymbolContext*)
140    ///
141    /// @see SymbolContextScope
142    //------------------------------------------------------------------
143    virtual void
144    CalculateSymbolContext (SymbolContext* sc);
145
146    virtual lldb::ModuleSP
147    CalculateSymbolContextModule ();
148
149    void
150    GetDescription (Stream *s,
151                    lldb::DescriptionLevel level = lldb::eDescriptionLevelFull);
152
153    //------------------------------------------------------------------
154    /// Dump a description of this object to a Stream.
155    ///
156    /// Dump a description of the contents of this object to the
157    /// supplied stream \a s. The dumped content will be only what has
158    /// been loaded or parsed up to this point at which this function
159    /// is called, so this is a good way to see what has been parsed
160    /// in a module.
161    ///
162    /// @param[in] s
163    ///     The stream to which to dump the object descripton.
164    //------------------------------------------------------------------
165    void
166    Dump (Stream *s);
167
168    //------------------------------------------------------------------
169    /// @copydoc SymbolContextScope::DumpSymbolContext(Stream*)
170    ///
171    /// @see SymbolContextScope
172    //------------------------------------------------------------------
173    virtual void
174    DumpSymbolContext (Stream *s);
175
176
177    //------------------------------------------------------------------
178    /// Find a symbol in the object file's symbol table.
179    ///
180    /// @param[in] name
181    ///     The name of the symbol that we are looking for.
182    ///
183    /// @param[in] symbol_type
184    ///     If set to eSymbolTypeAny, find a symbol of any type that
185    ///     has a name that matches \a name. If set to any other valid
186    ///     SymbolType enumeration value, then search only for
187    ///     symbols that match \a symbol_type.
188    ///
189    /// @return
190    ///     Returns a valid symbol pointer if a symbol was found,
191    ///     NULL otherwise.
192    //------------------------------------------------------------------
193    const Symbol *
194    FindFirstSymbolWithNameAndType (const ConstString &name,
195                                    lldb::SymbolType symbol_type = lldb::eSymbolTypeAny);
196
197    size_t
198    FindSymbolsWithNameAndType (const ConstString &name,
199                                lldb::SymbolType symbol_type,
200                                SymbolContextList &sc_list);
201
202    size_t
203    FindSymbolsMatchingRegExAndType (const RegularExpression &regex,
204                                     lldb::SymbolType symbol_type,
205                                     SymbolContextList &sc_list);
206
207    //------------------------------------------------------------------
208    /// Find a funciton symbols in the object file's symbol table.
209    ///
210    /// @param[in] name
211    ///     The name of the symbol that we are looking for.
212    ///
213    /// @param[in] name_type_mask
214    ///     A mask that has one or more bitwise OR'ed values from the
215    ///     lldb::FunctionNameType enumeration type that indicate what
216    ///     kind of names we are looking for.
217    ///
218    /// @param[out] sc_list
219    ///     A list to append any matching symbol contexts to.
220    ///
221    /// @return
222    ///     The number of symbol contexts that were added to \a sc_list
223    //------------------------------------------------------------------
224    size_t
225    FindFunctionSymbols (const ConstString &name,
226                         uint32_t name_type_mask,
227                         SymbolContextList& sc_list);
228
229    //------------------------------------------------------------------
230    /// Find compile units by partial or full path.
231    ///
232    /// Finds all compile units that match \a path in all of the modules
233    /// and returns the results in \a sc_list.
234    ///
235    /// @param[in] path
236    ///     The name of the function we are looking for.
237    ///
238    /// @param[in] append
239    ///     If \b true, then append any compile units that were found
240    ///     to \a sc_list. If \b false, then the \a sc_list is cleared
241    ///     and the contents of \a sc_list are replaced.
242    ///
243    /// @param[out] sc_list
244    ///     A symbol context list that gets filled in with all of the
245    ///     matches.
246    ///
247    /// @return
248    ///     The number of matches added to \a sc_list.
249    //------------------------------------------------------------------
250    size_t
251    FindCompileUnits (const FileSpec &path,
252                      bool append,
253                      SymbolContextList &sc_list);
254
255
256    //------------------------------------------------------------------
257    /// Find functions by name.
258    ///
259    /// If the function is an inlined function, it will have a block,
260    /// representing the inlined function, and the function will be the
261    /// containing function.  If it is not inlined, then the block will
262    /// be NULL.
263    ///
264    /// @param[in] name
265    ///     The name of the compile unit we are looking for.
266    ///
267    /// @param[in] namespace_decl
268    ///     If valid, a namespace to search in.
269    ///
270    /// @param[in] name_type_mask
271    ///     A bit mask of bits that indicate what kind of names should
272    ///     be used when doing the lookup. Bits include fully qualified
273    ///     names, base names, C++ methods, or ObjC selectors.
274    ///     See FunctionNameType for more details.
275    ///
276    /// @param[in] append
277    ///     If \b true, any matches will be appended to \a sc_list, else
278    ///     matches replace the contents of \a sc_list.
279    ///
280    /// @param[out] sc_list
281    ///     A symbol context list that gets filled in with all of the
282    ///     matches.
283    ///
284    /// @return
285    ///     The number of matches added to \a sc_list.
286    //------------------------------------------------------------------
287    size_t
288    FindFunctions (const ConstString &name,
289                   const ClangNamespaceDecl *namespace_decl,
290                   uint32_t name_type_mask,
291                   bool symbols_ok,
292                   bool inlines_ok,
293                   bool append,
294                   SymbolContextList& sc_list);
295
296    //------------------------------------------------------------------
297    /// Find functions by name.
298    ///
299    /// If the function is an inlined function, it will have a block,
300    /// representing the inlined function, and the function will be the
301    /// containing function.  If it is not inlined, then the block will
302    /// be NULL.
303    ///
304    /// @param[in] regex
305    ///     A regular expression to use when matching the name.
306    ///
307    /// @param[in] append
308    ///     If \b true, any matches will be appended to \a sc_list, else
309    ///     matches replace the contents of \a sc_list.
310    ///
311    /// @param[out] sc_list
312    ///     A symbol context list that gets filled in with all of the
313    ///     matches.
314    ///
315    /// @return
316    ///     The number of matches added to \a sc_list.
317    //------------------------------------------------------------------
318    size_t
319    FindFunctions (const RegularExpression& regex,
320                   bool symbols_ok,
321                   bool inlines_ok,
322                   bool append,
323                   SymbolContextList& sc_list);
324
325    //------------------------------------------------------------------
326    /// Find global and static variables by name.
327    ///
328    /// @param[in] name
329    ///     The name of the global or static variable we are looking
330    ///     for.
331    ///
332    /// @param[in] namespace_decl
333    ///     If valid, a namespace to search in.
334    ///
335    /// @param[in] append
336    ///     If \b true, any matches will be appended to \a
337    ///     variable_list, else matches replace the contents of
338    ///     \a variable_list.
339    ///
340    /// @param[in] max_matches
341    ///     Allow the number of matches to be limited to \a
342    ///     max_matches. Specify UINT32_MAX to get all possible matches.
343    ///
344    /// @param[in] variable_list
345    ///     A list of variables that gets the matches appended to (if
346    ///     \a append it \b true), or replace (if \a append is \b false).
347    ///
348    /// @return
349    ///     The number of matches added to \a variable_list.
350    //------------------------------------------------------------------
351    size_t
352    FindGlobalVariables (const ConstString &name,
353                         const ClangNamespaceDecl *namespace_decl,
354                         bool append,
355                         size_t max_matches,
356                         VariableList& variable_list);
357
358    //------------------------------------------------------------------
359    /// Find global and static variables by regular exression.
360    ///
361    /// @param[in] regex
362    ///     A regular expression to use when matching the name.
363    ///
364    /// @param[in] append
365    ///     If \b true, any matches will be appended to \a
366    ///     variable_list, else matches replace the contents of
367    ///     \a variable_list.
368    ///
369    /// @param[in] max_matches
370    ///     Allow the number of matches to be limited to \a
371    ///     max_matches. Specify UINT32_MAX to get all possible matches.
372    ///
373    /// @param[in] variable_list
374    ///     A list of variables that gets the matches appended to (if
375    ///     \a append it \b true), or replace (if \a append is \b false).
376    ///
377    /// @return
378    ///     The number of matches added to \a variable_list.
379    //------------------------------------------------------------------
380    size_t
381    FindGlobalVariables (const RegularExpression& regex,
382                         bool append,
383                         size_t max_matches,
384                         VariableList& variable_list);
385
386    //------------------------------------------------------------------
387    /// Find types by name.
388    ///
389    /// Type lookups in modules go through the SymbolVendor (which will
390    /// use one or more SymbolFile subclasses). The SymbolFile needs to
391    /// be able to lookup types by basename and not the fully qualified
392    /// typename. This allows the type accelerator tables to stay small,
393    /// even with heavily templatized C++. The type search will then
394    /// narrow down the search results. If "exact_match" is true, then
395    /// the type search will only match exact type name matches. If
396    /// "exact_match" is false, the type will match as long as the base
397    /// typename matches and as long as any immediate containing
398    /// namespaces/class scopes that are specified match. So to search
399    /// for a type "d" in "b::c", the name "b::c::d" can be specified
400    /// and it will match any class/namespace "b" which contains a
401    /// class/namespace "c" which contains type "d". We do this to
402    /// allow users to not always have to specify complete scoping on
403    /// all expressions, but it also allows for exact matching when
404    /// required.
405    ///
406    /// @param[in] sc
407    ///     A symbol context that scopes where to extract a type list
408    ///     from.
409    ///
410    /// @param[in] type_name
411    ///     The name of the type we are looking for that is a fully
412    ///     or partially qualfieid type name.
413    ///
414    /// @param[in] exact_match
415    ///     If \b true, \a type_name is fully qualifed and must match
416    ///     exactly. If \b false, \a type_name is a partially qualfied
417    ///     name where the leading namespaces or classes can be
418    ///     omitted to make finding types that a user may type
419    ///     easier.
420    ///
421    /// @param[out] type_list
422    ///     A type list gets populated with any matches.
423    ///
424    /// @return
425    ///     The number of matches added to \a type_list.
426    //------------------------------------------------------------------
427    size_t
428    FindTypes (const SymbolContext& sc,
429               const ConstString &type_name,
430               bool exact_match,
431               size_t max_matches,
432               TypeList& types);
433
434    lldb::TypeSP
435    FindFirstType (const SymbolContext& sc,
436                   const ConstString &type_name,
437                   bool exact_match);
438
439    //------------------------------------------------------------------
440    /// Find types by name that are in a namespace. This function is
441    /// used by the expression parser when searches need to happen in
442    /// an exact namespace scope.
443    ///
444    /// @param[in] sc
445    ///     A symbol context that scopes where to extract a type list
446    ///     from.
447    ///
448    /// @param[in] type_name
449    ///     The name of a type within a namespace that should not include
450    ///     any qualifying namespaces (just a type basename).
451    ///
452    /// @param[in] namespace_decl
453    ///     The namespace declaration that this type must exist in.
454    ///
455    /// @param[out] type_list
456    ///     A type list gets populated with any matches.
457    ///
458    /// @return
459    ///     The number of matches added to \a type_list.
460    //------------------------------------------------------------------
461    size_t
462    FindTypesInNamespace (const SymbolContext& sc,
463                          const ConstString &type_name,
464                          const ClangNamespaceDecl *namespace_decl,
465                          size_t max_matches,
466                          TypeList& type_list);
467
468    //------------------------------------------------------------------
469    /// Get const accessor for the module architecture.
470    ///
471    /// @return
472    ///     A const reference to the architecture object.
473    //------------------------------------------------------------------
474    const ArchSpec&
475    GetArchitecture () const;
476
477    //------------------------------------------------------------------
478    /// Get const accessor for the module file specification.
479    ///
480    /// This function returns the file for the module on the host system
481    /// that is running LLDB. This can differ from the path on the
482    /// platform since we might be doing remote debugging.
483    ///
484    /// @return
485    ///     A const reference to the file specification object.
486    //------------------------------------------------------------------
487    const FileSpec &
488    GetFileSpec () const
489    {
490        return m_file;
491    }
492
493    //------------------------------------------------------------------
494    /// Get accessor for the module platform file specification.
495    ///
496    /// Platform file refers to the path of the module as it is known on
497    /// the remote system on which it is being debugged. For local
498    /// debugging this is always the same as Module::GetFileSpec(). But
499    /// remote debugging might mention a file "/usr/lib/liba.dylib"
500    /// which might be locally downloaded and cached. In this case the
501    /// platform file could be something like:
502    /// "/tmp/lldb/platform-cache/remote.host.computer/usr/lib/liba.dylib"
503    /// The file could also be cached in a local developer kit directory.
504    ///
505    /// @return
506    ///     A const reference to the file specification object.
507    //------------------------------------------------------------------
508    const FileSpec &
509    GetPlatformFileSpec () const
510    {
511        if (m_platform_file)
512            return m_platform_file;
513        return m_file;
514    }
515
516    void
517    SetPlatformFileSpec (const FileSpec &file)
518    {
519        m_platform_file = file;
520    }
521
522    const FileSpec &
523    GetSymbolFileFileSpec () const
524    {
525        return m_symfile_spec;
526    }
527
528    void
529    SetSymbolFileFileSpec (const FileSpec &file)
530    {
531        m_symfile_spec = file;
532        m_symfile_ap.reset();
533        m_did_load_symbol_vendor = false;
534    }
535
536    const TimeValue &
537    GetModificationTime () const;
538
539    //------------------------------------------------------------------
540    /// Tells whether this module is capable of being the main executable
541    /// for a process.
542    ///
543    /// @return
544    ///     \b true if it is, \b false otherwise.
545    //------------------------------------------------------------------
546    bool
547    IsExecutable ();
548
549    //------------------------------------------------------------------
550    /// Tells whether this module has been loaded in the target passed in.
551    /// This call doesn't distinguish between whether the module is loaded
552    /// by the dynamic loader, or by a "target module add" type call.
553    ///
554    /// @param[in] target
555    ///    The target to check whether this is loaded in.
556    ///
557    /// @return
558    ///     \b true if it is, \b false otherwise.
559    //------------------------------------------------------------------
560    bool
561    IsLoadedInTarget (Target *target);
562
563    bool
564    LoadScriptingResourceInTarget (Target *target, Error& error);
565
566    //------------------------------------------------------------------
567    /// Get the number of compile units for this module.
568    ///
569    /// @return
570    ///     The number of compile units that the symbol vendor plug-in
571    ///     finds.
572    //------------------------------------------------------------------
573    size_t
574    GetNumCompileUnits();
575
576    lldb::CompUnitSP
577    GetCompileUnitAtIndex (size_t idx);
578
579    const ConstString &
580    GetObjectName() const;
581
582    uint64_t
583    GetObjectOffset() const
584    {
585        return m_object_offset;
586    }
587
588    //------------------------------------------------------------------
589    /// Get the object file representation for the current architecture.
590    ///
591    /// If the object file has not been located or parsed yet, this
592    /// function will find the best ObjectFile plug-in that can parse
593    /// Module::m_file.
594    ///
595    /// @return
596    ///     If Module::m_file does not exist, or no plug-in was found
597    ///     that can parse the file, or the object file doesn't contain
598    ///     the current architecture in Module::m_arch, NULL will be
599    ///     returned, else a valid object file interface will be
600    ///     returned. The returned pointer is owned by this object and
601    ///     remains valid as long as the object is around.
602    //------------------------------------------------------------------
603    virtual ObjectFile *
604    GetObjectFile ();
605
606    uint32_t
607    GetVersion (uint32_t *versions, uint32_t num_versions);
608
609    // Load an object file from memory.
610    ObjectFile *
611    GetMemoryObjectFile (const lldb::ProcessSP &process_sp,
612                         lldb::addr_t header_addr,
613                         Error &error);
614    //------------------------------------------------------------------
615    /// Get the symbol vendor interface for the current architecture.
616    ///
617    /// If the symbol vendor file has not been located yet, this
618    /// function will find the best SymbolVendor plug-in that can
619    /// use the current object file.
620    ///
621    /// @return
622    ///     If this module does not have a valid object file, or no
623    ///     plug-in can be found that can use the object file, NULL will
624    ///     be returned, else a valid symbol vendor plug-in interface
625    ///     will be returned. The returned pointer is owned by this
626    ///     object and remains valid as long as the object is around.
627    //------------------------------------------------------------------
628    virtual SymbolVendor*
629    GetSymbolVendor(bool can_create = true,
630                    lldb_private::Stream *feedback_strm = NULL);
631
632    //------------------------------------------------------------------
633    /// Get accessor the type list for this module.
634    ///
635    /// @return
636    ///     A valid type list pointer, or NULL if there is no valid
637    ///     symbol vendor for this module.
638    //------------------------------------------------------------------
639    TypeList*
640    GetTypeList ();
641
642    //------------------------------------------------------------------
643    /// Get a pointer to the UUID value contained in this object.
644    ///
645    /// If the executable image file doesn't not have a UUID value built
646    /// into the file format, an MD5 checksum of the entire file, or
647    /// slice of the file for the current architecture should be used.
648    ///
649    /// @return
650    ///     A const pointer to the internal copy of the UUID value in
651    ///     this module if this module has a valid UUID value, NULL
652    ///     otherwise.
653    //------------------------------------------------------------------
654    const lldb_private::UUID &
655    GetUUID ();
656
657    //------------------------------------------------------------------
658    /// A debugging function that will cause everything in a module to
659    /// be parsed.
660    ///
661    /// All compile units will be pasred, along with all globals and
662    /// static variables and all functions for those compile units.
663    /// All types, scopes, local variables, static variables, global
664    /// variables, and line tables will be parsed. This can be used
665    /// prior to dumping a module to see a complete list of the
666    /// resuling debug information that gets parsed, or as a debug
667    /// function to ensure that the module can consume all of the
668    /// debug data the symbol vendor provides.
669    //------------------------------------------------------------------
670    void
671    ParseAllDebugSymbols();
672
673    bool
674    ResolveFileAddress (lldb::addr_t vm_addr, Address& so_addr);
675
676    uint32_t
677    ResolveSymbolContextForAddress (const Address& so_addr, uint32_t resolve_scope, SymbolContext& sc);
678
679    //------------------------------------------------------------------
680    /// Resolve items in the symbol context for a given file and line.
681    ///
682    /// Tries to resolve \a file_path and \a line to a list of matching
683    /// symbol contexts.
684    ///
685    /// The line table entries contains addresses that can be used to
686    /// further resolve the values in each match: the function, block,
687    /// symbol. Care should be taken to minimize the amount of
688    /// information that is requested to only what is needed --
689    /// typically the module, compile unit, line table and line table
690    /// entry are sufficient.
691    ///
692    /// @param[in] file_path
693    ///     A path to a source file to match. If \a file_path does not
694    ///     specify a directory, then this query will match all files
695    ///     whose base filename matches. If \a file_path does specify
696    ///     a directory, the fullpath to the file must match.
697    ///
698    /// @param[in] line
699    ///     The source line to match, or zero if just the compile unit
700    ///     should be resolved.
701    ///
702    /// @param[in] check_inlines
703    ///     Check for inline file and line number matches. This option
704    ///     should be used sparingly as it will cause all line tables
705    ///     for every compile unit to be parsed and searched for
706    ///     matching inline file entries.
707    ///
708    /// @param[in] resolve_scope
709    ///     The scope that should be resolved (see
710    ///     SymbolContext::Scope).
711    ///
712    /// @param[out] sc_list
713    ///     A symbol context list that gets matching symbols contexts
714    ///     appended to.
715    ///
716    /// @return
717    ///     The number of matches that were added to \a sc_list.
718    ///
719    /// @see SymbolContext::Scope
720    //------------------------------------------------------------------
721    uint32_t
722    ResolveSymbolContextForFilePath (const char *file_path, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list);
723
724    //------------------------------------------------------------------
725    /// Resolve items in the symbol context for a given file and line.
726    ///
727    /// Tries to resolve \a file_spec and \a line to a list of matching
728    /// symbol contexts.
729    ///
730    /// The line table entries contains addresses that can be used to
731    /// further resolve the values in each match: the function, block,
732    /// symbol. Care should be taken to minimize the amount of
733    /// information that is requested to only what is needed --
734    /// typically the module, compile unit, line table and line table
735    /// entry are sufficient.
736    ///
737    /// @param[in] file_spec
738    ///     A file spec to a source file to match. If \a file_path does
739    ///     not specify a directory, then this query will match all
740    ///     files whose base filename matches. If \a file_path does
741    ///     specify a directory, the fullpath to the file must match.
742    ///
743    /// @param[in] line
744    ///     The source line to match, or zero if just the compile unit
745    ///     should be resolved.
746    ///
747    /// @param[in] check_inlines
748    ///     Check for inline file and line number matches. This option
749    ///     should be used sparingly as it will cause all line tables
750    ///     for every compile unit to be parsed and searched for
751    ///     matching inline file entries.
752    ///
753    /// @param[in] resolve_scope
754    ///     The scope that should be resolved (see
755    ///     SymbolContext::Scope).
756    ///
757    /// @param[out] sc_list
758    ///     A symbol context list that gets filled in with all of the
759    ///     matches.
760    ///
761    /// @return
762    ///     A integer that contains SymbolContext::Scope bits set for
763    ///     each item that was successfully resolved.
764    ///
765    /// @see SymbolContext::Scope
766    //------------------------------------------------------------------
767    uint32_t
768    ResolveSymbolContextsForFileSpec (const FileSpec &file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, SymbolContextList& sc_list);
769
770
771    void
772    SetFileSpecAndObjectName (const FileSpec &file,
773                              const ConstString &object_name);
774
775    bool
776    GetIsDynamicLinkEditor () const
777    {
778        return m_is_dynamic_loader_module;
779    }
780
781    void
782    SetIsDynamicLinkEditor (bool b)
783    {
784        m_is_dynamic_loader_module = b;
785    }
786
787    ClangASTContext &
788    GetClangASTContext ();
789
790    // Special error functions that can do printf style formatting that will prepend the message with
791    // something appropriate for this module (like the architecture, path and object name (if any)).
792    // This centralizes code so that everyone doesn't need to format their error and log messages on
793    // their own and keeps the output a bit more consistent.
794    void
795    LogMessage (Log *log, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
796
797    void
798    LogMessageVerboseBacktrace (Log *log, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
799
800    void
801    ReportWarning (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
802
803    void
804    ReportError (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
805
806    // Only report an error once when the module is first detected to be modified
807    // so we don't spam the console with many messages.
808    void
809    ReportErrorIfModifyDetected (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
810
811    //------------------------------------------------------------------
812    // Return true if the file backing this module has changed since the
813    // module was originally created  since we saved the intial file
814    // modification time when the module first gets created.
815    //------------------------------------------------------------------
816    bool
817    FileHasChanged () const;
818
819    //------------------------------------------------------------------
820    // SymbolVendor, SymbolFile and ObjectFile member objects should
821    // lock the module mutex to avoid deadlocks.
822    //------------------------------------------------------------------
823    Mutex &
824    GetMutex () const
825    {
826        return m_mutex;
827    }
828
829    PathMappingList &
830    GetSourceMappingList ()
831    {
832        return m_source_mappings;
833    }
834
835    const PathMappingList &
836    GetSourceMappingList () const
837    {
838        return m_source_mappings;
839    }
840
841    //------------------------------------------------------------------
842    /// Finds a source file given a file spec using the module source
843    /// path remappings (if any).
844    ///
845    /// Tries to resolve \a orig_spec by checking the module source path
846    /// remappings. It makes sure the file exists, so this call can be
847    /// expensive if the remappings are on a network file system, so
848    /// use this function sparingly (not in a tight debug info parsing
849    /// loop).
850    ///
851    /// @param[in] orig_spec
852    ///     The original source file path to try and remap.
853    ///
854    /// @param[out] new_spec
855    ///     The newly remapped filespec that is guaranteed to exist.
856    ///
857    /// @return
858    ///     /b true if \a orig_spec was successfully located and
859    ///     \a new_spec is filled in with an existing file spec,
860    ///     \b false otherwise.
861    //------------------------------------------------------------------
862    bool
863    FindSourceFile (const FileSpec &orig_spec, FileSpec &new_spec) const;
864
865    //------------------------------------------------------------------
866    /// Remaps a source file given \a path into \a new_path.
867    ///
868    /// Remaps \a path if any source remappings match. This function
869    /// does NOT stat the file system so it can be used in tight loops
870    /// where debug info is being parsed.
871    ///
872    /// @param[in] path
873    ///     The original source file path to try and remap.
874    ///
875    /// @param[out] new_path
876    ///     The newly remapped filespec that is may or may not exist.
877    ///
878    /// @return
879    ///     /b true if \a path was successfully located and \a new_path
880    ///     is filled in with a new source path, \b false otherwise.
881    //------------------------------------------------------------------
882    bool
883    RemapSourceFile (const char *path, std::string &new_path) const;
884
885protected:
886    //------------------------------------------------------------------
887    // Member Variables
888    //------------------------------------------------------------------
889    mutable Mutex               m_mutex;        ///< A mutex to keep this object happy in multi-threaded environments.
890    TimeValue                   m_mod_time;     ///< The modification time for this module when it was created.
891    ArchSpec                    m_arch;         ///< The architecture for this module.
892    lldb_private::UUID          m_uuid;         ///< Each module is assumed to have a unique identifier to help match it up to debug symbols.
893    FileSpec                    m_file;         ///< The file representation on disk for this module (if there is one).
894    FileSpec                    m_platform_file;///< The path to the module on the platform on which it is being debugged
895    FileSpec                    m_symfile_spec; ///< If this path is valid, then this is the file that _will_ be used as the symbol file for this module
896    ConstString                 m_object_name;  ///< The name an object within this module that is selected, or empty of the module is represented by \a m_file.
897    uint64_t                    m_object_offset;
898    lldb::ObjectFileSP          m_objfile_sp;   ///< A shared pointer to the object file parser for this module as it may or may not be shared with the SymbolFile
899    std::auto_ptr<SymbolVendor> m_symfile_ap;   ///< A pointer to the symbol vendor for this module.
900    ClangASTContext             m_ast;          ///< The AST context for this module.
901    PathMappingList             m_source_mappings; ///< Module specific source remappings for when you have debug info for a module that doesn't match where the sources currently are
902
903    bool                        m_did_load_objfile:1,
904                                m_did_load_symbol_vendor:1,
905                                m_did_parse_uuid:1,
906                                m_did_init_ast:1,
907                                m_is_dynamic_loader_module:1;
908    mutable bool                m_file_has_changed:1,
909                                m_first_file_changed_log:1;   /// See if the module was modified after it was initially opened.
910
911    //------------------------------------------------------------------
912    /// Resolve a file or load virtual address.
913    ///
914    /// Tries to resolve \a vm_addr as a file address (if \a
915    /// vm_addr_is_file_addr is true) or as a load address if \a
916    /// vm_addr_is_file_addr is false) in the symbol vendor.
917    /// \a resolve_scope indicates what clients wish to resolve
918    /// and can be used to limit the scope of what is parsed.
919    ///
920    /// @param[in] vm_addr
921    ///     The load virtual address to resolve.
922    ///
923    /// @param[in] vm_addr_is_file_addr
924    ///     If \b true, \a vm_addr is a file address, else \a vm_addr
925    ///     if a load address.
926    ///
927    /// @param[in] resolve_scope
928    ///     The scope that should be resolved (see
929    ///     SymbolContext::Scope).
930    ///
931    /// @param[out] so_addr
932    ///     The section offset based address that got resolved if
933    ///     any bits are returned.
934    ///
935    /// @param[out] sc
936    //      The symbol context that has objects filled in. Each bit
937    ///     in the \a resolve_scope pertains to a member in the \a sc.
938    ///
939    /// @return
940    ///     A integer that contains SymbolContext::Scope bits set for
941    ///     each item that was successfully resolved.
942    ///
943    /// @see SymbolContext::Scope
944    //------------------------------------------------------------------
945    uint32_t
946    ResolveSymbolContextForAddress (lldb::addr_t vm_addr,
947                                    bool vm_addr_is_file_addr,
948                                    uint32_t resolve_scope,
949                                    Address& so_addr,
950                                    SymbolContext& sc);
951
952    void
953    SymbolIndicesToSymbolContextList (Symtab *symtab,
954                                      std::vector<uint32_t> &symbol_indexes,
955                                      SymbolContextList &sc_list);
956
957    bool
958    SetArchitecture (const ArchSpec &new_arch);
959
960
961    friend class ModuleList;
962    friend class ObjectFile;
963
964private:
965
966    size_t
967    FindTypes_Impl (const SymbolContext& sc,
968                    const ConstString &name,
969                    const ClangNamespaceDecl *namespace_decl,
970                    bool append,
971                    size_t max_matches,
972                    TypeList& types);
973
974
975    DISALLOW_COPY_AND_ASSIGN (Module);
976};
977
978} // namespace lldb_private
979
980#endif  // liblldb_Module_h_
981