Skip to content

Commit ee137e4

Browse files
committed
[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 <[email protected]>
1 parent 0350943 commit ee137e4

File tree

4 files changed

+62
-35
lines changed

4 files changed

+62
-35
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===-- ScriptedMetadata.h ------------------------------------ -*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_INTERPRETER_SCRIPTEDMETADATA_H
10+
#define LLDB_INTERPRETER_SCRIPTEDMETADATA_H
11+
12+
#include "OptionGroupPythonClassWithDict.h"
13+
14+
#include "lldb/Host/Host.h"
15+
#include "lldb/Host/ProcessLaunchInfo.h"
16+
#include "lldb/Utility/StructuredData.h"
17+
18+
namespace lldb_private {
19+
class ScriptedMetadata {
20+
public:
21+
ScriptedMetadata(llvm::StringRef class_name,
22+
StructuredData::DictionarySP dict_sp)
23+
: m_class_name(class_name.data()), m_args_sp(dict_sp) {}
24+
25+
ScriptedMetadata(const ProcessLaunchInfo &launch_info) {
26+
m_class_name = launch_info.GetScriptedProcessClassName();
27+
m_args_sp = launch_info.GetScriptedProcessDictionarySP();
28+
}
29+
30+
ScriptedMetadata(const OptionGroupPythonClassWithDict &option_group) {
31+
auto opt_group = const_cast<OptionGroupPythonClassWithDict &>(option_group);
32+
m_class_name = opt_group.GetName();
33+
m_args_sp = opt_group.GetStructuredData();
34+
}
35+
36+
llvm::StringRef GetClassName() const { return m_class_name; }
37+
StructuredData::DictionarySP GetArgsSP() const { return m_args_sp; }
38+
39+
private:
40+
std::string m_class_name;
41+
StructuredData::DictionarySP m_args_sp;
42+
};
43+
} // namespace lldb_private
44+
45+
#endif // LLDB_INTERPRETER_SCRIPTEDMETADATA_H

lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "lldb/Interpreter/OptionArgParser.h"
1919
#include "lldb/Interpreter/OptionGroupBoolean.h"
2020
#include "lldb/Interpreter/ScriptInterpreter.h"
21+
#include "lldb/Interpreter/ScriptedMetadata.h"
2122
#include "lldb/Target/MemoryRegionInfo.h"
2223
#include "lldb/Target/RegisterContext.h"
2324
#include "lldb/Utility/LLDBLog.h"
@@ -58,12 +59,11 @@ lldb::ProcessSP ScriptedProcess::CreateInstance(lldb::TargetSP target_sp,
5859
!IsScriptLanguageSupported(target_sp->GetDebugger().GetScriptLanguage()))
5960
return nullptr;
6061

61-
Status error;
62-
ScriptedProcess::ScriptedProcessInfo scripted_process_info(
63-
target_sp->GetProcessLaunchInfo());
62+
ScriptedMetadata scripted_metadata(target_sp->GetProcessLaunchInfo());
6463

65-
auto process_sp = std::shared_ptr<ScriptedProcess>(new ScriptedProcess(
66-
target_sp, listener_sp, scripted_process_info, error));
64+
Status error;
65+
auto process_sp = std::shared_ptr<ScriptedProcess>(
66+
new ScriptedProcess(target_sp, listener_sp, scripted_metadata, error));
6767

6868
if (error.Fail() || !process_sp || !process_sp->m_script_object_sp ||
6969
!process_sp->m_script_object_sp->IsValid()) {
@@ -79,12 +79,11 @@ bool ScriptedProcess::CanDebug(lldb::TargetSP target_sp,
7979
return true;
8080
}
8181

82-
ScriptedProcess::ScriptedProcess(
83-
lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
84-
const ScriptedProcess::ScriptedProcessInfo &scripted_process_info,
85-
Status &error)
86-
: Process(target_sp, listener_sp),
87-
m_scripted_process_info(scripted_process_info) {
82+
ScriptedProcess::ScriptedProcess(lldb::TargetSP target_sp,
83+
lldb::ListenerSP listener_sp,
84+
const ScriptedMetadata &scripted_metadata,
85+
Status &error)
86+
: Process(target_sp, listener_sp), m_scripted_metadata(scripted_metadata) {
8887

8988
if (!target_sp) {
9089
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",
@@ -104,8 +103,8 @@ ScriptedProcess::ScriptedProcess(
104103
ExecutionContext exe_ctx(target_sp, /*get_process=*/false);
105104

106105
StructuredData::GenericSP object_sp = GetInterface().CreatePluginObject(
107-
m_scripted_process_info.GetClassName().c_str(), exe_ctx,
108-
m_scripted_process_info.GetArgsSP());
106+
m_scripted_metadata.GetClassName(), exe_ctx,
107+
m_scripted_metadata.GetArgsSP());
109108

110109
if (!object_sp || !object_sp->IsValid()) {
111110
error.SetErrorStringWithFormat("ScriptedProcess::%s () - ERROR: %s",

lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
1010
#define LLDB_SOURCE_PLUGINS_SCRIPTED_PROCESS_H
1111

12+
#include "lldb/Interpreter/ScriptedMetadata.h"
1213
#include "lldb/Target/Process.h"
1314
#include "lldb/Utility/ConstString.h"
1415
#include "lldb/Utility/Status.h"
@@ -18,24 +19,7 @@
1819
#include <mutex>
1920

2021
namespace lldb_private {
21-
2222
class ScriptedProcess : public Process {
23-
protected:
24-
class ScriptedProcessInfo {
25-
public:
26-
ScriptedProcessInfo(const ProcessLaunchInfo &launch_info) {
27-
m_class_name = launch_info.GetScriptedProcessClassName();
28-
m_args_sp = launch_info.GetScriptedProcessDictionarySP();
29-
}
30-
31-
std::string GetClassName() const { return m_class_name; }
32-
StructuredData::DictionarySP GetArgsSP() const { return m_args_sp; }
33-
34-
private:
35-
std::string m_class_name;
36-
StructuredData::DictionarySP m_args_sp;
37-
};
38-
3923
public:
4024
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
4125
lldb::ListenerSP listener_sp,
@@ -90,8 +74,7 @@ class ScriptedProcess : public Process {
9074

9175
protected:
9276
ScriptedProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
93-
const ScriptedProcess::ScriptedProcessInfo &launch_info,
94-
Status &error);
77+
const ScriptedMetadata &scripted_metadata, Status &error);
9578

9679
Status DoStop();
9780

@@ -111,7 +94,7 @@ class ScriptedProcess : public Process {
11194
static bool IsScriptLanguageSupported(lldb::ScriptLanguage language);
11295

11396
// Member variables.
114-
const ScriptedProcessInfo m_scripted_process_info;
97+
const ScriptedMetadata m_scripted_metadata;
11598
lldb_private::ScriptInterpreter *m_interpreter = nullptr;
11699
lldb_private::StructuredData::ObjectSP m_script_object_sp = nullptr;
117100
//@}

lldb/source/Plugins/Process/scripted/ScriptedThread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ ScriptedThread::Create(ScriptedProcess &process,
5757
ExecutionContext exe_ctx(process);
5858
StructuredData::GenericSP owned_script_object_sp =
5959
scripted_thread_interface->CreatePluginObject(
60-
thread_class_name, exe_ctx,
61-
process.m_scripted_process_info.GetArgsSP(), script_object);
60+
thread_class_name, exe_ctx, process.m_scripted_metadata.GetArgsSP(),
61+
script_object);
6262

6363
if (!owned_script_object_sp)
6464
return llvm::createStringError(llvm::inconvertibleErrorCode(),

0 commit comments

Comments
 (0)