[Lldb-commits] [lldb] r124926 - in /lldb/trunk: include/lldb/Target/SectionLoadList.h source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Target/SectionLoadList.cpp
Greg Clayton
gclayton at apple.com
Fri Feb 4 18:25:06 PST 2011
Author: gclayton
Date: Fri Feb 4 20:25:06 2011
New Revision: 124926
URL: http://llvm.org/viewvc/llvm-project?rev=124926&view=rev
Log:
Added a quicker lookup in the SectionLoadList when looking things up by
section by using a DenseMap.
Fixed some logging calls to get the log shared pointer.
Modified:
lldb/trunk/include/lldb/Target/SectionLoadList.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Target/SectionLoadList.cpp
Modified: lldb/trunk/include/lldb/Target/SectionLoadList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/SectionLoadList.h?rev=124926&r1=124925&r2=124926&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/SectionLoadList.h (original)
+++ lldb/trunk/include/lldb/Target/SectionLoadList.h Fri Feb 4 20:25:06 2011
@@ -15,6 +15,7 @@
#include <map>
// Other libraries and framework includes
+#include "llvm/ADT/DenseMap.h"
// Project includes
#include "lldb/lldb-include.h"
#include "lldb/Host/Mutex.h"
@@ -28,7 +29,8 @@
// Constructors and Destructors
//------------------------------------------------------------------
SectionLoadList () :
- m_collection (),
+ m_addr_to_sect (),
+ m_sect_to_addr (),
m_mutex (Mutex::eMutexTypeRecursive)
{
@@ -69,8 +71,10 @@
Dump (Stream &s, Target *target);
protected:
- typedef std::map<lldb::addr_t, const Section *> collection;
- collection m_collection;
+ typedef std::map<lldb::addr_t, const Section *> addr_to_sect_collection;
+ typedef llvm::DenseMap<const Section *, lldb::addr_t> sect_to_addr_collection;
+ addr_to_sect_collection m_addr_to_sect;
+ sect_to_addr_collection m_sect_to_addr;
mutable Mutex m_mutex;
private:
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=124926&r1=124925&r2=124926&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Fri Feb 4 20:25:06 2011
@@ -90,7 +90,9 @@
size_t
GDBRemoteCommunication::SendAck ()
{
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "send packet: +");
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
+ if (log)
+ log->Printf ("send packet: +");
ConnectionStatus status = eConnectionStatusSuccess;
char ack_char = '+';
return Write (&ack_char, 1, status, NULL) == 1;
@@ -99,7 +101,9 @@
size_t
GDBRemoteCommunication::SendNack ()
{
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "send packet: -");
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
+ if (log)
+ log->Printf ("send packet: -");
ConnectionStatus status = eConnectionStatusSuccess;
char nack_char = '-';
return Write (&nack_char, 1, status, NULL) == 1;
@@ -440,7 +444,9 @@
packet.PutChar('#');
packet.PutHex8(CalculcateChecksum (payload, payload_length));
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "send packet: %s", packet.GetData());
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
+ if (log)
+ log->Printf ("send packet: %s", packet.GetData());
ConnectionStatus status = eConnectionStatusSuccess;
size_t bytes_written = Write (packet.GetData(), packet.GetSize(), status, NULL);
if (bytes_written == packet.GetSize())
@@ -453,7 +459,9 @@
}
else
{
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "error: failed to send packet: %s", packet.GetData());
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
+ if (log)
+ log->Printf ("error: failed to send packet: %s", packet.GetData());
}
return bytes_written;
}
@@ -614,7 +622,9 @@
if (event_bytes)
{
const char * packet_data = (const char *)event_bytes->GetBytes();
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PACKETS, "read packet: %s", packet_data);
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
+ if (log)
+ log->Printf ("read packet: %s", packet_data);
const size_t packet_size = event_bytes->GetByteSize();
if (packet_data && packet_size > 0)
{
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124926&r1=124925&r2=124926&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Feb 4 20:25:06 2011
@@ -631,7 +631,9 @@
void
ProcessGDBRemote::DidLaunchOrAttach ()
{
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PROCESS, "ProcessGDBRemote::DidLaunch()");
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
+ if (log)
+ log->Printf ("ProcessGDBRemote::DidLaunch()");
if (GetID() == LLDB_INVALID_PROCESS_ID)
{
m_dynamic_loader_ap.reset();
@@ -704,10 +706,7 @@
// Clear out and clean up from any current state
Clear();
ArchSpec arch_spec = GetTarget().GetArchitecture();
-
- //LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
-
-
+
if (attach_pid != LLDB_INVALID_PROCESS_ID)
{
char host_port[128];
@@ -782,7 +781,6 @@
// HACK: require arch be set correctly at the target level until we can
// figure out a good way to determine the arch of what we are attaching to
- //LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
if (process_name && process_name[0])
{
ArchSpec arch_spec = GetTarget().GetArchitecture();
@@ -860,7 +858,9 @@
ProcessGDBRemote::DoResume ()
{
Error error;
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PROCESS, "ProcessGDBRemote::Resume()");
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
+ if (log)
+ log->Printf ("ProcessGDBRemote::Resume()");
Listener listener ("gdb-remote.resume-packet-sent");
if (listener.StartListeningForEvents (&m_gdb_comm, GDBRemoteCommunication::eBroadcastBitRunPacketSent))
@@ -1446,7 +1446,9 @@
size_t bytes_available = m_stdout_data.size();
if (bytes_available > 0)
{
- ProcessGDBRemoteLog::LogIf (GDBR_LOG_PROCESS, "ProcessGDBRemote::%s (&%p[%u]) ...", __FUNCTION__, buf, buf_size);
+ LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
+ if (log)
+ log->Printf ("ProcessGDBRemote::%s (&%p[%u]) ...", __FUNCTION__, buf, buf_size);
if (bytes_available > buf_size)
{
memcpy(buf, m_stdout_data.c_str(), buf_size);
@@ -1709,25 +1711,6 @@
return error;
}
-//void
-//ProcessGDBRemote::STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len)
-//{
-// ProcessGDBRemote *process = (ProcessGDBRemote *)baton;
-// process->AppendSTDOUT(static_cast<const char *>(src), src_len);
-//}
-
-//void
-//ProcessGDBRemote::AppendSTDOUT (const char* s, size_t len)
-//{
-// ProcessGDBRemoteLog::LogIf (GDBR_LOG_PROCESS, "ProcessGDBRemote::%s (<%d> %s) ...", __FUNCTION__, len, s);
-// Mutex::Locker locker(m_stdio_mutex);
-// m_stdout_data.append(s, len);
-//
-// // FIXME: Make a real data object for this and put it out.
-// BroadcastEventIfUnique (eBroadcastBitSTDOUT);
-//}
-
-
Error
ProcessGDBRemote::StartDebugserverProcess
(
@@ -2231,7 +2214,6 @@
bool done = false;
while (!done)
{
- log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) listener.WaitForEvent (NULL, event_sp)...", __FUNCTION__, arg, process->GetID());
if (listener.WaitForEvent (NULL, event_sp))
@@ -2250,7 +2232,6 @@
{
const char *continue_cstr = (const char *)continue_packet->GetBytes ();
const size_t continue_cstr_len = continue_packet->GetByteSize ();
- log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) got eBroadcastBitAsyncContinue: %s", __FUNCTION__, arg, process->GetID(), continue_cstr);
@@ -2289,14 +2270,12 @@
break;
case eBroadcastBitAsyncThreadShouldExit:
- log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) got eBroadcastBitAsyncThreadShouldExit...", __FUNCTION__, arg, process->GetID());
done = true;
break;
default:
- log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) got unknown event 0x%8.8x", __FUNCTION__, arg, process->GetID(), event_type);
done = true;
@@ -2305,7 +2284,6 @@
}
else
{
- log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) listener.WaitForEvent (NULL, event_sp) => false", __FUNCTION__, arg, process->GetID());
done = true;
@@ -2313,7 +2291,6 @@
}
}
- log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS);
if (log)
log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %i) thread exiting...", __FUNCTION__, arg, process->GetID());
Modified: lldb/trunk/source/Target/SectionLoadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/SectionLoadList.cpp?rev=124926&r1=124925&r2=124926&view=diff
==============================================================================
--- lldb/trunk/source/Target/SectionLoadList.cpp (original)
+++ lldb/trunk/source/Target/SectionLoadList.cpp Fri Feb 4 20:25:06 2011
@@ -29,14 +29,15 @@
SectionLoadList::IsEmpty() const
{
Mutex::Locker locker(m_mutex);
- return m_collection.empty();
+ return m_addr_to_sect.empty();
}
void
SectionLoadList::Clear ()
{
Mutex::Locker locker(m_mutex);
- return m_collection.clear();
+ m_addr_to_sect.clear();
+ m_sect_to_addr.clear();
}
addr_t
@@ -47,17 +48,10 @@
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;
- }
- }
+ sect_to_addr_collection::const_iterator pos = m_sect_to_addr.find (section);
+
+ if (pos != m_sect_to_addr.end())
+ section_load_addr = pos->second;
}
return section_load_addr;
}
@@ -81,18 +75,26 @@
}
Mutex::Locker locker(m_mutex);
- collection::iterator pos = m_collection.find(load_addr);
- if (pos != m_collection.end())
+ sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section);
+ if (sta_pos != m_sect_to_addr.end())
{
- if (section == pos->second)
+ if (load_addr == sta_pos->second)
return false; // No change...
else
- pos->second = section;
+ sta_pos->second = load_addr;
}
else
+ m_sect_to_addr[section] = load_addr;
+
+ addr_to_sect_collection::iterator ats_pos = m_addr_to_sect.find(load_addr);
+ if (ats_pos != m_addr_to_sect.end())
{
- m_collection[load_addr] = section;
+ assert (section != ats_pos->second);
+ ats_pos->second = section;
}
+ else
+ m_addr_to_sect[load_addr] = section;
+
return true; // Changed
}
@@ -115,19 +117,17 @@
size_t unload_count = 0;
Mutex::Locker locker(m_mutex);
- bool erased = false;
- do
+
+ sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section);
+ if (sta_pos != m_sect_to_addr.end())
{
- 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);
+ addr_t load_addr = sta_pos->second;
+ m_sect_to_addr.erase (sta_pos);
+
+ addr_to_sect_collection::iterator ats_pos = m_addr_to_sect.find(load_addr);
+ if (ats_pos != m_addr_to_sect.end())
+ m_addr_to_sect.erase (ats_pos);
+ }
return unload_count;
}
@@ -149,8 +149,23 @@
section->GetName().AsCString(),
load_addr);
}
+ bool erased = false;
Mutex::Locker locker(m_mutex);
- return m_collection.erase (load_addr) != 0;
+ sect_to_addr_collection::iterator sta_pos = m_sect_to_addr.find(section);
+ if (sta_pos != m_sect_to_addr.end())
+ {
+ erased = true;
+ m_sect_to_addr.erase (sta_pos);
+ }
+
+ addr_to_sect_collection::iterator ats_pos = m_addr_to_sect.find(load_addr);
+ if (ats_pos != m_addr_to_sect.end())
+ {
+ erased = true;
+ m_addr_to_sect.erase (ats_pos);
+ }
+
+ return erased;
}
@@ -159,10 +174,10 @@
{
// 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_to_sect_collection::const_iterator pos = m_addr_to_sect.lower_bound (load_addr);
+ if (pos != m_addr_to_sect.end())
{
- if (load_addr != pos->first && pos != m_collection.begin())
+ if (load_addr != pos->first && pos != m_addr_to_sect.begin())
--pos;
if (load_addr >= pos->first)
{
@@ -183,8 +198,8 @@
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)
+ addr_to_sect_collection::const_iterator pos, end;
+ for (pos = m_addr_to_sect.begin(), end = m_addr_to_sect.end(); pos != end; ++pos)
{
s.Printf("addr = 0x%16.16llx, section = %p: ", pos->first, pos->second);
pos->second->Dump (&s, target, 0);
More information about the lldb-commits
mailing list