diff options
author | dim <dim@FreeBSD.org> | 2017-04-02 17:24:58 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2017-04-02 17:24:58 +0000 |
commit | 60b571e49a90d38697b3aca23020d9da42fc7d7f (patch) | |
tree | 99351324c24d6cb146b6285b6caffa4d26fce188 /contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python | |
parent | bea1b22c7a9bce1dfdd73e6e5b65bc4752215180 (diff) | |
download | FreeBSD-src-60b571e49a90d38697b3aca23020d9da42fc7d7f.zip FreeBSD-src-60b571e49a90d38697b3aca23020d9da42fc7d7f.tar.gz |
Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release:
MFC r309142 (by emaste):
Add WITH_LLD_AS_LD build knob
If set it installs LLD as /usr/bin/ld. LLD (as of version 3.9) is not
capable of linking the world and kernel, but can self-host and link many
substantial applications. GNU ld continues to be used for the world and
kernel build, regardless of how this knob is set.
It is on by default for arm64, and off for all other CPU architectures.
Sponsored by: The FreeBSD Foundation
MFC r310840:
Reapply 310775, now it also builds correctly if lldb is disabled:
Move llvm-objdump from CLANG_EXTRAS to installed by default
We currently install three tools from binutils 2.17.50: as, ld, and
objdump. Work is underway to migrate to a permissively-licensed
tool-chain, with one goal being the retirement of binutils 2.17.50.
LLVM's llvm-objdump is intended to be compatible with GNU objdump
although it is currently missing some options and may have formatting
differences. Enable it by default for testing and further investigation.
It may later be changed to install as /usr/bin/objdump, it becomes a
fully viable replacement.
Reviewed by: emaste
Differential Revision: https://reviews.freebsd.org/D8879
MFC r312855 (by emaste):
Rename LLD_AS_LD to LLD_IS_LD, for consistency with CLANG_IS_CC
Reported by: Dan McGregor <dan.mcgregor usask.ca>
MFC r313559 | glebius | 2017-02-10 18:34:48 +0100 (Fri, 10 Feb 2017) | 5 lines
Don't check struct rtentry on FreeBSD, it is an internal kernel structure.
On other systems it may be API structure for SIOCADDRT/SIOCDELRT.
Reviewed by: emaste, dim
MFC r314152 (by jkim):
Remove an assembler flag, which is redundant since r309124. The upstream
took care of it by introducing a macro NO_EXEC_STACK_DIRECTIVE.
http://llvm.org/viewvc/llvm-project?rev=273500&view=rev
Reviewed by: dim
MFC r314564:
Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to
4.0.0 (branches/release_40 296509). The release will follow soon.
Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.
Also note that as of 4.0.0, lld should be able to link the base system
on amd64 and aarch64. See the WITH_LLD_IS_LLD setting in src.conf(5).
Though please be aware that this is work in progress.
Release notes for llvm, clang and lld will be available here:
<http://releases.llvm.org/4.0.0/docs/ReleaseNotes.html>
<http://releases.llvm.org/4.0.0/tools/clang/docs/ReleaseNotes.html>
<http://releases.llvm.org/4.0.0/tools/lld/docs/ReleaseNotes.html>
Thanks to Ed Maste, Jan Beich, Antoine Brodin and Eric Fiselier for
their help.
Relnotes: yes
Exp-run: antoine
PR: 215969, 216008
MFC r314708:
For now, revert r287232 from upstream llvm trunk (by Daniil Fukalov):
[SCEV] limit recursion depth of CompareSCEVComplexity
Summary:
CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled
loop) and runs almost infinite time.
Added cache of "equal" SCEV pairs to earlier cutoff of further
estimation. Recursion depth limit was also introduced as a parameter.
Reviewers: sanjoy
Subscribers: mzolotukhin, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D26389
This commit is the cause of excessive compile times on skein_block.c
(and possibly other files) during kernel builds on amd64.
We never saw the problematic behavior described in this upstream commit,
so for now it is better to revert it. An upstream bug has been filed
here: https://bugs.llvm.org/show_bug.cgi?id=32142
Reported by: mjg
MFC r314795:
Reapply r287232 from upstream llvm trunk (by Daniil Fukalov):
[SCEV] limit recursion depth of CompareSCEVComplexity
Summary:
CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled
loop) and runs almost infinite time.
Added cache of "equal" SCEV pairs to earlier cutoff of further
estimation. Recursion depth limit was also introduced as a parameter.
Reviewers: sanjoy
Subscribers: mzolotukhin, tstellarAMD, llvm-commits
Differential Revision: https://reviews.llvm.org/D26389
Pull in r296992 from upstream llvm trunk (by Sanjoy Das):
[SCEV] Decrease the recursion threshold for CompareValueComplexity
Fixes PR32142.
r287232 accidentally increased the recursion threshold for
CompareValueComplexity from 2 to 32. This change reverses that
change by introducing a separate flag for CompareValueComplexity's
threshold.
The latter revision fixes the excessive compile times for skein_block.c.
MFC r314907 | mmel | 2017-03-08 12:40:27 +0100 (Wed, 08 Mar 2017) | 7 lines
Unbreak ARMv6 world.
The new compiler_rt library imported with clang 4.0.0 have several fatal
issues (non-functional __udivsi3 for example) with ARM specific instrict
functions. As temporary workaround, until upstream solve these problems,
disable all thumb[1][2] related feature.
MFC r315016:
Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release.
We were already very close to the last release candidate, so this is a
pretty minor update.
Relnotes: yes
MFC r316005:
Revert r314907, and pull in r298713 from upstream compiler-rt trunk (by
Weiming Zhao):
builtins: Select correct code fragments when compiling for Thumb1/Thum2/ARM ISA.
Summary:
Value of __ARM_ARCH_ISA_THUMB isn't based on the actual compilation
mode (-mthumb, -marm), it reflect's capability of given CPU.
Due to this:
- use __tbumb__ and __thumb2__ insteand of __ARM_ARCH_ISA_THUMB
- use '.thumb' directive consistently in all affected files
- decorate all thumb functions using
DEFINE_COMPILERRT_THUMB_FUNCTION()
---------
Note: This patch doesn't fix broken Thumb1 variant of __udivsi3 !
Reviewers: weimingz, rengolin, compnerd
Subscribers: aemerson, dim
Differential Revision: https://reviews.llvm.org/D30938
Discussed with: mmel
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python')
-rw-r--r-- | contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp | 678 | ||||
-rw-r--r-- | contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h | 139 |
2 files changed, 400 insertions, 417 deletions
diff --git a/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp b/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp index dfb631e..69826a0 100644 --- a/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp +++ b/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp @@ -1,4 +1,4 @@ -//===-- OperatingSystemPython.cpp --------------------------------*- C++ -*-===// +//===-- OperatingSystemPython.cpp --------------------------------*- C++-*-===// // // The LLVM Compiler Infrastructure // @@ -13,6 +13,10 @@ // C Includes // C++ Includes // Other libraries and framework includes +#include "Plugins/Process/Utility/DynamicRegisterInfo.h" +#include "Plugins/Process/Utility/RegisterContextDummy.h" +#include "Plugins/Process/Utility/RegisterContextMemory.h" +#include "Plugins/Process/Utility/ThreadMemory.h" #include "lldb/Core/ArchSpec.h" #include "lldb/Core/DataBufferHeap.h" #include "lldb/Core/Debugger.h" @@ -29,395 +33,385 @@ #include "lldb/Target/Process.h" #include "lldb/Target/StopInfo.h" #include "lldb/Target/Target.h" -#include "lldb/Target/ThreadList.h" #include "lldb/Target/Thread.h" -#include "Plugins/Process/Utility/DynamicRegisterInfo.h" -#include "Plugins/Process/Utility/RegisterContextDummy.h" -#include "Plugins/Process/Utility/RegisterContextMemory.h" -#include "Plugins/Process/Utility/ThreadMemory.h" +#include "lldb/Target/ThreadList.h" using namespace lldb; using namespace lldb_private; -void -OperatingSystemPython::Initialize() -{ - PluginManager::RegisterPlugin(GetPluginNameStatic(), GetPluginDescriptionStatic(), CreateInstance, nullptr); +void OperatingSystemPython::Initialize() { + PluginManager::RegisterPlugin(GetPluginNameStatic(), + GetPluginDescriptionStatic(), CreateInstance, + nullptr); } -void -OperatingSystemPython::Terminate() -{ - PluginManager::UnregisterPlugin (CreateInstance); +void OperatingSystemPython::Terminate() { + PluginManager::UnregisterPlugin(CreateInstance); } -OperatingSystem * -OperatingSystemPython::CreateInstance (Process *process, bool force) -{ - // Python OperatingSystem plug-ins must be requested by name, so force must be true - FileSpec python_os_plugin_spec (process->GetPythonOSPluginPath()); - if (python_os_plugin_spec && python_os_plugin_spec.Exists()) - { - std::unique_ptr<OperatingSystemPython> os_ap (new OperatingSystemPython (process, python_os_plugin_spec)); - if (os_ap.get() && os_ap->IsValid()) - return os_ap.release(); - } - return NULL; +OperatingSystem *OperatingSystemPython::CreateInstance(Process *process, + bool force) { + // Python OperatingSystem plug-ins must be requested by name, so force must be + // true + FileSpec python_os_plugin_spec(process->GetPythonOSPluginPath()); + if (python_os_plugin_spec && python_os_plugin_spec.Exists()) { + std::unique_ptr<OperatingSystemPython> os_ap( + new OperatingSystemPython(process, python_os_plugin_spec)); + if (os_ap.get() && os_ap->IsValid()) + return os_ap.release(); + } + return NULL; } - -ConstString -OperatingSystemPython::GetPluginNameStatic() -{ - static ConstString g_name("python"); - return g_name; +ConstString OperatingSystemPython::GetPluginNameStatic() { + static ConstString g_name("python"); + return g_name; } -const char * -OperatingSystemPython::GetPluginDescriptionStatic() -{ - return "Operating system plug-in that gathers OS information from a python class that implements the necessary OperatingSystem functionality."; +const char *OperatingSystemPython::GetPluginDescriptionStatic() { + return "Operating system plug-in that gathers OS information from a python " + "class that implements the necessary OperatingSystem functionality."; } - -OperatingSystemPython::OperatingSystemPython (lldb_private::Process *process, const FileSpec &python_module_path) : - OperatingSystem (process), - m_thread_list_valobj_sp (), - m_register_info_ap (), - m_interpreter (NULL), - m_python_object_sp () -{ - if (!process) - return; - TargetSP target_sp = process->CalculateTarget(); - if (!target_sp) - return; - m_interpreter = target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); - if (m_interpreter) - { - - std::string os_plugin_class_name (python_module_path.GetFilename().AsCString("")); - if (!os_plugin_class_name.empty()) - { - const bool init_session = false; - const bool allow_reload = true; - char python_module_path_cstr[PATH_MAX]; - python_module_path.GetPath(python_module_path_cstr, sizeof(python_module_path_cstr)); - Error error; - if (m_interpreter->LoadScriptingModule (python_module_path_cstr, allow_reload, init_session, error)) - { - // Strip the ".py" extension if there is one - size_t py_extension_pos = os_plugin_class_name.rfind(".py"); - if (py_extension_pos != std::string::npos) - os_plugin_class_name.erase (py_extension_pos); - // Add ".OperatingSystemPlugIn" to the module name to get a string like "modulename.OperatingSystemPlugIn" - os_plugin_class_name += ".OperatingSystemPlugIn"; - StructuredData::ObjectSP object_sp = - m_interpreter->OSPlugin_CreatePluginObject(os_plugin_class_name.c_str(), process->CalculateProcess()); - if (object_sp && object_sp->IsValid()) - m_python_object_sp = object_sp; - } - } +OperatingSystemPython::OperatingSystemPython(lldb_private::Process *process, + const FileSpec &python_module_path) + : OperatingSystem(process), m_thread_list_valobj_sp(), m_register_info_ap(), + m_interpreter(NULL), m_python_object_sp() { + if (!process) + return; + TargetSP target_sp = process->CalculateTarget(); + if (!target_sp) + return; + m_interpreter = + target_sp->GetDebugger().GetCommandInterpreter().GetScriptInterpreter(); + if (m_interpreter) { + + std::string os_plugin_class_name( + python_module_path.GetFilename().AsCString("")); + if (!os_plugin_class_name.empty()) { + const bool init_session = false; + const bool allow_reload = true; + char python_module_path_cstr[PATH_MAX]; + python_module_path.GetPath(python_module_path_cstr, + sizeof(python_module_path_cstr)); + Error error; + if (m_interpreter->LoadScriptingModule( + python_module_path_cstr, allow_reload, init_session, error)) { + // Strip the ".py" extension if there is one + size_t py_extension_pos = os_plugin_class_name.rfind(".py"); + if (py_extension_pos != std::string::npos) + os_plugin_class_name.erase(py_extension_pos); + // Add ".OperatingSystemPlugIn" to the module name to get a string like + // "modulename.OperatingSystemPlugIn" + os_plugin_class_name += ".OperatingSystemPlugIn"; + StructuredData::ObjectSP object_sp = + m_interpreter->OSPlugin_CreatePluginObject( + os_plugin_class_name.c_str(), process->CalculateProcess()); + if (object_sp && object_sp->IsValid()) + m_python_object_sp = object_sp; + } } + } } -OperatingSystemPython::~OperatingSystemPython () -{ -} +OperatingSystemPython::~OperatingSystemPython() {} -DynamicRegisterInfo * -OperatingSystemPython::GetDynamicRegisterInfo () -{ - if (m_register_info_ap.get() == NULL) - { - if (!m_interpreter || !m_python_object_sp) - return NULL; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OS)); - - if (log) - log->Printf ("OperatingSystemPython::GetDynamicRegisterInfo() fetching thread register definitions from python for pid %" PRIu64, m_process->GetID()); - - StructuredData::DictionarySP dictionary = m_interpreter->OSPlugin_RegisterInfo(m_python_object_sp); - if (!dictionary) - return NULL; - - m_register_info_ap.reset(new DynamicRegisterInfo(*dictionary, m_process->GetTarget().GetArchitecture())); - assert (m_register_info_ap->GetNumRegisters() > 0); - assert (m_register_info_ap->GetNumRegisterSets() > 0); - } - return m_register_info_ap.get(); +DynamicRegisterInfo *OperatingSystemPython::GetDynamicRegisterInfo() { + if (m_register_info_ap.get() == NULL) { + if (!m_interpreter || !m_python_object_sp) + return NULL; + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS)); + + if (log) + log->Printf("OperatingSystemPython::GetDynamicRegisterInfo() fetching " + "thread register definitions from python for pid %" PRIu64, + m_process->GetID()); + + StructuredData::DictionarySP dictionary = + m_interpreter->OSPlugin_RegisterInfo(m_python_object_sp); + if (!dictionary) + return NULL; + + m_register_info_ap.reset(new DynamicRegisterInfo( + *dictionary, m_process->GetTarget().GetArchitecture())); + assert(m_register_info_ap->GetNumRegisters() > 0); + assert(m_register_info_ap->GetNumRegisterSets() > 0); + } + return m_register_info_ap.get(); } //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ -ConstString -OperatingSystemPython::GetPluginName() -{ - return GetPluginNameStatic(); +ConstString OperatingSystemPython::GetPluginName() { + return GetPluginNameStatic(); } -uint32_t -OperatingSystemPython::GetPluginVersion() -{ - return 1; -} - -bool -OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list, - ThreadList &core_thread_list, - ThreadList &new_thread_list) -{ - if (!m_interpreter || !m_python_object_sp) - return false; - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OS)); - - // First thing we have to do is to try to get the API lock, and the run lock. - // We're going to change the thread content of the process, and we're going - // to use python, which requires the API lock to do it. - // - // If someone already has the API lock, that is ok, we just want to avoid - // external code from making new API calls while this call is happening. - // - // This is a recursive lock so we can grant it to any Python code called on - // the stack below us. - Target &target = m_process->GetTarget(); - std::unique_lock<std::recursive_mutex> lock(target.GetAPIMutex(), std::defer_lock); - lock.try_lock(); - - if (log) - log->Printf ("OperatingSystemPython::UpdateThreadList() fetching thread data from python for pid %" PRIu64, m_process->GetID()); - - // The threads that are in "new_thread_list" upon entry are the threads from the - // lldb_private::Process subclass, no memory threads will be in this list. - - auto interpreter_lock = m_interpreter->AcquireInterpreterLock(); // to make sure threads_list stays alive - StructuredData::ArraySP threads_list = m_interpreter->OSPlugin_ThreadsInfo(m_python_object_sp); - - const uint32_t num_cores = core_thread_list.GetSize(false); - - // Make a map so we can keep track of which cores were used from the - // core_thread list. Any real threads/cores that weren't used should - // later be put back into the "new_thread_list". - std::vector<bool> core_used_map(num_cores, false); - if (threads_list) - { - if (log) - { - StreamString strm; - threads_list->Dump(strm); - log->Printf("threads_list = %s", strm.GetString().c_str()); - } - - const uint32_t num_threads = threads_list->GetSize(); - for (uint32_t i = 0; i < num_threads; ++i) - { - StructuredData::ObjectSP thread_dict_obj = threads_list->GetItemAtIndex(i); - if (auto thread_dict = thread_dict_obj->GetAsDictionary()) - { - ThreadSP thread_sp(CreateThreadFromThreadInfo(*thread_dict, core_thread_list, old_thread_list, core_used_map, NULL)); - if (thread_sp) - new_thread_list.AddThread(thread_sp); - } - } +uint32_t OperatingSystemPython::GetPluginVersion() { return 1; } + +bool OperatingSystemPython::UpdateThreadList(ThreadList &old_thread_list, + ThreadList &core_thread_list, + ThreadList &new_thread_list) { + if (!m_interpreter || !m_python_object_sp) + return false; + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OS)); + + // First thing we have to do is to try to get the API lock, and the run lock. + // We're going to change the thread content of the process, and we're going + // to use python, which requires the API lock to do it. + // + // If someone already has the API lock, that is ok, we just want to avoid + // external code from making new API calls while this call is happening. + // + // This is a recursive lock so we can grant it to any Python code called on + // the stack below us. + Target &target = m_process->GetTarget(); + std::unique_lock<std::recursive_mutex> lock(target.GetAPIMutex(), + std::defer_lock); + lock.try_lock(); + + if (log) + log->Printf("OperatingSystemPython::UpdateThreadList() fetching thread " + "data from python for pid %" PRIu64, + m_process->GetID()); + + // The threads that are in "new_thread_list" upon entry are the threads from + // the + // lldb_private::Process subclass, no memory threads will be in this list. + + auto interpreter_lock = + m_interpreter + ->AcquireInterpreterLock(); // to make sure threads_list stays alive + StructuredData::ArraySP threads_list = + m_interpreter->OSPlugin_ThreadsInfo(m_python_object_sp); + + const uint32_t num_cores = core_thread_list.GetSize(false); + + // Make a map so we can keep track of which cores were used from the + // core_thread list. Any real threads/cores that weren't used should + // later be put back into the "new_thread_list". + std::vector<bool> core_used_map(num_cores, false); + if (threads_list) { + if (log) { + StreamString strm; + threads_list->Dump(strm); + log->Printf("threads_list = %s", strm.GetData()); } - // Any real core threads that didn't end up backing a memory thread should - // still be in the main thread list, and they should be inserted at the beginning - // of the list - uint32_t insert_idx = 0; - for (uint32_t core_idx = 0; core_idx < num_cores; ++core_idx) - { - if (core_used_map[core_idx] == false) - { - new_thread_list.InsertThread (core_thread_list.GetThreadAtIndex(core_idx, false), insert_idx); - ++insert_idx; - } + const uint32_t num_threads = threads_list->GetSize(); + for (uint32_t i = 0; i < num_threads; ++i) { + StructuredData::ObjectSP thread_dict_obj = + threads_list->GetItemAtIndex(i); + if (auto thread_dict = thread_dict_obj->GetAsDictionary()) { + ThreadSP thread_sp( + CreateThreadFromThreadInfo(*thread_dict, core_thread_list, + old_thread_list, core_used_map, NULL)); + if (thread_sp) + new_thread_list.AddThread(thread_sp); + } } + } + + // Any real core threads that didn't end up backing a memory thread should + // still be in the main thread list, and they should be inserted at the + // beginning + // of the list + uint32_t insert_idx = 0; + for (uint32_t core_idx = 0; core_idx < num_cores; ++core_idx) { + if (core_used_map[core_idx] == false) { + new_thread_list.InsertThread( + core_thread_list.GetThreadAtIndex(core_idx, false), insert_idx); + ++insert_idx; + } + } - return new_thread_list.GetSize(false) > 0; + return new_thread_list.GetSize(false) > 0; } -ThreadSP -OperatingSystemPython::CreateThreadFromThreadInfo(StructuredData::Dictionary &thread_dict, ThreadList &core_thread_list, - ThreadList &old_thread_list, std::vector<bool> &core_used_map, bool *did_create_ptr) -{ - ThreadSP thread_sp; - tid_t tid = LLDB_INVALID_THREAD_ID; - if (!thread_dict.GetValueForKeyAsInteger("tid", tid)) - return ThreadSP(); - - uint32_t core_number; - addr_t reg_data_addr; - std::string name; - std::string queue; - - thread_dict.GetValueForKeyAsInteger("core", core_number, UINT32_MAX); - thread_dict.GetValueForKeyAsInteger("register_data_addr", reg_data_addr, LLDB_INVALID_ADDRESS); - thread_dict.GetValueForKeyAsString("name", name); - thread_dict.GetValueForKeyAsString("queue", queue); - - // See if a thread already exists for "tid" - thread_sp = old_thread_list.FindThreadByID(tid, false); - if (thread_sp) - { - // A thread already does exist for "tid", make sure it was an operating system - // plug-in generated thread. - if (!IsOperatingSystemPluginThread(thread_sp)) - { - // We have thread ID overlap between the protocol threads and the - // operating system threads, clear the thread so we create an - // operating system thread for this. - thread_sp.reset(); - } - } +ThreadSP OperatingSystemPython::CreateThreadFromThreadInfo( + StructuredData::Dictionary &thread_dict, ThreadList &core_thread_list, + ThreadList &old_thread_list, std::vector<bool> &core_used_map, + bool *did_create_ptr) { + ThreadSP thread_sp; + tid_t tid = LLDB_INVALID_THREAD_ID; + if (!thread_dict.GetValueForKeyAsInteger("tid", tid)) + return ThreadSP(); - if (!thread_sp) - { - if (did_create_ptr) - *did_create_ptr = true; - thread_sp.reset(new ThreadMemory(*m_process, tid, name.c_str(), queue.c_str(), reg_data_addr)); + uint32_t core_number; + addr_t reg_data_addr; + std::string name; + std::string queue; + + thread_dict.GetValueForKeyAsInteger("core", core_number, UINT32_MAX); + thread_dict.GetValueForKeyAsInteger("register_data_addr", reg_data_addr, + LLDB_INVALID_ADDRESS); + thread_dict.GetValueForKeyAsString("name", name); + thread_dict.GetValueForKeyAsString("queue", queue); + + // See if a thread already exists for "tid" + thread_sp = old_thread_list.FindThreadByID(tid, false); + if (thread_sp) { + // A thread already does exist for "tid", make sure it was an operating + // system + // plug-in generated thread. + if (!IsOperatingSystemPluginThread(thread_sp)) { + // We have thread ID overlap between the protocol threads and the + // operating system threads, clear the thread so we create an + // operating system thread for this. + thread_sp.reset(); } - - if (core_number < core_thread_list.GetSize(false)) - { - ThreadSP core_thread_sp(core_thread_list.GetThreadAtIndex(core_number, false)); - if (core_thread_sp) - { - // Keep track of which cores were set as the backing thread for memory threads... - if (core_number < core_used_map.size()) - core_used_map[core_number] = true; - - ThreadSP backing_core_thread_sp(core_thread_sp->GetBackingThread()); - if (backing_core_thread_sp) - { - thread_sp->SetBackingThread(backing_core_thread_sp); - } - else - { - thread_sp->SetBackingThread(core_thread_sp); - } - } + } + + if (!thread_sp) { + if (did_create_ptr) + *did_create_ptr = true; + thread_sp.reset(new ThreadMemory(*m_process, tid, name.c_str(), + queue.c_str(), reg_data_addr)); + } + + if (core_number < core_thread_list.GetSize(false)) { + ThreadSP core_thread_sp( + core_thread_list.GetThreadAtIndex(core_number, false)); + if (core_thread_sp) { + // Keep track of which cores were set as the backing thread for memory + // threads... + if (core_number < core_used_map.size()) + core_used_map[core_number] = true; + + ThreadSP backing_core_thread_sp(core_thread_sp->GetBackingThread()); + if (backing_core_thread_sp) { + thread_sp->SetBackingThread(backing_core_thread_sp); + } else { + thread_sp->SetBackingThread(core_thread_sp); + } } - return thread_sp; + } + return thread_sp; } - - -void -OperatingSystemPython::ThreadWasSelected (Thread *thread) -{ -} +void OperatingSystemPython::ThreadWasSelected(Thread *thread) {} RegisterContextSP -OperatingSystemPython::CreateRegisterContextForThread (Thread *thread, addr_t reg_data_addr) -{ - RegisterContextSP reg_ctx_sp; - if (!m_interpreter || !m_python_object_sp || !thread) - return reg_ctx_sp; - - if (!IsOperatingSystemPluginThread(thread->shared_from_this())) - return reg_ctx_sp; - - // First thing we have to do is get the API lock, and the run lock. We're going to change the thread - // content of the process, and we're going to use python, which requires the API lock to do it. - // So get & hold that. This is a recursive lock so we can grant it to any Python code called on the stack below us. - Target &target = m_process->GetTarget(); - std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex()); +OperatingSystemPython::CreateRegisterContextForThread(Thread *thread, + addr_t reg_data_addr) { + RegisterContextSP reg_ctx_sp; + if (!m_interpreter || !m_python_object_sp || !thread) + return reg_ctx_sp; - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); - - auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure python objects stays alive - if (reg_data_addr != LLDB_INVALID_ADDRESS) - { - // The registers data is in contiguous memory, just create the register - // context using the address provided - if (log) - log->Printf ("OperatingSystemPython::CreateRegisterContextForThread (tid = 0x%" PRIx64 ", 0x%" PRIx64 ", reg_data_addr = 0x%" PRIx64 ") creating memory register context", - thread->GetID(), - thread->GetProtocolID(), - reg_data_addr); - reg_ctx_sp.reset (new RegisterContextMemory (*thread, 0, *GetDynamicRegisterInfo (), reg_data_addr)); - } - else - { - // No register data address is provided, query the python plug-in to let - // it make up the data as it sees fit - if (log) - log->Printf ("OperatingSystemPython::CreateRegisterContextForThread (tid = 0x%" PRIx64 ", 0x%" PRIx64 ") fetching register data from python", - thread->GetID(), - thread->GetProtocolID()); - - StructuredData::StringSP reg_context_data = m_interpreter->OSPlugin_RegisterContextData(m_python_object_sp, thread->GetID()); - if (reg_context_data) - { - std::string value = reg_context_data->GetValue(); - DataBufferSP data_sp(new DataBufferHeap(value.c_str(), value.length())); - if (data_sp->GetByteSize()) - { - RegisterContextMemory *reg_ctx_memory = new RegisterContextMemory (*thread, 0, *GetDynamicRegisterInfo (), LLDB_INVALID_ADDRESS); - if (reg_ctx_memory) - { - reg_ctx_sp.reset(reg_ctx_memory); - reg_ctx_memory->SetAllRegisterData (data_sp); - } - } + if (!IsOperatingSystemPluginThread(thread->shared_from_this())) + return reg_ctx_sp; + + // First thing we have to do is get the API lock, and the run lock. We're + // going to change the thread + // content of the process, and we're going to use python, which requires the + // API lock to do it. + // So get & hold that. This is a recursive lock so we can grant it to any + // Python code called on the stack below us. + Target &target = m_process->GetTarget(); + std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex()); + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); + + auto lock = + m_interpreter + ->AcquireInterpreterLock(); // to make sure python objects stays alive + if (reg_data_addr != LLDB_INVALID_ADDRESS) { + // The registers data is in contiguous memory, just create the register + // context using the address provided + if (log) + log->Printf("OperatingSystemPython::CreateRegisterContextForThread (tid " + "= 0x%" PRIx64 ", 0x%" PRIx64 ", reg_data_addr = 0x%" PRIx64 + ") creating memory register context", + thread->GetID(), thread->GetProtocolID(), reg_data_addr); + reg_ctx_sp.reset(new RegisterContextMemory( + *thread, 0, *GetDynamicRegisterInfo(), reg_data_addr)); + } else { + // No register data address is provided, query the python plug-in to let + // it make up the data as it sees fit + if (log) + log->Printf("OperatingSystemPython::CreateRegisterContextForThread (tid " + "= 0x%" PRIx64 ", 0x%" PRIx64 + ") fetching register data from python", + thread->GetID(), thread->GetProtocolID()); + + StructuredData::StringSP reg_context_data = + m_interpreter->OSPlugin_RegisterContextData(m_python_object_sp, + thread->GetID()); + if (reg_context_data) { + std::string value = reg_context_data->GetValue(); + DataBufferSP data_sp(new DataBufferHeap(value.c_str(), value.length())); + if (data_sp->GetByteSize()) { + RegisterContextMemory *reg_ctx_memory = new RegisterContextMemory( + *thread, 0, *GetDynamicRegisterInfo(), LLDB_INVALID_ADDRESS); + if (reg_ctx_memory) { + reg_ctx_sp.reset(reg_ctx_memory); + reg_ctx_memory->SetAllRegisterData(data_sp); } + } } - // if we still have no register data, fallback on a dummy context to avoid crashing - if (!reg_ctx_sp) - { - if (log) - log->Printf ("OperatingSystemPython::CreateRegisterContextForThread (tid = 0x%" PRIx64 ") forcing a dummy register context", thread->GetID()); - reg_ctx_sp.reset(new RegisterContextDummy(*thread,0,target.GetArchitecture().GetAddressByteSize())); - } - return reg_ctx_sp; + } + // if we still have no register data, fallback on a dummy context to avoid + // crashing + if (!reg_ctx_sp) { + if (log) + log->Printf("OperatingSystemPython::CreateRegisterContextForThread (tid " + "= 0x%" PRIx64 ") forcing a dummy register context", + thread->GetID()); + reg_ctx_sp.reset(new RegisterContextDummy( + *thread, 0, target.GetArchitecture().GetAddressByteSize())); + } + return reg_ctx_sp; } StopInfoSP -OperatingSystemPython::CreateThreadStopReason (lldb_private::Thread *thread) -{ - // We should have gotten the thread stop info from the dictionary of data for - // the thread in the initial call to get_thread_info(), this should have been - // cached so we can return it here - StopInfoSP stop_info_sp; //(StopInfo::CreateStopReasonWithSignal (*thread, SIGSTOP)); - return stop_info_sp; +OperatingSystemPython::CreateThreadStopReason(lldb_private::Thread *thread) { + // We should have gotten the thread stop info from the dictionary of data for + // the thread in the initial call to get_thread_info(), this should have been + // cached so we can return it here + StopInfoSP + stop_info_sp; //(StopInfo::CreateStopReasonWithSignal (*thread, SIGSTOP)); + return stop_info_sp; } -lldb::ThreadSP -OperatingSystemPython::CreateThread (lldb::tid_t tid, addr_t context) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD)); - - if (log) - log->Printf ("OperatingSystemPython::CreateThread (tid = 0x%" PRIx64 ", context = 0x%" PRIx64 ") fetching register data from python", tid, context); - - if (m_interpreter && m_python_object_sp) - { - // First thing we have to do is get the API lock, and the run lock. We're going to change the thread - // content of the process, and we're going to use python, which requires the API lock to do it. - // So get & hold that. This is a recursive lock so we can grant it to any Python code called on the stack below us. - Target &target = m_process->GetTarget(); - std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex()); - - auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure thread_info_dict stays alive - StructuredData::DictionarySP thread_info_dict = m_interpreter->OSPlugin_CreateThread(m_python_object_sp, tid, context); - std::vector<bool> core_used_map; - if (thread_info_dict) - { - ThreadList core_threads(m_process); - ThreadList &thread_list = m_process->GetThreadList(); - bool did_create = false; - ThreadSP thread_sp(CreateThreadFromThreadInfo(*thread_info_dict, core_threads, thread_list, core_used_map, &did_create)); - if (did_create) - thread_list.AddThread(thread_sp); - return thread_sp; - } +lldb::ThreadSP OperatingSystemPython::CreateThread(lldb::tid_t tid, + addr_t context) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); + + if (log) + log->Printf("OperatingSystemPython::CreateThread (tid = 0x%" PRIx64 + ", context = 0x%" PRIx64 ") fetching register data from python", + tid, context); + + if (m_interpreter && m_python_object_sp) { + // First thing we have to do is get the API lock, and the run lock. We're + // going to change the thread + // content of the process, and we're going to use python, which requires the + // API lock to do it. + // So get & hold that. This is a recursive lock so we can grant it to any + // Python code called on the stack below us. + Target &target = m_process->GetTarget(); + std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex()); + + auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure + // thread_info_dict + // stays alive + StructuredData::DictionarySP thread_info_dict = + m_interpreter->OSPlugin_CreateThread(m_python_object_sp, tid, context); + std::vector<bool> core_used_map; + if (thread_info_dict) { + ThreadList core_threads(m_process); + ThreadList &thread_list = m_process->GetThreadList(); + bool did_create = false; + ThreadSP thread_sp( + CreateThreadFromThreadInfo(*thread_info_dict, core_threads, + thread_list, core_used_map, &did_create)); + if (did_create) + thread_list.AddThread(thread_sp); + return thread_sp; } - return ThreadSP(); + } + return ThreadSP(); } - - #endif // #ifndef LLDB_DISABLE_PYTHON diff --git a/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h b/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h index 1b33c42..1eec30e 100644 --- a/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h +++ b/contrib/llvm/tools/lldb/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h @@ -21,87 +21,76 @@ class DynamicRegisterInfo; -namespace lldb_private -{ +namespace lldb_private { class ScriptInterpreter; } -class OperatingSystemPython : public lldb_private::OperatingSystem -{ +class OperatingSystemPython : public lldb_private::OperatingSystem { public: - OperatingSystemPython(lldb_private::Process *process, - const lldb_private::FileSpec &python_module_path); - - ~OperatingSystemPython() override; - - //------------------------------------------------------------------ - // Static Functions - //------------------------------------------------------------------ - static lldb_private::OperatingSystem * - CreateInstance (lldb_private::Process *process, bool force); - - static void - Initialize(); - - static void - Terminate(); - - static lldb_private::ConstString - GetPluginNameStatic(); - - static const char * - GetPluginDescriptionStatic(); - - //------------------------------------------------------------------ - // lldb_private::PluginInterface Methods - //------------------------------------------------------------------ - lldb_private::ConstString - GetPluginName() override; - - uint32_t - GetPluginVersion() override; - - //------------------------------------------------------------------ - // lldb_private::OperatingSystem Methods - //------------------------------------------------------------------ - bool - UpdateThreadList(lldb_private::ThreadList &old_thread_list, - lldb_private::ThreadList &real_thread_list, - lldb_private::ThreadList &new_thread_list) override; - - void - ThreadWasSelected(lldb_private::Thread *thread) override; - - lldb::RegisterContextSP - CreateRegisterContextForThread(lldb_private::Thread *thread, - lldb::addr_t reg_data_addr) override; - - lldb::StopInfoSP - CreateThreadStopReason(lldb_private::Thread *thread) override; - - //------------------------------------------------------------------ - // Method for lazy creation of threads on demand - //------------------------------------------------------------------ - lldb::ThreadSP - CreateThread(lldb::tid_t tid, lldb::addr_t context) override; + OperatingSystemPython(lldb_private::Process *process, + const lldb_private::FileSpec &python_module_path); + + ~OperatingSystemPython() override; + + //------------------------------------------------------------------ + // Static Functions + //------------------------------------------------------------------ + static lldb_private::OperatingSystem * + CreateInstance(lldb_private::Process *process, bool force); + + static void Initialize(); + + static void Terminate(); + + static lldb_private::ConstString GetPluginNameStatic(); + + static const char *GetPluginDescriptionStatic(); + + //------------------------------------------------------------------ + // lldb_private::PluginInterface Methods + //------------------------------------------------------------------ + lldb_private::ConstString GetPluginName() override; + + uint32_t GetPluginVersion() override; + + //------------------------------------------------------------------ + // lldb_private::OperatingSystem Methods + //------------------------------------------------------------------ + bool UpdateThreadList(lldb_private::ThreadList &old_thread_list, + lldb_private::ThreadList &real_thread_list, + lldb_private::ThreadList &new_thread_list) override; + + void ThreadWasSelected(lldb_private::Thread *thread) override; + + lldb::RegisterContextSP + CreateRegisterContextForThread(lldb_private::Thread *thread, + lldb::addr_t reg_data_addr) override; + + lldb::StopInfoSP + CreateThreadStopReason(lldb_private::Thread *thread) override; + + //------------------------------------------------------------------ + // Method for lazy creation of threads on demand + //------------------------------------------------------------------ + lldb::ThreadSP CreateThread(lldb::tid_t tid, lldb::addr_t context) override; protected: - bool IsValid() const - { - return m_python_object_sp && m_python_object_sp->IsValid(); - } - - lldb::ThreadSP CreateThreadFromThreadInfo(lldb_private::StructuredData::Dictionary &thread_dict, - lldb_private::ThreadList &core_thread_list, lldb_private::ThreadList &old_thread_list, - std::vector<bool> &core_used_map, bool *did_create_ptr); - - DynamicRegisterInfo * - GetDynamicRegisterInfo (); - - lldb::ValueObjectSP m_thread_list_valobj_sp; - std::unique_ptr<DynamicRegisterInfo> m_register_info_ap; - lldb_private::ScriptInterpreter *m_interpreter; - lldb_private::StructuredData::ObjectSP m_python_object_sp; + bool IsValid() const { + return m_python_object_sp && m_python_object_sp->IsValid(); + } + + lldb::ThreadSP CreateThreadFromThreadInfo( + lldb_private::StructuredData::Dictionary &thread_dict, + lldb_private::ThreadList &core_thread_list, + lldb_private::ThreadList &old_thread_list, + std::vector<bool> &core_used_map, bool *did_create_ptr); + + DynamicRegisterInfo *GetDynamicRegisterInfo(); + + lldb::ValueObjectSP m_thread_list_valobj_sp; + std::unique_ptr<DynamicRegisterInfo> m_register_info_ap; + lldb_private::ScriptInterpreter *m_interpreter; + lldb_private::StructuredData::ObjectSP m_python_object_sp; }; #endif // LLDB_DISABLE_PYTHON |