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.

llvm-svn: 118147
This commit is contained in:
Greg Clayton 2010-11-03 04:08:06 +00:00
parent 2d5f8b4201
commit 6ba508507e
6 changed files with 37 additions and 120 deletions

View File

@ -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 |\

View File

@ -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 */,

View File

@ -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 @@ DynamicLoaderMacOSXDYLD::ReadAllImageInfosStructure ()
uint32_t
DynamicLoaderMacOSXDYLD::UpdateAllImageInfos()
{
Log *log = lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER);
if (ReadAllImageInfosStructure ())
{
Mutex::Locker locker(m_mutex);
@ -566,18 +566,45 @@ DynamicLoaderMacOSXDYLD::UpdateAllImageInfos()
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));
for (old_idx = idx; old_idx < old_dyld_all_image_infos.size(); ++old_idx)
{
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[idx]))
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 @@ DynamicLoaderMacOSXDYLD::UpdateAllImageInfos()
}
}
}
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 @@ DynamicLoaderMacOSXDYLD::PutToLog(Log *log) const
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);
}

View File

@ -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);
}
}

View File

@ -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_

View File

@ -124,6 +124,7 @@ lldb_private::DisableLog (Args &args, Stream *feedback_strm)
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 @@ lldb_private::EnableLog (StreamSP &log_stream_sp, uint32_t log_options, Args &ar
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;