Added the ability to dump sections to a certain depth (for when sections

have children sections).

Modified SectionLoadList to do it's own multi-threaded protected on its map.
The ThreadSafeSTLMap class was difficult to deal with and wasn't providing
much utility, it was only getting in the way.

Make sure when the communication read thread is about to exit, it clears the
thread in the main class.

Fixed the ModuleList to correctly ignore architectures and UUIDs if they aren't
valid when searching for a matching module. If we specified a file with no arch,
and then modified the file and loaded it again, it would not match on subsequent
searches if the arch was invalid since it would compare an invalid architecture
to the one that was found or selected within the shared library or executable.
This was causing stale modules to stay around in the global module list when they
should have been removed.

Removed deprecated functions from the DynamicLoaderMacOSXDYLD class.

Modified "ProcessGDBRemote::IsAlive" to check if we are connected to a gdb
server and also make sure our process hasn't exited.

llvm-svn: 121236
This commit is contained in:
Greg Clayton
2010-12-08 05:08:21 +00:00
parent bc5cad6c6b
commit 10177aa05e
13 changed files with 108 additions and 84 deletions

View File

@@ -46,7 +46,7 @@ public:
ContainsSection(lldb::user_id_t sect_id) const;
void
Dump (Stream *s, Target *target, bool show_header) const;
Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const;
lldb::SectionSP
FindSectionByName (const ConstString &section_dstr) const;
@@ -137,7 +137,7 @@ public:
}
void
Dump (Stream *s, Target *target) const;
Dump (Stream *s, Target *target, uint32_t depth) const;
void
DumpName (Stream *s) const;

View File

@@ -12,10 +12,12 @@
// C Includes
// C++ Includes
#include <map>
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-include.h"
#include "lldb/Core/ThreadSafeSTLMap.h"
#include "lldb/Host/Mutex.h"
namespace lldb_private {
@@ -26,7 +28,9 @@ public:
// Constructors and Destructors
//------------------------------------------------------------------
SectionLoadList () :
m_section_load_info ()
m_collection (),
m_mutex (Mutex::eMutexTypeRecursive)
{
}
@@ -61,10 +65,13 @@ public:
size_t
SetSectionUnloaded (const Section *section);
void
Dump (Stream &s, Target *target);
protected:
typedef ThreadSafeSTLMap<lldb::addr_t, const Section *> collection;
collection m_section_load_info; ///< A mapping of all currently loaded sections.
typedef std::map<lldb::addr_t, const Section *> collection;
collection m_collection;
mutable Mutex m_mutex;
private:
DISALLOW_COPY_AND_ASSIGN (SectionLoadList);

View File

@@ -185,7 +185,7 @@ DumpModuleSections (CommandInterpreter &interpreter, Stream &strm, Module *modul
strm << module->GetFileSpec();
strm.Printf ("' (%s):\n", module->GetArchitecture().AsCString());
strm.IndentMore();
section_list->Dump(&strm, interpreter.GetDebugger().GetExecutionContext().target, true);
section_list->Dump(&strm, interpreter.GetDebugger().GetExecutionContext().target, true, UINT32_MAX);
strm.IndentLess();
}
}

View File

@@ -346,6 +346,7 @@ Communication::ReadThread (void *p)
// Let clients know that this thread is exiting
comm->BroadcastEvent (eBroadcastBitReadThreadDidExit);
comm->m_read_thread = LLDB_INVALID_HOST_THREAD;
return NULL;
}

View File

