Thread.h 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  1. //===-- Thread.h ------------------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLDB_TARGET_THREAD_H
  9. #define LLDB_TARGET_THREAD_H
  10. #include <memory>
  11. #include <mutex>
  12. #include <string>
  13. #include <vector>
  14. #include "lldb/Core/UserSettingsController.h"
  15. #include "lldb/Target/ExecutionContextScope.h"
  16. #include "lldb/Target/RegisterCheckpoint.h"
  17. #include "lldb/Target/StackFrameList.h"
  18. #include "lldb/Utility/Broadcaster.h"
  19. #include "lldb/Utility/CompletionRequest.h"
  20. #include "lldb/Utility/Event.h"
  21. #include "lldb/Utility/StructuredData.h"
  22. #include "lldb/Utility/UserID.h"
  23. #include "lldb/lldb-private.h"
  24. #define LLDB_THREAD_MAX_STOP_EXC_DATA 8
  25. namespace lldb_private {
  26. class ThreadPlanStack;
  27. class ThreadProperties : public Properties {
  28. public:
  29. ThreadProperties(bool is_global);
  30. ~ThreadProperties() override;
  31. /// The regular expression returned determines symbols that this
  32. /// thread won't stop in during "step-in" operations.
  33. ///
  34. /// \return
  35. /// A pointer to a regular expression to compare against symbols,
  36. /// or nullptr if all symbols are allowed.
  37. ///
  38. const RegularExpression *GetSymbolsToAvoidRegexp();
  39. FileSpecList GetLibrariesToAvoid() const;
  40. bool GetTraceEnabledState() const;
  41. bool GetStepInAvoidsNoDebug() const;
  42. bool GetStepOutAvoidsNoDebug() const;
  43. uint64_t GetMaxBacktraceDepth() const;
  44. };
  45. typedef std::shared_ptr<ThreadProperties> ThreadPropertiesSP;
  46. class Thread : public std::enable_shared_from_this<Thread>,
  47. public ThreadProperties,
  48. public UserID,
  49. public ExecutionContextScope,
  50. public Broadcaster {
  51. public:
  52. /// Broadcaster event bits definitions.
  53. enum {
  54. eBroadcastBitStackChanged = (1 << 0),
  55. eBroadcastBitThreadSuspended = (1 << 1),
  56. eBroadcastBitThreadResumed = (1 << 2),
  57. eBroadcastBitSelectedFrameChanged = (1 << 3),
  58. eBroadcastBitThreadSelected = (1 << 4)
  59. };
  60. static ConstString &GetStaticBroadcasterClass();
  61. ConstString &GetBroadcasterClass() const override {
  62. return GetStaticBroadcasterClass();
  63. }
  64. class ThreadEventData : public EventData {
  65. public:
  66. ThreadEventData(const lldb::ThreadSP thread_sp);
  67. ThreadEventData(const lldb::ThreadSP thread_sp, const StackID &stack_id);
  68. ThreadEventData();
  69. ~ThreadEventData() override;
  70. static ConstString GetFlavorString();
  71. ConstString GetFlavor() const override {
  72. return ThreadEventData::GetFlavorString();
  73. }
  74. void Dump(Stream *s) const override;
  75. static const ThreadEventData *GetEventDataFromEvent(const Event *event_ptr);
  76. static lldb::ThreadSP GetThreadFromEvent(const Event *event_ptr);
  77. static StackID GetStackIDFromEvent(const Event *event_ptr);
  78. static lldb::StackFrameSP GetStackFrameFromEvent(const Event *event_ptr);
  79. lldb::ThreadSP GetThread() const { return m_thread_sp; }
  80. StackID GetStackID() const { return m_stack_id; }
  81. private:
  82. lldb::ThreadSP m_thread_sp;
  83. StackID m_stack_id;
  84. ThreadEventData(const ThreadEventData &) = delete;
  85. const ThreadEventData &operator=(const ThreadEventData &) = delete;
  86. };
  87. struct ThreadStateCheckpoint {
  88. uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting
  89. // bit of data.
  90. lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you
  91. // might continue with the wrong signals.
  92. size_t m_completed_plan_checkpoint;
  93. lldb::RegisterCheckpointSP
  94. register_backup_sp; // You need to restore the registers, of course...
  95. uint32_t current_inlined_depth;
  96. lldb::addr_t current_inlined_pc;
  97. };
  98. /// Constructor
  99. ///
  100. /// \param [in] use_invalid_index_id
  101. /// Optional parameter, defaults to false. The only subclass that
  102. /// is likely to set use_invalid_index_id == true is the HistoryThread
  103. /// class. In that case, the Thread we are constructing represents
  104. /// a thread from earlier in the program execution. We may have the
  105. /// tid of the original thread that they represent but we don't want
  106. /// to reuse the IndexID of that thread, or create a new one. If a
  107. /// client wants to know the original thread's IndexID, they should use
  108. /// Thread::GetExtendedBacktraceOriginatingIndexID().
  109. Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id = false);
  110. ~Thread() override;
  111. static void SettingsInitialize();
  112. static void SettingsTerminate();
  113. static const ThreadPropertiesSP &GetGlobalProperties();
  114. lldb::ProcessSP GetProcess() const { return m_process_wp.lock(); }
  115. int GetResumeSignal() const { return m_resume_signal; }
  116. void SetResumeSignal(int signal) { m_resume_signal = signal; }
  117. lldb::StateType GetState() const;
  118. void SetState(lldb::StateType state);
  119. /// Sets the USER resume state for this thread. If you set a thread to
  120. /// suspended with
  121. /// this API, it won't take part in any of the arbitration for ShouldResume,
  122. /// and will stay
  123. /// suspended even when other threads do get to run.
  124. ///
  125. /// N.B. This is not the state that is used internally by thread plans to
  126. /// implement
  127. /// staying on one thread while stepping over a breakpoint, etc. The is the
  128. /// TemporaryResume state, and if you are implementing some bit of strategy in
  129. /// the stepping
  130. /// machinery you should be using that state and not the user resume state.
  131. ///
  132. /// If you are just preparing all threads to run, you should not override the
  133. /// threads that are
  134. /// marked as suspended by the debugger. In that case, pass override_suspend
  135. /// = false. If you want
  136. /// to force the thread to run (e.g. the "thread continue" command, or are
  137. /// resetting the state
  138. /// (e.g. in SBThread::Resume()), then pass true to override_suspend.
  139. void SetResumeState(lldb::StateType state, bool override_suspend = false) {
  140. if (m_resume_state == lldb::eStateSuspended && !override_suspend)
  141. return;
  142. m_resume_state = state;
  143. }
  144. /// Gets the USER resume state for this thread. This is not the same as what
  145. /// this thread is going to do for any particular step, however if this thread
  146. /// returns eStateSuspended, then the process control logic will never allow
  147. /// this
  148. /// thread to run.
  149. ///
  150. /// \return
  151. /// The User resume state for this thread.
  152. lldb::StateType GetResumeState() const { return m_resume_state; }
  153. // This function is called on all the threads before "ShouldResume" and
  154. // "WillResume" in case a thread needs to change its state before the
  155. // ThreadList polls all the threads to figure out which ones actually will
  156. // get to run and how.
  157. void SetupForResume();
  158. // Do not override this function, it is for thread plan logic only
  159. bool ShouldResume(lldb::StateType resume_state);
  160. // Override this to do platform specific tasks before resume.
  161. virtual void WillResume(lldb::StateType resume_state) {}
  162. // This clears generic thread state after a resume. If you subclass this, be
  163. // sure to call it.
  164. virtual void DidResume();
  165. // This notifies the thread when a private stop occurs.
  166. virtual void DidStop();
  167. virtual void RefreshStateAfterStop() = 0;
  168. void SelectMostRelevantFrame();
  169. std::string GetStopDescription();
  170. std::string GetStopDescriptionRaw();
  171. void WillStop();
  172. bool ShouldStop(Event *event_ptr);
  173. Vote ShouldReportStop(Event *event_ptr);
  174. Vote ShouldReportRun(Event *event_ptr);
  175. void Flush();
  176. // Return whether this thread matches the specification in ThreadSpec. This
  177. // is a virtual method because at some point we may extend the thread spec
  178. // with a platform specific dictionary of attributes, which then only the
  179. // platform specific Thread implementation would know how to match. For now,
  180. // this just calls through to the ThreadSpec's ThreadPassesBasicTests method.
  181. virtual bool MatchesSpec(const ThreadSpec *spec);
  182. lldb::StopInfoSP GetStopInfo();
  183. lldb::StopReason GetStopReason();
  184. bool StopInfoIsUpToDate() const;
  185. // This sets the stop reason to a "blank" stop reason, so you can call
  186. // functions on the thread without having the called function run with
  187. // whatever stop reason you stopped with.
  188. void SetStopInfoToNothing();
  189. bool ThreadStoppedForAReason();
  190. static std::string RunModeAsString(lldb::RunMode mode);
  191. static std::string StopReasonAsString(lldb::StopReason reason);
  192. virtual const char *GetInfo() { return nullptr; }
  193. /// Retrieve a dictionary of information about this thread
  194. ///
  195. /// On Mac OS X systems there may be voucher information.
  196. /// The top level dictionary returned will have an "activity" key and the
  197. /// value of the activity is a dictionary. Keys in that dictionary will
  198. /// be "name" and "id", among others.
  199. /// There may also be "trace_messages" (an array) with each entry in that
  200. /// array
  201. /// being a dictionary (keys include "message" with the text of the trace
  202. /// message).
  203. StructuredData::ObjectSP GetExtendedInfo() {
  204. if (!m_extended_info_fetched) {
  205. m_extended_info = FetchThreadExtendedInfo();
  206. m_extended_info_fetched = true;
  207. }
  208. return m_extended_info;
  209. }
  210. virtual const char *GetName() { return nullptr; }
  211. virtual void SetName(const char *name) {}
  212. /// Whether this thread can be associated with a libdispatch queue
  213. ///
  214. /// The Thread may know if it is associated with a libdispatch queue,
  215. /// it may know definitively that it is NOT associated with a libdispatch
  216. /// queue, or it may be unknown whether it is associated with a libdispatch
  217. /// queue.
  218. ///
  219. /// \return
  220. /// eLazyBoolNo if this thread is definitely not associated with a
  221. /// libdispatch queue (e.g. on a non-Darwin system where GCD aka
  222. /// libdispatch is not available).
  223. ///
  224. /// eLazyBoolYes this thread is associated with a libdispatch queue.
  225. ///
  226. /// eLazyBoolCalculate this thread may be associated with a libdispatch
  227. /// queue but the thread doesn't know one way or the other.
  228. virtual lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() {
  229. return eLazyBoolNo;
  230. }
  231. virtual void SetAssociatedWithLibdispatchQueue(
  232. lldb_private::LazyBool associated_with_libdispatch_queue) {}
  233. /// Retrieve the Queue ID for the queue currently using this Thread
  234. ///
  235. /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
  236. /// retrieve the QueueID.
  237. ///
  238. /// This is a unique identifier for the libdispatch/GCD queue in a
  239. /// process. Often starting at 1 for the initial system-created
  240. /// queues and incrementing, a QueueID will not be reused for a
  241. /// different queue during the lifetime of a process.
  242. ///
  243. /// \return
  244. /// A QueueID if the Thread subclass implements this, else
  245. /// LLDB_INVALID_QUEUE_ID.
  246. virtual lldb::queue_id_t GetQueueID() { return LLDB_INVALID_QUEUE_ID; }
  247. virtual void SetQueueID(lldb::queue_id_t new_val) {}
  248. /// Retrieve the Queue name for the queue currently using this Thread
  249. ///
  250. /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
  251. /// retrieve the Queue name.
  252. ///
  253. /// \return
  254. /// The Queue name, if the Thread subclass implements this, else
  255. /// nullptr.
  256. virtual const char *GetQueueName() { return nullptr; }
  257. virtual void SetQueueName(const char *name) {}
  258. /// Retrieve the Queue kind for the queue currently using this Thread
  259. ///
  260. /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
  261. /// retrieve the Queue kind - either eQueueKindSerial or
  262. /// eQueueKindConcurrent, indicating that this queue processes work
  263. /// items serially or concurrently.
  264. ///
  265. /// \return
  266. /// The Queue kind, if the Thread subclass implements this, else
  267. /// eQueueKindUnknown.
  268. virtual lldb::QueueKind GetQueueKind() { return lldb::eQueueKindUnknown; }
  269. virtual void SetQueueKind(lldb::QueueKind kind) {}
  270. /// Retrieve the Queue for this thread, if any.
  271. ///
  272. /// \return
  273. /// A QueueSP for the queue that is currently associated with this
  274. /// thread.
  275. /// An empty shared pointer indicates that this thread is not
  276. /// associated with a queue, or libdispatch queues are not
  277. /// supported on this target.
  278. virtual lldb::QueueSP GetQueue() { return lldb::QueueSP(); }
  279. /// Retrieve the address of the libdispatch_queue_t struct for queue
  280. /// currently using this Thread
  281. ///
  282. /// If this Thread is doing work on behalf of a libdispatch/GCD queue,
  283. /// retrieve the address of the libdispatch_queue_t structure describing
  284. /// the queue.
  285. ///
  286. /// This address may be reused for different queues later in the Process
  287. /// lifetime and should not be used to identify a queue uniquely. Use
  288. /// the GetQueueID() call for that.
  289. ///
  290. /// \return
  291. /// The Queue's libdispatch_queue_t address if the Thread subclass
  292. /// implements this, else LLDB_INVALID_ADDRESS.
  293. virtual lldb::addr_t GetQueueLibdispatchQueueAddress() {
  294. return LLDB_INVALID_ADDRESS;
  295. }
  296. virtual void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) {}
  297. /// Whether this Thread already has all the Queue information cached or not
  298. ///
  299. /// A Thread may be associated with a libdispatch work Queue at a given
  300. /// public stop event. If so, the thread can satisify requests like
  301. /// GetQueueLibdispatchQueueAddress, GetQueueKind, GetQueueName, and
  302. /// GetQueueID
  303. /// either from information from the remote debug stub when it is initially
  304. /// created, or it can query the SystemRuntime for that information.
  305. ///
  306. /// This method allows the SystemRuntime to discover if a thread has this
  307. /// information already, instead of calling the thread to get the information
  308. /// and having the thread call the SystemRuntime again.
  309. virtual bool ThreadHasQueueInformation() const { return false; }
  310. virtual uint32_t GetStackFrameCount() {
  311. return GetStackFrameList()->GetNumFrames();
  312. }
  313. virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx) {
  314. return GetStackFrameList()->GetFrameAtIndex(idx);
  315. }
  316. virtual lldb::StackFrameSP
  317. GetFrameWithConcreteFrameIndex(uint32_t unwind_idx);
  318. bool DecrementCurrentInlinedDepth() {
  319. return GetStackFrameList()->DecrementCurrentInlinedDepth();
  320. }
  321. uint32_t GetCurrentInlinedDepth() {
  322. return GetStackFrameList()->GetCurrentInlinedDepth();
  323. }
  324. Status ReturnFromFrameWithIndex(uint32_t frame_idx,
  325. lldb::ValueObjectSP return_value_sp,
  326. bool broadcast = false);
  327. Status ReturnFromFrame(lldb::StackFrameSP frame_sp,
  328. lldb::ValueObjectSP return_value_sp,
  329. bool broadcast = false);
  330. Status JumpToLine(const FileSpec &file, uint32_t line,
  331. bool can_leave_function, std::string *warnings = nullptr);
  332. virtual lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id) {
  333. if (stack_id.IsValid())
  334. return GetStackFrameList()->GetFrameWithStackID(stack_id);
  335. return lldb::StackFrameSP();
  336. }
  337. uint32_t GetSelectedFrameIndex() {
  338. return GetStackFrameList()->GetSelectedFrameIndex();
  339. }
  340. lldb::StackFrameSP GetSelectedFrame();
  341. uint32_t SetSelectedFrame(lldb_private::StackFrame *frame,
  342. bool broadcast = false);
  343. bool SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast = false);
  344. bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx,
  345. Stream &output_stream);
  346. void SetDefaultFileAndLineToSelectedFrame() {
  347. GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame();
  348. }
  349. virtual lldb::RegisterContextSP GetRegisterContext() = 0;
  350. virtual lldb::RegisterContextSP
  351. CreateRegisterContextForFrame(StackFrame *frame) = 0;
  352. virtual void ClearStackFrames();
  353. virtual bool SetBackingThread(const lldb::ThreadSP &thread_sp) {
  354. return false;
  355. }
  356. virtual lldb::ThreadSP GetBackingThread() const { return lldb::ThreadSP(); }
  357. virtual void ClearBackingThread() {
  358. // Subclasses can use this function if a thread is actually backed by
  359. // another thread. This is currently used for the OperatingSystem plug-ins
  360. // where they might have a thread that is in memory, yet its registers are
  361. // available through the lldb_private::Thread subclass for the current
  362. // lldb_private::Process class. Since each time the process stops the
  363. // backing threads for memory threads can change, we need a way to clear
  364. // the backing thread for all memory threads each time we stop.
  365. }
  366. /// Dump \a count instructions of the thread's \a Trace starting at the \a
  367. /// start_position position in reverse order.
  368. ///
  369. /// The instructions are indexed in reverse order, which means that the \a
  370. /// start_position 0 represents the last instruction of the trace
  371. /// chronologically.
  372. ///
  373. /// \param[in] s
  374. /// The stream object where the instructions are printed.
  375. ///
  376. /// \param[in] count
  377. /// The number of instructions to print.
  378. ///
  379. /// \param[in] start_position
  380. /// The position of the first instruction to print.
  381. void DumpTraceInstructions(Stream &s, size_t count,
  382. size_t start_position = 0) const;
  383. // If stop_format is true, this will be the form used when we print stop
  384. // info. If false, it will be the form we use for thread list and co.
  385. void DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
  386. bool stop_format);
  387. bool GetDescription(Stream &s, lldb::DescriptionLevel level,
  388. bool print_json_thread, bool print_json_stopinfo);
  389. /// Default implementation for stepping into.
  390. ///
  391. /// This function is designed to be used by commands where the
  392. /// process is publicly stopped.
  393. ///
  394. /// \param[in] source_step
  395. /// If true and the frame has debug info, then do a source level
  396. /// step in, else do a single instruction step in.
  397. ///
  398. /// \param[in] step_in_avoids_code_without_debug_info
  399. /// If \a true, then avoid stepping into code that doesn't have
  400. /// debug info, else step into any code regardless of whether it
  401. /// has debug info.
  402. ///
  403. /// \param[in] step_out_avoids_code_without_debug_info
  404. /// If \a true, then if you step out to code with no debug info, keep
  405. /// stepping out till you get to code with debug info.
  406. ///
  407. /// \return
  408. /// An error that describes anything that went wrong
  409. virtual Status
  410. StepIn(bool source_step,
  411. LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
  412. LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
  413. /// Default implementation for stepping over.
  414. ///
  415. /// This function is designed to be used by commands where the
  416. /// process is publicly stopped.
  417. ///
  418. /// \param[in] source_step
  419. /// If true and the frame has debug info, then do a source level
  420. /// step over, else do a single instruction step over.
  421. ///
  422. /// \return
  423. /// An error that describes anything that went wrong
  424. virtual Status StepOver(
  425. bool source_step,
  426. LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
  427. /// Default implementation for stepping out.
  428. ///
  429. /// This function is designed to be used by commands where the
  430. /// process is publicly stopped.
  431. ///
  432. /// \return
  433. /// An error that describes anything that went wrong
  434. virtual Status StepOut();
  435. /// Retrieves the per-thread data area.
  436. /// Most OSs maintain a per-thread pointer (e.g. the FS register on
  437. /// x64), which we return the value of here.
  438. ///
  439. /// \return
  440. /// LLDB_INVALID_ADDRESS if not supported, otherwise the thread
  441. /// pointer value.
  442. virtual lldb::addr_t GetThreadPointer();
  443. /// Retrieves the per-module TLS block for a thread.
  444. ///
  445. /// \param[in] module
  446. /// The module to query TLS data for.
  447. ///
  448. /// \param[in] tls_file_addr
  449. /// The thread local address in module
  450. /// \return
  451. /// If the thread has TLS data allocated for the
  452. /// module, the address of the TLS block. Otherwise
  453. /// LLDB_INVALID_ADDRESS is returned.
  454. virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module,
  455. lldb::addr_t tls_file_addr);
  456. /// Check whether this thread is safe to run functions
  457. ///
  458. /// The SystemRuntime may know of certain thread states (functions in
  459. /// process of execution, for instance) which can make it unsafe for
  460. /// functions to be called.
  461. ///
  462. /// \return
  463. /// True if it is safe to call functions on this thread.
  464. /// False if function calls should be avoided on this thread.
  465. virtual bool SafeToCallFunctions();
  466. // Thread Plan Providers:
  467. // This section provides the basic thread plans that the Process control
  468. // machinery uses to run the target. ThreadPlan.h provides more details on
  469. // how this mechanism works. The thread provides accessors to a set of plans
  470. // that perform basic operations. The idea is that particular Platform
  471. // plugins can override these methods to provide the implementation of these
  472. // basic operations appropriate to their environment.
  473. //
  474. // NB: All the QueueThreadPlanXXX providers return Shared Pointers to
  475. // Thread plans. This is useful so that you can modify the plans after
  476. // creation in ways specific to that plan type. Also, it is often necessary
  477. // for ThreadPlans that utilize other ThreadPlans to implement their task to
  478. // keep a shared pointer to the sub-plan. But besides that, the shared
  479. // pointers should only be held onto by entities who live no longer than the
  480. // thread containing the ThreadPlan.
  481. // FIXME: If this becomes a problem, we can make a version that just returns a
  482. // pointer,
  483. // which it is clearly unsafe to hold onto, and a shared pointer version, and
  484. // only allow ThreadPlan and Co. to use the latter. That is made more
  485. // annoying to do because there's no elegant way to friend a method to all
  486. // sub-classes of a given class.
  487. //
  488. /// Queues the base plan for a thread.
  489. /// The version returned by Process does some things that are useful,
  490. /// like handle breakpoints and signals, so if you return a plugin specific
  491. /// one you probably want to call through to the Process one for anything
  492. /// your plugin doesn't explicitly handle.
  493. ///
  494. /// \param[in] abort_other_plans
  495. /// \b true if we discard the currently queued plans and replace them with
  496. /// this one.
  497. /// Otherwise this plan will go on the end of the plan stack.
  498. ///
  499. /// \return
  500. /// A shared pointer to the newly queued thread plan, or nullptr if the
  501. /// plan could not be queued.
  502. lldb::ThreadPlanSP QueueBasePlan(bool abort_other_plans);
  503. /// Queues the plan used to step one instruction from the current PC of \a
  504. /// thread.
  505. ///
  506. /// \param[in] step_over
  507. /// \b true if we step over calls to functions, false if we step in.
  508. ///
  509. /// \param[in] abort_other_plans
  510. /// \b true if we discard the currently queued plans and replace them with
  511. /// this one.
  512. /// Otherwise this plan will go on the end of the plan stack.
  513. ///
  514. /// \param[in] stop_other_threads
  515. /// \b true if we will stop other threads while we single step this one.
  516. ///
  517. /// \param[out] status
  518. /// A status with an error if queuing failed.
  519. ///
  520. /// \return
  521. /// A shared pointer to the newly queued thread plan, or nullptr if the
  522. /// plan could not be queued.
  523. virtual lldb::ThreadPlanSP QueueThreadPlanForStepSingleInstruction(
  524. bool step_over, bool abort_other_plans, bool stop_other_threads,
  525. Status &status);
  526. /// Queues the plan used to step through an address range, stepping over
  527. /// function calls.
  528. ///
  529. /// \param[in] abort_other_plans
  530. /// \b true if we discard the currently queued plans and replace them with
  531. /// this one.
  532. /// Otherwise this plan will go on the end of the plan stack.
  533. ///
  534. /// \param[in] type
  535. /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported
  536. /// by this plan.
  537. ///
  538. /// \param[in] range
  539. /// The address range to step through.
  540. ///
  541. /// \param[in] addr_context
  542. /// When dealing with stepping through inlined functions the current PC is
  543. /// not enough information to know
  544. /// what "step" means. For instance a series of nested inline functions
  545. /// might start at the same address.
  546. // The \a addr_context provides the current symbol context the step
  547. /// is supposed to be out of.
  548. // FIXME: Currently unused.
  549. ///
  550. /// \param[in] stop_other_threads
  551. /// \b true if we will stop other threads while we single step this one.
  552. ///
  553. /// \param[out] status
  554. /// A status with an error if queuing failed.
  555. ///
  556. /// \param[in] step_out_avoids_code_without_debug_info
  557. /// If eLazyBoolYes, if the step over steps out it will continue to step
  558. /// out till it comes to a frame with debug info.
  559. /// If eLazyBoolCalculate, we will consult the default set in the thread.
  560. ///
  561. /// \return
  562. /// A shared pointer to the newly queued thread plan, or nullptr if the
  563. /// plan could not be queued.
  564. virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange(
  565. bool abort_other_plans, const AddressRange &range,
  566. const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
  567. Status &status,
  568. LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
  569. // Helper function that takes a LineEntry to step, insted of an AddressRange.
  570. // This may combine multiple LineEntries of the same source line number to
  571. // step over a longer address range in a single operation.
  572. virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange(
  573. bool abort_other_plans, const LineEntry &line_entry,
  574. const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
  575. Status &status,
  576. LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
  577. /// Queues the plan used to step through an address range, stepping into
  578. /// functions.
  579. ///
  580. /// \param[in] abort_other_plans
  581. /// \b true if we discard the currently queued plans and replace them with
  582. /// this one.
  583. /// Otherwise this plan will go on the end of the plan stack.
  584. ///
  585. /// \param[in] type
  586. /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported
  587. /// by this plan.
  588. ///
  589. /// \param[in] range
  590. /// The address range to step through.
  591. ///
  592. /// \param[in] addr_context
  593. /// When dealing with stepping through inlined functions the current PC is
  594. /// not enough information to know
  595. /// what "step" means. For instance a series of nested inline functions
  596. /// might start at the same address.
  597. // The \a addr_context provides the current symbol context the step
  598. /// is supposed to be out of.
  599. // FIXME: Currently unused.
  600. ///
  601. /// \param[in] step_in_target
  602. /// Name if function we are trying to step into. We will step out if we
  603. /// don't land in that function.
  604. ///
  605. /// \param[in] stop_other_threads
  606. /// \b true if we will stop other threads while we single step this one.
  607. ///
  608. /// \param[out] status
  609. /// A status with an error if queuing failed.
  610. ///
  611. /// \param[in] step_in_avoids_code_without_debug_info
  612. /// If eLazyBoolYes we will step out if we step into code with no debug
  613. /// info.
  614. /// If eLazyBoolCalculate we will consult the default set in the thread.
  615. ///
  616. /// \param[in] step_out_avoids_code_without_debug_info
  617. /// If eLazyBoolYes, if the step over steps out it will continue to step
  618. /// out till it comes to a frame with debug info.
  619. /// If eLazyBoolCalculate, it will consult the default set in the thread.
  620. ///
  621. /// \return
  622. /// A shared pointer to the newly queued thread plan, or nullptr if the
  623. /// plan could not be queued.
  624. virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange(
  625. bool abort_other_plans, const AddressRange &range,
  626. const SymbolContext &addr_context, const char *step_in_target,
  627. lldb::RunMode stop_other_threads, Status &status,
  628. LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
  629. LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
  630. // Helper function that takes a LineEntry to step, insted of an AddressRange.
  631. // This may combine multiple LineEntries of the same source line number to
  632. // step over a longer address range in a single operation.
  633. virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange(
  634. bool abort_other_plans, const LineEntry &line_entry,
  635. const SymbolContext &addr_context, const char *step_in_target,
  636. lldb::RunMode stop_other_threads, Status &status,
  637. LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate,
  638. LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
  639. /// Queue the plan used to step out of the function at the current PC of
  640. /// \a thread.
  641. ///
  642. /// \param[in] abort_other_plans
  643. /// \b true if we discard the currently queued plans and replace them with
  644. /// this one.
  645. /// Otherwise this plan will go on the end of the plan stack.
  646. ///
  647. /// \param[in] addr_context
  648. /// When dealing with stepping through inlined functions the current PC is
  649. /// not enough information to know
  650. /// what "step" means. For instance a series of nested inline functions
  651. /// might start at the same address.
  652. // The \a addr_context provides the current symbol context the step
  653. /// is supposed to be out of.
  654. // FIXME: Currently unused.
  655. ///
  656. /// \param[in] first_insn
  657. /// \b true if this is the first instruction of a function.
  658. ///
  659. /// \param[in] stop_other_threads
  660. /// \b true if we will stop other threads while we single step this one.
  661. ///
  662. /// \param[in] report_stop_vote
  663. /// See standard meanings for the stop & run votes in ThreadPlan.h.
  664. ///
  665. /// \param[in] report_run_vote
  666. /// See standard meanings for the stop & run votes in ThreadPlan.h.
  667. ///
  668. /// \param[out] status
  669. /// A status with an error if queuing failed.
  670. ///
  671. /// \param[in] step_out_avoids_code_without_debug_info
  672. /// If eLazyBoolYes, if the step over steps out it will continue to step
  673. /// out till it comes to a frame with debug info.
  674. /// If eLazyBoolCalculate, it will consult the default set in the thread.
  675. ///
  676. /// \return
  677. /// A shared pointer to the newly queued thread plan, or nullptr if the
  678. /// plan could not be queued.
  679. virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut(
  680. bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
  681. bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
  682. uint32_t frame_idx, Status &status,
  683. LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate);
  684. /// Queue the plan used to step out of the function at the current PC of
  685. /// a thread. This version does not consult the should stop here callback,
  686. /// and should only
  687. /// be used by other thread plans when they need to retain control of the step
  688. /// out.
  689. ///
  690. /// \param[in] abort_other_plans
  691. /// \b true if we discard the currently queued plans and replace them with
  692. /// this one.
  693. /// Otherwise this plan will go on the end of the plan stack.
  694. ///
  695. /// \param[in] addr_context
  696. /// When dealing with stepping through inlined functions the current PC is
  697. /// not enough information to know
  698. /// what "step" means. For instance a series of nested inline functions
  699. /// might start at the same address.
  700. // The \a addr_context provides the current symbol context the step
  701. /// is supposed to be out of.
  702. // FIXME: Currently unused.
  703. ///
  704. /// \param[in] first_insn
  705. /// \b true if this is the first instruction of a function.
  706. ///
  707. /// \param[in] stop_other_threads
  708. /// \b true if we will stop other threads while we single step this one.
  709. ///
  710. /// \param[in] report_stop_vote
  711. /// See standard meanings for the stop & run votes in ThreadPlan.h.
  712. ///
  713. /// \param[in] report_run_vote
  714. /// See standard meanings for the stop & run votes in ThreadPlan.h.
  715. ///
  716. /// \param[in] frame_idx
  717. /// The fame index.
  718. ///
  719. /// \param[out] status
  720. /// A status with an error if queuing failed.
  721. ///
  722. /// \param[in] continue_to_next_branch
  723. /// Normally this will enqueue a plan that will put a breakpoint on the
  724. /// return address and continue
  725. /// to there. If continue_to_next_branch is true, this is an operation not
  726. /// involving the user --
  727. /// e.g. stepping "next" in a source line and we instruction stepped into
  728. /// another function --
  729. /// so instead of putting a breakpoint on the return address, advance the
  730. /// breakpoint to the
  731. /// end of the source line that is doing the call, or until the next flow
  732. /// control instruction.
  733. /// If the return value from the function call is to be retrieved /
  734. /// displayed to the user, you must stop
  735. /// on the return address. The return value may be stored in volatile
  736. /// registers which are overwritten
  737. /// before the next branch instruction.
  738. ///
  739. /// \return
  740. /// A shared pointer to the newly queued thread plan, or nullptr if the
  741. /// plan could not be queued.
  742. virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop(
  743. bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
  744. bool stop_other_threads, Vote report_stop_vote, Vote report_run_vote,
  745. uint32_t frame_idx, Status &status, bool continue_to_next_branch = false);
  746. /// Gets the plan used to step through the code that steps from a function
  747. /// call site at the current PC into the actual function call.
  748. ///
  749. /// \param[in] return_stack_id
  750. /// The stack id that we will return to (by setting backstop breakpoints on
  751. /// the return
  752. /// address to that frame) if we fail to step through.
  753. ///
  754. /// \param[in] abort_other_plans
  755. /// \b true if we discard the currently queued plans and replace them with
  756. /// this one.
  757. /// Otherwise this plan will go on the end of the plan stack.
  758. ///
  759. /// \param[in] stop_other_threads
  760. /// \b true if we will stop other threads while we single step this one.
  761. ///
  762. /// \param[out] status
  763. /// A status with an error if queuing failed.
  764. ///
  765. /// \return
  766. /// A shared pointer to the newly queued thread plan, or nullptr if the
  767. /// plan could not be queued.
  768. virtual lldb::ThreadPlanSP
  769. QueueThreadPlanForStepThrough(StackID &return_stack_id,
  770. bool abort_other_plans, bool stop_other_threads,
  771. Status &status);
  772. /// Gets the plan used to continue from the current PC.
  773. /// This is a simple plan, mostly useful as a backstop when you are continuing
  774. /// for some particular purpose.
  775. ///
  776. /// \param[in] abort_other_plans
  777. /// \b true if we discard the currently queued plans and replace them with
  778. /// this one.
  779. /// Otherwise this plan will go on the end of the plan stack.
  780. ///
  781. /// \param[in] target_addr
  782. /// The address to which we're running.
  783. ///
  784. /// \param[in] stop_other_threads
  785. /// \b true if we will stop other threads while we single step this one.
  786. ///
  787. /// \param[out] status
  788. /// A status with an error if queuing failed.
  789. ///
  790. /// \return
  791. /// A shared pointer to the newly queued thread plan, or nullptr if the
  792. /// plan could not be queued.
  793. virtual lldb::ThreadPlanSP
  794. QueueThreadPlanForRunToAddress(bool abort_other_plans, Address &target_addr,
  795. bool stop_other_threads, Status &status);
  796. virtual lldb::ThreadPlanSP QueueThreadPlanForStepUntil(
  797. bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses,
  798. bool stop_others, uint32_t frame_idx, Status &status);
  799. virtual lldb::ThreadPlanSP
  800. QueueThreadPlanForStepScripted(bool abort_other_plans, const char *class_name,
  801. StructuredData::ObjectSP extra_args_sp,
  802. bool stop_other_threads, Status &status);
  803. // Thread Plan accessors:
  804. /// Format the thread plan information for auto completion.
  805. ///
  806. /// \param[in] request
  807. /// The reference to the completion handler.
  808. void AutoCompleteThreadPlans(CompletionRequest &request) const;
  809. /// Gets the plan which will execute next on the plan stack.
  810. ///
  811. /// \return
  812. /// A pointer to the next executed plan.
  813. ThreadPlan *GetCurrentPlan() const;
  814. /// Unwinds the thread stack for the innermost expression plan currently
  815. /// on the thread plan stack.
  816. ///
  817. /// \return
  818. /// An error if the thread plan could not be unwound.
  819. Status UnwindInnermostExpression();
  820. /// Gets the outer-most plan that was popped off the plan stack in the
  821. /// most recent stop. Useful for printing the stop reason accurately.
  822. ///
  823. /// \return
  824. /// A pointer to the last completed plan.
  825. lldb::ThreadPlanSP GetCompletedPlan() const;
  826. /// Gets the outer-most return value from the completed plans
  827. ///
  828. /// \return
  829. /// A ValueObjectSP, either empty if there is no return value,
  830. /// or containing the return value.
  831. lldb::ValueObjectSP GetReturnValueObject() const;
  832. /// Gets the outer-most expression variable from the completed plans
  833. ///
  834. /// \return
  835. /// A ExpressionVariableSP, either empty if there is no
  836. /// plan completed an expression during the current stop
  837. /// or the expression variable that was made for the completed expression.
  838. lldb::ExpressionVariableSP GetExpressionVariable() const;
  839. /// Checks whether the given plan is in the completed plans for this
  840. /// stop.
  841. ///
  842. /// \param[in] plan
  843. /// Pointer to the plan you're checking.
  844. ///
  845. /// \return
  846. /// Returns true if the input plan is in the completed plan stack,
  847. /// false otherwise.
  848. bool IsThreadPlanDone(ThreadPlan *plan) const;
  849. /// Checks whether the given plan is in the discarded plans for this
  850. /// stop.
  851. ///
  852. /// \param[in] plan
  853. /// Pointer to the plan you're checking.
  854. ///
  855. /// \return
  856. /// Returns true if the input plan is in the discarded plan stack,
  857. /// false otherwise.
  858. bool WasThreadPlanDiscarded(ThreadPlan *plan) const;
  859. /// Check if we have completed plan to override breakpoint stop reason
  860. ///
  861. /// \return
  862. /// Returns true if completed plan stack is not empty
  863. /// false otherwise.
  864. bool CompletedPlanOverridesBreakpoint() const;
  865. /// Queues a generic thread plan.
  866. ///
  867. /// \param[in] plan_sp
  868. /// The plan to queue.
  869. ///
  870. /// \param[in] abort_other_plans
  871. /// \b true if we discard the currently queued plans and replace them with
  872. /// this one.
  873. /// Otherwise this plan will go on the end of the plan stack.
  874. ///
  875. /// \return
  876. /// A pointer to the last completed plan.
  877. Status QueueThreadPlan(lldb::ThreadPlanSP &plan_sp, bool abort_other_plans);
  878. /// Discards the plans queued on the plan stack of the current thread. This
  879. /// is
  880. /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call.
  881. // But if \a force is true, all thread plans are discarded.
  882. void DiscardThreadPlans(bool force);
  883. /// Discards the plans queued on the plan stack of the current thread up to
  884. /// and
  885. /// including up_to_plan_sp.
  886. //
  887. // \param[in] up_to_plan_sp
  888. // Discard all plans up to and including this one.
  889. void DiscardThreadPlansUpToPlan(lldb::ThreadPlanSP &up_to_plan_sp);
  890. void DiscardThreadPlansUpToPlan(ThreadPlan *up_to_plan_ptr);
  891. /// Discards the plans queued on the plan stack of the current thread up to
  892. /// and
  893. /// including the plan in that matches \a thread_index counting only
  894. /// the non-Private plans.
  895. ///
  896. /// \param[in] thread_index
  897. /// Discard all plans up to and including this user plan given by this
  898. /// index.
  899. ///
  900. /// \return
  901. /// \b true if there was a thread plan with that user index, \b false
  902. /// otherwise.
  903. bool DiscardUserThreadPlansUpToIndex(uint32_t thread_index);
  904. virtual bool CheckpointThreadState(ThreadStateCheckpoint &saved_state);
  905. virtual bool
  906. RestoreRegisterStateFromCheckpoint(ThreadStateCheckpoint &saved_state);
  907. void RestoreThreadStateFromCheckpoint(ThreadStateCheckpoint &saved_state);
  908. // Get the thread index ID. The index ID that is guaranteed to not be re-used
  909. // by a process. They start at 1 and increase with each new thread. This
  910. // allows easy command line access by a unique ID that is easier to type than
  911. // the actual system thread ID.
  912. uint32_t GetIndexID() const;
  913. // Get the originating thread's index ID.
  914. // In the case of an "extended" thread -- a thread which represents the stack
  915. // that enqueued/spawned work that is currently executing -- we need to
  916. // provide the IndexID of the thread that actually did this work. We don't
  917. // want to just masquerade as that thread's IndexID by using it in our own
  918. // IndexID because that way leads to madness - but the driver program which
  919. // is iterating over extended threads may ask for the OriginatingThreadID to
  920. // display that information to the user.
  921. // Normal threads will return the same thing as GetIndexID();
  922. virtual uint32_t GetExtendedBacktraceOriginatingIndexID() {
  923. return GetIndexID();
  924. }
  925. // The API ID is often the same as the Thread::GetID(), but not in all cases.
  926. // Thread::GetID() is the user visible thread ID that clients would want to
  927. // see. The API thread ID is the thread ID that is used when sending data
  928. // to/from the debugging protocol.
  929. virtual lldb::user_id_t GetProtocolID() const { return GetID(); }
  930. // lldb::ExecutionContextScope pure virtual functions
  931. lldb::TargetSP CalculateTarget() override;
  932. lldb::ProcessSP CalculateProcess() override;
  933. lldb::ThreadSP CalculateThread() override;
  934. lldb::StackFrameSP CalculateStackFrame() override;
  935. void CalculateExecutionContext(ExecutionContext &exe_ctx) override;
  936. lldb::StackFrameSP
  937. GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr);
  938. size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames,
  939. uint32_t num_frames_with_source, bool stop_format,
  940. bool only_stacks = false);
  941. size_t GetStackFrameStatus(Stream &strm, uint32_t first_frame,
  942. uint32_t num_frames, bool show_frame_info,
  943. uint32_t num_frames_with_source);
  944. // We need a way to verify that even though we have a thread in a shared
  945. // pointer that the object itself is still valid. Currently this won't be the
  946. // case if DestroyThread() was called. DestroyThread is called when a thread
  947. // has been removed from the Process' thread list.
  948. bool IsValid() const { return !m_destroy_called; }
  949. // Sets and returns a valid stop info based on the process stop ID and the
  950. // current thread plan. If the thread stop ID does not match the process'
  951. // stop ID, the private stop reason is not set and an invalid StopInfoSP may
  952. // be returned.
  953. //
  954. // NOTE: This function must be called before the current thread plan is
  955. // moved to the completed plan stack (in Thread::ShouldStop()).
  956. //
  957. // NOTE: If subclasses override this function, ensure they do not overwrite
  958. // the m_actual_stop_info if it is valid. The stop info may be a
  959. // "checkpointed and restored" stop info, so if it is still around it is
  960. // right even if you have not calculated this yourself, or if it disagrees
  961. // with what you might have calculated.
  962. virtual lldb::StopInfoSP GetPrivateStopInfo();
  963. // Calculate the stop info that will be shown to lldb clients. For instance,
  964. // a "step out" is implemented by running to a breakpoint on the function
  965. // return PC, so the process plugin initially sets the stop info to a
  966. // StopInfoBreakpoint. But once we've run the ShouldStop machinery, we
  967. // discover that there's a completed ThreadPlanStepOut, and that's really
  968. // the StopInfo we want to show. That will happen naturally the next
  969. // time GetStopInfo is called, but if you want to force the replacement,
  970. // you can call this.
  971. void CalculatePublicStopInfo();
  972. // Ask the thread subclass to set its stop info.
  973. //
  974. // Thread subclasses should call Thread::SetStopInfo(...) with the reason the
  975. // thread stopped.
  976. //
  977. // \return
  978. // True if Thread::SetStopInfo(...) was called, false otherwise.
  979. virtual bool CalculateStopInfo() = 0;
  980. // Gets the temporary resume state for a thread.
  981. //
  982. // This value gets set in each thread by complex debugger logic in
  983. // Thread::ShouldResume() and an appropriate thread resume state will get set
  984. // in each thread every time the process is resumed prior to calling
  985. // Process::DoResume(). The lldb_private::Process subclass should adhere to
  986. // the thread resume state request which will be one of:
  987. //
  988. // eStateRunning - thread will resume when process is resumed
  989. // eStateStepping - thread should step 1 instruction and stop when process
  990. // is resumed
  991. // eStateSuspended - thread should not execute any instructions when
  992. // process is resumed
  993. lldb::StateType GetTemporaryResumeState() const {
  994. return m_temporary_resume_state;
  995. }
  996. void SetStopInfo(const lldb::StopInfoSP &stop_info_sp);
  997. void ResetStopInfo();
  998. void SetShouldReportStop(Vote vote);
  999. /// Sets the extended backtrace token for this thread
  1000. ///
  1001. /// Some Thread subclasses may maintain a token to help with providing
  1002. /// an extended backtrace. The SystemRuntime plugin will set/request this.
  1003. ///
  1004. /// \param [in] token The extended backtrace token.
  1005. virtual void SetExtendedBacktraceToken(uint64_t token) {}
  1006. /// Gets the extended backtrace token for this thread
  1007. ///
  1008. /// Some Thread subclasses may maintain a token to help with providing
  1009. /// an extended backtrace. The SystemRuntime plugin will set/request this.
  1010. ///
  1011. /// \return
  1012. /// The token needed by the SystemRuntime to create an extended backtrace.
  1013. /// LLDB_INVALID_ADDRESS is returned if no token is available.
  1014. virtual uint64_t GetExtendedBacktraceToken() { return LLDB_INVALID_ADDRESS; }
  1015. lldb::ValueObjectSP GetCurrentException();
  1016. lldb::ThreadSP GetCurrentExceptionBacktrace();
  1017. protected:
  1018. friend class ThreadPlan;
  1019. friend class ThreadList;
  1020. friend class ThreadEventData;
  1021. friend class StackFrameList;
  1022. friend class StackFrame;
  1023. friend class OperatingSystem;
  1024. // This is necessary to make sure thread assets get destroyed while the
  1025. // thread is still in good shape to call virtual thread methods. This must
  1026. // be called by classes that derive from Thread in their destructor.
  1027. virtual void DestroyThread();
  1028. ThreadPlanStack &GetPlans() const;
  1029. void PushPlan(lldb::ThreadPlanSP plan_sp);
  1030. void PopPlan();
  1031. void DiscardPlan();
  1032. ThreadPlan *GetPreviousPlan(ThreadPlan *plan) const;
  1033. virtual Unwind &GetUnwinder();
  1034. // Check to see whether the thread is still at the last breakpoint hit that
  1035. // stopped it.
  1036. virtual bool IsStillAtLastBreakpointHit();
  1037. // Some threads are threads that are made up by OperatingSystem plugins that
  1038. // are threads that exist and are context switched out into memory. The
  1039. // OperatingSystem plug-in need a ways to know if a thread is "real" or made
  1040. // up.
  1041. virtual bool IsOperatingSystemPluginThread() const { return false; }
  1042. // Subclasses that have a way to get an extended info dictionary for this
  1043. // thread should fill
  1044. virtual lldb_private::StructuredData::ObjectSP FetchThreadExtendedInfo() {
  1045. return StructuredData::ObjectSP();
  1046. }
  1047. lldb::StackFrameListSP GetStackFrameList();
  1048. void SetTemporaryResumeState(lldb::StateType new_state) {
  1049. m_temporary_resume_state = new_state;
  1050. }
  1051. void FrameSelectedCallback(lldb_private::StackFrame *frame);
  1052. // Classes that inherit from Process can see and modify these
  1053. lldb::ProcessWP m_process_wp; ///< The process that owns this thread.
  1054. lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread
  1055. uint32_t m_stop_info_stop_id; // This is the stop id for which the StopInfo is
  1056. // valid. Can use this so you know that
  1057. // the thread's m_stop_info_sp is current and you don't have to fetch it
  1058. // again
  1059. uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time
  1060. // the stop info was checked against
  1061. // the stop info override
  1062. const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread
  1063. ///for easy UI/command line access.
  1064. lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this
  1065. ///thread's current register state.
  1066. lldb::StateType m_state; ///< The state of our process.
  1067. mutable std::recursive_mutex
  1068. m_state_mutex; ///< Multithreaded protection for m_state.
  1069. mutable std::recursive_mutex
  1070. m_frame_mutex; ///< Multithreaded protection for m_state.
  1071. lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily
  1072. ///populated after a thread stops.
  1073. lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from
  1074. ///the last time this thread stopped.
  1075. int m_resume_signal; ///< The signal that should be used when continuing this
  1076. ///thread.
  1077. lldb::StateType m_resume_state; ///< This state is used to force a thread to
  1078. ///be suspended from outside the ThreadPlan
  1079. ///logic.
  1080. lldb::StateType m_temporary_resume_state; ///< This state records what the
  1081. ///thread was told to do by the
  1082. ///thread plan logic for the current
  1083. ///resume.
  1084. /// It gets set in Thread::ShouldResume.
  1085. std::unique_ptr<lldb_private::Unwind> m_unwinder_up;
  1086. bool m_destroy_called; // This is used internally to make sure derived Thread
  1087. // classes call DestroyThread.
  1088. LazyBool m_override_should_notify;
  1089. mutable std::unique_ptr<ThreadPlanStack> m_null_plan_stack_up;
  1090. private:
  1091. bool m_extended_info_fetched; // Have we tried to retrieve the m_extended_info
  1092. // for this thread?
  1093. StructuredData::ObjectSP m_extended_info; // The extended info for this thread
  1094. void BroadcastSelectedFrameChange(StackID &new_frame_id);
  1095. Thread(const Thread &) = delete;
  1096. const Thread &operator=(const Thread &) = delete;
  1097. };
  1098. } // namespace lldb_private
  1099. #endif // LLDB_TARGET_THREAD_H