18
18
#include " Host/macosx/cfcpp/CFCData.h"
19
19
#include " Host/macosx/cfcpp/CFCReleaser.h"
20
20
#include " Host/macosx/cfcpp/CFCString.h"
21
+ #include " lldb/Core/Module.h"
21
22
#include " lldb/Core/ModuleList.h"
22
23
#include " lldb/Core/ModuleSpec.h"
23
24
#include " lldb/Host/Host.h"
25
+ #include " lldb/Host/HostInfo.h"
24
26
#include " lldb/Symbol/ObjectFile.h"
25
27
#include " lldb/Utility/ArchSpec.h"
26
28
#include " lldb/Utility/DataBuffer.h"
@@ -108,12 +110,10 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
108
110
if (dsym_url.get ()) {
109
111
if (::CFURLGetFileSystemRepresentation (
110
112
dsym_url.get (), true , (UInt8 *)path, sizeof (path) - 1 )) {
111
- if (log) {
112
- LLDB_LOGF (log,
113
- " DebugSymbols framework returned dSYM path of %s for "
114
- " UUID %s -- looking for the dSYM" ,
115
- path, uuid->GetAsString ().c_str ());
116
- }
113
+ LLDB_LOGF (log,
114
+ " DebugSymbols framework returned dSYM path of %s for "
115
+ " UUID %s -- looking for the dSYM" ,
116
+ path, uuid->GetAsString ().c_str ());
117
117
FileSpec dsym_filespec (path);
118
118
if (path[0 ] == ' ~' )
119
119
FileSystem::Instance ().Resolve (dsym_filespec);
@@ -147,16 +147,54 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
147
147
uuid_dict = static_cast <CFDictionaryRef>(
148
148
::CFDictionaryGetValue (dict.get(), uuid_cfstr.get()));
149
149
}
150
- if (uuid_dict) {
150
+
151
+ // Check to see if we have the file on the local filesystem.
152
+ if (FileSystem::Instance ().Exists (module_spec.GetFileSpec ())) {
153
+ ModuleSpec exe_spec;
154
+ exe_spec.GetFileSpec () = module_spec.GetFileSpec ();
155
+ exe_spec.GetUUID () = module_spec.GetUUID ();
156
+ ModuleSP module_sp;
157
+ module_sp.reset (new Module (exe_spec));
158
+ if (module_sp && module_sp->GetObjectFile () &&
159
+ module_sp->MatchesModuleSpec (exe_spec)) {
160
+ success = true ;
161
+ return_module_spec.GetFileSpec () = module_spec.GetFileSpec ();
162
+ LLDB_LOGF (log, " using original binary filepath %s for UUID %s" ,
163
+ module_spec.GetFileSpec ().GetPath ().c_str (),
164
+ uuid->GetAsString ().c_str ());
165
+ ++items_found;
166
+ }
167
+ }
168
+
169
+ // Check if the requested image is in our shared cache.
170
+ if (!success) {
171
+ SharedCacheImageInfo image_info = HostInfo::GetSharedCacheImageInfo (
172
+ module_spec.GetFileSpec ().GetPath ());
173
+
174
+ // If we found it and it has the correct UUID, let's proceed with
175
+ // creating a module from the memory contents.
176
+ if (image_info.uuid && (!module_spec.GetUUID () ||
177
+ module_spec.GetUUID () == image_info.uuid )) {
178
+ success = true ;
179
+ return_module_spec.GetFileSpec () = module_spec.GetFileSpec ();
180
+ LLDB_LOGF (log,
181
+ " using binary from shared cache for filepath %s for "
182
+ " UUID %s" ,
183
+ module_spec.GetFileSpec ().GetPath ().c_str (),
184
+ uuid->GetAsString ().c_str ());
185
+ ++items_found;
186
+ }
187
+ }
188
+
189
+ // Use the DBGSymbolRichExecutable filepath if present
190
+ if (!success && uuid_dict) {
151
191
CFStringRef exec_cf_path =
152
192
static_cast <CFStringRef>(::CFDictionaryGetValue (
153
193
uuid_dict, CFSTR (" DBGSymbolRichExecutable" )));
154
194
if (exec_cf_path && ::CFStringGetFileSystemRepresentation (
155
195
exec_cf_path, path, sizeof (path))) {
156
- if (log) {
157
- LLDB_LOGF (log, " plist bundle has exec path of %s for UUID %s" ,
158
- path, uuid->GetAsString ().c_str ());
159
- }
196
+ LLDB_LOGF (log, " plist bundle has exec path of %s for UUID %s" ,
197
+ path, uuid->GetAsString ().c_str ());
160
198
++items_found;
161
199
FileSpec exec_filespec (path);
162
200
if (path[0 ] == ' ~' )
@@ -168,20 +206,17 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
168
206
}
169
207
}
170
208
209
+ // Look next to the dSYM for the binary file.
171
210
if (!success) {
172
- // No dictionary, check near the dSYM bundle for an executable that
173
- // matches...
174
211
if (::CFURLGetFileSystemRepresentation (
175
212
dsym_url.get (), true , (UInt8 *)path, sizeof (path) - 1 )) {
176
213
char *dsym_extension_pos = ::strstr (path, " .dSYM" );
177
214
if (dsym_extension_pos) {
178
215
*dsym_extension_pos = ' \0 ' ;
179
- if (log) {
180
- LLDB_LOGF (log,
181
- " Looking for executable binary next to dSYM "
182
- " bundle with name with name %s" ,
183
- path);
184
- }
216
+ LLDB_LOGF (log,
217
+ " Looking for executable binary next to dSYM "
218
+ " bundle with name with name %s" ,
219
+ path);
185
220
FileSpec file_spec (path);
186
221
FileSystem::Instance ().Resolve (file_spec);
187
222
ModuleSpecList module_specs;
@@ -208,12 +243,10 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
208
243
{
209
244
++items_found;
210
245
return_module_spec.GetFileSpec () = bundle_exe_file_spec;
211
- if (log) {
212
- LLDB_LOGF (log,
213
- " Executable binary %s next to dSYM is "
214
- " compatible; using" ,
215
- path);
216
- }
246
+ LLDB_LOGF (log,
247
+ " Executable binary %s next to dSYM is "
248
+ " compatible; using" ,
249
+ path);
217
250
}
218
251
}
219
252
}
@@ -238,12 +271,10 @@ int LocateMacOSXFilesUsingDebugSymbols(const ModuleSpec &module_spec,
238
271
{
239
272
++items_found;
240
273
return_module_spec.GetFileSpec () = file_spec;
241
- if (log) {
242
- LLDB_LOGF (log,
243
- " Executable binary %s next to dSYM is "
244
- " compatible; using" ,
245
- path);
246
- }
274
+ LLDB_LOGF (log,
275
+ " Executable binary %s next to dSYM is "
276
+ " compatible; using" ,
277
+ path);
247
278
}
248
279
break ;
249
280
}
@@ -321,11 +352,9 @@ static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
321
352
if (CFCString::FileSystemRepresentation (cf_str, str)) {
322
353
module_spec.GetFileSpec ().SetFile (str.c_str (), FileSpec::Style::native);
323
354
FileSystem::Instance ().Resolve (module_spec.GetFileSpec ());
324
- if (log) {
325
- LLDB_LOGF (log,
326
- " From dsymForUUID plist: Symbol rich executable is at '%s'" ,
327
- str.c_str ());
328
- }
355
+ LLDB_LOGF (log,
356
+ " From dsymForUUID plist: Symbol rich executable is at '%s'" ,
357
+ str.c_str ());
329
358
}
330
359
}
331
360
@@ -337,10 +366,7 @@ static bool GetModuleSpecInfoFromUUIDDictionary(CFDictionaryRef uuid_dict,
337
366
FileSpec::Style::native);
338
367
FileSystem::Instance ().Resolve (module_spec.GetFileSpec ());
339
368
success = true ;
340
- if (log) {
341
- LLDB_LOGF (log, " From dsymForUUID plist: dSYM is at '%s'" ,
342
- str.c_str ());
343
- }
369
+ LLDB_LOGF (log, " From dsymForUUID plist: dSYM is at '%s'" , str.c_str ());
344
370
}
345
371
}
346
372
@@ -640,14 +666,12 @@ bool Symbols::DownloadObjectAndSymbolFile(ModuleSpec &module_spec,
640
666
}
641
667
}
642
668
} else {
643
- if (log) {
644
- if (!uuid_str.empty ())
645
- LLDB_LOGF (log, " Called %s on %s, no matches" ,
646
- g_dsym_for_uuid_exe_path, uuid_str.c_str ());
647
- else if (file_path[0 ] != ' \0 ' )
648
- LLDB_LOGF (log, " Called %s on %s, no matches" ,
649
- g_dsym_for_uuid_exe_path, file_path);
650
- }
669
+ if (!uuid_str.empty ())
670
+ LLDB_LOGF (log, " Called %s on %s, no matches" ,
671
+ g_dsym_for_uuid_exe_path, uuid_str.c_str ());
672
+ else if (file_path[0 ] != ' \0 ' )
673
+ LLDB_LOGF (log, " Called %s on %s, no matches" ,
674
+ g_dsym_for_uuid_exe_path, file_path);
651
675
}
652
676
}
653
677
}
0 commit comments