mib created this revision.
mib added a reviewer: JDevlieghere.
mib added a project: LLDB.
mib requested review of this revision.
Herald added a subscriber: lldb-commits.

This patch replaces the type of the ProcessLaunchInfo ScriptedProcess
Dictionary from a StructuredData pointer to be serialized in a string.

The reason behind this change is that the lifetime of the dictionary's
pointer could be managed by an actor other than the debugger (i.e. the
Python Interpreter). In some cases, this caused the dictionary's pointer
to point to corrupted memory, which can interfere with the good functionning
of Scripted Processes and Scripted Threads.

This patch also updates the related-code to take these changes into account.

Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112109

Files:
  lldb/include/lldb/Host/ProcessLaunchInfo.h
  lldb/source/API/SBLaunchInfo.cpp
  lldb/source/Commands/CommandObjectProcess.cpp
  lldb/source/Host/common/ProcessLaunchInfo.cpp
  lldb/source/Plugins/Process/scripted/ScriptedProcess.h
  lldb/source/Target/Target.cpp

Index: lldb/source/Target/Target.cpp
===================================================================
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -2930,8 +2930,8 @@
     default_launch_info.SetProcessPluginName("ScriptedProcess");
     default_launch_info.SetScriptedProcessClassName(
         launch_info.GetScriptedProcessClassName());
-    default_launch_info.SetScriptedProcessDictionarySP(
-        launch_info.GetScriptedProcessDictionarySP());
+    default_launch_info.SetScriptedProcessDictionary(
+        launch_info.GetScriptedProcessDictionary());
 
     SetProcessLaunchInfo(launch_info);
   }
Index: lldb/source/Plugins/Process/scripted/ScriptedProcess.h
===================================================================
--- lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -25,6 +25,8 @@
   public:
     ScriptedProcessInfo(const ProcessLaunchInfo &launch_info) {
       m_class_name = launch_info.GetScriptedProcessClassName();
+      m_args_sp =
+          StructuredData::ParseJSON(launch_info.GetScriptedProcessDictionary());
     }
 
     std::string GetClassName() const { return m_class_name; }
Index: lldb/source/Host/common/ProcessLaunchInfo.cpp
===================================================================
--- lldb/source/Host/common/ProcessLaunchInfo.cpp
+++ lldb/source/Host/common/ProcessLaunchInfo.cpp
@@ -32,7 +32,7 @@
     : ProcessInfo(), m_working_dir(), m_plugin_name(), m_flags(0),
       m_file_actions(), m_pty(new PseudoTerminal), m_monitor_callback(nullptr),
       m_listener_sp(), m_hijack_listener_sp(), m_scripted_process_class_name(),
-      m_scripted_process_dictionary_sp() {}
+      m_scripted_process_dict() {}
 
 ProcessLaunchInfo::ProcessLaunchInfo(const FileSpec &stdin_file_spec,
                                      const FileSpec &stdout_file_spec,
@@ -43,7 +43,7 @@
       m_file_actions(), m_pty(new PseudoTerminal), m_resume_count(0),
       m_monitor_callback(nullptr), m_monitor_callback_baton(nullptr),
       m_monitor_signals(false), m_listener_sp(), m_hijack_listener_sp(),
-      m_scripted_process_class_name(), m_scripted_process_dictionary_sp() {
+      m_scripted_process_class_name(), m_scripted_process_dict() {
   if (stdin_file_spec) {
     FileAction file_action;
     const bool read = true;
@@ -173,7 +173,7 @@
   m_listener_sp.reset();
   m_hijack_listener_sp.reset();
   m_scripted_process_class_name.clear();
-  m_scripted_process_dictionary_sp.reset();
+  m_scripted_process_dict.clear();
 }
 
 void ProcessLaunchInfo::SetMonitorProcessCallback(
Index: lldb/source/Commands/CommandObjectProcess.cpp
===================================================================
--- lldb/source/Commands/CommandObjectProcess.cpp
+++ lldb/source/Commands/CommandObjectProcess.cpp
@@ -190,8 +190,16 @@
       m_options.launch_info.SetProcessPluginName("ScriptedProcess");
       m_options.launch_info.SetScriptedProcessClassName(
           m_class_options.GetName());
-      m_options.launch_info.SetScriptedProcessDictionarySP(
-          m_class_options.GetStructuredData());
+      const StructuredData::DictionarySP dict_sp =
+          m_class_options.GetStructuredData();
+
+      if (dict_sp) {
+        StreamString stream;
+        llvm::json::OStream s(stream.AsRawOstream());
+        dict_sp->Serialize(s);
+        m_options.launch_info.SetScriptedProcessDictionary(stream.GetData());
+      }
+
       target->SetProcessLaunchInfo(m_options.launch_info);
     }
 
Index: lldb/source/API/SBLaunchInfo.cpp
===================================================================
--- lldb/source/API/SBLaunchInfo.cpp
+++ lldb/source/API/SBLaunchInfo.cpp
@@ -367,12 +367,9 @@
 lldb::SBStructuredData SBLaunchInfo::GetScriptedProcessDictionary() const {
   LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::SBStructuredData, SBLaunchInfo,
                                    GetScriptedProcessDictionary);
-
-  lldb_private::StructuredData::DictionarySP dict_sp =
-      m_opaque_sp->GetScriptedProcessDictionarySP();
-
   SBStructuredData data;
-  data.m_impl_up->SetObjectSP(dict_sp);
+  data.m_impl_up->SetObjectSP(
+      StructuredData::ParseJSON(m_opaque_sp->GetScriptedProcessDictionary()));
 
   return LLDB_RECORD_RESULT(data);
 }
@@ -387,11 +384,7 @@
   if (error.Fail())
     return;
 
-  StructuredData::DictionarySP dict_sp;
-  llvm::json::OStream s(stream.ref().AsRawOstream());
-  dict_sp->Serialize(s);
-
-  m_opaque_sp->SetScriptedProcessDictionarySP(dict_sp);
+  m_opaque_sp->SetScriptedProcessDictionary(stream.GetData());
 }
 
 namespace lldb_private {
Index: lldb/include/lldb/Host/ProcessLaunchInfo.h
===================================================================
--- lldb/include/lldb/Host/ProcessLaunchInfo.h
+++ lldb/include/lldb/Host/ProcessLaunchInfo.h
@@ -159,14 +159,12 @@
     m_scripted_process_class_name = name;
   }
 
-  lldb_private::StructuredData::DictionarySP
-  GetScriptedProcessDictionarySP() const {
-    return m_scripted_process_dictionary_sp;
+  std::string GetScriptedProcessDictionary() const {
+    return m_scripted_process_dict;
   }
 
-  void SetScriptedProcessDictionarySP(
-      lldb_private::StructuredData::DictionarySP dictionary_sp) {
-    m_scripted_process_dictionary_sp = dictionary_sp;
+  void SetScriptedProcessDictionary(std::string dict) {
+    m_scripted_process_dict = dict;
   }
 
 protected:
@@ -186,9 +184,9 @@
   lldb::ListenerSP m_hijack_listener_sp;
   std::string m_scripted_process_class_name; // The name of the class that will
                                              // manage a scripted process.
-  StructuredData::DictionarySP
-      m_scripted_process_dictionary_sp; // A dictionary that holds key/value
-                                        // pairs passed to the scripted process.
+  std::string
+      m_scripted_process_dict; // A serialized dictionary that holds key/value
+                               // pairs passed to the scripted process.
 };
 }
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
  • [Lldb-commits] [PATCH]... Med Ismail Bennani via Phabricator via lldb-commits

Reply via email to