@@ -223,13 +223,13 @@ public:
return false;
}
if (m_arch_ptr)
if (m_arch_ptr && m_arch_ptr->IsValid())
{
if (module_sp->GetArchitecture() != *m_arch_ptr)
return false;
}
if (m_uuid_ptr)
if (m_uuid_ptr && m_uuid_ptr->IsValid())
{
if (module_sp->GetUUID() != *m_uuid_ptr)
return false;

View File

@@ -222,7 +222,7 @@ Section::Compare (const Section& a, const Section& b)
void
Section::Dump (Stream *s, Target *target) const
Section::Dump (Stream *s, Target *target, uint32_t depth) const
{
// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
s->Indent();
@@ -283,7 +283,8 @@ Section::Dump (Stream *s, Target *target) const
s->Printf(" + 0x%llx\n", m_linked_offset);
}
m_children.Dump(s, target, false);
if (depth > 0)
m_children.Dump(s, target, false, depth - 1);
}
void
@@ -666,7 +667,7 @@ SectionList::ContainsSection(user_id_t sect_id) const
}
void
SectionList::Dump (Stream *s, Target *target, bool show_header) const
SectionList::Dump (Stream *s, Target *target, bool show_header, uint32_t depth) const
{
bool target_has_loaded_sections = target && !target->GetSectionLoadList().IsEmpty();
if (show_header && !m_sections.empty())
@@ -688,7 +689,7 @@ SectionList::Dump (Stream *s, Target *target, bool show_header) const
const_iterator end = m_sections.end();
for (sect_iter = m_sections.begin(); sect_iter != end; ++sect_iter)
{
(*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL);
(*sect_iter)->Dump(s, target_has_loaded_sections ? target : NULL, depth);
}
if (show_header && !m_sections.empty())

View File

@@ -1019,33 +1019,13 @@ DynamicLoaderMacOSXDYLD::PutToLog(Log *log) const
}
}
//----------------------------------------------------------------------
// Static callback function that gets called when the process state
// changes.
//----------------------------------------------------------------------
void
DynamicLoaderMacOSXDYLD::Initialize(void *baton, Process *process)
{
((DynamicLoaderMacOSXDYLD*)baton)->PrivateInitialize(process);
}
void
DynamicLoaderMacOSXDYLD::PrivateInitialize(Process *process)
{
DEBUG_PRINTF("DynamicLoaderMacOSXDYLD::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Clear(true);
m_process = process;
}
//----------------------------------------------------------------------
// Static callback function that gets called when the process state
// changes.
//----------------------------------------------------------------------
void
DynamicLoaderMacOSXDYLD::ProcessStateChanged(void *baton, Process *process, StateType state)
{
((DynamicLoaderMacOSXDYLD*)baton)->PrivateProcessStateChanged(process, state);
m_process->GetTarget().GetSectionLoadList().Clear();
}
bool

View File

@@ -62,18 +62,6 @@ public:
virtual void
DidLaunch ();
//------------------------------------------------------------------
// Process::Notifications callback functions
//------------------------------------------------------------------
static void
Initialize (void *baton,
lldb_private::Process *process);
static void
ProcessStateChanged (void *baton,
lldb_private::Process *process,
lldb::StateType state);
virtual lldb::ThreadPlanSP
GetStepThroughTrampolinePlan (lldb_private::Thread &thread,
bool stop_others);

View File

@@ -684,7 +684,7 @@ ObjectFileELF::Dump(Stream *s)
s->EOL();
SectionList *section_list = GetSectionList();
if (section_list)
section_list->Dump(s, NULL, true);
section_list->Dump(s, NULL, true, UINT32_MAX);
Symtab *symtab = GetSymtab();
if (symtab)
symtab->Dump(s, NULL, lldb::eSortOrderNone);

View File

@@ -1346,7 +1346,7 @@ ObjectFileMachO::Dump (Stream *s)
*s << ", file = '" << m_file << "', arch = " << header_arch.AsCString() << "\n";
if (m_sections_ap.get())
m_sections_ap->Dump(s, NULL, true);
m_sections_ap->Dump(s, NULL, true, UINT32_MAX);
if (m_symtab_ap.get())
m_symtab_ap->Dump(s, NULL, eSortOrderNone);

View File

@@ -1242,7 +1242,7 @@ ProcessGDBRemote::DoDestroy ()
bool
ProcessGDBRemote::IsAlive ()
{
return m_gdb_comm.IsConnected();
return m_gdb_comm.IsConnected() && m_private_state.GetValue() != eStateExited;
}
addr_t

View File

@@ -414,13 +414,18 @@ Process::GetExitDescription ()
void
Process::SetExitStatus (int status, const char *cstr)
{
m_exit_status = status;
if (cstr)
m_exit_string = cstr;
else
m_exit_string.clear();
if (m_private_state.GetValue() != eStateExited)
{
m_exit_status = status;
if (cstr)
m_exit_string = cstr;
else
m_exit_string.clear();
SetPrivateState (eStateExited);
DidExit ();
SetPrivateState (eStateExited);
}
}
// This static callback can be used to watch for local child processes on

View File

@@ -28,13 +28,15 @@ using namespace lldb_private;
bool
SectionLoadList::IsEmpty() const
{
return m_section_load_info.IsEmpty();
Mutex::Locker locker(m_mutex);
return m_collection.empty();
}
void
SectionLoadList::Clear ()
{
m_section_load_info.Clear();
Mutex::Locker locker(m_mutex);
return m_collection.clear();
}
addr_t
@@ -42,9 +44,22 @@ SectionLoadList::GetSectionLoadAddress (const Section *section) const
{
// TODO: add support for the same section having multiple load addresses
addr_t section_load_addr = LLDB_INVALID_ADDRESS;
if (m_section_load_info.GetFirstKeyForValue (section, section_load_addr))
return section_load_addr;
return LLDB_INVALID_ADDRESS;
if (section)
{
Mutex::Locker locker(m_mutex);
collection::const_iterator pos, end = m_collection.end();
for (pos = m_collection.begin(); pos != end; ++pos)
{
const addr_t pos_load_addr = pos->first;
const Section *pos_section = pos->second;
if (pos_section == section)
{
section_load_addr = pos_load_addr;
break;
}
}
}
return section_load_addr;
}
bool
@@ -60,16 +75,19 @@ SectionLoadList::SetSectionLoadAddress (const Section *section, addr_t load_addr
section->GetName().AsCString(),
load_addr);
const Section *existing_section = NULL;
Mutex::Locker locker(m_section_load_info.GetMutex());
if (m_section_load_info.GetValueForKeyNoLock (load_addr, existing_section))
Mutex::Locker locker(m_mutex);
collection::iterator pos = m_collection.find(load_addr);
if (pos != m_collection.end())
{
if (existing_section == section)
return false; // No change
if (section == pos->second)
return false; // No change...
else
pos->second = section;
}
else
{
m_collection[load_addr] = section;
}
m_section_load_info.SetValueForKeyNoLock (load_addr, section);
return true; // Changed
}
@@ -85,14 +103,22 @@ SectionLoadList::SetSectionUnloaded (const Section *section)
section->GetModule()->GetFileSpec().GetFilename().AsCString(),
section->GetName().AsCString());
Mutex::Locker locker(m_section_load_info.GetMutex());
size_t unload_count = 0;
addr_t section_load_addr;
while (m_section_load_info.GetFirstKeyForValueNoLock (section, section_load_addr))
Mutex::Locker locker(m_mutex);
bool erased = false;
do
{
unload_count += m_section_load_info.EraseNoLock (section_load_addr);
}
erased = false;
for (collection::iterator pos = m_collection.begin(); pos != m_collection.end(); ++pos)
{
if (pos->second == section)
{
m_collection.erase(pos);
erased = true;
}
}
} while (erased);
return unload_count;
}
@@ -108,28 +134,44 @@ SectionLoadList::SetSectionUnloaded (const Section *section, addr_t load_addr)
section->GetModule()->GetFileSpec().GetFilename().AsCString(),
section->GetName().AsCString(),
load_addr);
return m_section_load_info.Erase (load_addr) == 1;
Mutex::Locker locker(m_mutex);
return m_collection.erase (load_addr) != 0;
}
bool
SectionLoadList::ResolveLoadAddress (addr_t load_addr, Address &so_addr) const
{
addr_t section_load_addr = LLDB_INVALID_ADDRESS;
const Section *section = NULL;
// First find the top level section that this load address exists in
if (m_section_load_info.LowerBound (load_addr, section_load_addr, section, true))
// First find the top level section that this load address exists in
Mutex::Locker locker(m_mutex);
collection::const_iterator pos = m_collection.lower_bound (load_addr);
if (pos != m_collection.end())
{
addr_t offset = load_addr - section_load_addr;
if (offset < section->GetByteSize())
if (load_addr != pos->first && pos != m_collection.begin())
--pos;
assert (load_addr >= pos->first);
addr_t offset = load_addr - pos->first;
if (offset < pos->second->GetByteSize())
{
// We have found the top level section, now we need to find the
// deepest child section.
return section->ResolveContainedAddress (offset, so_addr);
return pos->second->ResolveContainedAddress (offset, so_addr);
}
}
so_addr.Clear();
return false;
}
void
SectionLoadList::Dump (Stream &s, Target *target)
{
Mutex::Locker locker(m_mutex);
collection::const_iterator pos, end;
for (pos = m_collection.begin(), end = m_collection.end(); pos != end; ++pos)
{
s.Printf("addr = 0x%16.16llx, section = %p: ", pos->first, pos->second);
pos->second->Dump (&s, target, 0);
}
}