[Lldb-commits] [lldb] r168948 - in /lldb/trunk: include/lldb/Target/Process.h source/Target/Process.cpp tools/debugserver/source/DNB.cpp tools/debugserver/source/DNB.h tools/debugserver/source/MacOSX/MachProcess.cpp tools/debugserver/source/MacOSX/MachProcess.h tools/debugserver/source/MacOSX/MachTask.cpp tools/debugserver/source/MacOSX/MachTask.h tools/debugserver/source/RNBRemote.cpp
Han Ming Ong
hanming at apple.com
Thu Nov 29 14:14:46 PST 2012
Author: hanming
Date: Thu Nov 29 16:14:45 2012
New Revision: 168948
URL: http://llvm.org/viewvc/llvm-project?rev=168948&view=rev
Log:
<rdar://problem/12780259>
Prevent async and sync calls to get profile data from stomping on each other.
At the same time, don't use '$' as end delimiter per chunk of profile data.
Modified:
lldb/trunk/include/lldb/Target/Process.h
lldb/trunk/source/Target/Process.cpp
lldb/trunk/tools/debugserver/source/DNB.cpp
lldb/trunk/tools/debugserver/source/DNB.h
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp
lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h
lldb/trunk/tools/debugserver/source/RNBRemote.cpp
Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Thu Nov 29 16:14:45 2012
@@ -3461,7 +3461,7 @@
std::string m_stdout_data;
std::string m_stderr_data;
Mutex m_profile_data_comm_mutex;
- std::string m_profile_data;
+ std::vector<std::string> m_profile_data;
MemoryCache m_memory_cache;
AllocatedMemoryCache m_allocated_memory_cache;
bool m_should_detach; /// Should we detach if the process object goes away with an explicit call to Kill or Detach?
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Thu Nov 29 16:14:45 2012
@@ -4009,7 +4009,7 @@
Process::BroadcastAsyncProfileData(const char *s, size_t len)
{
Mutex::Locker locker (m_profile_data_comm_mutex);
- m_profile_data.append (s, len);
+ m_profile_data.push_back(s);
BroadcastEventIfUnique (eBroadcastBitProfileData, new ProcessEventData (shared_from_this(), GetState()));
}
@@ -4017,7 +4017,10 @@
Process::GetAsyncProfileData (char *buf, size_t buf_size, Error &error)
{
Mutex::Locker locker(m_profile_data_comm_mutex);
- size_t bytes_available = m_profile_data.size();
+ if (m_profile_data.empty())
+ return 0;
+
+ size_t bytes_available = m_profile_data.front().size();
if (bytes_available > 0)
{
LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_PROCESS));
@@ -4025,14 +4028,14 @@
log->Printf ("Process::GetProfileData (buf = %p, size = %" PRIu64 ")", buf, (uint64_t)buf_size);
if (bytes_available > buf_size)
{
- memcpy(buf, m_profile_data.c_str(), buf_size);
- m_profile_data.erase(0, buf_size);
+ memcpy(buf, m_profile_data.front().data(), buf_size);
+ m_profile_data.front().erase(0, buf_size);
bytes_available = buf_size;
}
else
{
- memcpy(buf, m_profile_data.c_str(), bytes_available);
- m_profile_data.clear();
+ memcpy(buf, m_profile_data.front().data(), bytes_available);
+ m_profile_data.erase(m_profile_data.begin());
}
}
return bytes_available;
Modified: lldb/trunk/tools/debugserver/source/DNB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.cpp (original)
+++ lldb/trunk/tools/debugserver/source/DNB.cpp Thu Nov 29 16:14:45 2012
@@ -1217,14 +1217,14 @@
return -1;
}
-const char *
-DNBProcessGetProfileDataAsCString (nub_process_t pid)
+std::string
+DNBProcessGetProfileData (nub_process_t pid)
{
MachProcessSP procSP;
if (GetProcessSP (pid, procSP))
- return procSP->Task().GetProfileDataAsCString();
+ return procSP->Task().GetProfileData();
- return NULL;
+ return std::string("");
}
nub_bool_t
Modified: lldb/trunk/tools/debugserver/source/DNB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.h?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.h (original)
+++ lldb/trunk/tools/debugserver/source/DNB.h Thu Nov 29 16:14:45 2012
@@ -67,7 +67,7 @@
nub_addr_t DNBProcessMemoryAllocate (nub_process_t pid, nub_size_t size, uint32_t permissions) DNB_EXPORT;
nub_bool_t DNBProcessMemoryDeallocate (nub_process_t pid, nub_addr_t addr) DNB_EXPORT;
int DNBProcessMemoryRegionInfo (nub_process_t pid, nub_addr_t addr, DNBRegionInfo *region_info) DNB_EXPORT;
-const char * DNBProcessGetProfileDataAsCString (nub_process_t pid) DNB_EXPORT; // Process owns the returned string. Do not free.
+std::string DNBProcessGetProfileData (nub_process_t pid) DNB_EXPORT;
nub_bool_t DNBProcessSetAsyncEnableProfiling (nub_process_t pid, nub_bool_t enable, uint64_t interval_usec) DNB_EXPORT;
//----------------------------------------------------------------------
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Thu Nov 29 16:14:45 2012
@@ -1347,7 +1347,7 @@
{
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::%s (%s) ...", __FUNCTION__, info);
PTHREAD_MUTEX_LOCKER (locker, m_profile_data_mutex);
- m_profile_data.append(info);
+ m_profile_data.push_back(info);
m_events.SetEvents(eEventProfileDataAvailable);
// Wait for the event bit to reset if a reset ACK is requested
@@ -1360,19 +1360,22 @@
{
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::%s (&%p[%llu]) ...", __FUNCTION__, buf, (uint64_t)buf_size);
PTHREAD_MUTEX_LOCKER (locker, m_profile_data_mutex);
- size_t bytes_available = m_profile_data.size();
+ if (m_profile_data.empty())
+ return 0;
+
+ size_t bytes_available = m_profile_data.front().size();
if (bytes_available > 0)
{
if (bytes_available > buf_size)
{
- memcpy(buf, m_profile_data.data(), buf_size);
- m_profile_data.erase(0, buf_size);
+ memcpy(buf, m_profile_data.front().data(), buf_size);
+ m_profile_data.front().erase(0, buf_size);
bytes_available = buf_size;
}
else
{
- memcpy(buf, m_profile_data.data(), bytes_available);
- m_profile_data.clear();
+ memcpy(buf, m_profile_data.front().data(), bytes_available);
+ m_profile_data.erase(m_profile_data.begin());
}
}
return bytes_available;
@@ -1390,10 +1393,10 @@
nub_state_t state = proc->GetState();
if (state == eStateRunning)
{
- const char *data = proc->Task().GetProfileDataAsCString();
- if (data)
+ std::string data = proc->Task().GetProfileData();
+ if (!data.empty())
{
- proc->SignalAsyncProfileData(data);
+ proc->SignalAsyncProfileData(data.c_str());
}
}
else if ((state == eStateUnloaded) || (state == eStateDetached) || (state == eStateUnloaded))
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Thu Nov 29 16:14:45 2012
@@ -282,7 +282,7 @@
uint64_t m_profile_interval_usec; // If enable, the profiling interval in microseconds
pthread_t m_profile_thread; // Thread ID for the thread that profiles the inferior
PThreadMutex m_profile_data_mutex; // Multithreaded protection for profile info data
- std::string m_profile_data; // Profile data, must be protected by m_profile_data_mutex
+ std::vector<std::string> m_profile_data; // Profile data, must be protected by m_profile_data_mutex
DNBThreadResumeActions m_thread_actions; // The thread actions for the current MachProcess::Resume() call
MachException::Message::collection
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp Thu Nov 29 16:14:45 2012
@@ -54,7 +54,6 @@
m_exception_port (MACH_PORT_NULL)
{
memset(&m_exc_port_info, 0, sizeof(m_exc_port_info));
-
}
//----------------------------------------------------------------------
@@ -277,19 +276,20 @@
kr = mach_vm_deallocate(mach_task_self(), (mach_vm_address_t)(uintptr_t)threads, tcnt * sizeof(*threads));
}
-const char *
-MachTask::GetProfileDataAsCString ()
+std::string
+MachTask::GetProfileData ()
{
+ std::string result;
task_t task = TaskPort();
if (task == TASK_NULL)
- return NULL;
+ return result;
struct task_basic_info task_info;
DNBError err;
err = BasicInfo(task, &task_info);
if (!err.Success())
- return NULL;
+ return result;
uint64_t elapsed_usec = 0;
uint64_t task_used_usec = 0;
@@ -347,19 +347,15 @@
profile_data_stream << "vprvt:" << vprvt << ';';
profile_data_stream << "vsize:" << vsize << ';';
profile_data_stream << "dirty:" << dirty_size << ';';
- profile_data_stream << "$";
+ profile_data_stream << "end;";
- m_profile_data = profile_data_stream.str();
- }
- else
- {
- m_profile_data.clear();
+ result = profile_data_stream.str();
}
free(threads_id);
free(threads_used_usec);
- return m_profile_data.c_str();
+ return result;
}
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.h Thu Nov 29 16:14:45 2012
@@ -66,7 +66,7 @@
nub_size_t ReadMemory (nub_addr_t addr, nub_size_t size, void *buf);
nub_size_t WriteMemory (nub_addr_t addr, nub_size_t size, const void *buf);
int GetMemoryRegionInfo (nub_addr_t addr, DNBRegionInfo *region_info);
- const char * GetProfileDataAsCString ();
+ std::string GetProfileData ();
nub_addr_t AllocateMemory (nub_size_t size, uint32_t permissions);
nub_bool_t DeallocateMemory (nub_addr_t addr);
@@ -123,7 +123,6 @@
typedef std::map <mach_vm_address_t, size_t> allocation_collection;
allocation_collection m_allocations;
- std::string m_profile_data;
private:
MachTask(const MachTask&); // Outlaw
Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=168948&r1=168947&r2=168948&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Thu Nov 29 16:14:45 2012
@@ -234,7 +234,7 @@
if (m_ctx.HasValidProcessID())
{
nub_process_t pid = m_ctx.ProcessID();
- char buf[256];
+ char buf[1024];
nub_size_t count;
do
{
@@ -3467,10 +3467,10 @@
if (pid == INVALID_NUB_PROCESS)
return SendPacket ("OK");
- const char *data = DNBProcessGetProfileDataAsCString(pid);
- if (data)
+ std::string data = DNBProcessGetProfileData(pid);
+ if (!data.empty())
{
- return SendPacket (data);
+ return SendPacket (data.c_str());
}
else
{
More information about the lldb-commits
mailing list