1cfca06d7SDimitry Andric //===-- OperatingSystemPython.cpp -----------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9706b4fc4SDimitry Andric #include "lldb/Host/Config.h"
10706b4fc4SDimitry Andric
11706b4fc4SDimitry Andric #if LLDB_ENABLE_PYTHON
12f034231aSEd Maste
13f034231aSEd Maste #include "OperatingSystemPython.h"
145f29bb8aSDimitry Andric
1514f1b3e8SDimitry Andric #include "Plugins/Process/Utility/RegisterContextDummy.h"
1614f1b3e8SDimitry Andric #include "Plugins/Process/Utility/RegisterContextMemory.h"
1714f1b3e8SDimitry Andric #include "Plugins/Process/Utility/ThreadMemory.h"
18f034231aSEd Maste #include "lldb/Core/Debugger.h"
19f034231aSEd Maste #include "lldb/Core/Module.h"
20f034231aSEd Maste #include "lldb/Core/PluginManager.h"
21f034231aSEd Maste #include "lldb/Core/ValueObjectVariable.h"
22f034231aSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
235e95aa85SEd Maste #include "lldb/Interpreter/ScriptInterpreter.h"
24f034231aSEd Maste #include "lldb/Symbol/ObjectFile.h"
25f034231aSEd Maste #include "lldb/Symbol/VariableList.h"
26f034231aSEd Maste #include "lldb/Target/Process.h"
27f034231aSEd Maste #include "lldb/Target/StopInfo.h"
28f034231aSEd Maste #include "lldb/Target/Target.h"
29f034231aSEd Maste #include "lldb/Target/Thread.h"
3014f1b3e8SDimitry Andric #include "lldb/Target/ThreadList.h"
3174a628f7SDimitry Andric #include "lldb/Utility/DataBufferHeap.h"
32145449b1SDimitry Andric #include "lldb/Utility/LLDBLog.h"
3394994d37SDimitry Andric #include "lldb/Utility/RegisterValue.h"
3474a628f7SDimitry Andric #include "lldb/Utility/StreamString.h"
351b306c26SDimitry Andric #include "lldb/Utility/StructuredData.h"
36f034231aSEd Maste
375f29bb8aSDimitry Andric #include <memory>
385f29bb8aSDimitry Andric
39f034231aSEd Maste using namespace lldb;
40f034231aSEd Maste using namespace lldb_private;
41f034231aSEd Maste
LLDB_PLUGIN_DEFINE(OperatingSystemPython)42cfca06d7SDimitry Andric LLDB_PLUGIN_DEFINE(OperatingSystemPython)
43cfca06d7SDimitry Andric
4414f1b3e8SDimitry Andric void OperatingSystemPython::Initialize() {
4514f1b3e8SDimitry Andric PluginManager::RegisterPlugin(GetPluginNameStatic(),
4614f1b3e8SDimitry Andric GetPluginDescriptionStatic(), CreateInstance,
4714f1b3e8SDimitry Andric nullptr);
48f034231aSEd Maste }
49f034231aSEd Maste
Terminate()5014f1b3e8SDimitry Andric void OperatingSystemPython::Terminate() {
51f034231aSEd Maste PluginManager::UnregisterPlugin(CreateInstance);
52f034231aSEd Maste }
53f034231aSEd Maste
CreateInstance(Process * process,bool force)5414f1b3e8SDimitry Andric OperatingSystem *OperatingSystemPython::CreateInstance(Process *process,
5514f1b3e8SDimitry Andric bool force) {
56f73363f1SDimitry Andric // Python OperatingSystem plug-ins must be requested by name, so force must
57f73363f1SDimitry Andric // be true
58f034231aSEd Maste FileSpec python_os_plugin_spec(process->GetPythonOSPluginPath());
5994994d37SDimitry Andric if (python_os_plugin_spec &&
6094994d37SDimitry Andric FileSystem::Instance().Exists(python_os_plugin_spec)) {
615f29bb8aSDimitry Andric std::unique_ptr<OperatingSystemPython> os_up(
6214f1b3e8SDimitry Andric new OperatingSystemPython(process, python_os_plugin_spec));
635f29bb8aSDimitry Andric if (os_up.get() && os_up->IsValid())
645f29bb8aSDimitry Andric return os_up.release();
65f034231aSEd Maste }
665f29bb8aSDimitry Andric return nullptr;
67f034231aSEd Maste }
68f034231aSEd Maste
GetPluginDescriptionStatic()69c0981da4SDimitry Andric llvm::StringRef OperatingSystemPython::GetPluginDescriptionStatic() {
7014f1b3e8SDimitry Andric return "Operating system plug-in that gathers OS information from a python "
7114f1b3e8SDimitry Andric "class that implements the necessary OperatingSystem functionality.";
72f034231aSEd Maste }
73f034231aSEd Maste
OperatingSystemPython(lldb_private::Process * process,const FileSpec & python_module_path)7414f1b3e8SDimitry Andric OperatingSystemPython::OperatingSystemPython(lldb_private::Process *process,
7514f1b3e8SDimitry Andric const FileSpec &python_module_path)
765f29bb8aSDimitry Andric : OperatingSystem(process), m_thread_list_valobj_sp(), m_register_info_up(),
77b1c73532SDimitry Andric m_interpreter(nullptr), m_script_object_sp() {
78f034231aSEd Maste if (!process)
79f034231aSEd Maste return;
80f034231aSEd Maste TargetSP target_sp = process->CalculateTarget();
81f034231aSEd Maste if (!target_sp)
82f034231aSEd Maste return;
835f29bb8aSDimitry Andric m_interpreter = target_sp->GetDebugger().GetScriptInterpreter();
84b1c73532SDimitry Andric if (!m_interpreter)
85b1c73532SDimitry Andric return;
86f034231aSEd Maste
8714f1b3e8SDimitry Andric std::string os_plugin_class_name(
8814f1b3e8SDimitry Andric python_module_path.GetFilename().AsCString(""));
89b1c73532SDimitry Andric if (os_plugin_class_name.empty())
90b1c73532SDimitry Andric return;
91b1c73532SDimitry Andric
92344a3780SDimitry Andric LoadScriptOptions options;
93f034231aSEd Maste char python_module_path_cstr[PATH_MAX];
9414f1b3e8SDimitry Andric python_module_path.GetPath(python_module_path_cstr,
9514f1b3e8SDimitry Andric sizeof(python_module_path_cstr));
96b76161e4SDimitry Andric Status error;
97b1c73532SDimitry Andric if (!m_interpreter->LoadScriptingModule(python_module_path_cstr, options,
98b1c73532SDimitry Andric error))
99b1c73532SDimitry Andric return;
100b1c73532SDimitry Andric
101f034231aSEd Maste // Strip the ".py" extension if there is one
102f034231aSEd Maste size_t py_extension_pos = os_plugin_class_name.rfind(".py");
103f034231aSEd Maste if (py_extension_pos != std::string::npos)
104f034231aSEd Maste os_plugin_class_name.erase(py_extension_pos);
10514f1b3e8SDimitry Andric // Add ".OperatingSystemPlugIn" to the module name to get a string like
10614f1b3e8SDimitry Andric // "modulename.OperatingSystemPlugIn"
107f034231aSEd Maste os_plugin_class_name += ".OperatingSystemPlugIn";
108b1c73532SDimitry Andric
109b1c73532SDimitry Andric auto operating_system_interface =
110b1c73532SDimitry Andric m_interpreter->CreateOperatingSystemInterface();
111b1c73532SDimitry Andric if (!operating_system_interface)
112b1c73532SDimitry Andric // FIXME: We should pass an Status& to raise the error to the user.
113b1c73532SDimitry Andric // return llvm::createStringError(
114b1c73532SDimitry Andric // llvm::inconvertibleErrorCode(),
115b1c73532SDimitry Andric // "Failed to create scripted thread interface.");
116b1c73532SDimitry Andric return;
117b1c73532SDimitry Andric
118b1c73532SDimitry Andric ExecutionContext exe_ctx(process);
119b1c73532SDimitry Andric auto obj_or_err = operating_system_interface->CreatePluginObject(
120b1c73532SDimitry Andric os_plugin_class_name, exe_ctx, nullptr);
121b1c73532SDimitry Andric
122b1c73532SDimitry Andric if (!obj_or_err) {
123b1c73532SDimitry Andric llvm::consumeError(obj_or_err.takeError());
124b1c73532SDimitry Andric return;
125f034231aSEd Maste }
126b1c73532SDimitry Andric
127b1c73532SDimitry Andric StructuredData::GenericSP owned_script_object_sp = *obj_or_err;
128b1c73532SDimitry Andric if (!owned_script_object_sp->IsValid())
129b1c73532SDimitry Andric // return llvm::createStringError(llvm::inconvertibleErrorCode(),
130b1c73532SDimitry Andric // "Created script object is invalid.");
131b1c73532SDimitry Andric return;
132b1c73532SDimitry Andric
133b1c73532SDimitry Andric m_script_object_sp = owned_script_object_sp;
134b1c73532SDimitry Andric m_operating_system_interface_sp = operating_system_interface;
135f034231aSEd Maste }
136f034231aSEd Maste
137344a3780SDimitry Andric OperatingSystemPython::~OperatingSystemPython() = default;
138f034231aSEd Maste
GetDynamicRegisterInfo()13914f1b3e8SDimitry Andric DynamicRegisterInfo *OperatingSystemPython::GetDynamicRegisterInfo() {
1405f29bb8aSDimitry Andric if (m_register_info_up == nullptr) {
141b1c73532SDimitry Andric if (!m_interpreter || !m_operating_system_interface_sp)
1425f29bb8aSDimitry Andric return nullptr;
143145449b1SDimitry Andric Log *log = GetLog(LLDBLog::OS);
144f034231aSEd Maste
145ead24645SDimitry Andric LLDB_LOGF(log,
146ead24645SDimitry Andric "OperatingSystemPython::GetDynamicRegisterInfo() fetching "
14714f1b3e8SDimitry Andric "thread register definitions from python for pid %" PRIu64,
14814f1b3e8SDimitry Andric m_process->GetID());
149f034231aSEd Maste
15014f1b3e8SDimitry Andric StructuredData::DictionarySP dictionary =
151b1c73532SDimitry Andric m_operating_system_interface_sp->GetRegisterInfo();
152f034231aSEd Maste if (!dictionary)
1535f29bb8aSDimitry Andric return nullptr;
154f034231aSEd Maste
1557fa27ce4SDimitry Andric m_register_info_up = DynamicRegisterInfo::Create(
156b60736ecSDimitry Andric *dictionary, m_process->GetTarget().GetArchitecture());
1577fa27ce4SDimitry Andric assert(m_register_info_up);
1585f29bb8aSDimitry Andric assert(m_register_info_up->GetNumRegisters() > 0);
1595f29bb8aSDimitry Andric assert(m_register_info_up->GetNumRegisterSets() > 0);
160f034231aSEd Maste }
1615f29bb8aSDimitry Andric return m_register_info_up.get();
162f034231aSEd Maste }
163f034231aSEd Maste
UpdateThreadList(ThreadList & old_thread_list,ThreadList & core_thread_list,ThreadList & new_thread_list)16414f1b3e8SDimitry Andric bool OperatingSystemPython::UpdateThreadList(ThreadList &old_thread_list,
165f034231aSEd Maste ThreadList &core_thread_list,
16614f1b3e8SDimitry Andric ThreadList &new_thread_list) {
167b1c73532SDimitry Andric if (!m_interpreter || !m_operating_system_interface_sp)
168f034231aSEd Maste return false;
169f034231aSEd Maste
170145449b1SDimitry Andric Log *log = GetLog(LLDBLog::OS);
171f034231aSEd Maste
172ead24645SDimitry Andric LLDB_LOGF(log,
173ead24645SDimitry Andric "OperatingSystemPython::UpdateThreadList() fetching thread "
17414f1b3e8SDimitry Andric "data from python for pid %" PRIu64,
17514f1b3e8SDimitry Andric m_process->GetID());
176f034231aSEd Maste
177ead24645SDimitry Andric // The threads that are in "core_thread_list" upon entry are the threads from
178f73363f1SDimitry Andric // the lldb_private::Process subclass, no memory threads will be in this
179f73363f1SDimitry Andric // list.
18014f1b3e8SDimitry Andric StructuredData::ArraySP threads_list =
181b1c73532SDimitry Andric m_operating_system_interface_sp->GetThreadInfo();
182866dcdacSEd Maste
183866dcdacSEd Maste const uint32_t num_cores = core_thread_list.GetSize(false);
184866dcdacSEd Maste
185866dcdacSEd Maste // Make a map so we can keep track of which cores were used from the
186f73363f1SDimitry Andric // core_thread list. Any real threads/cores that weren't used should later be
187f73363f1SDimitry Andric // put back into the "new_thread_list".
188866dcdacSEd Maste std::vector<bool> core_used_map(num_cores, false);
18914f1b3e8SDimitry Andric if (threads_list) {
19014f1b3e8SDimitry Andric if (log) {
191f034231aSEd Maste StreamString strm;
1925e95aa85SEd Maste threads_list->Dump(strm);
193ead24645SDimitry Andric LLDB_LOGF(log, "threads_list = %s", strm.GetData());
194f034231aSEd Maste }
1955e95aa85SEd Maste
1965e95aa85SEd Maste const uint32_t num_threads = threads_list->GetSize();
19714f1b3e8SDimitry Andric for (uint32_t i = 0; i < num_threads; ++i) {
19814f1b3e8SDimitry Andric StructuredData::ObjectSP thread_dict_obj =
19914f1b3e8SDimitry Andric threads_list->GetItemAtIndex(i);
20014f1b3e8SDimitry Andric if (auto thread_dict = thread_dict_obj->GetAsDictionary()) {
2015f29bb8aSDimitry Andric ThreadSP thread_sp(CreateThreadFromThreadInfo(
2025f29bb8aSDimitry Andric *thread_dict, core_thread_list, old_thread_list, core_used_map,
2035f29bb8aSDimitry Andric nullptr));
204f034231aSEd Maste if (thread_sp)
205f034231aSEd Maste new_thread_list.AddThread(thread_sp);
206f034231aSEd Maste }
207f034231aSEd Maste }
208f034231aSEd Maste }
209f034231aSEd Maste
210866dcdacSEd Maste // Any real core threads that didn't end up backing a memory thread should
21114f1b3e8SDimitry Andric // still be in the main thread list, and they should be inserted at the
212f73363f1SDimitry Andric // beginning of the list
213866dcdacSEd Maste uint32_t insert_idx = 0;
21414f1b3e8SDimitry Andric for (uint32_t core_idx = 0; core_idx < num_cores; ++core_idx) {
21594994d37SDimitry Andric if (!core_used_map[core_idx]) {
21614f1b3e8SDimitry Andric new_thread_list.InsertThread(
21714f1b3e8SDimitry Andric core_thread_list.GetThreadAtIndex(core_idx, false), insert_idx);
218866dcdacSEd Maste ++insert_idx;
219866dcdacSEd Maste }
220866dcdacSEd Maste }
221f034231aSEd Maste
222f034231aSEd Maste return new_thread_list.GetSize(false) > 0;
223f034231aSEd Maste }
224f034231aSEd Maste
CreateThreadFromThreadInfo(StructuredData::Dictionary & thread_dict,ThreadList & core_thread_list,ThreadList & old_thread_list,std::vector<bool> & core_used_map,bool * did_create_ptr)22514f1b3e8SDimitry Andric ThreadSP OperatingSystemPython::CreateThreadFromThreadInfo(
22614f1b3e8SDimitry Andric StructuredData::Dictionary &thread_dict, ThreadList &core_thread_list,
22714f1b3e8SDimitry Andric ThreadList &old_thread_list, std::vector<bool> &core_used_map,
22814f1b3e8SDimitry Andric bool *did_create_ptr) {
229f034231aSEd Maste ThreadSP thread_sp;
2305e95aa85SEd Maste tid_t tid = LLDB_INVALID_THREAD_ID;
2315e95aa85SEd Maste if (!thread_dict.GetValueForKeyAsInteger("tid", tid))
2325e95aa85SEd Maste return ThreadSP();
233f034231aSEd Maste
2345e95aa85SEd Maste uint32_t core_number;
2355e95aa85SEd Maste addr_t reg_data_addr;
236b76161e4SDimitry Andric llvm::StringRef name;
237b76161e4SDimitry Andric llvm::StringRef queue;
2385e95aa85SEd Maste
2395e95aa85SEd Maste thread_dict.GetValueForKeyAsInteger("core", core_number, UINT32_MAX);
24014f1b3e8SDimitry Andric thread_dict.GetValueForKeyAsInteger("register_data_addr", reg_data_addr,
24114f1b3e8SDimitry Andric LLDB_INVALID_ADDRESS);
2425e95aa85SEd Maste thread_dict.GetValueForKeyAsString("name", name);
2435e95aa85SEd Maste thread_dict.GetValueForKeyAsString("queue", queue);
244f034231aSEd Maste
245f034231aSEd Maste // See if a thread already exists for "tid"
246f034231aSEd Maste thread_sp = old_thread_list.FindThreadByID(tid, false);
24714f1b3e8SDimitry Andric if (thread_sp) {
24814f1b3e8SDimitry Andric // A thread already does exist for "tid", make sure it was an operating
24914f1b3e8SDimitry Andric // system
250f034231aSEd Maste // plug-in generated thread.
25114f1b3e8SDimitry Andric if (!IsOperatingSystemPluginThread(thread_sp)) {
252f034231aSEd Maste // We have thread ID overlap between the protocol threads and the
253f73363f1SDimitry Andric // operating system threads, clear the thread so we create an operating
254f73363f1SDimitry Andric // system thread for this.
255f034231aSEd Maste thread_sp.reset();
256f034231aSEd Maste }
257f034231aSEd Maste }
258f034231aSEd Maste
25914f1b3e8SDimitry Andric if (!thread_sp) {
260f034231aSEd Maste if (did_create_ptr)
261f034231aSEd Maste *did_create_ptr = true;
2625f29bb8aSDimitry Andric thread_sp = std::make_shared<ThreadMemory>(*m_process, tid, name, queue,
2635f29bb8aSDimitry Andric reg_data_addr);
264f034231aSEd Maste }
265f034231aSEd Maste
26614f1b3e8SDimitry Andric if (core_number < core_thread_list.GetSize(false)) {
26714f1b3e8SDimitry Andric ThreadSP core_thread_sp(
26814f1b3e8SDimitry Andric core_thread_list.GetThreadAtIndex(core_number, false));
26914f1b3e8SDimitry Andric if (core_thread_sp) {
27014f1b3e8SDimitry Andric // Keep track of which cores were set as the backing thread for memory
27114f1b3e8SDimitry Andric // threads...
272866dcdacSEd Maste if (core_number < core_used_map.size())
273866dcdacSEd Maste core_used_map[core_number] = true;
274866dcdacSEd Maste
275f034231aSEd Maste ThreadSP backing_core_thread_sp(core_thread_sp->GetBackingThread());
27614f1b3e8SDimitry Andric if (backing_core_thread_sp) {
277f034231aSEd Maste thread_sp->SetBackingThread(backing_core_thread_sp);
27814f1b3e8SDimitry Andric } else {
279f034231aSEd Maste thread_sp->SetBackingThread(core_thread_sp);
280f034231aSEd Maste }
281f034231aSEd Maste }
282f034231aSEd Maste }
283f034231aSEd Maste return thread_sp;
284f034231aSEd Maste }
285f034231aSEd Maste
ThreadWasSelected(Thread * thread)28614f1b3e8SDimitry Andric void OperatingSystemPython::ThreadWasSelected(Thread *thread) {}
287f034231aSEd Maste
288f034231aSEd Maste RegisterContextSP
CreateRegisterContextForThread(Thread * thread,addr_t reg_data_addr)28914f1b3e8SDimitry Andric OperatingSystemPython::CreateRegisterContextForThread(Thread *thread,
29014f1b3e8SDimitry Andric addr_t reg_data_addr) {
291f034231aSEd Maste RegisterContextSP reg_ctx_sp;
292b1c73532SDimitry Andric if (!m_interpreter || !m_script_object_sp || !thread)
293f034231aSEd Maste return reg_ctx_sp;
294f034231aSEd Maste
295f034231aSEd Maste if (!IsOperatingSystemPluginThread(thread->shared_from_this()))
296f034231aSEd Maste return reg_ctx_sp;
297f034231aSEd Maste
298145449b1SDimitry Andric Log *log = GetLog(LLDBLog::Thread);
299f034231aSEd Maste
30014f1b3e8SDimitry Andric if (reg_data_addr != LLDB_INVALID_ADDRESS) {
301f034231aSEd Maste // The registers data is in contiguous memory, just create the register
302f034231aSEd Maste // context using the address provided
303ead24645SDimitry Andric LLDB_LOGF(log,
304ead24645SDimitry Andric "OperatingSystemPython::CreateRegisterContextForThread (tid "
30514f1b3e8SDimitry Andric "= 0x%" PRIx64 ", 0x%" PRIx64 ", reg_data_addr = 0x%" PRIx64
30614f1b3e8SDimitry Andric ") creating memory register context",
30714f1b3e8SDimitry Andric thread->GetID(), thread->GetProtocolID(), reg_data_addr);
3085f29bb8aSDimitry Andric reg_ctx_sp = std::make_shared<RegisterContextMemory>(
3095f29bb8aSDimitry Andric *thread, 0, *GetDynamicRegisterInfo(), reg_data_addr);
31014f1b3e8SDimitry Andric } else {
311f73363f1SDimitry Andric // No register data address is provided, query the python plug-in to let it
312f73363f1SDimitry Andric // make up the data as it sees fit
313ead24645SDimitry Andric LLDB_LOGF(log,
314ead24645SDimitry Andric "OperatingSystemPython::CreateRegisterContextForThread (tid "
31514f1b3e8SDimitry Andric "= 0x%" PRIx64 ", 0x%" PRIx64
31614f1b3e8SDimitry Andric ") fetching register data from python",
31714f1b3e8SDimitry Andric thread->GetID(), thread->GetProtocolID());
318f034231aSEd Maste
319b1c73532SDimitry Andric std::optional<std::string> reg_context_data =
320b1c73532SDimitry Andric m_operating_system_interface_sp->GetRegisterContextForTID(
32114f1b3e8SDimitry Andric thread->GetID());
32214f1b3e8SDimitry Andric if (reg_context_data) {
323b1c73532SDimitry Andric std::string value = *reg_context_data;
3245e95aa85SEd Maste DataBufferSP data_sp(new DataBufferHeap(value.c_str(), value.length()));
32514f1b3e8SDimitry Andric if (data_sp->GetByteSize()) {
32614f1b3e8SDimitry Andric RegisterContextMemory *reg_ctx_memory = new RegisterContextMemory(
32714f1b3e8SDimitry Andric *thread, 0, *GetDynamicRegisterInfo(), LLDB_INVALID_ADDRESS);
32814f1b3e8SDimitry Andric if (reg_ctx_memory) {
329f034231aSEd Maste reg_ctx_sp.reset(reg_ctx_memory);
330f034231aSEd Maste reg_ctx_memory->SetAllRegisterData(data_sp);
331f034231aSEd Maste }
332f034231aSEd Maste }
333f034231aSEd Maste }
334f034231aSEd Maste }
33514f1b3e8SDimitry Andric // if we still have no register data, fallback on a dummy context to avoid
33614f1b3e8SDimitry Andric // crashing
33714f1b3e8SDimitry Andric if (!reg_ctx_sp) {
338ead24645SDimitry Andric LLDB_LOGF(log,
339ead24645SDimitry Andric "OperatingSystemPython::CreateRegisterContextForThread (tid "
34014f1b3e8SDimitry Andric "= 0x%" PRIx64 ") forcing a dummy register context",
34114f1b3e8SDimitry Andric thread->GetID());
342b1c73532SDimitry Andric Target &target = m_process->GetTarget();
3435f29bb8aSDimitry Andric reg_ctx_sp = std::make_shared<RegisterContextDummy>(
3445f29bb8aSDimitry Andric *thread, 0, target.GetArchitecture().GetAddressByteSize());
345f034231aSEd Maste }
346f034231aSEd Maste return reg_ctx_sp;
347f034231aSEd Maste }
348f034231aSEd Maste
349f034231aSEd Maste StopInfoSP
CreateThreadStopReason(lldb_private::Thread * thread)35014f1b3e8SDimitry Andric OperatingSystemPython::CreateThreadStopReason(lldb_private::Thread *thread) {
351f034231aSEd Maste // We should have gotten the thread stop info from the dictionary of data for
352f034231aSEd Maste // the thread in the initial call to get_thread_info(), this should have been
353f034231aSEd Maste // cached so we can return it here
35414f1b3e8SDimitry Andric StopInfoSP
35514f1b3e8SDimitry Andric stop_info_sp; //(StopInfo::CreateStopReasonWithSignal (*thread, SIGSTOP));
356f034231aSEd Maste return stop_info_sp;
357f034231aSEd Maste }
358f034231aSEd Maste
CreateThread(lldb::tid_t tid,addr_t context)35914f1b3e8SDimitry Andric lldb::ThreadSP OperatingSystemPython::CreateThread(lldb::tid_t tid,
36014f1b3e8SDimitry Andric addr_t context) {
361145449b1SDimitry Andric Log *log = GetLog(LLDBLog::Thread);
362f034231aSEd Maste
363ead24645SDimitry Andric LLDB_LOGF(log,
364ead24645SDimitry Andric "OperatingSystemPython::CreateThread (tid = 0x%" PRIx64
36514f1b3e8SDimitry Andric ", context = 0x%" PRIx64 ") fetching register data from python",
36614f1b3e8SDimitry Andric tid, context);
367f034231aSEd Maste
368b1c73532SDimitry Andric if (m_interpreter && m_script_object_sp) {
369f034231aSEd Maste
37014f1b3e8SDimitry Andric StructuredData::DictionarySP thread_info_dict =
371b1c73532SDimitry Andric m_operating_system_interface_sp->CreateThread(tid, context);
372b1c73532SDimitry Andric
373866dcdacSEd Maste std::vector<bool> core_used_map;
37414f1b3e8SDimitry Andric if (thread_info_dict) {
375ac9a064cSDimitry Andric ThreadList core_threads(*m_process);
376f034231aSEd Maste ThreadList &thread_list = m_process->GetThreadList();
377f034231aSEd Maste bool did_create = false;
37814f1b3e8SDimitry Andric ThreadSP thread_sp(
37914f1b3e8SDimitry Andric CreateThreadFromThreadInfo(*thread_info_dict, core_threads,
38014f1b3e8SDimitry Andric thread_list, core_used_map, &did_create));
381f034231aSEd Maste if (did_create)
382f034231aSEd Maste thread_list.AddThread(thread_sp);
383f034231aSEd Maste return thread_sp;
384f034231aSEd Maste }
385f034231aSEd Maste }
386f034231aSEd Maste return ThreadSP();
387f034231aSEd Maste }
388f034231aSEd Maste
389706b4fc4SDimitry Andric #endif // #if LLDB_ENABLE_PYTHON
390