1 //===-- ObjectFileMachO.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_ObjectFileMachO_h_
11 #define liblldb_ObjectFileMachO_h_
12 
13 #include <mach-o/loader.h>
14 #include "lldb/Core/FileSpec.h"
15 #include "lldb/Host/Mutex.h"
16 #include "lldb/Symbol/ObjectFile.h"
17 
18 //----------------------------------------------------------------------
19 // This class needs to be hidden as eventually belongs in a plugin that
20 // will export the ObjectFile protocol
21 //----------------------------------------------------------------------
22 class ObjectFileMachO :
23     public lldb_private::ObjectFile
24 {
25 public:
26     //------------------------------------------------------------------
27     // Static Functions
28     //------------------------------------------------------------------
29     static void
30     Initialize();
31 
32     static void
33     Terminate();
34 
35     static const char *
36     GetPluginNameStatic();
37 
38     static const char *
39     GetPluginDescriptionStatic();
40 
41     static ObjectFile *
42     CreateInstance (lldb_private::Module* module,
43                     lldb::DataBufferSP& dataSP,
44                     const lldb_private::FileSpec* file,
45                     lldb::addr_t offset,
46                     lldb::addr_t length);
47 
48     static bool
49     MagicBytesMatch (lldb::DataBufferSP& dataSP);
50 
51     //------------------------------------------------------------------
52     // Member Functions
53     //------------------------------------------------------------------
54     ObjectFileMachO (lldb_private::Module* module,
55                      lldb::DataBufferSP& dataSP,
56                      const lldb_private::FileSpec* file,
57                      lldb::addr_t offset,
58                      lldb::addr_t length);
59 
60     virtual
61     ~ObjectFileMachO();
62 
63     virtual bool
64     ParseHeader ();
65 
66     virtual lldb::ByteOrder
67     GetByteOrder () const;
68 
69     virtual size_t
70     GetAddressByteSize ()  const;
71 
72     virtual lldb_private::Symtab *
73     GetSymtab();
74 
75     virtual lldb_private::SectionList *
76     GetSectionList();
77 
78     virtual void
79     Dump (lldb_private::Stream *s);
80 
81     virtual bool
82     GetTargetTriple (lldb_private::ConstString &target_triple);
83 
84     virtual bool
85     GetUUID (lldb_private::UUID* uuid);
86 
87     virtual uint32_t
88     GetDependentModules (lldb_private::FileSpecList& files);
89 
90     //------------------------------------------------------------------
91     // PluginInterface protocol
92     //------------------------------------------------------------------
93     virtual const char *
94     GetPluginName();
95 
96     virtual const char *
97     GetShortPluginName();
98 
99     virtual uint32_t
100     GetPluginVersion();
101 
102     virtual void
103     GetPluginCommandHelp (const char *command, lldb_private::Stream *strm);
104 
105     virtual lldb_private::Error
106     ExecutePluginCommand (lldb_private::Args &command, lldb_private::Stream *strm);
107 
108     virtual lldb_private::Log *
109     EnablePluginLogging (lldb_private::Stream *strm, lldb_private::Args &command);
110 
111 
112 
113 protected:
114     mutable lldb_private::Mutex m_mutex;
115     struct  mach_header m_header;
116     mutable std::auto_ptr<lldb_private::SectionList> m_sections_ap;
117     mutable std::auto_ptr<lldb_private::Symtab> m_symtab_ap;
118 
119     struct dysymtab_command m_dysymtab;
120     std::vector<struct segment_command_64> m_mach_segments;
121     std::vector<struct section_64> m_mach_sections;
122 
123     size_t
124     ParseSections ();
125 
126     size_t
127     ParseSymtab (bool minimize);
128 
129 };
130 
131 #endif  // liblldb_ObjectFileMachO_h_
132