Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ThreadGDBRemote.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | |
| 11 | #include "ThreadGDBRemote.h" |
| 12 | |
Jason Molenda | 3dc4f44 | 2013-10-18 05:55:24 +0000 | [diff] [blame] | 13 | #include "lldb/Breakpoint/Watchpoint.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Core/ArchSpec.h" |
| 15 | #include "lldb/Core/DataExtractor.h" |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 16 | #include "lldb/Core/State.h" |
Jason Molenda | 3dc4f44 | 2013-10-18 05:55:24 +0000 | [diff] [blame] | 17 | #include "lldb/Core/StreamString.h" |
| 18 | #include "lldb/Target/Platform.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Process.h" |
| 20 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 21 | #include "lldb/Target/StopInfo.h" |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 22 | #include "lldb/Target/SystemRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Target.h" |
Zachary Turner | 93749ab | 2015-03-03 21:51:25 +0000 | [diff] [blame] | 24 | #include "lldb/Target/UnixSignals.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Unwind.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 27 | #include "ProcessGDBRemote.h" |
| 28 | #include "ProcessGDBRemoteLog.h" |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 29 | #include "Utility/StringExtractorGDBRemote.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | |
| 31 | using namespace lldb; |
| 32 | using namespace lldb_private; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 33 | using namespace lldb_private::process_gdb_remote; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | |
| 35 | //---------------------------------------------------------------------- |
| 36 | // Thread Registers |
| 37 | //---------------------------------------------------------------------- |
| 38 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 39 | ThreadGDBRemote::ThreadGDBRemote (Process &process, lldb::tid_t tid) : |
| 40 | Thread(process, tid), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | m_thread_name (), |
| 42 | m_dispatch_queue_name (), |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 43 | m_thread_dispatch_qaddr (LLDB_INVALID_ADDRESS), |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 44 | m_dispatch_queue_t (LLDB_INVALID_ADDRESS), |
| 45 | m_queue_kind (eQueueKindUnknown), |
| 46 | m_queue_serial_number (LLDB_INVALID_QUEUE_ID), |
| 47 | m_associated_with_libdispatch_queue (eLazyBoolCalculate) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | { |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 49 | ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 50 | this, |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 51 | process.GetID(), |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 52 | GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | ThreadGDBRemote::~ThreadGDBRemote () |
| 56 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 57 | ProcessSP process_sp(GetProcess()); |
| 58 | ProcessGDBRemoteLog::LogIf(GDBR_LOG_THREAD, "%p: ThreadGDBRemote::~ThreadGDBRemote (pid = %i, tid = 0x%4.4x)", |
| 59 | this, |
| 60 | process_sp ? process_sp->GetID() : LLDB_INVALID_PROCESS_ID, |
| 61 | GetID()); |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 62 | DestroyThread(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | const char * |
| 66 | ThreadGDBRemote::GetName () |
| 67 | { |
| 68 | if (m_thread_name.empty()) |
| 69 | return NULL; |
| 70 | return m_thread_name.c_str(); |
| 71 | } |
| 72 | |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 73 | void |
| 74 | ThreadGDBRemote::ClearQueueInfo () |
| 75 | { |
| 76 | m_dispatch_queue_name.clear(); |
| 77 | m_queue_kind = eQueueKindUnknown; |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 78 | m_queue_serial_number = 0; |
| 79 | m_dispatch_queue_t = LLDB_INVALID_ADDRESS; |
| 80 | m_associated_with_libdispatch_queue = eLazyBoolCalculate; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | void |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 84 | ThreadGDBRemote::SetQueueInfo (std::string &&queue_name, QueueKind queue_kind, uint64_t queue_serial, addr_t dispatch_queue_t, LazyBool associated_with_libdispatch_queue) |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 85 | { |
| 86 | m_dispatch_queue_name = queue_name; |
| 87 | m_queue_kind = queue_kind; |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 88 | m_queue_serial_number = queue_serial; |
| 89 | m_dispatch_queue_t = dispatch_queue_t; |
| 90 | m_associated_with_libdispatch_queue = associated_with_libdispatch_queue; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | |
| 94 | const char * |
| 95 | ThreadGDBRemote::GetQueueName () |
| 96 | { |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 97 | // If our cached queue info is valid, then someone called ThreadGDBRemote::SetQueueInfo(...) |
| 98 | // with valid information that was gleaned from the stop reply packet. In this case we trust |
| 99 | // that the info is valid in m_dispatch_queue_name without refetching it |
| 100 | if (CachedQueueInfoIsValid()) |
| 101 | { |
| 102 | if (m_dispatch_queue_name.empty()) |
| 103 | return nullptr; |
| 104 | else |
| 105 | return m_dispatch_queue_name.c_str(); |
| 106 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | // Always re-fetch the dispatch queue name since it can change |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 108 | |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 109 | if (m_associated_with_libdispatch_queue == eLazyBoolNo) |
| 110 | return nullptr; |
| 111 | |
| 112 | if (m_thread_dispatch_qaddr != 0 && m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 113 | { |
| 114 | ProcessSP process_sp (GetProcess()); |
| 115 | if (process_sp) |
| 116 | { |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 117 | SystemRuntime *runtime = process_sp->GetSystemRuntime (); |
| 118 | if (runtime) |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 119 | m_dispatch_queue_name = runtime->GetQueueNameFromThreadQAddress (m_thread_dispatch_qaddr); |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 120 | else |
| 121 | m_dispatch_queue_name.clear(); |
| 122 | |
| 123 | if (!m_dispatch_queue_name.empty()) |
Jason Molenda | 3dc4f44 | 2013-10-18 05:55:24 +0000 | [diff] [blame] | 124 | return m_dispatch_queue_name.c_str(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 127 | return NULL; |
| 128 | } |
| 129 | |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 130 | QueueKind |
| 131 | ThreadGDBRemote::GetQueueKind () |
| 132 | { |
| 133 | // If our cached queue info is valid, then someone called ThreadGDBRemote::SetQueueInfo(...) |
| 134 | // with valid information that was gleaned from the stop reply packet. In this case we trust |
| 135 | // that the info is valid in m_dispatch_queue_name without refetching it |
| 136 | if (CachedQueueInfoIsValid()) |
| 137 | { |
| 138 | return m_queue_kind; |
| 139 | } |
| 140 | |
| 141 | if (m_associated_with_libdispatch_queue == eLazyBoolNo) |
| 142 | return eQueueKindUnknown; |
| 143 | |
| 144 | if (m_thread_dispatch_qaddr != 0 && m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) |
| 145 | { |
| 146 | ProcessSP process_sp (GetProcess()); |
| 147 | if (process_sp) |
| 148 | { |
| 149 | SystemRuntime *runtime = process_sp->GetSystemRuntime (); |
| 150 | if (runtime) |
| 151 | m_queue_kind = runtime->GetQueueKind (m_thread_dispatch_qaddr); |
| 152 | return m_queue_kind; |
| 153 | } |
| 154 | } |
| 155 | return eQueueKindUnknown; |
| 156 | } |
| 157 | |
| 158 | |
Jason Molenda | 3dc4f44 | 2013-10-18 05:55:24 +0000 | [diff] [blame] | 159 | queue_id_t |
| 160 | ThreadGDBRemote::GetQueueID () |
| 161 | { |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 162 | // If our cached queue info is valid, then someone called ThreadGDBRemote::SetQueueInfo(...) |
| 163 | // with valid information that was gleaned from the stop reply packet. In this case we trust |
| 164 | // that the info is valid in m_dispatch_queue_name without refetching it |
| 165 | if (CachedQueueInfoIsValid()) |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 166 | return m_queue_serial_number; |
Greg Clayton | 0b90be1 | 2015-06-23 21:27:50 +0000 | [diff] [blame] | 167 | |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 168 | if (m_associated_with_libdispatch_queue == eLazyBoolNo) |
| 169 | return LLDB_INVALID_QUEUE_ID; |
| 170 | |
| 171 | if (m_thread_dispatch_qaddr != 0 && m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) |
Jason Molenda | 3dc4f44 | 2013-10-18 05:55:24 +0000 | [diff] [blame] | 172 | { |
| 173 | ProcessSP process_sp (GetProcess()); |
| 174 | if (process_sp) |
| 175 | { |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 176 | SystemRuntime *runtime = process_sp->GetSystemRuntime (); |
| 177 | if (runtime) |
Jason Molenda | 3dc4f44 | 2013-10-18 05:55:24 +0000 | [diff] [blame] | 178 | { |
Jason Molenda | 2fd8335 | 2014-02-05 05:44:54 +0000 | [diff] [blame] | 179 | return runtime->GetQueueIDFromThreadQAddress (m_thread_dispatch_qaddr); |
Jason Molenda | 3dc4f44 | 2013-10-18 05:55:24 +0000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | } |
| 183 | return LLDB_INVALID_QUEUE_ID; |
| 184 | } |
| 185 | |
Jason Molenda | b9ffa98 | 2014-04-25 00:01:15 +0000 | [diff] [blame] | 186 | QueueSP |
| 187 | ThreadGDBRemote::GetQueue () |
| 188 | { |
| 189 | queue_id_t queue_id = GetQueueID(); |
| 190 | QueueSP queue; |
| 191 | if (queue_id != LLDB_INVALID_QUEUE_ID) |
| 192 | { |
| 193 | ProcessSP process_sp (GetProcess()); |
| 194 | if (process_sp) |
| 195 | { |
| 196 | queue = process_sp->GetQueueList().FindQueueByID (queue_id); |
| 197 | } |
| 198 | } |
| 199 | return queue; |
| 200 | } |
| 201 | |
Jason Molenda | aac16e0 | 2014-03-13 02:54:54 +0000 | [diff] [blame] | 202 | addr_t |
| 203 | ThreadGDBRemote::GetQueueLibdispatchQueueAddress () |
| 204 | { |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 205 | if (m_dispatch_queue_t == LLDB_INVALID_ADDRESS) |
Jason Molenda | aac16e0 | 2014-03-13 02:54:54 +0000 | [diff] [blame] | 206 | { |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 207 | if (m_thread_dispatch_qaddr != 0 && m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS) |
Jason Molenda | aac16e0 | 2014-03-13 02:54:54 +0000 | [diff] [blame] | 208 | { |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 209 | ProcessSP process_sp (GetProcess()); |
| 210 | if (process_sp) |
Jason Molenda | aac16e0 | 2014-03-13 02:54:54 +0000 | [diff] [blame] | 211 | { |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 212 | SystemRuntime *runtime = process_sp->GetSystemRuntime (); |
| 213 | if (runtime) |
| 214 | { |
| 215 | m_dispatch_queue_t = runtime->GetLibdispatchQueueAddressFromThreadQAddress (m_thread_dispatch_qaddr); |
| 216 | } |
Jason Molenda | aac16e0 | 2014-03-13 02:54:54 +0000 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | } |
Jason Molenda | 77f8935 | 2016-01-12 07:09:16 +0000 | [diff] [blame] | 220 | return m_dispatch_queue_t; |
| 221 | } |
| 222 | |
| 223 | void |
| 224 | ThreadGDBRemote::SetQueueLibdispatchQueueAddress (lldb::addr_t dispatch_queue_t) |
| 225 | { |
| 226 | m_dispatch_queue_t = dispatch_queue_t; |
| 227 | } |
| 228 | |
| 229 | bool |
| 230 | ThreadGDBRemote::ThreadHasQueueInformation () const |
| 231 | { |
| 232 | if (m_thread_dispatch_qaddr != 0 |
| 233 | && m_thread_dispatch_qaddr != LLDB_INVALID_ADDRESS |
| 234 | && m_dispatch_queue_t != LLDB_INVALID_ADDRESS |
| 235 | && m_queue_kind != eQueueKindUnknown |
| 236 | && m_queue_serial_number != 0) |
| 237 | { |
| 238 | return true; |
| 239 | } |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | LazyBool |
| 244 | ThreadGDBRemote::GetAssociatedWithLibdispatchQueue () |
| 245 | { |
| 246 | return m_associated_with_libdispatch_queue; |
| 247 | } |
| 248 | |
| 249 | void |
| 250 | ThreadGDBRemote::SetAssociatedWithLibdispatchQueue (LazyBool associated_with_libdispatch_queue) |
| 251 | { |
| 252 | m_associated_with_libdispatch_queue = associated_with_libdispatch_queue; |
Jason Molenda | aac16e0 | 2014-03-13 02:54:54 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 255 | StructuredData::ObjectSP |
| 256 | ThreadGDBRemote::FetchThreadExtendedInfo () |
| 257 | { |
| 258 | StructuredData::ObjectSP object_sp; |
| 259 | const lldb::user_id_t tid = GetProtocolID(); |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 260 | Log *log(GetLogIfAnyCategoriesSet (GDBR_LOG_THREAD)); |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 261 | if (log) |
| 262 | log->Printf ("Fetching extended information for thread %4.4" PRIx64, tid); |
| 263 | ProcessSP process_sp (GetProcess()); |
| 264 | if (process_sp) |
| 265 | { |
| 266 | ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get()); |
| 267 | object_sp = gdb_process->GetExtendedInfoForThread (tid); |
| 268 | } |
| 269 | return object_sp; |
| 270 | } |
| 271 | |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 272 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 273 | ThreadGDBRemote::WillResume (StateType resume_state) |
| 274 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | int signo = GetResumeSignal(); |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 276 | const lldb::user_id_t tid = GetProtocolID(); |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 277 | Log *log(GetLogIfAnyCategoriesSet (GDBR_LOG_THREAD)); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 278 | if (log) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 279 | log->Printf ("Resuming thread: %4.4" PRIx64 " with state: %s.", tid, StateAsCString(resume_state)); |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 280 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 281 | ProcessSP process_sp (GetProcess()); |
| 282 | if (process_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 283 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 284 | ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get()); |
| 285 | switch (resume_state) |
| 286 | { |
| 287 | case eStateSuspended: |
| 288 | case eStateStopped: |
| 289 | // Don't append anything for threads that should stay stopped. |
| 290 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 291 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 292 | case eStateRunning: |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 293 | if (gdb_process->GetUnixSignals()->SignalIsValid(signo)) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 294 | gdb_process->m_continue_C_tids.push_back(std::make_pair(tid, signo)); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 295 | else |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 296 | gdb_process->m_continue_c_tids.push_back(tid); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 297 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 299 | case eStateStepping: |
Chaoren Lin | 98d0a4b | 2015-07-14 01:09:28 +0000 | [diff] [blame] | 300 | if (gdb_process->GetUnixSignals()->SignalIsValid(signo)) |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 301 | gdb_process->m_continue_S_tids.push_back(std::make_pair(tid, signo)); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 302 | else |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 303 | gdb_process->m_continue_s_tids.push_back(tid); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 304 | break; |
Greg Clayton | c982c76 | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 305 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 306 | default: |
| 307 | break; |
| 308 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 309 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void |
| 313 | ThreadGDBRemote::RefreshStateAfterStop() |
| 314 | { |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 315 | // Invalidate all registers in our register context. We don't set "force" to |
| 316 | // true because the stop reply packet might have had some register values |
| 317 | // that were expedited and these will already be copied into the register |
| 318 | // context by the time this function gets called. The GDBRemoteRegisterContext |
| 319 | // class has been made smart enough to detect when it needs to invalidate |
| 320 | // which registers are valid by putting hooks in the register read and |
| 321 | // register supply functions where they check the process stop ID and do |
| 322 | // the right thing. |
| 323 | const bool force = false; |
| 324 | GetRegisterContext()->InvalidateIfNeeded (force); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 327 | bool |
| 328 | ThreadGDBRemote::ThreadIDIsValid (lldb::tid_t thread) |
| 329 | { |
| 330 | return thread != 0; |
| 331 | } |
| 332 | |
| 333 | void |
| 334 | ThreadGDBRemote::Dump(Log *log, uint32_t index) |
| 335 | { |
| 336 | } |
| 337 | |
| 338 | |
| 339 | bool |
| 340 | ThreadGDBRemote::ShouldStop (bool &step_more) |
| 341 | { |
| 342 | return true; |
| 343 | } |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 344 | lldb::RegisterContextSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 345 | ThreadGDBRemote::GetRegisterContext () |
| 346 | { |
| 347 | if (m_reg_context_sp.get() == NULL) |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 348 | m_reg_context_sp = CreateRegisterContextForFrame (NULL); |
| 349 | return m_reg_context_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 350 | } |
| 351 | |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 352 | lldb::RegisterContextSP |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 353 | ThreadGDBRemote::CreateRegisterContextForFrame (StackFrame *frame) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 354 | { |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 355 | lldb::RegisterContextSP reg_ctx_sp; |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 356 | uint32_t concrete_frame_idx = 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 357 | |
| 358 | if (frame) |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 359 | concrete_frame_idx = frame->GetConcreteFrameIndex (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 361 | |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 362 | if (concrete_frame_idx == 0) |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 363 | { |
| 364 | ProcessSP process_sp (GetProcess()); |
| 365 | if (process_sp) |
| 366 | { |
| 367 | ProcessGDBRemote *gdb_process = static_cast<ProcessGDBRemote *>(process_sp.get()); |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 368 | // read_all_registers_at_once will be true if 'p' packet is not supported. |
Sean Callanan | b1de114 | 2013-09-04 23:24:15 +0000 | [diff] [blame] | 369 | bool read_all_registers_at_once = !gdb_process->GetGDBRemote().GetpPacketSupported (GetID()); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 370 | reg_ctx_sp.reset (new GDBRemoteRegisterContext (*this, concrete_frame_idx, gdb_process->m_register_info, read_all_registers_at_once)); |
| 371 | } |
| 372 | } |
Greg Clayton | b3ae876 | 2013-04-12 20:07:46 +0000 | [diff] [blame] | 373 | else |
| 374 | { |
| 375 | Unwind *unwinder = GetUnwinder (); |
| 376 | if (unwinder) |
| 377 | reg_ctx_sp = unwinder->CreateRegisterContextForFrame (frame); |
| 378 | } |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 379 | return reg_ctx_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 382 | bool |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 383 | ThreadGDBRemote::PrivateSetRegisterValue (uint32_t reg, StringExtractor &response) |
| 384 | { |
| 385 | GDBRemoteRegisterContext *gdb_reg_ctx = static_cast<GDBRemoteRegisterContext *>(GetRegisterContext ().get()); |
| 386 | assert (gdb_reg_ctx); |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 387 | return gdb_reg_ctx->PrivateSetRegisterValue (reg, response); |
Greg Clayton | 3e06bd9 | 2011-01-09 21:07:35 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 390 | bool |
Jason Molenda | 545304d | 2015-12-18 00:45:35 +0000 | [diff] [blame] | 391 | ThreadGDBRemote::PrivateSetRegisterValue (uint32_t reg, uint64_t regval) |
| 392 | { |
| 393 | GDBRemoteRegisterContext *gdb_reg_ctx = static_cast<GDBRemoteRegisterContext *>(GetRegisterContext ().get()); |
| 394 | assert (gdb_reg_ctx); |
| 395 | return gdb_reg_ctx->PrivateSetRegisterValue (reg, regval); |
| 396 | } |
| 397 | |
| 398 | bool |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 399 | ThreadGDBRemote::CalculateStopInfo () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 400 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 401 | ProcessSP process_sp (GetProcess()); |
| 402 | if (process_sp) |
Greg Clayton | 358cf1e | 2015-06-25 21:46:34 +0000 | [diff] [blame] | 403 | return static_cast<ProcessGDBRemote *>(process_sp.get())->CalculateThreadStopInfo(this); |
Greg Clayton | 6e0ff1a | 2013-05-09 01:55:29 +0000 | [diff] [blame] | 404 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |