1//===-- MachThreadList.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//
9// Created by Greg Clayton on 6/19/07.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHTHREADLIST_H
14#define LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHTHREADLIST_H
15
16#include "MachThread.h"
17#include "ThreadInfo.h"
18
19class DNBThreadResumeActions;
20
21class MachThreadList {
22public:
23 MachThreadList();
24 ~MachThreadList();
25
26 void Clear();
27 void Dump() const;
28 bool GetRegisterValue(nub_thread_t tid, uint32_t set, uint32_t reg,
29 DNBRegisterValue *reg_value) const;
30 bool SetRegisterValue(nub_thread_t tid, uint32_t set, uint32_t reg,
31 const DNBRegisterValue *reg_value) const;
32 nub_size_t GetRegisterContext(nub_thread_t tid, void *buf, size_t buf_len);
33 nub_size_t SetRegisterContext(nub_thread_t tid, const void *buf,
34 size_t buf_len);
35 uint32_t SaveRegisterState(nub_thread_t tid);
36 bool RestoreRegisterState(nub_thread_t tid, uint32_t save_id);
37 const char *GetThreadInfo(nub_thread_t tid) const;
38 void ProcessWillResume(MachProcess *process,
39 const DNBThreadResumeActions &thread_actions);
40 uint32_t ProcessDidStop(MachProcess *process);
41 bool NotifyException(MachException::Data &exc);
42 bool ShouldStop(bool &step_more);
43 const char *GetName(nub_thread_t tid);
44 nub_state_t GetState(nub_thread_t tid);
45 nub_thread_t SetCurrentThread(nub_thread_t tid);
46
47 ThreadInfo::QoS GetRequestedQoS(nub_thread_t tid, nub_addr_t tsd,
48 uint64_t dti_qos_class_index);
49 nub_addr_t GetPThreadT(nub_thread_t tid);
50 nub_addr_t GetDispatchQueueT(nub_thread_t tid);
51 nub_addr_t
52 GetTSDAddressForThread(nub_thread_t tid,
53 uint64_t plo_pthread_tsd_base_address_offset,
54 uint64_t plo_pthread_tsd_base_offset,
55 uint64_t plo_pthread_tsd_entry_size);
56
57 bool GetThreadStoppedReason(nub_thread_t tid,
58 struct DNBThreadStopInfo *stop_info) const;
59 void DumpThreadStoppedReason(nub_thread_t tid) const;
60 bool GetIdentifierInfo(nub_thread_t tid,
61 thread_identifier_info_data_t *ident_info);
62 nub_size_t NumThreads() const;
63 nub_thread_t ThreadIDAtIndex(nub_size_t idx) const;
64 nub_thread_t CurrentThreadID();
65 void CurrentThread(MachThreadSP &threadSP);
66 void NotifyBreakpointChanged(const DNBBreakpoint *bp);
67 uint32_t EnableHardwareBreakpoint(const DNBBreakpoint *bp) const;
68 bool DisableHardwareBreakpoint(const DNBBreakpoint *bp) const;
69 uint32_t EnableHardwareWatchpoint(const DNBBreakpoint *wp) const;
70 bool DisableHardwareWatchpoint(const DNBBreakpoint *wp) const;
71 uint32_t NumSupportedHardwareWatchpoints() const;
72
73 uint32_t GetThreadIndexForThreadStoppedWithSignal(const int signo) const;
74
75 MachThreadSP GetThreadByID(nub_thread_t tid) const;
76
77 MachThreadSP GetThreadByMachPortNumber(thread_t mach_port_number) const;
78 nub_thread_t GetThreadIDByMachPortNumber(thread_t mach_port_number) const;
79 thread_t GetMachPortNumberByThreadID(nub_thread_t globally_unique_id) const;
80
81protected:
82 typedef std::vector<MachThreadSP> collection;
83 typedef collection::iterator iterator;
84 typedef collection::const_iterator const_iterator;
85
86 enum class HardwareBreakpointAction {
87 EnableWatchpoint,
88 DisableWatchpoint,
89 EnableBreakpoint,
90 DisableBreakpoint,
91 };
92
93 uint32_t DoHardwareBreakpointAction(const DNBBreakpoint *bp,
94 HardwareBreakpointAction action) const;
95
96 uint32_t UpdateThreadList(MachProcess *process, bool update,
97 collection *num_threads = NULL);
98 // const_iterator FindThreadByID (thread_t tid) const;
99
100 collection m_threads;
101 mutable PThreadMutex m_threads_mutex;
102 MachThreadSP m_current_thread;
103 bool m_is_64_bit;
104};
105
106#endif // LLDB_TOOLS_DEBUGSERVER_SOURCE_MACOSX_MACHTHREADLIST_H
107

source code of lldb/tools/debugserver/source/MacOSX/MachThreadList.h