[Lldb-commits] [lldb] r118147 - in /lldb/trunk: include/lldb/lldb-private-log.h lldb.xcodeproj/project.pbxproj source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.cpp source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.h source/lldb-log.cpp
Greg Clayton
gclayton at apple.com
Tue Nov 2 21:08:06 PDT 2010
Author: gclayton
Date: Tue Nov 2 23:08:06 2010
New Revision: 118147
URL: http://llvm.org/viewvc/llvm-project?rev=118147&view=rev
Log:
Fixed shared library unloads when the unloaded library doesn't come off
the end of the list. We had an issue in the MacOSX dynamic loader where if
we had shlibs:
1 - a.out
2 - a.dylib
3 - b.dylib
And then a.dylib got unloaded, we would unload b.dylib due to the assumption
that only shared libraries could come off the end of the list. We now properly
search and find which ones get loaded.
Added a new internal logging category for the "lldb" log channel named "dyld".
This should allow all dynamic loaders to use this as a generic log channel so
we can track shared library loads and unloads in the logs without having to
have each plug-in make up its own logging channel.
Removed:
lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.cpp
lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.h
Modified:
lldb/trunk/include/lldb/lldb-private-log.h
lldb/trunk/lldb.xcodeproj/project.pbxproj
lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
lldb/trunk/source/lldb-log.cpp
Modified: lldb/trunk/include/lldb/lldb-private-log.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-private-log.h?rev=118147&r1=118146&r2=118147&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-private-log.h (original)
+++ lldb/trunk/include/lldb/lldb-private-log.h Tue Nov 2 23:08:06 2010
@@ -36,6 +36,7 @@
#define LIBLLDB_LOG_HOST (1u << 14)
#define LIBLLDB_LOG_UNWIND (1u << 15)
#define LIBLLDB_LOG_API (1u << 16)
+#define LIBLLDB_LOG_DYNAMIC_LOADER (1u << 17)
#define LIBLLDB_LOG_ALL (UINT32_MAX)
#define LIBLLDB_LOG_DEFAULT (LIBLLDB_LOG_PROCESS |\
LIBLLDB_LOG_THREAD |\
Modified: lldb/trunk/lldb.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lldb.xcodeproj/project.pbxproj?rev=118147&r1=118146&r2=118147&view=diff
==============================================================================
--- lldb/trunk/lldb.xcodeproj/project.pbxproj (original)
+++ lldb/trunk/lldb.xcodeproj/project.pbxproj Tue Nov 2 23:08:06 2010
@@ -195,7 +195,6 @@
26D5B0F211B07550009A862E /* ThreadPlanStepThrough.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C847510F50EFC00BB2B04 /* ThreadPlanStepThrough.cpp */; };
26D5B0F311B07550009A862E /* ThreadPlanStepRange.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C847610F50EFC00BB2B04 /* ThreadPlanStepRange.cpp */; };
26D5B0F411B07550009A862E /* DynamicLoaderMacOSXDYLD.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C897A10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLD.cpp */; };
- 26D5B0F511B07550009A862E /* DynamicLoaderMacOSXDYLDLog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C897C10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLDLog.cpp */; };
26D5B0F611B07550009A862E /* ObjectContainerUniversalMachO.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C898010F57C5600BB2B04 /* ObjectContainerUniversalMachO.cpp */; };
26D5B0F711B07550009A862E /* ObjectFileELF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C898510F57C5600BB2B04 /* ObjectFileELF.cpp */; };
26D5B0F811B07550009A862E /* ObjectFileMachO.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 260C898810F57C5600BB2B04 /* ObjectFileMachO.cpp */; };
@@ -436,8 +435,6 @@
260C897510F57C5600BB2B04 /* DisassemblerLLVM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DisassemblerLLVM.h; sourceTree = "<group>"; };
260C897A10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLD.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DynamicLoaderMacOSXDYLD.cpp; sourceTree = "<group>"; };
260C897B10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicLoaderMacOSXDYLD.h; sourceTree = "<group>"; };
- 260C897C10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLDLog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DynamicLoaderMacOSXDYLDLog.cpp; sourceTree = "<group>"; };
- 260C897D10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLDLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DynamicLoaderMacOSXDYLDLog.h; sourceTree = "<group>"; };
260C898010F57C5600BB2B04 /* ObjectContainerUniversalMachO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectContainerUniversalMachO.cpp; sourceTree = "<group>"; };
260C898110F57C5600BB2B04 /* ObjectContainerUniversalMachO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ObjectContainerUniversalMachO.h; sourceTree = "<group>"; };
260C898510F57C5600BB2B04 /* ObjectFileELF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ObjectFileELF.cpp; sourceTree = "<group>"; };
@@ -1237,8 +1234,6 @@
children = (
260C897B10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLD.h */,
260C897A10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLD.cpp */,
- 260C897D10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLDLog.h */,
- 260C897C10F57C5600BB2B04 /* DynamicLoaderMacOSXDYLDLog.cpp */,
);
path = "MacOSX-DYLD";
sourceTree = "<group>";
@@ -2680,7 +2675,6 @@
26D5B0F211B07550009A862E /* ThreadPlanStepThrough.cpp in Sources */,
26D5B0F311B07550009A862E /* ThreadPlanStepRange.cpp in Sources */,
26D5B0F411B07550009A862E /* DynamicLoaderMacOSXDYLD.cpp in Sources */,
- 26D5B0F511B07550009A862E /* DynamicLoaderMacOSXDYLDLog.cpp in Sources */,
26D5B0F611B07550009A862E /* ObjectContainerUniversalMachO.cpp in Sources */,
26D5B0F711B07550009A862E /* ObjectFileELF.cpp in Sources */,
26D5B0F811B07550009A862E /* ObjectFileMachO.cpp in Sources */,
Modified: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp?rev=118147&r1=118146&r2=118147&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp Tue Nov 2 23:08:06 2010
@@ -23,7 +23,6 @@
#include "lldb/Target/StackFrame.h"
#include "DynamicLoaderMacOSXDYLD.h"
-#include "DynamicLoaderMacOSXDYLDLog.h"
//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
#ifdef ENABLE_DEBUG_PRINTF
@@ -501,6 +500,7 @@
uint32_t
DynamicLoaderMacOSXDYLD::UpdateAllImageInfos()
{
+ Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER);
if (ReadAllImageInfosStructure ())
{
Mutex::Locker locker(m_mutex);
@@ -566,18 +566,45 @@
if (m_dyld_image_infos.size() < old_dyld_all_image_infos.size())
{
ModuleList unloaded_module_list;
- for (idx = m_dyld_image_infos.size(); idx < old_dyld_all_image_infos.size(); ++idx)
+ uint32_t old_idx;
+ for (idx = 0; idx < old_dyld_all_image_infos.size(); ++idx)
{
- ModuleSP unload_image_module_sp(m_process->GetTarget().GetImages().FindFirstModuleForFileSpec (old_dyld_all_image_infos[idx].file_spec));
- if (unload_image_module_sp.get())
+ for (old_idx = idx; old_idx < old_dyld_all_image_infos.size(); ++old_idx)
{
- if (UnloadImageLoadAddress (unload_image_module_sp.get(), old_dyld_all_image_infos[idx]))
- unloaded_module_list.AppendInNeeded (unload_image_module_sp);
+ if (m_dyld_image_infos[idx].file_spec == old_dyld_all_image_infos[old_idx].file_spec)
+ {
+ old_dyld_all_image_infos[old_idx].address = LLDB_INVALID_ADDRESS;
+ break;
+ }
+ }
+ }
+
+ if (log)
+ log->PutCString("Unloaded:");
+
+ for (old_idx = 0; old_idx < old_dyld_all_image_infos.size(); ++old_idx)
+ {
+ if (old_dyld_all_image_infos[old_idx].address != LLDB_INVALID_ADDRESS)
+ {
+ if (log)
+ old_dyld_all_image_infos[old_idx].PutToLog (log);
+ ModuleSP unload_image_module_sp(m_process->GetTarget().GetImages().FindFirstModuleForFileSpec (old_dyld_all_image_infos[old_idx].file_spec));
+ if (unload_image_module_sp.get())
+ {
+ if (UnloadImageLoadAddress (unload_image_module_sp.get(), old_dyld_all_image_infos[old_idx]))
+ unloaded_module_list.AppendInNeeded (unload_image_module_sp);
+ }
}
}
+
if (unloaded_module_list.GetSize() > 0)
m_process->GetTarget().ModulesDidUnload (unloaded_module_list);
}
+ else
+ {
+ if (log)
+ PutToLog(log);
+ }
}
else
{
@@ -640,7 +667,6 @@
}
}
}
- PutToLog(DynamicLoaderMacOSXDYLDLog::GetLogIfAllCategoriesSet (1));
if (loaded_module_list.GetSize() > 0)
{
// FIXME: This should really be in the Runtime handlers class, which should get
@@ -960,7 +986,7 @@
const size_t count = m_dyld_image_infos.size();
if (count > 0)
{
- log->Printf("\tdyld_image_infos");
+ log->PutCString("Loaded:");
for (i = 0; i<count; i++)
m_dyld_image_infos[i].PutToLog(log);
}
Removed: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.cpp?rev=118146&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.cpp (removed)
@@ -1,72 +0,0 @@
-//===-- DynamicLoaderMacOSXDYLDLog.cpp --------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "DynamicLoaderMacOSXDYLDLog.h"
-#include "lldb/Core/Log.h"
-
-using namespace lldb_private;
-
-static Log *
-LogAccessor (bool get, Log *log)
-{
- static Log* g_log = NULL; // Leak for now as auto_ptr was being cleaned up
- // by global constructors before other threads
- // were done with it.
- if (get)
- {
-// // Debug code below for enabling logging by default
-// if (g_log == NULL)
-// {
-// g_log = new Log("/dev/stdout", false);
-// g_log->GetMask().SetAllFlagBits(0xffffffffu);
-// g_log->GetOptions().Set(LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_THREAD_NAME);
-// }
- }
- else
- {
- if (g_log)
- delete g_log;
- g_log = log;
- }
-
- return g_log;
-}
-
-Log *
-DynamicLoaderMacOSXDYLDLog::GetLogIfAllCategoriesSet (uint32_t mask)
-{
- Log *log = LogAccessor (true, NULL);
- if (log && mask)
- {
- uint32_t log_mask = log->GetMask().Get();
- if ((log_mask & mask) != mask)
- return NULL;
- }
- return log;
-}
-
-void
-DynamicLoaderMacOSXDYLDLog::SetLog (Log *log)
-{
- LogAccessor (false, log);
-}
-
-
-void
-DynamicLoaderMacOSXDYLDLog::LogIf (uint32_t mask, const char *format, ...)
-{
- Log *log = DynamicLoaderMacOSXDYLDLog::GetLogIfAllCategoriesSet (mask);
- if (log)
- {
- va_list args;
- va_start (args, format);
- log->VAPrintf (format, args);
- va_end (args);
- }
-}
Removed: lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.h?rev=118146&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLDLog.h (removed)
@@ -1,34 +0,0 @@
-//===-- DynamicLoaderMacOSXDYLDLog.h ----------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_DynamicLoaderMacOSXDYLDLog_h_
-#define liblldb_DynamicLoaderMacOSXDYLDLog_h_
-
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-
-#include "lldb/lldb-private.h"
-
-// Project includes
-
-class DynamicLoaderMacOSXDYLDLog
-{
-public:
- static lldb_private::Log *
- GetLogIfAllCategoriesSet (uint32_t mask);
-
- static void
- SetLog (lldb_private::Log *log);
-
- static void
- LogIf (uint32_t mask, const char *format, ...);
-};
-
-#endif // liblldb_DynamicLoaderMacOSXDYLDLog_h_
Modified: lldb/trunk/source/lldb-log.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb-log.cpp?rev=118147&r1=118146&r2=118147&view=diff
==============================================================================
--- lldb/trunk/source/lldb-log.cpp (original)
+++ lldb/trunk/source/lldb-log.cpp Tue Nov 2 23:08:06 2010
@@ -124,6 +124,7 @@
else if (strcasecmp(arg, "api") == 0) flag_bits &= ~LIBLLDB_LOG_API;
else if (strcasestr(arg, "break") == arg) flag_bits &= ~LIBLLDB_LOG_BREAKPOINTS;
else if (strcasecmp(arg, "default") == 0 ) flag_bits &= ~LIBLLDB_LOG_DEFAULT;
+ else if (strcasecmp(arg, "dyld") == 0 ) flag_bits &= ~LIBLLDB_LOG_DYNAMIC_LOADER;
else if (strcasestr(arg, "event") == arg) flag_bits &= ~LIBLLDB_LOG_EVENTS;
else if (strcasestr(arg, "expr") == arg) flag_bits &= ~LIBLLDB_LOG_EXPRESSIONS;
else if (strcasestr(arg, "object") == arg) flag_bits &= ~LIBLLDB_LOG_OBJECT;
@@ -182,6 +183,7 @@
else if (strcasecmp(arg, "api") == 0) flag_bits |= LIBLLDB_LOG_API;
else if (strcasestr(arg, "break") == arg) flag_bits |= LIBLLDB_LOG_BREAKPOINTS;
else if (strcasecmp(arg, "default") == 0 ) flag_bits |= LIBLLDB_LOG_DEFAULT;
+ else if (strcasecmp(arg, "dyld") == 0 ) flag_bits |= LIBLLDB_LOG_DYNAMIC_LOADER;
else if (strcasestr(arg, "event") == arg) flag_bits |= LIBLLDB_LOG_EVENTS;
else if (strcasestr(arg, "expr") == arg) flag_bits |= LIBLLDB_LOG_EXPRESSIONS;
else if (strcasestr(arg, "object") == arg) flag_bits |= LIBLLDB_LOG_OBJECT;
More information about the lldb-commits
mailing list