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