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