While tracking down memory consumption issue a few things were needed: the

ability to dump more information about modules in "target modules list". We
can now dump the shared pointer reference count for modules, the pointer to
the module itself (in case performance tools can help track down who has
references to said pointer), and the modification time.

Added "target delete [target-idx ...]" to be able to delete targets when they
are no longer needed. This will help track down memory usage issues and help 
to resolve when module ref counts keep getting incremented. If the command gets
no arguments, the currently selected target will be deleted. If any arguments 
are given, they must all be valid target indexes (use the "target list" 
command to get the current target indexes).

Took care of a bunch of "no newline at end of file" warnings.

TimeValue objects can now dump their time to a lldb_private::Stream object.

Modified the "target modules list --global" command to not error out if there
are no targets since it doesn't require a target.

Fixed an issue in the MacOSX DYLD dynamic loader plug-in where if a shared 
library was updated on disk, we would keep using the older one, even if it was
updated.

Don't allow the ModuleList::GetSharedModule(...) to return an empty module.
Previously we could specify a valid path on disc to a module, and specify an
architecture that wasn't contained in that module and get a shared pointer to
a module that wouldn't be able to return an object file or a symbol file. We
now make sure an object file can be extracted prior to adding the shared pointer
to the module to get added to the shared list.

llvm-svn: 137196
This commit is contained in:
Greg Clayton 2011-08-10 02:10:13 +00:00
parent 78b40c3f3a
commit 3418c85771
18 changed files with 278 additions and 48 deletions

View File

@ -381,6 +381,12 @@ public:
return var_sp;
}
void
Clear()
{
m_variables.clear();
}
private:
std::vector <lldb::ClangExpressionVariableSP> m_variables;
};

View File

@ -23,6 +23,7 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-private.h"
namespace lldb_private {
@ -57,6 +58,9 @@ public:
uint64_t
GetAsMicroSecondsSinceJan1_1970() const;
uint64_t
GetAsSecondsSinceJan1_1970() const;
struct timespec
GetAsTimeSpec () const;
@ -77,6 +81,9 @@ public:
static TimeValue
Now();
void
Dump (Stream *s, uint32_t width = 0) const;
protected:
//------------------------------------------------------------------

View File

@ -199,6 +199,9 @@ public:
lldb::TargetSP
GetSP();
void
Destroy();
//------------------------------------------------------------------
// This part handles the breakpoints.

View File

@ -395,4 +395,4 @@ SBModule::FindTypes (const char* type)
}
return retval;
}
}

View File

