<rdar://problem/13128331>
Fixed "target symbols add" to correctly extract all module specifications from a dSYM file that is supplied and match the symbol file to a current target module using the UUID values if they are available.
This fixes the case where you add a dSYM file (like "foo.dSYM") which is for a renamed executable (like "bar"). In our case it was "mach_kernel.dSYM" which didn't match "mach_kernel.sys".
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@181916 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Commands/CommandObjectTarget.cpp b/source/Commands/CommandObjectTarget.cpp
index 5d3de8d..7765352 100644
--- a/source/Commands/CommandObjectTarget.cpp
+++ b/source/Commands/CommandObjectTarget.cpp
@@ -4272,7 +4272,53 @@
// current target, so we need to find that module in the
// target
ModuleList matching_module_list;
- size_t num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
+
+ size_t num_matches = 0;
+ // First extract all module specs from the symbol file
+ lldb_private::ModuleSpecList symfile_module_specs;
+ if (ObjectFile::GetModuleSpecifications(module_spec.GetSymbolFileSpec(), 0, symfile_module_specs))
+ {
+ // Now extract the module spec that matches the target architecture
+ ModuleSpec target_arch_module_spec;
+ ModuleSpec symfile_module_spec;
+ target_arch_module_spec.GetArchitecture() = target->GetArchitecture();
+ if (symfile_module_specs.FindMatchingModuleSpec(target_arch_module_spec, symfile_module_spec))
+ {
+ // See if it has a UUID?
+ if (symfile_module_spec.GetUUID().IsValid())
+ {
+ // It has a UUID, look for this UUID in the target modules
+ ModuleSpec symfile_uuid_module_spec;
+ symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
+ num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
+ }
+ }
+
+ if (num_matches == 0)
+ {
+ // No matches yet, iterate through the module specs to find a UUID value that
+ // we can match up to an image in our target
+ const size_t num_symfile_module_specs = symfile_module_specs.GetSize();
+ for (size_t i=0; i<num_symfile_module_specs && num_matches == 0; ++i)
+ {
+ if (symfile_module_specs.GetModuleSpecAtIndex(i, symfile_module_spec))
+ {
+ if (symfile_module_spec.GetUUID().IsValid())
+ {
+ // It has a UUID, look for this UUID in the target modules
+ ModuleSpec symfile_uuid_module_spec;
+ symfile_uuid_module_spec.GetUUID() = symfile_module_spec.GetUUID();
+ num_matches = target->GetImages().FindModules (symfile_uuid_module_spec, matching_module_list);
+ }
+ }
+ }
+ }
+ }
+
+ // Just try to match up the file by basename if we have no matches at this point
+ if (num_matches == 0)
+ num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
+
while (num_matches == 0)
{
ConstString filename_no_extension(module_spec.GetFileSpec().GetFileNameStrippingExtension());
@@ -4288,6 +4334,7 @@
module_spec.GetFileSpec().GetFilename() = filename_no_extension;
num_matches = target->GetImages().FindModules (module_spec, matching_module_list);
+
}
if (num_matches > 1)