aboutsummaryrefslogtreecommitdiff
path: root/source/Plugins/OperatingSystem
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2015-07-03 16:57:06 +0000
committerEd Maste <emaste@FreeBSD.org>2015-07-03 16:57:06 +0000
commit5e95aa85bb660d45e9905ef1d7180b2678280660 (patch)
tree3c2e41c3be19b7fc7666ed45a5f91ec3b6e35f2a /source/Plugins/OperatingSystem
parent12bd4897ff0678fa663e09d78ebc22dd255ceb86 (diff)
downloadsrc-5e95aa85bb660d45e9905ef1d7180b2678280660.tar.gz
src-5e95aa85bb660d45e9905ef1d7180b2678280660.zip
Import LLDB as of upstream SVN 241361 (git 612c075f)vendor/lldb/lldb-r241361
Notes
Notes: svn path=/vendor/lldb/dist/; revision=285101 svn path=/vendor/lldb/lldb-r241361/; revision=285102; tag=vendor/lldb/lldb-r241361
Diffstat (limited to 'source/Plugins/OperatingSystem')
-rw-r--r--source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp184
-rw-r--r--source/Plugins/OperatingSystem/Python/OperatingSystemPython.h23
2 files changed, 98 insertions, 109 deletions
diff --git a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
index 7ca337e797da..e744d13deec1 100644
--- a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
+++ b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp
@@ -7,8 +7,6 @@
//
//===----------------------------------------------------------------------===//
-#include "lldb/lldb-python.h"
-
#ifndef LLDB_DISABLE_PYTHON
#include "OperatingSystemPython.h"
@@ -22,9 +20,10 @@
#include "lldb/Core/PluginManager.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/StreamString.h"
+#include "lldb/Core/StructuredData.h"
#include "lldb/Core/ValueObjectVariable.h"
#include "lldb/Interpreter/CommandInterpreter.h"
-#include "lldb/Interpreter/PythonDataObjects.h"
+#include "lldb/Interpreter/ScriptInterpreter.h"
#include "lldb/Symbol/ClangNamespaceDecl.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Symbol/VariableList.h"
@@ -116,8 +115,9 @@ OperatingSystemPython::OperatingSystemPython (lldb_private::Process *process, co
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";
- ScriptInterpreterObjectSP object_sp = m_interpreter->OSPlugin_CreatePluginObject(os_plugin_class_name.c_str(), process->CalculateProcess());
- if (object_sp && object_sp->GetObject())
+ 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;
}
}
@@ -139,12 +139,12 @@ OperatingSystemPython::GetDynamicRegisterInfo ()
if (log)
log->Printf ("OperatingSystemPython::GetDynamicRegisterInfo() fetching thread register definitions from python for pid %" PRIu64, m_process->GetID());
-
- PythonDictionary dictionary(m_interpreter->OSPlugin_RegisterInfo(m_python_object_sp));
+
+ 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().GetByteOrder()));
+
+ 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);
}
@@ -176,11 +176,18 @@ OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list,
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OS));
- // 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.
+ // 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();
- Mutex::Locker api_locker (target.GetAPIMutex());
+ Mutex::Locker api_locker;
+ api_locker.TryLock(target.GetAPIMutex());
if (log)
log->Printf ("OperatingSystemPython::UpdateThreadList() fetching thread data from python for pid %" PRIu64, m_process->GetID());
@@ -189,8 +196,8 @@ OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list,
// lldb_private::Process subclass, no memory threads will be in this list.
auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure threads_list stays alive
- PythonList threads_list(m_interpreter->OSPlugin_ThreadsInfo(m_python_object_sp));
-
+ 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
@@ -202,22 +209,19 @@ OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list,
if (log)
{
StreamString strm;
- threads_list.Dump(strm);
+ threads_list->Dump(strm);
log->Printf("threads_list = %s", strm.GetString().c_str());
}
- uint32_t i;
- const uint32_t num_threads = threads_list.GetSize();
- if (num_threads > 0)
+
+ const uint32_t num_threads = threads_list->GetSize();
+ for (uint32_t i = 0; i < num_threads; ++i)
{
- for (i=0; i<num_threads; ++i)
+ StructuredData::ObjectSP thread_dict_obj = threads_list->GetItemAtIndex(i);
+ if (auto thread_dict = thread_dict_obj->GetAsDictionary())
{
- PythonDictionary thread_dict(threads_list.GetItemAtIndex(i));
- if (thread_dict)
- {
- 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);
- }
+ 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);
}
}
}
@@ -239,79 +243,63 @@ OperatingSystemPython::UpdateThreadList (ThreadList &old_thread_list,
}
ThreadSP
-OperatingSystemPython::CreateThreadFromThreadInfo (PythonDictionary &thread_dict,
- ThreadList &core_thread_list,
- ThreadList &old_thread_list,
- std::vector<bool> &core_used_map,
- bool *did_create_ptr)
+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;
- if (thread_dict)
+ 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)
{
- PythonString tid_pystr("tid");
- const tid_t tid = thread_dict.GetItemForKeyAsInteger (tid_pystr, LLDB_INVALID_THREAD_ID);
- if (tid != LLDB_INVALID_THREAD_ID)
+ // A thread already does exist for "tid", make sure it was an operating system
+ // plug-in generated thread.
+ if (!IsOperatingSystemPluginThread(thread_sp))
{
- PythonString core_pystr("core");
- PythonString name_pystr("name");
- PythonString queue_pystr("queue");
- //PythonString state_pystr("state");
- //PythonString stop_reason_pystr("stop_reason");
- PythonString reg_data_addr_pystr ("register_data_addr");
-
- const uint32_t core_number = thread_dict.GetItemForKeyAsInteger (core_pystr, UINT32_MAX);
- const addr_t reg_data_addr = thread_dict.GetItemForKeyAsInteger (reg_data_addr_pystr, LLDB_INVALID_ADDRESS);
- const char *name = thread_dict.GetItemForKeyAsString (name_pystr);
- const char *queue = thread_dict.GetItemForKeyAsString (queue_pystr);
- //const char *state = thread_dict.GetItemForKeyAsString (state_pystr);
- //const char *stop_reason = thread_dict.GetItemForKeyAsString (stop_reason_pystr);
-
- // 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 (!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 (!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)
{
- if (did_create_ptr)
- *did_create_ptr = true;
- thread_sp.reset (new ThreadMemory (*m_process,
- tid,
- name,
- queue,
- reg_data_addr));
-
+ thread_sp->SetBackingThread(backing_core_thread_sp);
}
-
- if (core_number < core_thread_list.GetSize(false))
+ else
{
- 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);
- }
- }
+ thread_sp->SetBackingThread(core_thread_sp);
}
}
}
@@ -364,11 +352,11 @@ OperatingSystemPython::CreateRegisterContextForThread (Thread *thread, addr_t re
thread->GetID(),
thread->GetProtocolID());
- PythonString reg_context_data(m_interpreter->OSPlugin_RegisterContextData (m_python_object_sp, thread->GetID()));
+ StructuredData::StringSP reg_context_data = m_interpreter->OSPlugin_RegisterContextData(m_python_object_sp, thread->GetID());
if (reg_context_data)
{
- DataBufferSP data_sp (new DataBufferHeap (reg_context_data.GetString(),
- reg_context_data.GetSize()));
+ 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);
@@ -417,14 +405,14 @@ OperatingSystemPython::CreateThread (lldb::tid_t tid, addr_t context)
Mutex::Locker api_locker (target.GetAPIMutex());
auto lock = m_interpreter->AcquireInterpreterLock(); // to make sure thread_info_dict stays alive
- PythonDictionary thread_info_dict (m_interpreter->OSPlugin_CreateThread(m_python_object_sp, tid, context));
+ 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));
+ 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;
diff --git a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
index 3b7dd264dc62..e29bf8054f6c 100644
--- a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
+++ b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.h
@@ -14,11 +14,16 @@
// C Includes
// C++ Includes
// Other libraries and framework includes
-#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Core/StructuredData.h"
#include "lldb/Target/OperatingSystem.h"
class DynamicRegisterInfo;
+namespace lldb_private
+{
+class ScriptInterpreter;
+}
+
class OperatingSystemPython : public lldb_private::OperatingSystem
{
public:
@@ -86,15 +91,12 @@ protected:
bool IsValid() const
{
- return m_python_object_sp && m_python_object_sp->GetObject() != NULL;
+ return m_python_object_sp && m_python_object_sp->IsValid();
}
-
- lldb::ThreadSP
- CreateThreadFromThreadInfo (lldb_private::PythonDictionary &thread_dict,
- lldb_private::ThreadList &core_thread_list,
- lldb_private::ThreadList &old_thread_list,
- std::vector<bool> &core_used_map,
- bool *did_create_ptr);
+
+ 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 ();
@@ -102,8 +104,7 @@ protected:
lldb::ValueObjectSP m_thread_list_valobj_sp;
std::unique_ptr<DynamicRegisterInfo> m_register_info_ap;
lldb_private::ScriptInterpreter *m_interpreter;
- lldb::ScriptInterpreterObjectSP m_python_object_sp;
-
+ lldb_private::StructuredData::ObjectSP m_python_object_sp;
};
#endif // #ifndef liblldb_OperatingSystemPython_h_