blob: 88aba019ead4288c37379576ad1fb12bc73d55a0 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- ObjectContainerBSDArchive.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_ObjectContainerBSDArchive_h_
11#define liblldb_ObjectContainerBSDArchive_h_
12
13#include "lldb/Symbol/ObjectContainer.h"
14
15#include "lldb/Core/ArchSpec.h"
16#include "lldb/Core/ConstString.h"
17#include "lldb/Core/FileSpec.h"
18#include "lldb/Core/UniqueCStringMap.h"
19#include "lldb/Host/TimeValue.h"
20
21class ObjectContainerBSDArchive :
22 public lldb_private::ObjectContainer
23{
24public:
25
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 lldb_private::ObjectContainer *
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 ObjectContainerBSDArchive (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 ~ObjectContainerBSDArchive();
62
63 virtual bool
64 ParseHeader ();
65
66 virtual void
67 Dump (lldb_private::Stream *s) const;
68
69 virtual lldb_private::ObjectFile *
70 GetObjectFile (const lldb_private::FileSpec *file);
71
72 //------------------------------------------------------------------
73 // PluginInterface protocol
74 //------------------------------------------------------------------
75 virtual const char *
76 GetPluginName();
77
78 virtual const char *
79 GetShortPluginName();
80
81 virtual uint32_t
82 GetPluginVersion();
83
84 virtual void
85 GetPluginCommandHelp (const char *command, lldb_private::Stream *strm);
86
87 virtual lldb_private::Error
88 ExecutePluginCommand (lldb_private::Args &command, lldb_private::Stream *strm);
89
90 virtual lldb_private::Log *
91 EnablePluginLogging (lldb_private::Stream *strm, lldb_private::Args &command);
92
93
94protected:
95
96 struct Object
97 {
98 Object();
99
100 void
101 Clear();
102
103 uint32_t
104 Extract (const lldb_private::DataExtractor& data, uint32_t offset);
105
106 lldb_private::ConstString ar_name; // name
107 uint32_t ar_date; // modification time
108 uint16_t ar_uid; // user id
109 uint16_t ar_gid; // group id
110 uint16_t ar_mode; // octal file permissions
111 uint32_t ar_size; // size in bytes
112 uint32_t ar_file_offset; // file offset in bytes from the beginning of the file of the object data
113 uint32_t ar_file_size; // length of the object data
114
115 typedef std::vector<Object> collection;
116 typedef collection::iterator iterator;
117 typedef collection::const_iterator const_iterator;
118 };
119
120 class Archive
121 {
122 public:
123 typedef lldb::SharedPtr<Archive>::Type shared_ptr;
124 typedef std::multimap<lldb_private::FileSpec, shared_ptr> Map;
125
126 static Map &
127 GetArchiveCache ();
128
129 static lldb_private::Mutex &
130 GetArchiveCacheMutex ();
131
132 static Archive::shared_ptr
133 FindCachedArchive (const lldb_private::FileSpec &file,
134 const lldb_private::ArchSpec &arch,
135 const lldb_private::TimeValue &mod_time);
136
137 static Archive::shared_ptr
138 ParseAndCacheArchiveForFile (const lldb_private::FileSpec &file,
139 const lldb_private::ArchSpec &arch,
140 const lldb_private::TimeValue &mod_time,
141 lldb_private::DataExtractor &data);
142
143 Archive (const lldb_private::ArchSpec &arch,
144 const lldb_private::TimeValue &mod_time);
145
146 ~Archive ();
147
148 size_t
149 ParseObjects (lldb_private::DataExtractor &data);
150
151 Object *
152 FindObject (const lldb_private::ConstString &object_name);
153
154 const lldb_private::TimeValue &
155 GetModificationTime()
156 {
157 return m_time;
158 }
159
160 const lldb_private::ArchSpec &
161 GetArchitecture ()
162 {
163 return m_arch;
164 }
165
166 protected:
167
168 //----------------------------------------------------------------------
169 // Member Variables
170 //----------------------------------------------------------------------
171 lldb_private::ArchSpec m_arch;
172 lldb_private::TimeValue m_time;
173 Object::collection m_objects;
174 lldb_private::UniqueCStringMap<uint32_t> m_object_name_to_index_map;
175 };
176
177 void
178 SetArchive (Archive::shared_ptr &archive_sp);
179
180 Archive::shared_ptr m_archive_sp;
181};
182
183#endif // liblldb_ObjectContainerBSDArchive_h_