[Lldb-commits] [lldb] d9f4d1b - [lldb/Interpreter] Make ScriptedProcessInfo more generic
Med Ismail Bennani via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 12 12:54:13 PST 2023
Author: Med Ismail Bennani
Date: 2023-01-12T12:49:05-08:00
New Revision: d9f4d1b048520c50ca06e24b7886d77d3bb2fc29
URL: https://github.com/llvm/llvm-project/commit/d9f4d1b048520c50ca06e24b7886d77d3bb2fc29
DIFF: https://github.com/llvm/llvm-project/commit/d9f4d1b048520c50ca06e24b7886d77d3bb2fc29.diff
LOG: [lldb/Interpreter] Make ScriptedProcessInfo more generic
This patch moves the ScriptedProcessInfo class out of the
ScriptedProcess and hoist it as a standalone interpreter class, so it can be
reused with the Scripted Platform.
Differential Revision: https://reviews.llvm.org/D139247
Signed-off-by: Med Ismail Bennani <medismail.bennani at gmail.com>
Added:
lldb/include/lldb/Interpreter/ScriptedMetadata.h
Modified:
lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
lldb/source/Plugins/Process/scripted/ScriptedProcess.h
lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
Removed:
################################################################################
diff --git a/lldb/include/lldb/Interpreter/ScriptedMetadata.h b/lldb/include/lldb/Interpreter/ScriptedMetadata.h
new file mode 100644
index 0000000000000..00ebce323bf88
--- /dev/null
+++ b/lldb/include/lldb/Interpreter/ScriptedMetadata.h
@@ -0,0 +1,45 @@
+//===-- ScriptedMetadata.h ------------------------------------ -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_INTERPRETER_SCRIPTEDMETADATA_H
+#define LLDB_INTERPRETER_SCRIPTEDMETADATA_H
+
+#include "OptionGroupPythonClassWithDict.h"
+
+#include "lldb/Host/Host.h"
+#include "lldb/Host/ProcessLaunchInfo.h"
+#include "lldb/Utility/StructuredData.h"
+
+namespace lldb_private {
+class ScriptedMetadata {
+public:
+ ScriptedMetadata(llvm::StringRef class_name,
+ StructuredData::DictionarySP dict_sp)
+ : m_class_name(class_name.data()), m_args_sp(dict_sp) {}
+
+ ScriptedMetadata(const ProcessLaunchInfo &launch_info) {
+ m_class_name = launch_info.GetScriptedProcessClassName();
+ m_args_sp = launch_info.GetScriptedProcessDictionarySP();
+ }
+
+ ScriptedMetadata(const OptionGroupPythonClassWithDict &option_group) {
+ auto opt_group = const_cast<OptionGroupPythonClassWithDict &>(option_group);
+ m_class_name = opt_group.GetName();
+ m_args_sp = opt_group.GetStructuredData();
+ }
+
+ llvm::StringRef GetClassName() const { return m_class_name; }
+ StructuredData::DictionarySP GetArgsSP() const { return m_args_sp; }
+
+private:
+ std::string m_class_name;
+ StructuredData::DictionarySP m_args_sp;
+};
+} // namespace lldb_private
+
+#endif // LLDB_INTERPRETER_SCRIPTEDMETADATA_H
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
index 855a67aae1b5f..576e620220984 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp
@@ -18,6 +18,7 @@
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionGroupBoolean.h"
#include "lldb/Interpreter/ScriptInterpreter.h"
+#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Utility/LLDBLog.h"
@@ -58,12 +59,11 @@ lldb::ProcessSP ScriptedProcess::CreateInstance(lldb::TargetSP target_sp,
!IsScriptLanguageSupported(target_sp->GetDebugger().GetScriptLanguage()))
return nullptr;
- Status error;
- ScriptedProcess::ScriptedProcessInfo scripted_process_info(
- target_sp->GetProcessLaunchInfo());
+ ScriptedMetadata scripted_metadata(target_sp->GetProcessLaunchInfo());
- auto process_sp = std::shared_ptr<ScriptedProcess>(new ScriptedProcess(
- target_sp, listener_sp, scripted_process_info, error));
+ Status error;
+ auto process_sp = std::shared_ptr<ScriptedProcess>(
+ new ScriptedProcess(target_sp, listener_sp, scripted_metadata, error));
if (error.Fail() || !process_sp || !process_sp->m_script_object_sp ||
!process_sp->m_script_object_sp->IsValid()) {
@@ -79,12 +79,11 @@ bool ScriptedProcess::CanDebug(lldb::TargetSP target_sp,
return true;
}
-ScriptedProcess::ScriptedProcess(
- lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
- const ScriptedProcess::ScriptedProcessInfo &scripted_process_info,
- Status &error)
- : Process(target_sp, listener_sp),
- m_scripted_process_info(scripted_process_info) {
+ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
+ lldb::ListenerSP listener_sp,
+ const ScriptedMetadata &scripted_metadata,
+ Status &error)
+ : Process(target_sp, listener_sp), m_scripted_metadata(scripted_metadata) {
if (!target_sp) {
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
@@ -104,8 +103,8 @@ ScriptedProcess::ScriptedProcess(
ExecutionContext exe_ctx(target_sp, /*get_process=*/false);
StructuredData::GenericSP object_sp = GetInterface().CreatePluginObject(
- m_scripted_process_info.GetClassName().c_str(), exe_ctx,
- m_scripted_process_info.GetArgsSP());
+ m_scripted_metadata.GetClassName(), exe_ctx,
+ m_scripted_metadata.GetArgsSP());
if (!object_sp || !object_sp->IsValid()) {
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
index e8f8dd4a965d5..350c427724761 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
+++ b/lldb/source/Plugins/Process/scripted/ScriptedProcess.h
@@ -9,6 +9,7 @@
#ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
#define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
+#include "lldb/Interpreter/ScriptedMetadata.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/Status.h"
@@ -18,24 +19,7 @@
#include <mutex>
namespace lldb_private {
-
class ScriptedProcess : public Process {
-protected:
- class ScriptedProcessInfo {
- public:
- ScriptedProcessInfo(const ProcessLaunchInfo &launch_info) {
- m_class_name = launch_info.GetScriptedProcessClassName();
- m_args_sp = launch_info.GetScriptedProcessDictionarySP();
- }
-
- std::string GetClassName() const { return m_class_name; }
- StructuredData::DictionarySP GetArgsSP() const { return m_args_sp; }
-
- private:
- std::string m_class_name;
- StructuredData::DictionarySP m_args_sp;
- };
-
public:
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
lldb::ListenerSP listener_sp,
@@ -90,8 +74,7 @@ class ScriptedProcess : public Process {
protected:
ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
- const ScriptedProcess::ScriptedProcessInfo &launch_info,
- Status &error);
+ const ScriptedMetadata &scripted_metadata, Status &error);
Status DoStop();
@@ -111,7 +94,7 @@ class ScriptedProcess : public Process {
static bool IsScriptLanguageSupported(lldb::ScriptLanguage language);
// Member variables.
- const ScriptedProcessInfo m_scripted_process_info;
+ const ScriptedMetadata m_scripted_metadata;
lldb_private::ScriptInterpreter *m_interpreter = nullptr;
lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
//@}
diff --git a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index c2f01395f09dc..ad0d26af88798 100644
--- a/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -58,8 +58,8 @@ ScriptedThread::Create(ScriptedProcess &process,
ExecutionContext exe_ctx(process);
StructuredData::GenericSP owned_script_object_sp =
scripted_thread_interface->CreatePluginObject(
- thread_class_name, exe_ctx,
- process.m_scripted_process_info.GetArgsSP(), script_object);
+ thread_class_name, exe_ctx, process.m_scripted_metadata.GetArgsSP(),
+ script_object);
if (!owned_script_object_sp)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
More information about the lldb-commits
mailing list