aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sartain <mikesart@valvesoftware.com>2013-07-31 23:27:46 +0000
committerMichael Sartain <mikesart@valvesoftware.com>2013-07-31 23:27:46 +0000
commit4349bcb8ec51f3fd447b511b2ce8292a92d3c771 (patch)
tree8f17813155d6da6f7a2fe14d09f9b15a5b64702e
parent17c4bc477e3007db9d34f6f4947543f8ad946717 (diff)
downloadlldb-4349bcb8ec51f3fd447b511b2ce8292a92d3c771.tar.gz
Fix thread name updating in Linux. "thread list" should report correct names always now.
Created new LinuxThread class inherited from POSIXThread and removed linux / freebsd ifdefs Removed several un-needed set thread name calls CR (and multiple suggestions): mkopec git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@187545 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessMonitor.cpp4
-rw-r--r--source/Plugins/Process/Linux/CMakeLists.txt1
-rw-r--r--source/Plugins/Process/Linux/LinuxThread.cpp63
-rw-r--r--source/Plugins/Process/Linux/LinuxThread.h43
-rw-r--r--source/Plugins/Process/Linux/ProcessLinux.cpp12
-rw-r--r--source/Plugins/Process/Linux/ProcessLinux.h4
-rw-r--r--source/Plugins/Process/Linux/ProcessMonitor.cpp12
-rw-r--r--source/Plugins/Process/POSIX/POSIXThread.cpp26
-rw-r--r--source/Plugins/Process/POSIX/POSIXThread.h5
-rw-r--r--source/Plugins/Process/POSIX/ProcessPOSIX.cpp13
-rw-r--r--source/Plugins/Process/POSIX/ProcessPOSIX.h4
-rw-r--r--source/Target/TargetList.cpp17
12 files changed, 163 insertions, 41 deletions
diff --git a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index d16ad9ae6..9fd51d2d6 100644
--- a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -1003,7 +1003,7 @@ ProcessMonitor::Launch(LaunchArgs *args)
goto FINISH;
// Update the process thread list with this new thread.
- inferior.reset(new POSIXThread(*processSP, pid));
+ inferior.reset(process.CreateNewPOSIXThread(*processSP, pid));
if (log)
log->Printf ("ProcessMonitor::%s() adding pid = %" PRIu64, __FUNCTION__, pid);
process.GetThreadList().AddThread(inferior);
@@ -1085,7 +1085,7 @@ ProcessMonitor::Attach(AttachArgs *args)
}
// Update the process thread list with the attached thread.
- inferior.reset(new POSIXThread(*processSP, pid));
+ inferior.reset(process.CreateNewPOSIXThread(*processSP, pid));
tl.AddThread(inferior);
// Let our process instance know the thread has stopped.
diff --git a/source/Plugins/Process/Linux/CMakeLists.txt b/source/Plugins/Process/Linux/CMakeLists.txt
index 96ccb4d1f..221a682a2 100644
--- a/source/Plugins/Process/Linux/CMakeLists.txt
+++ b/source/Plugins/Process/Linux/CMakeLists.txt
@@ -7,5 +7,6 @@ add_lldb_library(lldbPluginProcessLinux
ProcessLinux.cpp
ProcessMonitor.cpp
LinuxSignals.cpp
+ LinuxThread.cpp
)
diff --git a/source/Plugins/Process/Linux/LinuxThread.cpp b/source/Plugins/Process/Linux/LinuxThread.cpp
new file mode 100644
index 000000000..edb21bdbe
--- /dev/null
+++ b/source/Plugins/Process/Linux/LinuxThread.cpp
@@ -0,0 +1,63 @@
+//===-- LinuxThread.cpp -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// C Includes
+// C++ Includes
+// Other libraries and framework includes
+// Project includes
+#include "LinuxThread.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//------------------------------------------------------------------------------
+// Constructors and destructors.
+
+LinuxThread::LinuxThread(Process &process, lldb::tid_t tid)
+ : POSIXThread(process, tid)
+{
+}
+
+LinuxThread::~LinuxThread()
+{
+}
+
+//------------------------------------------------------------------------------
+// ProcessInterface protocol.
+
+void
+LinuxThread::RefreshStateAfterStop()
+{
+ // Invalidate the thread names every time we get a stop event on Linux so we
+ // will re-read the procfs comm virtual file when folks ask for the thread name.
+ m_thread_name_valid = false;
+
+ POSIXThread::RefreshStateAfterStop();
+}
+
+void
+LinuxThread::TraceNotify(const ProcessMessage &message)
+{
+ RegisterContextPOSIX* reg_ctx = GetRegisterContextPOSIX();
+ if (reg_ctx)
+ {
+ uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
+ uint32_t wp_idx;
+ for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++)
+ {
+ if (reg_ctx->IsWatchpointHit(wp_idx))
+ {
+ WatchNotify(message);
+ return;
+ }
+ }
+ }
+
+ POSIXThread::TraceNotify (message);
+} \ No newline at end of file
diff --git a/source/Plugins/Process/Linux/LinuxThread.h b/source/Plugins/Process/Linux/LinuxThread.h
new file mode 100644
index 000000000..7d253aa98
--- /dev/null
+++ b/source/Plugins/Process/Linux/LinuxThread.h
@@ -0,0 +1,43 @@
+//===-- LinuxThread.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_LinuxThread_H_
+#define liblldb_LinuxThread_H_
+
+// Other libraries and framework includes
+#include "POSIXThread.h"
+
+//------------------------------------------------------------------------------
+// @class LinuxThread
+// @brief Abstraction of a Linux thread.
+class LinuxThread
+ : public POSIXThread
+{
+public:
+
+ //------------------------------------------------------------------
+ // Constructors and destructors
+ //------------------------------------------------------------------
+ LinuxThread(lldb_private::Process &process, lldb::tid_t tid);
+
+ virtual ~LinuxThread();
+
+ //--------------------------------------------------------------------------
+ // LinuxThread internal API.
+
+ // POSIXThread override
+ virtual void
+ RefreshStateAfterStop();
+
+protected:
+ virtual void
+ TraceNotify(const ProcessMessage &message);
+};
+
+#endif // #ifndef liblldb_LinuxThread_H_
diff --git a/source/Plugins/Process/Linux/ProcessLinux.cpp b/source/Plugins/Process/Linux/ProcessLinux.cpp
index c53a2eb2e..e503ff088 100644
--- a/source/Plugins/Process/Linux/ProcessLinux.cpp
+++ b/source/Plugins/Process/Linux/ProcessLinux.cpp
@@ -23,7 +23,7 @@
#include "ProcessPOSIXLog.h"
#include "Plugins/Process/Utility/InferiorCallPOSIX.h"
#include "ProcessMonitor.h"
-#include "POSIXThread.h"
+#include "LinuxThread.h"
using namespace lldb;
using namespace lldb_private;
@@ -64,7 +64,7 @@ ProcessLinux::Initialize()
// Constructors and destructors.
ProcessLinux::ProcessLinux(Target& target, Listener &listener, FileSpec *core_file)
- : ProcessPOSIX(target, listener), m_stopping_threads(false), m_core_file(core_file)
+ : ProcessPOSIX(target, listener), m_core_file(core_file), m_stopping_threads(false)
{
#if 0
// FIXME: Putting this code in the ctor and saving the byte order in a
@@ -81,6 +81,7 @@ void
ProcessLinux::Terminate()
{
}
+
lldb_private::ConstString
ProcessLinux::GetPluginNameStatic()
{
@@ -171,6 +172,13 @@ ProcessLinux::StopAllThreads(lldb::tid_t stop_tid)
log->Printf ("ProcessLinux::%s() finished", __FUNCTION__);
}
+// ProcessPOSIX override
+POSIXThread *
+ProcessLinux::CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid)
+{
+ return new LinuxThread(process, tid);
+}
+
bool
ProcessLinux::CanDebug(Target &target, bool plugin_specified_by_name)
{
diff --git a/source/Plugins/Process/Linux/ProcessLinux.h b/source/Plugins/Process/Linux/ProcessLinux.h
index c65135159..742627f37 100644
--- a/source/Plugins/Process/Linux/ProcessLinux.h
+++ b/source/Plugins/Process/Linux/ProcessLinux.h
@@ -56,6 +56,7 @@ public:
virtual bool
UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list);
+
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
@@ -94,6 +95,9 @@ public:
virtual void
StopAllThreads(lldb::tid_t stop_tid);
+ virtual POSIXThread *
+ CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid);
+
private:
/// Linux-specific signal set.
diff --git a/source/Plugins/Process/Linux/ProcessMonitor.cpp b/source/Plugins/Process/Linux/ProcessMonitor.cpp
index cfb816a1d..e52d07ce5 100644
--- a/source/Plugins/Process/Linux/ProcessMonitor.cpp
+++ b/source/Plugins/Process/Linux/ProcessMonitor.cpp
@@ -1098,7 +1098,6 @@ ProcessMonitor::Launch(LaunchArgs *args)
lldb::pid_t pid;
lldb::ThreadSP inferior;
- POSIXThread *thread;
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
// Propagate the environment if one is not supplied.
@@ -1232,10 +1231,7 @@ ProcessMonitor::Launch(LaunchArgs *args)
// Update the process thread list with this new thread.
// FIXME: should we be letting UpdateThreadList handle this?
// FIXME: by using pids instead of tids, we can only support one thread.
- inferior.reset(new POSIXThread(process, pid));
-
- thread = static_cast<POSIXThread*>(inferior.get());
- thread->SetName(Host::GetThreadName(pid, pid).c_str());
+ inferior.reset(process.CreateNewPOSIXThread(process, pid));
if (log)
log->Printf ("ProcessMonitor::%s() adding pid = %" PRIu64, __FUNCTION__, pid);
@@ -1297,7 +1293,6 @@ ProcessMonitor::Attach(AttachArgs *args)
ProcessMonitor *monitor = args->m_monitor;
ProcessLinux &process = monitor->GetProcess();
lldb::ThreadSP inferior;
- POSIXThread *thread;
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
// Use a map to keep track of the threads which we have attached/need to attach.
@@ -1362,10 +1357,7 @@ ProcessMonitor::Attach(AttachArgs *args)
}
// Update the process thread list with the attached thread.
- inferior.reset(new POSIXThread(process, tid));
-
- thread = static_cast<POSIXThread*>(inferior.get());
- thread->SetName(Host::GetThreadName(pid, tid).c_str());
+ inferior.reset(process.CreateNewPOSIXThread(process, tid));
if (log)
log->Printf ("ProcessMonitor::%s() adding tid = %" PRIu64, __FUNCTION__, tid);
diff --git a/source/Plugins/Process/POSIX/POSIXThread.cpp b/source/Plugins/Process/POSIX/POSIXThread.cpp
index a5cccee3b..93c296679 100644
--- a/source/Plugins/Process/POSIX/POSIXThread.cpp
+++ b/source/Plugins/Process/POSIX/POSIXThread.cpp
@@ -45,6 +45,7 @@ POSIXThread::POSIXThread(Process &process, lldb::tid_t tid)
: Thread(process, tid),
m_frame_ap (),
m_breakpoint (),
+ m_thread_name_valid (false),
m_thread_name ()
{
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
@@ -111,7 +112,8 @@ POSIXThread::GetInfo()
void
POSIXThread::SetName (const char *name)
{
- if (name && name[0])
+ m_thread_name_valid = (name && name[0]);
+ if (m_thread_name_valid)
m_thread_name.assign (name);
else
m_thread_name.clear();
@@ -120,6 +122,12 @@ POSIXThread::SetName (const char *name)
const char *
POSIXThread::GetName ()
{
+ if (!m_thread_name_valid)
+ {
+ SetName(Host::GetThreadName(GetProcess()->GetID(), GetID()).c_str());
+ m_thread_name_valid = true;
+ }
+
if (m_thread_name.empty())
return NULL;
return m_thread_name.c_str();
@@ -460,22 +468,6 @@ POSIXThread::WatchNotify(const ProcessMessage &message)
void
POSIXThread::TraceNotify(const ProcessMessage &message)
{
-#ifndef __FreeBSD__
- RegisterContextPOSIX* reg_ctx = GetRegisterContextPOSIX();
- if (reg_ctx)
- {
- uint32_t num_hw_wps = reg_ctx->NumSupportedHardwareWatchpoints();
- uint32_t wp_idx;
- for (wp_idx = 0; wp_idx < num_hw_wps; wp_idx++)
- {
- if (reg_ctx->IsWatchpointHit(wp_idx))
- {
- WatchNotify(message);
- return;
- }
- }
- }
-#endif
SetStopInfo (StopInfo::CreateStopReasonToTrace(*this));
}
diff --git a/source/Plugins/Process/POSIX/POSIXThread.h b/source/Plugins/Process/POSIX/POSIXThread.h
index 59b02a75f..d051d2386 100644
--- a/source/Plugins/Process/POSIX/POSIXThread.h
+++ b/source/Plugins/Process/POSIX/POSIXThread.h
@@ -91,7 +91,7 @@ public:
uint32_t FindVacantWatchpointIndex();
-private:
+protected:
RegisterContextPOSIX *
GetRegisterContextPOSIX ()
{
@@ -107,6 +107,7 @@ private:
lldb::BreakpointSiteSP m_breakpoint;
+ bool m_thread_name_valid;
std::string m_thread_name;
ProcessMonitor &
@@ -117,7 +118,7 @@ private:
void BreakNotify(const ProcessMessage &message);
void WatchNotify(const ProcessMessage &message);
- void TraceNotify(const ProcessMessage &message);
+ virtual void TraceNotify(const ProcessMessage &message);
void LimboNotify(const ProcessMessage &message);
void SignalNotify(const ProcessMessage &message);
void SignalDeliveredNotify(const ProcessMessage &message);
diff --git a/source/Plugins/Process/POSIX/ProcessPOSIX.cpp b/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
index 1cba5f17c..545e7923a 100644
--- a/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
+++ b/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
@@ -479,6 +479,12 @@ ProcessPOSIX::AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid)
return added_to_set;
}
+POSIXThread *
+ProcessPOSIX::CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid)
+{
+ return new POSIXThread(process, tid);
+}
+
void
ProcessPOSIX::RefreshStateAfterStop()
{
@@ -508,10 +514,7 @@ ProcessPOSIX::RefreshStateAfterStop()
log->Printf ("ProcessPOSIX::%s() adding thread, tid = %" PRIi64, __FUNCTION__, message.GetChildTID());
lldb::tid_t child_tid = message.GetChildTID();
ThreadSP thread_sp;
- thread_sp.reset(new POSIXThread(*this, child_tid));
-
- POSIXThread *thread = static_cast<POSIXThread*>(thread_sp.get());
- thread->SetName(Host::GetThreadName(GetID(), child_tid).c_str());
+ thread_sp.reset(CreateNewPOSIXThread(*this, child_tid));
Mutex::Locker lock(m_thread_list.GetMutex());
@@ -821,7 +824,7 @@ ProcessPOSIX::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thre
assert(m_monitor);
ThreadSP thread_sp (old_thread_list.FindThreadByID (GetID(), false));
if (!thread_sp) {
- thread_sp.reset(new POSIXThread(*this, GetID()));
+ thread_sp.reset(CreateNewPOSIXThread(*this, GetID()));
}
if (log && log->GetMask().Test(POSIX_LOG_VERBOSE))
diff --git a/source/Plugins/Process/POSIX/ProcessPOSIX.h b/source/Plugins/Process/POSIX/ProcessPOSIX.h
index fd029ef5a..48b19bac4 100644
--- a/source/Plugins/Process/POSIX/ProcessPOSIX.h
+++ b/source/Plugins/Process/POSIX/ProcessPOSIX.h
@@ -22,6 +22,7 @@
#include "ProcessMessage.h"
class ProcessMonitor;
+class POSIXThread;
class ProcessPOSIX :
public lldb_private::Process
@@ -166,6 +167,9 @@ public:
bool
AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
+ virtual POSIXThread *
+ CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid);
+
protected:
/// Target byte order.
lldb::ByteOrder m_byte_order;
diff --git a/source/Target/TargetList.cpp b/source/Target/TargetList.cpp
index 5bd6ea9db..8d907f432 100644
--- a/source/Target/TargetList.cpp
+++ b/source/Target/TargetList.cpp
@@ -222,8 +222,19 @@ TargetList::CreateTarget (Debugger &debugger,
FileSpec file (user_exe_path, false);
if (!file.Exists() && user_exe_path && user_exe_path[0] == '~')
{
- file = FileSpec(user_exe_path, true);
+ // we want to expand the tilde but we don't want to resolve any symbolic links
+ // so we can't use the FileSpec constructor's resolve flag
+ char unglobbed_path[PATH_MAX];
+ unglobbed_path[0] = '\0';
+
+ size_t return_count = FileSpec::ResolveUsername(user_exe_path, unglobbed_path, sizeof(unglobbed_path));
+
+ if (return_count == 0 || return_count >= sizeof(unglobbed_path))
+ ::snprintf (unglobbed_path, sizeof(unglobbed_path), "%s", user_exe_path);
+
+ file = FileSpec(unglobbed_path, false);
}
+
bool user_exe_path_is_bundle = false;
char resolved_bundle_exe_path[PATH_MAX];
resolved_bundle_exe_path[0] = '\0';
@@ -305,8 +316,8 @@ TargetList::CreateTarget (Debugger &debugger,
}
else
{
- // Just use what the user typed
- target_sp->SetArg0 (user_exe_path);
+ // Use resolved path
+ target_sp->SetArg0 (file.GetPath().c_str());
}
}
if (file.GetDirectory())