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
llvm-svn: 187545
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);
}
// 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.
ProcessLinux.cpp
ProcessMonitor.cpp
LinuxSignals.cpp
+ LinuxThread.cpp
)
--- /dev/null
+//===-- 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
--- /dev/null
+//===-- 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_
#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;
// 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
ProcessLinux::Terminate()
{
}
+
lldb_private::ConstString
ProcessLinux::GetPluginNameStatic()
{
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)
{
virtual bool
UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list);
+
//------------------------------------------------------------------
// PluginInterface protocol
//------------------------------------------------------------------
virtual void
StopAllThreads(lldb::tid_t stop_tid);
+ virtual POSIXThread *
+ CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid);
+
private:
/// Linux-specific signal set.
lldb::pid_t pid;
lldb::ThreadSP inferior;
- POSIXThread *thread;
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
// Propagate the environment if one is not supplied.
// 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);
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.
}
// 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);
: Thread(process, tid),
m_frame_ap (),
m_breakpoint (),
+ m_thread_name_valid (false),
m_thread_name ()
{
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
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();
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();
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));
}
uint32_t FindVacantWatchpointIndex();
-private:
+protected:
RegisterContextPOSIX *
GetRegisterContextPOSIX ()
{
lldb::BreakpointSiteSP m_breakpoint;
+ bool m_thread_name_valid;
std::string m_thread_name;
ProcessMonitor &
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);
return added_to_set;
}
+POSIXThread *
+ProcessPOSIX::CreateNewPOSIXThread(lldb_private::Process &process, lldb::tid_t tid)
+{
+ return new POSIXThread(process, tid);
+}
+
void
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());
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))
#include "ProcessMessage.h"
class ProcessMonitor;
+class POSIXThread;
class ProcessPOSIX :
public lldb_private::Process
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;
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';
}
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())