Index: source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp =================================================================== --- source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp +++ source/Plugins/MemoryHistory/asan/MemoryHistoryASan.cpp @@ -25,6 +25,18 @@ using namespace lldb; using namespace lldb_private; +bool ModuleContainsASanRuntime(Module * module) +{ + SymbolContextList sc_list; + const bool include_symbols = true; + const bool append = true; + const bool include_inlines = true; + + size_t num_matches = module->FindFunctions(ConstString("__asan_get_alloc_stack"), NULL, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); + + return num_matches > 0; +} + MemoryHistorySP MemoryHistoryASan::CreateInstance (const ProcessSP &process_sp) { @@ -33,7 +45,14 @@ Target & target = process_sp->GetTarget(); - bool found_asan_runtime = false; + Module *exe_module = target.GetExecutableModulePointer(); + if (exe_module) + { + if (ModuleContainsASanRuntime(exe_module)) + { + return MemoryHistorySP(new MemoryHistoryASan(process_sp)); + } + } const ModuleList &target_modules = target.GetImages(); Mutex::Locker modules_locker(target_modules.GetMutex()); @@ -41,25 +60,26 @@ for (size_t i = 0; i < num_modules; ++i) { Module *module_pointer = target_modules.GetModulePointerAtIndexUnlocked(i); - - SymbolContextList sc_list; - const bool include_symbols = true; - const bool append = true; - const bool include_inlines = true; + const FileSpec & file_spec = module_pointer->GetFileSpec(); + if (! file_spec) + { + continue; + } - size_t num_matches = module_pointer->FindFunctions(ConstString("__asan_get_alloc_stack"), NULL, eFunctionNameTypeAuto, include_symbols, include_inlines, append, sc_list); + static RegularExpression g_asan_runtime_regex("libclang_rt.asan_(.*)_dynamic\\.dylib"); + if (! g_asan_runtime_regex.Execute (file_spec.GetFilename().GetCString())) + { + continue; + } - if (num_matches) + if (ModuleContainsASanRuntime(module_pointer)) { - found_asan_runtime = true; - break; + return MemoryHistorySP(new MemoryHistoryASan(process_sp)); } } - if (! found_asan_runtime) - return MemoryHistorySP(); - - return MemoryHistorySP(new MemoryHistoryASan(process_sp)); + // not found + return MemoryHistorySP(); } void