@ -400,6 +400,101 @@ public:
}
};
#pragma mark CommandObjectTargetSelect
//----------------------------------------------------------------------
// "target delete"
//----------------------------------------------------------------------
class CommandObjectTargetDelete : public CommandObject
{
public:
CommandObjectTargetDelete (CommandInterpreter &interpreter) :
CommandObject (interpreter,
"target delete",
"Delete one or more targets by target index.",
NULL,
0)
{
}
virtual
~CommandObjectTargetDelete ()
{
}
virtual bool
Execute (Args& args, CommandReturnObject &result)
{
const size_t argc = args.GetArgumentCount();
std::vector<TargetSP> delete_target_list;
TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
bool success = true;
TargetSP target_sp;
if (argc > 0)
{
const uint32_t num_targets = target_list.GetNumTargets();
for (uint32_t arg_idx = 0; success && arg_idx < argc; ++arg_idx)
{
const char *target_idx_arg = args.GetArgumentAtIndex(arg_idx);
uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
if (success)
{
if (target_idx < num_targets)
{
target_sp = target_list.GetTargetAtIndex (target_idx);
if (target_sp)
{
delete_target_list.push_back (target_sp);
continue;
}
}
result.AppendErrorWithFormat ("target index %u is out of range, valid target indexes are 0 - %u\n",
target_idx,
num_targets - 1);
result.SetStatus (eReturnStatusFailed);
success = false;
}
else
{
result.AppendErrorWithFormat("invalid target index '%s'\n", target_idx_arg);
result.SetStatus (eReturnStatusFailed);
success = false;
}
}
}
else
{
target_sp = target_list.GetSelectedTarget();
if (target_sp)
{
delete_target_list.push_back (target_sp);
}
else
{
result.AppendErrorWithFormat("no target is currently selected\n");
result.SetStatus (eReturnStatusFailed);
success = false;
}
}
if (success)
{
const size_t num_targets_to_delete = delete_target_list.size();
for (size_t idx = 0; idx < num_targets_to_delete; ++idx)
{
target_sp = delete_target_list[idx];
target_list.DeleteTarget(target_sp);
target_sp->Destroy();
}
result.GetOutputStream().Printf("%u targets deleted.\n", (uint32_t)num_targets_to_delete);
result.SetStatus(eReturnStatusSuccessFinishResult);
}
return result.Succeeded();
}
};
#pragma mark CommandObjectTargetVariable
@ -991,7 +1086,10 @@ DumpModuleArchitecture (Stream &strm, Module *module, bool full_triple, uint32_t
static void
DumpModuleUUID (Stream &strm, Module *module)
{
module->GetUUID().Dump (&strm);
if (module->GetUUID().IsValid())
module->GetUUID().Dump (&strm);
else
strm.PutCString(" ");
}
static uint32_t
@ -2545,7 +2643,8 @@ public:
CommandReturnObject &result)
{
Target *target = m_interpreter.GetDebugger().GetSelectedTarget().get();
if (target == NULL)
const bool use_global_module_list = m_options.m_use_global_module_list;
if (target == NULL && use_global_module_list == false)
{
result.AppendError ("invalid target, create a debug target using the 'target create' command");
result.SetStatus (eReturnStatusFailed);
@ -2553,13 +2652,16 @@ public:
}
else
{
uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
result.GetOutputStream().SetAddressByteSize(addr_byte_size);
result.GetErrorStream().SetAddressByteSize(addr_byte_size);
if (target)
{
uint32_t addr_byte_size = target->GetArchitecture().GetAddressByteSize();
result.GetOutputStream().SetAddressByteSize(addr_byte_size);
result.GetErrorStream().SetAddressByteSize(addr_byte_size);
}
// Dump all sections for all modules images
uint32_t num_modules = 0;
Mutex::Locker locker;
if (m_options.m_use_global_module_list)
if (use_global_module_list)
{
locker.Reset (Module::GetAllocationModuleCollectionMutex().GetMutex());
num_modules = Module::GetNumberAllocatedModules();
@ -2573,20 +2675,21 @@ public:
for (uint32_t image_idx = 0; image_idx<num_modules; ++image_idx)
{
ModuleSP module_sp;
Module *module;
if (m_options.m_use_global_module_list)
if (use_global_module_list)
{
module = Module::GetAllocatedModuleAtIndex(image_idx);
ModuleSP module_sp(module->GetSP());
// Show the module reference count when showing the global module index
strm.Printf("[%3u] ref_count = %lu ", image_idx, module_sp ? module_sp.use_count() - 1 : 0);
module_sp = module->GetSP();
}
else
{
module = target->GetImages().GetModulePointerAtIndex(image_idx);
strm.Printf("[%3u] ", image_idx);
module_sp = target->GetImages().GetModuleAtIndex(image_idx);
module = module_sp.get();
}
strm.Printf("[%3u] ", image_idx);
bool dump_object_name = false;
if (m_options.m_format_array.empty())
{
@ -2626,27 +2729,50 @@ public:
dump_object_name = true;
break;
case 'r':
{
uint32_t ref_count = 0;
if (module_sp)
{
// Take one away to make sure we don't count our local "module_sp"
ref_count = module_sp.use_count() - 1;
}
if (width)
strm.Printf("{%*u}", width, ref_count);
else
strm.Printf("{%u}", ref_count);
}
break;
case 's':
case 'S':
{
SymbolVendor *symbol_vendor = module->GetSymbolVendor();
if (symbol_vendor)
{
SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
if (symbol_file)
SymbolVendor *symbol_vendor = module->GetSymbolVendor();
if (symbol_vendor)
{
if (format_char == 'S')
DumpBasename(strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
else
DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
dump_object_name = true;
break;
SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
if (symbol_file)
{
if (format_char == 'S')
DumpBasename(strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
else
DumpFullpath (strm, &symbol_file->GetObjectFile()->GetFileSpec(), width);
dump_object_name = true;
break;
}
}
strm.Printf("%.*s", width, "<NONE>");
}
strm.Printf("%.*s", width, "<NONE>");
}
break;
case 'm':
module->GetModificationTime().Dump(&strm, width);
break;
case 'p':
strm.Printf("%p", module);
break;
case 'u':
DumpModuleUUID(strm, module);
break;
@ -2669,7 +2795,10 @@ public:
}
else
{
result.AppendError ("the target has no associated executable images");
if (use_global_module_list)
result.AppendError ("the global module list is empty");
else
result.AppendError ("the target has no associated executable images");
result.SetStatus (eReturnStatusFailed);
return false;
}
@ -2692,6 +2821,9 @@ CommandObjectTargetModulesList::CommandOptions::g_option_table[] =
{ LLDB_OPT_SET_1, false, "basename", 'b', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename with optional width for the image object file."},
{ LLDB_OPT_SET_1, false, "symfile", 's', optional_argument, NULL, 0, eArgTypeWidth, "Display the fullpath to the image symbol file with optional width."},
{ LLDB_OPT_SET_1, false, "symfile-basename", 'S', optional_argument, NULL, 0, eArgTypeWidth, "Display the basename to the image symbol file with optional width."},
{ LLDB_OPT_SET_1, false, "mod-time", 'm', optional_argument, NULL, 0, eArgTypeWidth, "Display the modification time with optional width of the module."},
{ LLDB_OPT_SET_1, false, "ref-count", 'r', optional_argument, NULL, 0, eArgTypeWidth, "Display the reference count if the module is still in the shared module cache."},
{ LLDB_OPT_SET_1, false, "pointer", 'p', optional_argument, NULL, 0, eArgTypeNone, "Display the module pointer."},
{ LLDB_OPT_SET_1, false, "global", 'g', no_argument, NULL, 0, eArgTypeNone, "Display the modules from the global module list, not just the current target."},
{ 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
};
@ -3811,6 +3943,7 @@ CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &
{
LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTargetDelete (interpreter)));
LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));

View File

@ -231,4 +231,4 @@ SyntheticScriptProvider::GetDescription()
m_python_class.c_str());
return sstr.GetString();
}
}

View File

@ -258,4 +258,4 @@ FormatManager::GetSingleItemFormat(lldb::Format vector_format)
default:
return lldb::eFormatInvalid;
}
}
}

