summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins')
-rw-r--r--lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp111
-rw-r--r--lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h17
-rw-r--r--lldb/source/Plugins/Process/Linux/LinuxThread.cpp21
-rw-r--r--lldb/source/Plugins/Process/Linux/LinuxThread.h4
-rw-r--r--lldb/source/Plugins/Process/POSIX/POSIXThread.cpp26
-rw-r--r--lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_i386.cpp14
-rw-r--r--lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_x86_64.cpp15
-rw-r--r--lldb/source/Plugins/Process/POSIX/RegisterContextPOSIX.h4
-rw-r--r--lldb/source/Plugins/Process/POSIX/RegisterContextPOSIXProcessMonitor_x86.cpp16
9 files changed, 195 insertions, 33 deletions
diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index 3b260538b19..3d793d0c1c2 100644
--- a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -101,8 +101,8 @@ PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
log->Printf("ptrace() failed; errno=%d (%s)", errno, str);
}
-#ifdef __amd64__
if (log) {
+#ifdef __amd64__
if (req == PT_GETREGS) {
struct reg *r = (struct reg *) addr;
@@ -111,8 +111,15 @@ PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
log->Printf("PT_GETREGS: bp=0x%lx", r->r_rbp);
log->Printf("PT_GETREGS: ax=0x%lx", r->r_rax);
}
- }
#endif
+ if (req == PT_GETDBREGS || req == PT_SETDBREGS) {
+ struct dbreg *r = (struct dbreg *) addr;
+ char setget = (req == PT_GETDBREGS) ? 'G' : 'S';
+
+ for (int i = 0; i <= 7; i++)
+ log->Printf("PT_%cETDBREGS: dr[%d]=0x%lx", setget, i, r->dr[i]);
+ }
+ }
return result;
}
@@ -348,6 +355,82 @@ WriteRegOperation::Execute(ProcessMonitor *monitor)
}
//------------------------------------------------------------------------------
+/// @class ReadDebugRegOperation
+/// @brief Implements ProcessMonitor::ReadDebugRegisterValue.
+class ReadDebugRegOperation : public Operation
+{
+public:
+ ReadDebugRegOperation(lldb::tid_t tid, unsigned offset, unsigned size,
+ RegisterValue &value, bool &result)
+ : m_tid(tid), m_offset(offset), m_size(size),
+ m_value(value), m_result(result)
+ { }
+
+ void Execute(ProcessMonitor *monitor);
+
+private:
+ lldb::tid_t m_tid;
+ unsigned m_offset;
+ unsigned m_size;
+ RegisterValue &m_value;
+ bool &m_result;
+};
+
+void
+ReadDebugRegOperation::Execute(ProcessMonitor *monitor)
+{
+ struct dbreg regs;
+ int rc;
+
+ if ((rc = PTRACE(PT_GETDBREGS, m_tid, (caddr_t)&regs, 0)) < 0) {
+ m_result = false;
+ } else {
+ if (m_size == sizeof(uintptr_t))
+ m_value = *(uintptr_t *)(((caddr_t)&regs) + m_offset);
+ else
+ memcpy(&m_value, (((caddr_t)&regs) + m_offset), m_size);
+ m_result = true;
+ }
+}
+
+//------------------------------------------------------------------------------
+/// @class WriteDebugRegOperation
+/// @brief Implements ProcessMonitor::WriteDebugRegisterValue.
+class WriteDebugRegOperation : public Operation
+{
+public:
+ WriteDebugRegOperation(lldb::tid_t tid, unsigned offset,
+ const RegisterValue &value, bool &result)
+ : m_tid(tid), m_offset(offset),
+ m_value(value), m_result(result)
+ { }
+
+ void Execute(ProcessMonitor *monitor);
+
+private:
+ lldb::tid_t m_tid;
+ unsigned m_offset;
+ const RegisterValue &m_value;
+ bool &m_result;
+};
+
+void
+WriteDebugRegOperation::Execute(ProcessMonitor *monitor)
+{
+ struct dbreg regs;
+
+ if (PTRACE(PT_GETDBREGS, m_tid, (caddr_t)&regs, 0) < 0) {
+ m_result = false;
+ return;
+ }
+ *(uintptr_t *)(((caddr_t)&regs) + m_offset) = (uintptr_t)m_value.GetAsUInt64();
+ if (PTRACE(PT_SETDBREGS, m_tid, (caddr_t)&regs, 0) < 0)
+ m_result = false;
+ else
+ m_result = true;
+}
+
+//------------------------------------------------------------------------------
/// @class ReadGPROperation
/// @brief Implements ProcessMonitor::ReadGPR.
class ReadGPROperation : public Operation
@@ -1175,7 +1258,7 @@ ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor,
case 0:
case TRAP_TRACE:
if (log)
- log->Printf ("ProcessMonitor::%s() received trace event, tid = %" PRIu64, __FUNCTION__, tid);
+ log->Printf ("ProcessMonitor::%s() received trace event, tid = %" PRIu64 " : si_code = %d", __FUNCTION__, tid, info->si_code);
message = ProcessMessage::Trace(tid);
break;
@@ -1464,6 +1547,28 @@ ProcessMonitor::WriteRegisterValue(lldb::tid_t tid, unsigned offset,
}
bool
+ProcessMonitor::ReadDebugRegisterValue(lldb::tid_t tid, unsigned offset,
+ const char *reg_name, unsigned size,
+ lldb_private::RegisterValue &value)
+{
+ bool result;
+ ReadDebugRegOperation op(tid, offset, size, value, result);
+ DoOperation(&op);
+ return result;
+}
+
+bool
+ProcessMonitor::WriteDebugRegisterValue(lldb::tid_t tid, unsigned offset,
+ const char *reg_name,
+ const lldb_private::RegisterValue &value)
+{
+ bool result;
+ WriteDebugRegOperation op(tid, offset, value, result);
+ DoOperation(&op);
+ return result;
+}
+
+bool
ProcessMonitor::ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size)
{
bool result;
diff --git a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
index 84bbac16e5e..4c8198fb2e4 100644
--- a/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
+++ b/lldb/source/Plugins/Process/FreeBSD/ProcessMonitor.h
@@ -116,6 +116,23 @@ public:
WriteRegisterValue(lldb::tid_t tid, unsigned offset, const char *reg_name,
const lldb_private::RegisterValue &value);
+ /// Reads the contents from the debug register identified by the given
+ /// (architecture dependent) offset.
+ ///
+ /// This method is provided for use by RegisterContextFreeBSD derivatives.
+ bool
+ ReadDebugRegisterValue(lldb::tid_t tid, unsigned offset,
+ const char *reg_name, unsigned size,
+ lldb_private::RegisterValue &value);
+
+ /// Writes the given value to the debug register identified by the given
+ /// (architecture dependent) offset.
+ ///
+ /// This method is provided for use by RegisterContextFreeBSD derivatives.
+ bool
+ WriteDebugRegisterValue(lldb::tid_t tid, unsigned offset,
+ const char *reg_name,
+ const lldb_private::RegisterValue &value);
/// Reads all general purpose registers into the specified buffer.
bool
ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size);
diff --git a/lldb/source/Plugins/Process/Linux/LinuxThread.cpp b/lldb/source/Plugins/Process/Linux/LinuxThread.cpp
index d69f96f1424..78668e682da 100644
--- a/lldb/source/Plugins/Process/Linux/LinuxThread.cpp
+++ b/lldb/source/Plugins/Process/Linux/LinuxThread.cpp
@@ -40,24 +40,3 @@ LinuxThread::RefreshStateAfterStop()
POSIXThread::RefreshStateAfterStop();
}
-
-void
-LinuxThread::TraceNotify(const ProcessMessage &message)
-{
- POSIXBreakpointProtocol* reg_ctx = GetPOSIXBreakpointProtocol();
- 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);
-}
diff --git a/lldb/source/Plugins/Process/Linux/LinuxThread.h b/lldb/source/Plugins/Process/Linux/LinuxThread.h
index 7d253aa98eb..bcb2cfd0221 100644
--- a/lldb/source/Plugins/Process/Linux/LinuxThread.h
+++ b/lldb/source/Plugins/Process/Linux/LinuxThread.h
@@ -34,10 +34,6 @@ public:
// POSIXThread override
virtual void
RefreshStateAfterStop();
-
-protected:
- virtual void
- TraceNotify(const ProcessMessage &message);
};
#endif // #ifndef liblldb_LinuxThread_H_
diff --git a/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp b/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp
index 8d4c71ff269..cc759eaad96 100644
--- a/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp
+++ b/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp
@@ -65,7 +65,16 @@ POSIXThread::POSIXThread(Process &process, lldb::tid_t tid)
lldb::WatchpointSP wp = wp_list.GetByIndex(wp_idx);
if (wp.get() && wp->IsEnabled())
{
- assert(EnableHardwareWatchpoint(wp.get()));
+ // This watchpoint as been enabled; obviously this "new" thread
+ // has been created since that watchpoint was enabled. Since
+ // the POSIXBreakpointProtocol has yet to be initialized, its
+ // m_watchpoints_initialized member will be FALSE. Attempting to
+ // read the debug status register to determine if a watchpoint
+ // has been hit would result in the zeroing of that register.
+ // Since the active debug registers would have been cloned when
+ // this thread was created, simply force the m_watchpoints_initized
+ // member to TRUE and avoid resetting dr6 and dr7.
+ GetPOSIXBreakpointProtocol()->ForceWatchpointsInitialized();
}
}
}
@@ -509,6 +518,21 @@ POSIXThread::WatchNotify(const ProcessMessage &message)
void
POSIXThread::TraceNotify(const ProcessMessage &message)
{
+ POSIXBreakpointProtocol* reg_ctx = GetPOSIXBreakpointProtocol();
+ 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;
+ }
+ }
+ }
+
SetStopInfo (StopInfo::CreateStopReasonToTrace(*this));
}
diff --git a/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_i386.cpp b/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_i386.cpp
index 50ec8d414a1..01c9bb4cde8 100644
--- a/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_i386.cpp
+++ b/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_i386.cpp
@@ -37,8 +37,18 @@ struct GPR
uint32_t gs;
};
-#define DR_SIZE 0
-#define DR_OFFSET(reg_index) 0
+struct dbreg {
+ uint32_t dr[8]; /* debug registers */
+ /* Index 0-3: debug address registers */
+ /* Index 4-5: reserved */
+ /* Index 6: debug status */
+ /* Index 7: debug control */
+};
+
+
+#define DR_SIZE sizeof(uint32_t)
+#define DR_OFFSET(reg_index) \
+ (LLVM_EXTENSION offsetof(dbreg, dr[reg_index]))
//---------------------------------------------------------------------------
// Include RegisterInfos_i386 to declare our g_register_infos_i386 structure.
diff --git a/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_x86_64.cpp b/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_x86_64.cpp
index 471734580ff..2162aaffff1 100644
--- a/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_x86_64.cpp
+++ b/lldb/source/Plugins/Process/POSIX/RegisterContextFreeBSD_x86_64.cpp
@@ -46,8 +46,19 @@ typedef struct _GPR
uint64_t ss;
} GPR;
-#define DR_SIZE 0
-#define DR_OFFSET(reg_index) 0
+struct dbreg {
+ uint64_t dr[16]; /* debug registers */
+ /* Index 0-3: debug address registers */
+ /* Index 4-5: reserved */
+ /* Index 6: debug status */
+ /* Index 7: debug control */
+ /* Index 8-15: reserved */
+};
+
+#define DR_SIZE sizeof(uint64_t)
+#define DR_OFFSET(reg_index) \
+ (LLVM_EXTENSION offsetof(dbreg, dr[reg_index]))
+
//---------------------------------------------------------------------------
// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64 structure.
diff --git a/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIX.h b/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIX.h
index e48c528403e..600dae73b5b 100644
--- a/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIX.h
+++ b/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIX.h
@@ -66,6 +66,10 @@ public:
virtual uint32_t
NumSupportedHardwareWatchpoints () = 0;
+ // Force m_watchpoints_initialized to TRUE
+ void
+ ForceWatchpointsInitialized () {m_watchpoints_initialized = true;}
+
protected:
bool m_watchpoints_initialized;
};
diff --git a/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIXProcessMonitor_x86.cpp b/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIXProcessMonitor_x86.cpp
index f833c9b4752..c446bbfa7dc 100644
--- a/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIXProcessMonitor_x86.cpp
+++ b/lldb/source/Plugins/Process/POSIX/RegisterContextPOSIXProcessMonitor_x86.cpp
@@ -109,6 +109,15 @@ RegisterContextPOSIXProcessMonitor_x86_64::ReadRegister(const unsigned reg,
RegisterValue &value)
{
ProcessMonitor &monitor = GetMonitor();
+
+#if defined(__FreeBSD__)
+ if (reg >= m_reg_info.first_dr)
+ return monitor.ReadDebugRegisterValue(m_thread.GetID(),
+ GetRegisterOffset(reg),
+ GetRegisterName(reg),
+ GetRegisterSize(reg),
+ value);
+#endif
return monitor.ReadRegisterValue(m_thread.GetID(),
GetRegisterOffset(reg),
GetRegisterName(reg),
@@ -164,6 +173,13 @@ RegisterContextPOSIXProcessMonitor_x86_64::WriteRegister(const unsigned reg,
}
ProcessMonitor &monitor = GetMonitor();
+#if defined(__FreeBSD__)
+ if (reg >= m_reg_info.first_dr)
+ return monitor.WriteDebugRegisterValue(m_thread.GetID(),
+ GetRegisterOffset(reg_to_write),
+ GetRegisterName(reg_to_write),
+ value_to_write);
+#endif
return monitor.WriteRegisterValue(m_thread.GetID(),
GetRegisterOffset(reg_to_write),
GetRegisterName(reg_to_write),
OpenPOWER on IntegriCloud