diff options
| author | Greg Clayton <gclayton@apple.com> | 2013-02-01 21:38:35 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2013-02-01 21:38:35 +0000 |
| commit | 39f7ee86c8d8a81e9c1ddc1514e2db5a1778bd06 (patch) | |
| tree | a1d15f6154b536529cfb3fb4f30d12bb59ad6bfb | |
| parent | 25c3b6acc04c3c4eec063b349d73779e523b9d37 (diff) | |
| download | bcm5719-llvm-39f7ee86c8d8a81e9c1ddc1514e2db5a1778bd06.tar.gz bcm5719-llvm-39f7ee86c8d8a81e9c1ddc1514e2db5a1778bd06.zip | |
<rdar://problem/13092722>
Fix in loading mach files from memory when using DynamicLoaderMacOSXDYLD.
Removed the uuid mismatch warning that could be spit out and any time during debugging and removed the test case that was looking for that. Currently the "add-dsym" or "target symbols add" command will report an error when the UUID's don't match.
Be more careful when checking and resolving section + offset addresses to make sure none of the base addresses are invalid.
llvm-svn: 174222
| -rw-r--r-- | lldb/include/lldb/Target/Process.h | 4 | ||||
| -rw-r--r-- | lldb/source/API/SBModule.cpp | 14 | ||||
| -rw-r--r-- | lldb/source/Host/macosx/Symbols.cpp | 12 | ||||
| -rw-r--r-- | lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp | 4 | ||||
| -rw-r--r-- | lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp | 161 | ||||
| -rw-r--r-- | lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h | 10 | ||||
| -rw-r--r-- | lldb/source/Symbol/ObjectFile.cpp | 20 | ||||
| -rw-r--r-- | lldb/source/Target/Process.cpp | 15 | ||||
| -rw-r--r-- | lldb/source/Target/SectionLoadList.cpp | 5 | ||||
| -rw-r--r-- | lldb/test/warnings/uuid/TestUUIDMismatchWanring.py | 113 |
10 files changed, 96 insertions, 262 deletions
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h index 3c0a61acc0c..b5c421622eb 100644 --- a/lldb/include/lldb/Target/Process.h +++ b/lldb/include/lldb/Target/Process.h @@ -2890,9 +2890,7 @@ public: lldb::ModuleSP ReadModuleFromMemory (const FileSpec& file_spec, - lldb::addr_t header_addr, - bool add_image_to_target, - bool load_sections_in_target); + lldb::addr_t header_addr); //------------------------------------------------------------------ /// Attempt to get the attributes for a region of memory in the process. diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp index 219870c733c..681d416c2ae 100644 --- a/lldb/source/API/SBModule.cpp +++ b/lldb/source/API/SBModule.cpp @@ -50,12 +50,14 @@ SBModule::SBModule (lldb::SBProcess &process, lldb::addr_t header_addr) : ProcessSP process_sp (process.GetSP()); if (process_sp) { - const bool add_image_to_target = true; - const bool load_image_sections_in_target = true; - m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), - header_addr, - add_image_to_target, - load_image_sections_in_target); + m_opaque_sp = process_sp->ReadModuleFromMemory (FileSpec(), header_addr); + if (m_opaque_sp) + { + Target &target = process_sp->GetTarget(); + bool changed = false; + m_opaque_sp->SetLoadAddress(target, 0, changed); + target.GetImages().Append(m_opaque_sp); + } } } diff --git a/lldb/source/Host/macosx/Symbols.cpp b/lldb/source/Host/macosx/Symbols.cpp index 1036b025879..a577f1868a8 100644 --- a/lldb/source/Host/macosx/Symbols.cpp +++ b/lldb/source/Host/macosx/Symbols.cpp @@ -124,18 +124,6 @@ SkinnyMachOFileContainsArchAndUUID lldb_private::UUID file_uuid (data.GetData(&data_offset, 16), 16); if (file_uuid == *uuid) return true; - - // Emit some warning messages since the UUIDs do not match! - char path_buf[PATH_MAX]; - path_buf[0] = '\0'; - const char *path = file_spec.GetPath(path_buf, PATH_MAX) ? path_buf - : file_spec.GetFilename().AsCString(); - StreamString ss_m_uuid, ss_o_uuid; - uuid->Dump(&ss_m_uuid); - file_uuid.Dump(&ss_o_uuid); - Host::SystemLog (Host::eSystemLogWarning, - "warning: UUID mismatch detected between binary (%s) and:\n\t'%s' (%s)\n", - ss_m_uuid.GetData(), path, ss_o_uuid.GetData()); return false; } data_offset = cmd_offset + cmd_size; diff --git a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp index ab310f80382..5bd4a8c6fe5 100644 --- a/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp +++ b/lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp @@ -420,7 +420,7 @@ DynamicLoaderDarwinKernel::CheckForKernelImageAtAddress (lldb::addr_t addr, Proc && (header.flags & llvm::MachO::HeaderFlagBitIsDynamicLinkObject) == 0) { // Create a full module to get the UUID - ModuleSP memory_module_sp = process->ReadModuleFromMemory (FileSpec ("temp_mach_kernel", false), addr, false, false); + ModuleSP memory_module_sp = process->ReadModuleFromMemory (FileSpec ("temp_mach_kernel", false), addr); if (!memory_module_sp.get()) return UUID(); @@ -557,7 +557,7 @@ DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageUsingMemoryModule ( else file_spec.SetFile (name, false); - memory_module_sp = process->ReadModuleFromMemory (file_spec, address, false, false); + memory_module_sp = process->ReadModuleFromMemory (file_spec, address); if (memory_module_sp && !uuid_is_valid) { uuid = memory_module_sp->GetUUID(); diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index fe761ebdcce..e7827f38ad7 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -273,30 +273,33 @@ DynamicLoaderMacOSXDYLD::LocateDYLD() // mach header for dyld, or it might point to the // dyld_all_image_infos struct const addr_t shlib_addr = m_process->GetImageInfoAddress (); - ByteOrder byte_order = m_process->GetTarget().GetArchitecture().GetByteOrder(); - uint8_t buf[4]; - DataExtractor data (buf, sizeof(buf), byte_order, 4); - Error error; - if (m_process->ReadMemory (shlib_addr, buf, 4, error) == 4) + if (shlib_addr != LLDB_INVALID_ADDRESS) { - lldb::offset_t offset = 0; - uint32_t magic = data.GetU32 (&offset); - switch (magic) + ByteOrder byte_order = m_process->GetTarget().GetArchitecture().GetByteOrder(); + uint8_t buf[4]; + DataExtractor data (buf, sizeof(buf), byte_order, 4); + Error error; + if (m_process->ReadMemory (shlib_addr, buf, 4, error) == 4) { - case llvm::MachO::HeaderMagic32: - case llvm::MachO::HeaderMagic64: - case llvm::MachO::HeaderMagic32Swapped: - case llvm::MachO::HeaderMagic64Swapped: - m_process_image_addr_is_all_images_infos = false; - return ReadDYLDInfoFromMemoryAndSetNotificationCallback(shlib_addr); - - default: - break; + lldb::offset_t offset = 0; + uint32_t magic = data.GetU32 (&offset); + switch (magic) + { + case llvm::MachO::HeaderMagic32: + case llvm::MachO::HeaderMagic64: + case llvm::MachO::HeaderMagic32Swapped: + case llvm::MachO::HeaderMagic64Swapped: + m_process_image_addr_is_all_images_infos = false; + return ReadDYLDInfoFromMemoryAndSetNotificationCallback(shlib_addr); + + default: + break; + } } + // Maybe it points to the all image infos? + m_dyld_all_image_infos_addr = shlib_addr; + m_process_image_addr_is_all_images_infos = true; } - // Maybe it points to the all image infos? - m_dyld_all_image_infos_addr = shlib_addr; - m_process_image_addr_is_all_images_infos = true; } if (m_dyld_all_image_infos_addr != LLDB_INVALID_ADDRESS) @@ -333,13 +336,13 @@ DynamicLoaderMacOSXDYLD::LocateDYLD() } ModuleSP -DynamicLoaderMacOSXDYLD::FindTargetModuleForDYLDImageInfo (const DYLDImageInfo &image_info, bool can_create, bool *did_create_ptr) +DynamicLoaderMacOSXDYLD::FindTargetModuleForDYLDImageInfo (DYLDImageInfo &image_info, bool can_create, bool *did_create_ptr) { if (did_create_ptr) *did_create_ptr = false; - - const ModuleList &target_images = m_process->GetTarget().GetImages(); + Target &target = m_process->GetTarget(); + const ModuleList &target_images = target.GetImages(); ModuleSpec module_spec (image_info.file_spec, image_info.GetArchitecture ()); module_spec.GetUUID() = image_info.uuid; ModuleSP module_sp (target_images.FindFirstModule (module_spec)); @@ -356,16 +359,9 @@ DynamicLoaderMacOSXDYLD::FindTargetModuleForDYLDImageInfo (const DYLDImageInfo & { if (can_create) { - module_sp = m_process->GetTarget().GetSharedModule (module_spec); + module_sp = target.GetSharedModule (module_spec); if (!module_sp || module_sp->GetObjectFile() == NULL) - { - const bool add_image_to_target = true; - const bool load_image_sections_in_target = false; - module_sp = m_process->ReadModuleFromMemory (image_info.file_spec, - image_info.address, - add_image_to_target, - load_image_sections_in_target); - } + module_sp = m_process->ReadModuleFromMemory (image_info.file_spec, image_info.address); if (did_create_ptr) *did_create_ptr = (bool) module_sp; @@ -399,12 +395,14 @@ DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb:: } } + Target &target = m_process->GetTarget(); + if (m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS && dyld_module_sp.get()) { static ConstString g_dyld_all_image_infos ("dyld_all_image_infos"); const Symbol *symbol = dyld_module_sp->FindFirstSymbolWithNameAndType (g_dyld_all_image_infos, eSymbolTypeData); if (symbol) - m_dyld_all_image_infos_addr = symbol->GetAddress().GetLoadAddress(&m_process->GetTarget()); + m_dyld_all_image_infos_addr = symbol->GetAddress().GetLoadAddress(&target); } // Update all image infos @@ -417,13 +415,12 @@ DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb:: /// unique! if (dyld_module_sp) { - if (m_process->GetTarget().GetImages().AppendIfNeeded (dyld_module_sp)) - UpdateImageLoadAddress(dyld_module_sp.get(), m_dyld); + target.GetImages().AppendIfNeeded (dyld_module_sp); // At this point we should have read in dyld's module, and so we should set breakpoints in it: ModuleList modules; modules.Append(dyld_module_sp); - m_process->GetTarget().ModulesDidLoad(modules); + target.ModulesDidLoad(modules); } return true; } @@ -437,40 +434,6 @@ DynamicLoaderMacOSXDYLD::NeedToLocateDYLD () const return m_dyld_all_image_infos_addr == LLDB_INVALID_ADDRESS; } -bool -DynamicLoaderMacOSXDYLD::UpdateCommPageLoadAddress(Module *module) -{ - bool changed = false; - if (module) - { - ObjectFile *image_object_file = module->GetObjectFile(); - if (image_object_file) - { - SectionList *section_list = image_object_file->GetSectionList (); - if (section_list) - { - const size_t num_sections = section_list->GetSize(); - for (size_t i=0; i<num_sections; ++i) - { - SectionSP section_sp (section_list->GetSectionAtIndex (i)); - if (section_sp) - { - const addr_t new_section_load_addr = section_sp->GetFileAddress (); - const addr_t old_section_load_addr = m_process->GetTarget().GetSectionLoadList().GetSectionLoadAddress (section_sp); - if (old_section_load_addr == LLDB_INVALID_ADDRESS || - old_section_load_addr != new_section_load_addr) - { - if (m_process->GetTarget().GetSectionLoadList().SetSectionLoadAddress (section_sp, section_sp->GetFileAddress ())) - changed = true; - } - } - } - } - } - } - return changed; -} - //---------------------------------------------------------------------- // Update the load addresses for all segments in MODULE using the // updated INFO that is passed in. @@ -566,6 +529,14 @@ DynamicLoaderMacOSXDYLD::UpdateImageLoadAddress (Module *module, DYLDImageInfo& } } } + // We might have an in memory image that was loaded as soon as it was created + if (info.load_stop_id == m_process->GetStopID()) + changed = true; + else if (changed) + { + // Update the stop ID when this library was updated + info.load_stop_id = m_process->GetStopID(); + } return changed; } @@ -843,6 +814,8 @@ DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfos (DYLDImageInfo::collection &i // Now add these images to the main list. ModuleList loaded_module_list; LogSP log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER)); + Target &target = m_process->GetTarget(); + ModuleList& target_images = target.GetImages(); for (uint32_t idx = 0; idx < image_infos.size(); ++idx) { @@ -871,26 +844,31 @@ DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfos (DYLDImageInfo::collection &i Section *commpage_section = sections->FindSectionByName(commpage_dbstr).get(); if (commpage_section) { - const ModuleList& target_images = m_process->GetTarget().GetImages(); ModuleSpec module_spec (objfile->GetFileSpec(), image_infos[idx].GetArchitecture ()); module_spec.GetObjectName() = commpage_dbstr; ModuleSP commpage_image_module_sp(target_images.FindFirstModule (module_spec)); if (!commpage_image_module_sp) { module_spec.SetObjectOffset (objfile->GetOffset() + commpage_section->GetFileOffset()); - commpage_image_module_sp = m_process->GetTarget().GetSharedModule (module_spec); + commpage_image_module_sp = target.GetSharedModule (module_spec); if (!commpage_image_module_sp || commpage_image_module_sp->GetObjectFile() == NULL) { - const bool add_image_to_target = true; - const bool load_image_sections_in_target = false; commpage_image_module_sp = m_process->ReadModuleFromMemory (image_infos[idx].file_spec, - image_infos[idx].address, - add_image_to_target, - load_image_sections_in_target); + image_infos[idx].address); + // Always load a memory image right away in the target in case + // we end up trying to read the symbol table from memory... The + // __LINKEDIT will need to be mapped so we can figure out where + // the symbol table bits are... + bool changed = false; + UpdateImageLoadAddress (commpage_image_module_sp.get(), image_infos[idx]); + target.GetImages().Append(commpage_image_module_sp); + if (changed) + { + image_infos[idx].load_stop_id = m_process->GetStopID(); + loaded_module_list.AppendIfNeeded (commpage_image_module_sp); + } } } - if (commpage_image_module_sp) - UpdateCommPageLoadAddress (commpage_image_module_sp.get()); } } } @@ -902,6 +880,7 @@ DynamicLoaderMacOSXDYLD::AddModulesUsingImageInfos (DYLDImageInfo::collection &i // shared libraries each time. if (UpdateImageLoadAddress (image_module_sp.get(), image_infos[idx])) { + target_images.AppendIfNeeded(image_module_sp); loaded_module_list.AppendIfNeeded (image_module_sp); } } @@ -1343,32 +1322,18 @@ DynamicLoaderMacOSXDYLD::UpdateImageInfosHeaderAndLoadCommands(DYLDImageInfo::co } } + Target &target = m_process->GetTarget(); + if (exe_idx < image_infos.size()) { const bool can_create = true; ModuleSP exe_module_sp (FindTargetModuleForDYLDImageInfo (image_infos[exe_idx], can_create, NULL)); - if (!exe_module_sp) - { - ArchSpec exe_arch_spec (image_infos[exe_idx].GetArchitecture ()); - ModuleSpec module_spec (image_infos[exe_idx].file_spec, - image_infos[exe_idx].GetArchitecture ()); - module_spec.GetUUID() = image_infos[exe_idx].uuid; - exe_module_sp = m_process->GetTarget().GetSharedModule (module_spec); - if (!exe_module_sp || exe_module_sp->GetObjectFile() == NULL) - { - const bool add_image_to_target = true; - const bool load_image_sections_in_target = false; - exe_module_sp = m_process->ReadModuleFromMemory (image_infos[exe_idx].file_spec, - image_infos[exe_idx].address, - add_image_to_target, - load_image_sections_in_target); - } - } - if (exe_module_sp) { - if (exe_module_sp.get() != m_process->GetTarget().GetExecutableModulePointer()) + UpdateImageLoadAddress (exe_module_sp.get(), image_infos[exe_idx]); + + if (exe_module_sp.get() != target.GetExecutableModulePointer()) { // Don't load dependent images since we are in dyld where we will know // and find out about all images that are loaded diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h index 2e0d2504288..0b1a9a6a593 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.h @@ -178,6 +178,7 @@ protected: lldb_private::UUID uuid; // UUID for this dylib if it has one, else all zeros llvm::MachO::mach_header header; // The mach header for this image std::vector<Segment> segments; // All segment vmaddr and vmsize pairs for this executable (from memory of inferior) + uint32_t load_stop_id; // The process stop ID that the sections for this image were loadeded DYLDImageInfo() : address(LLDB_INVALID_ADDRESS), @@ -186,7 +187,8 @@ protected: file_spec(), uuid(), header(), - segments() + segments(), + load_stop_id(0) { } @@ -203,6 +205,7 @@ protected: } uuid.Clear(); segments.clear(); + load_stop_id = 0; } bool @@ -316,7 +319,7 @@ protected: DYLDImageInfo& info); lldb::ModuleSP - FindTargetModuleForDYLDImageInfo (const DYLDImageInfo &image_info, + FindTargetModuleForDYLDImageInfo (DYLDImageInfo &image_info, bool can_create, bool *did_create_ptr); @@ -358,9 +361,6 @@ protected: bool update_executable); bool - UpdateCommPageLoadAddress (lldb_private::Module *module); - - bool ReadImageInfos (lldb::addr_t image_infos_addr, uint32_t image_infos_count, DYLDImageInfo::collection &image_infos); diff --git a/lldb/source/Symbol/ObjectFile.cpp b/lldb/source/Symbol/ObjectFile.cpp index 2388c6df400..cd3447c150d 100644 --- a/lldb/source/Symbol/ObjectFile.cpp +++ b/lldb/source/Symbol/ObjectFile.cpp @@ -364,7 +364,9 @@ ObjectFile::ReadSectionData (const Section *section, off_t section_offset, void if (process_sp) { Error error; - return process_sp->ReadMemory (section->GetLoadBaseAddress (&process_sp->GetTarget()) + section_offset, dst, dst_len, error); + const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget()); + if (base_load_addr != LLDB_INVALID_ADDRESS) + return process_sp->ReadMemory (base_load_addr + section_offset, dst, dst_len, error); } } else @@ -406,13 +408,17 @@ ObjectFile::ReadSectionData (const Section *section, DataExtractor& section_data ProcessSP process_sp (m_process_wp.lock()); if (process_sp) { - DataBufferSP data_sp (ReadMemory (process_sp, section->GetLoadBaseAddress (&process_sp->GetTarget()), section->GetByteSize())); - if (data_sp) + const addr_t base_load_addr = section->GetLoadBaseAddress (&process_sp->GetTarget()); + if (base_load_addr != LLDB_INVALID_ADDRESS) { - section_data.SetData (data_sp, 0, data_sp->GetByteSize()); - section_data.SetByteOrder (process_sp->GetByteOrder()); - section_data.SetAddressByteSize (process_sp->GetAddressByteSize()); - return section_data.GetByteSize(); + DataBufferSP data_sp (ReadMemory (process_sp, base_load_addr, section->GetByteSize())); + if (data_sp) + { + section_data.SetData (data_sp, 0, data_sp->GetByteSize()); + section_data.SetByteOrder (process_sp->GetByteOrder()); + section_data.SetAddressByteSize (process_sp->GetAddressByteSize()); + return section_data.GetByteSize(); + } } } } diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index a1ce46928da..f46f6ac99fd 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -2666,9 +2666,7 @@ Process::DeallocateMemory (addr_t ptr) ModuleSP Process::ReadModuleFromMemory (const FileSpec& file_spec, - lldb::addr_t header_addr, - bool add_image_to_target, - bool load_sections_in_target) + lldb::addr_t header_addr) { ModuleSP module_sp (new Module (file_spec, ArchSpec())); if (module_sp) @@ -2676,18 +2674,7 @@ Process::ReadModuleFromMemory (const FileSpec& file_spec, Error error; ObjectFile *objfile = module_sp->GetMemoryObjectFile (shared_from_this(), header_addr, error); if (objfile) - { - if (add_image_to_target) - { - m_target.GetImages().Append(module_sp); - if (load_sections_in_target) - { - bool changed = false; - module_sp->SetLoadAddress (m_target, 0, changed); - } - } return module_sp; - } } return ModuleSP(); } diff --git a/lldb/source/Target/SectionLoadList.cpp b/lldb/source/Target/SectionLoadList.cpp index 17e558144ce..6a701b35ce9 100644 --- a/lldb/source/Target/SectionLoadList.cpp +++ b/lldb/source/Target/SectionLoadList.cpp @@ -216,9 +216,10 @@ SectionLoadList::ResolveLoadAddress (addr_t load_addr, Address &so_addr) const { if (load_addr != pos->first && pos != m_addr_to_sect.begin()) --pos; - if (load_addr >= pos->first) + const addr_t pos_load_addr = pos->first; + if (load_addr >= pos_load_addr) { - addr_t offset = load_addr - pos->first; + addr_t offset = load_addr - pos_load_addr; if (offset < pos->second->GetByteSize()) { // We have found the top level section, now we need to find the diff --git a/lldb/test/warnings/uuid/TestUUIDMismatchWanring.py b/lldb/test/warnings/uuid/TestUUIDMismatchWanring.py deleted file mode 100644 index bafcbc3351c..00000000000 --- a/lldb/test/warnings/uuid/TestUUIDMismatchWanring.py +++ /dev/null @@ -1,113 +0,0 @@ -"""Test that the 'warning: UUID mismatch detected ...' message is emitted if a -dsym in vicinity of the executable does not match its UUID.""" - -import os, time -import unittest2 -import lldb -import pexpect -from lldbtest import * - -@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") -class UUIDMismatchWarningCase(TestBase): - - mydir = os.path.join("warnings", "uuid") - - @classmethod - def classCleanup(cls): - """Cleanup the test byproducts.""" - cls.RemoveTempFile("child_send.txt") - cls.RemoveTempFile("child_read.txt") - - def setUp(self): - TestBase.setUp(self) - self.template = 'main.cpp.template' - self.source = 'main.cpp' - self.teardown_hook_added = False - - def test_uuid_mismatch_warning(self): - """Test that the 'warning: UUID mismatch detected ...' message is emitted.""" - - # Call the program generator to produce main.cpp, version 1. - self.generate_main_cpp(version=1) - self.line_to_break = line_number(self.source, '// Set breakpoint here.') - self.buildDsym(clean=True) - - # Insert some delay and then call the program generator to produce main.cpp, version 2. - time.sleep(5) - self.generate_main_cpp(version=101) - # Now call make again, but this time don't generate the dSYM. - self.buildDwarf(clean=False) - - self.exe_name = 'a.out' - self.check_executable_and_dsym(self.exe_name) - - def generate_main_cpp(self, version=0): - """Generate main.cpp from main.cpp.template.""" - temp = os.path.join(os.getcwd(), self.template) - with open(temp, 'r') as f: - content = f.read() - - new_content = content.replace('%ADD_EXTRA_CODE%', - 'printf("This is version %d\\n");' % version) - src = os.path.join(os.getcwd(), self.source) - with open(src, 'w') as f: - f.write(new_content) - - # The main.cpp has been generated, add a teardown hook to remove it. - if not self.teardown_hook_added: - self.addTearDownHook(lambda: os.remove(src)) - self.teardown_hook_added = True - - def check_executable_and_dsym(self, exe_name): - """Sanity check executable compiled from the auto-generated program.""" - - # The default lldb prompt. - prompt = "(lldb) " - - # So that the child gets torn down after the test. - self.child = pexpect.spawn('%s %s' % (self.lldbHere, self.lldbOption)) - child = self.child - # Turn on logging for input/output to/from the child. - with open('child_send.txt', 'w') as f_send: - with open('child_read.txt', 'w') as f_read: - child.logfile_send = f_send - child.logfile_read = f_read - - child.expect_exact(prompt) - child.setecho(True) - - # Execute the file command, followed by a breakpoint set, the - # UUID mismatch warning should be generated by then. - - child.sendline("file %s" % exe_name) - child.expect_exact(prompt) - child.sendline("breakpoint set -f %s -l %d" % (self.source, self.line_to_break)) - child.expect_exact(prompt) - child.sendline("run") - child.expect_exact(prompt) - - # Now that the necessary logging is done, restore logfile to None to - # stop further logging. - child.logfile_send = None - child.logfile_read = None - - with open('child_send.txt', 'r') as fs: - if self.TraceOn(): - print "\n\nContents of child_send.txt:" - print fs.read() - with open('child_read.txt', 'r') as fr: - from_child = fr.read() - if self.TraceOn(): - print "\n\nContents of child_read.txt:" - print from_child - - # Test that lldb emits the "UUID mismatch detected" message. - self.expect(from_child, msg="UUID mismatch expected!", exe=False, - substrs = ['warning: UUID mismatch detected']) - - -if __name__ == '__main__': - import atexit - lldb.SBDebugger.Initialize() - atexit.register(lambda: lldb.SBDebugger.Terminate()) - unittest2.main() |