View File

@ -382,4 +382,4 @@ lldb::StreamSP
InputReader::HandlerData::GetOutStream()
{
return reader.GetDebugger().GetAsyncOutputStream();
}
}

View File

@ -93,4 +93,4 @@ InputReaderEZ::Initialize(InitializationParameters& params)
InputReaderEZ::~InputReaderEZ ()
{
}
}

View File

@ -756,7 +756,10 @@ ModuleList::GetSharedModule
else
{
module_sp.reset (new Module (in_file_spec, arch, object_name_ptr, object_offset));
if (module_sp)
// Make sure there are a module and an object file since we can specify
// a valid file path with an architecture that might not be in that file.
// By getting the object file we can guarantee that the architecture matches
if (module_sp && module_sp->GetObjectFile())
{
// If we get in here we got the correct arch, now we just need
// to verify the UUID if one was given
@ -766,7 +769,7 @@ ModuleList::GetSharedModule
{
if (did_create_ptr)
*did_create_ptr = true;
shared_module_list.Append(module_sp);
return error;
}
@ -844,7 +847,10 @@ ModuleList::GetSharedModule
if (module_sp.get() == NULL)
{
module_sp.reset (new Module (file_spec, arch, object_name_ptr, object_offset));
if (module_sp)
// Make sure there are a module and an object file since we can specify
// a valid file path with an architecture that might not be in that file.
// By getting the object file we can guarantee that the architecture matches
if (module_sp && module_sp->GetObjectFile())
{
if (did_create_ptr)
*did_create_ptr = true;

View File

@ -236,4 +236,4 @@ StringList::operator << (StringList strings)
{
AppendList(strings);
return *this;
}
}

View File

@ -40,4 +40,4 @@ ProcessDataAllocator::Dump(Stream &stream)
0); // bit alignment (bitfields only; 0 means ignore)
stream.PutChar('\n');
}
}

View File

@ -8,12 +8,15 @@
//===----------------------------------------------------------------------===//
#include "lldb/Host/TimeValue.h"
#include <stddef.h>
// C Includes
#include <stddef.h>
#include <time.h>
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "lldb/Core/Stream.h"
using namespace lldb_private;
@ -63,6 +66,14 @@ TimeValue::GetAsMicroSecondsSinceJan1_1970() const
return m_nano_seconds / NanoSecPerMicroSec;
}
uint64_t
TimeValue::GetAsSecondsSinceJan1_1970() const
{
return m_nano_seconds / NanoSecPerSec;
}
struct timespec
TimeValue::GetAsTimeSpec () const
{
@ -130,6 +141,28 @@ TimeValue::operator=(const TimeValue& rhs)
return *this;
}
void
TimeValue::Dump (Stream *s, uint32_t width) const
{
if (s == NULL)
return;
char time_buf[32];
time_t time = GetAsSecondsSinceJan1_1970();
char *time_cstr = ::ctime_r(&time, time_buf);
if (time_cstr)
{
char *newline = ::strpbrk(time_cstr, "\n\r");
if (newline)
*newline = '\0';
if (width > 0)
s->Printf("%-*s", width, time_cstr);
else
s->PutCString(time_cstr);
}
else if (width > 0)
s->Printf("%-*s", width, "");
}
bool
lldb_private::operator == (const TimeValue &lhs, const TimeValue &rhs)

