@@ -49,37 +49,49 @@ ObjectFileJSON::CreateInstance(const ModuleSP &module_sp, DataBufferSP data_sp,
49
49
if (!MagicBytesMatch (data_sp, 0 , data_sp->GetByteSize ()))
50
50
return nullptr ;
51
51
52
+ // Update the data to contain the entire file if it doesn't already.
52
53
if (data_sp->GetByteSize () < length) {
53
54
data_sp = MapFileData (*file, length, file_offset);
54
55
if (!data_sp)
55
56
return nullptr ;
56
57
data_offset = 0 ;
57
58
}
58
59
60
+ Log *log = GetLog (LLDBLog::Symbols);
61
+
59
62
auto text =
60
63
llvm::StringRef (reinterpret_cast <const char *>(data_sp->GetBytes ()));
61
64
62
65
Expected<json::Value> json = json::parse (text);
63
66
if (!json) {
64
- llvm::consumeError (json.takeError ());
67
+ LLDB_LOG_ERROR (log, json.takeError (),
68
+ " failed to parse JSON object file: {0}" );
65
69
return nullptr ;
66
70
}
67
71
68
72
json::Path::Root root;
69
73
Header header;
70
- if (!fromJSON (*json, header, root))
74
+ if (!fromJSON (*json, header, root)) {
75
+ LLDB_LOG_ERROR (log, root.getError (),
76
+ " failed to parse JSON object file header: {0}" );
71
77
return nullptr ;
78
+ }
72
79
73
80
ArchSpec arch (header.triple );
74
81
UUID uuid;
75
82
uuid.SetFromStringRef (header.uuid );
83
+ Type type = header.type .value_or (eTypeDebugInfo);
76
84
77
85
Body body;
78
- fromJSON (*json, body, root);
86
+ if (!fromJSON (*json, body, root)) {
87
+ LLDB_LOG_ERROR (log, root.getError (),
88
+ " failed to parse JSON object file body: {0}" );
89
+ return nullptr ;
90
+ }
79
91
80
92
return new ObjectFileJSON (module_sp, data_sp, data_offset, file, file_offset,
81
- length, std::move (arch), std::move (uuid),
82
- std::move (body.symbols ));
93
+ length, std::move (arch), std::move (uuid), type,
94
+ std::move (body.symbols ), std::move (body. sections ) );
83
95
}
84
96
85
97
ObjectFile *ObjectFileJSON::CreateMemoryInstance (const ModuleSP &module_sp,
@@ -92,23 +104,36 @@ ObjectFile *ObjectFileJSON::CreateMemoryInstance(const ModuleSP &module_sp,
92
104
size_t ObjectFileJSON::GetModuleSpecifications (
93
105
const FileSpec &file, DataBufferSP &data_sp, offset_t data_offset,
94
106
offset_t file_offset, offset_t length, ModuleSpecList &specs) {
95
-
96
107
if (!MagicBytesMatch (data_sp, data_offset, data_sp->GetByteSize ()))
97
108
return 0 ;
98
109
110
+ // Update the data to contain the entire file if it doesn't already.
111
+ if (data_sp->GetByteSize () < length) {
112
+ data_sp = MapFileData (file, length, file_offset);
113
+ if (!data_sp)
114
+ return 0 ;
115
+ data_offset = 0 ;
116
+ }
117
+
118
+ Log *log = GetLog (LLDBLog::Symbols);
119
+
99
120
auto text =
100
121
llvm::StringRef (reinterpret_cast <const char *>(data_sp->GetBytes ()));
101
122
102
123
Expected<json::Value> json = json::parse (text);
103
124
if (!json) {
104
- llvm::consumeError (json.takeError ());
125
+ LLDB_LOG_ERROR (log, json.takeError (),
126
+ " failed to parse JSON object file: {0}" );
105
127
return 0 ;
106
128
}
107
129
108
130
json::Path::Root root;
109
131
Header header;
110
- if (!fromJSON (*json, header, root))
132
+ if (!fromJSON (*json, header, root)) {
133
+ LLDB_LOG_ERROR (log, root.getError (),
134
+ " failed to parse JSON object file header: {0}" );
111
135
return 0 ;
136
+ }
112
137
113
138
ArchSpec arch (header.triple );
114
139
UUID uuid;
@@ -123,10 +148,12 @@ size_t ObjectFileJSON::GetModuleSpecifications(
123
148
ObjectFileJSON::ObjectFileJSON (const ModuleSP &module_sp, DataBufferSP &data_sp,
124
149
offset_t data_offset, const FileSpec *file,
125
150
offset_t offset, offset_t length, ArchSpec arch,
126
- UUID uuid, std::vector<JSONSymbol> symbols)
151
+ UUID uuid, Type type,
152
+ std::vector<JSONSymbol> symbols,
153
+ std::vector<JSONSection> sections)
127
154
: ObjectFile(module_sp, file, offset, length, data_sp, data_offset),
128
- m_arch(std::move(arch)), m_uuid(std::move(uuid)),
129
- m_symbols(std::move(symbols)) {}
155
+ m_arch(std::move(arch)), m_uuid(std::move(uuid)), m_type(type),
156
+ m_symbols(std::move(symbols)), m_sections(std::move(sections)) {}
130
157
131
158
bool ObjectFileJSON::ParseHeader () {
132
159
// We already parsed the header during initialization.
@@ -139,15 +166,29 @@ void ObjectFileJSON::ParseSymtab(Symtab &symtab) {
139
166
for (JSONSymbol json_symbol : m_symbols) {
140
167
llvm::Expected<Symbol> symbol = Symbol::FromJSON (json_symbol, section_list);
141
168
if (!symbol) {
142
- LLDB_LOG_ERROR (log, symbol.takeError (), " invalid symbol" );
169
+ LLDB_LOG_ERROR (log, symbol.takeError (), " invalid symbol: {0} " );
143
170
continue ;
144
171
}
145
172
symtab.AddSymbol (*symbol);
146
173
}
147
174
symtab.Finalize ();
148
175
}
149
176
150
- void ObjectFileJSON::CreateSections (SectionList &unified_section_list) {}
177
+ void ObjectFileJSON::CreateSections (SectionList &unified_section_list) {
178
+ if (m_sections_up)
179
+ return ;
180
+ m_sections_up = std::make_unique<SectionList>();
181
+
182
+ lldb::user_id_t id = 1 ;
183
+ for (const auto §ion : m_sections) {
184
+ auto section_sp = std::make_shared<Section>(
185
+ GetModule (), this , id++, ConstString (section.name ),
186
+ section.type .value_or (eSectionTypeCode), 0 , section.size .value_or (0 ), 0 ,
187
+ section.size .value_or (0 ), /* log2align*/ 0 , /* flags*/ 0 );
188
+ m_sections_up->AddSection (section_sp);
189
+ unified_section_list.AddSection (section_sp);
190
+ }
191
+ }
151
192
152
193
bool ObjectFileJSON::MagicBytesMatch (DataBufferSP data_sp,
153
194
lldb::addr_t data_offset,
@@ -164,13 +205,15 @@ namespace lldb_private {
164
205
bool fromJSON (const json::Value &value, ObjectFileJSON::Header &header,
165
206
json::Path path) {
166
207
json::ObjectMapper o (value, path);
167
- return o && o.map (" triple" , header.triple ) && o.map (" uuid" , header.uuid );
208
+ return o && o.map (" triple" , header.triple ) && o.map (" uuid" , header.uuid ) &&
209
+ o.map (" type" , header.type );
168
210
}
169
211
170
212
bool fromJSON (const json::Value &value, ObjectFileJSON::Body &body,
171
213
json::Path path) {
172
214
json::ObjectMapper o (value, path);
173
- return o && o.map (" symbols" , body.symbols );
215
+ return o && o.mapOptional (" symbols" , body.symbols ) &&
216
+ o.mapOptional (" sections" , body.sections );
174
217
}
175
218
176
219
} // namespace lldb_private
0 commit comments