[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@gmail.com>
This commit is contained in:
Med Ismail Bennani
2022-12-05 13:54:21 -08:00
parent c17e40ba52
commit d9f4d1b048
4 changed files with 62 additions and 35 deletions

View File

@@ -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

View File

@@ -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",

View File

@@ -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 @@ public:
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 @@ private:
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;
//@}

View File

@@ -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(),