View File

@ -263,13 +263,32 @@ DynamicLoaderMacOSXDYLD::FindTargetModuleForDYLDImageInfo (const DYLDImageInfo &
module_sp = target_images.FindFirstModuleForFileSpec (image_info.file_spec, &arch, NULL);
if (can_create && !module_sp)
if (can_create)
{
module_sp = m_process->GetTarget().GetSharedModule (image_info.file_spec,
arch,
image_info_uuid_is_valid ? &image_info.uuid : NULL);
if (did_create_ptr)
*did_create_ptr = module_sp;
if (module_sp)
{
if (image_info.UUIDValid())
{
if (module_sp->GetUUID() != image_info.uuid)
module_sp.reset();
}
else
{
// No UUID, we must rely upon the cached module modification
// time and the modification time of the file on disk
if (module_sp->GetModificationTime() != module_sp->GetFileSpec().GetModificationTime())
module_sp.reset();
}
}
if (!module_sp)
{
module_sp = m_process->GetTarget().GetSharedModule (image_info.file_spec,
arch,
image_info_uuid_is_valid ? &image_info.uuid : NULL);
if (did_create_ptr)
*did_create_ptr = module_sp;
}
}
}
return module_sp;

View File

@ -1446,7 +1446,7 @@ GDBRemoteCommunicationClient::TestPacketSpeed (const uint32_t num_packets)
end_time = TimeValue::Now();
total_time_nsec = end_time.GetAsNanoSecondsSinceJan1_1970() - start_time.GetAsNanoSecondsSinceJan1_1970();
packets_per_second = (((float)num_packets)/(float)total_time_nsec) * (float)TimeValue::NanoSecPerSec;
printf ("%u qSpeedTest(send=%-5u, recv=%-5u) in %llu.%09.9llu sec for %f packets/sec.\n",
printf ("%u qSpeedTest(send=%-5u, recv=%-5u) in %llu.%9.9llu sec for %f packets/sec.\n",
num_packets,
send_size,
recv_size,
@ -1470,7 +1470,7 @@ GDBRemoteCommunicationClient::TestPacketSpeed (const uint32_t num_packets)
end_time = TimeValue::Now();
total_time_nsec = end_time.GetAsNanoSecondsSinceJan1_1970() - start_time.GetAsNanoSecondsSinceJan1_1970();
packets_per_second = (((float)num_packets)/(float)total_time_nsec) * (float)TimeValue::NanoSecPerSec;
printf ("%u 'qC' packets packets in 0x%llu%09.9llu sec for %f packets/sec.\n",
printf ("%u 'qC' packets packets in 0x%llu%9.9llu sec for %f packets/sec.\n",
num_packets,
total_time_nsec / TimeValue::NanoSecPerSec,
total_time_nsec % TimeValue::NanoSecPerSec,

View File

@ -1331,7 +1331,7 @@ ProcessGDBRemote::SetThreadStopInfo (StringExtractor& stop_packet)
if (stop_info_sp)
{
stop_info_sp->SetDescription (description.c_str());
}
}
else
{
gdb_thread->SetStopInfo (StopInfo::CreateStopReasonWithException (*thread_sp, description.c_str()));

View File

@ -121,4 +121,4 @@ clang::Decl
}
return clang::ASTImporter::Imported(from, to);
}
}

View File

@ -145,6 +145,29 @@ Target::GetSP()
return m_debugger.GetTargetList().GetTargetSP(this);
}
void
Target::Destroy()
{
Mutex::Locker locker (m_mutex);
DeleteCurrentProcess ();
m_platform_sp.reset();
m_arch.Clear();
m_images.Clear();
m_section_load_list.Clear();
const bool notify = false;
m_breakpoint_list.RemoveAll(notify);
m_internal_breakpoint_list.RemoveAll(notify);
m_last_created_breakpoint.reset();
m_search_filter_sp.reset();
m_image_search_paths.Clear(notify);
m_scratch_ast_context_ap.reset();
m_persistent_variables.Clear();
m_stop_hooks.clear();
m_stop_hook_next_id = 0;
m_suppress_stop_hooks = false;
}
BreakpointList &
Target::GetBreakpointList(bool internal)
{