Skip to content

Commit fbf0ce9

Browse files
Merge pull request swiftlang#9414 from medismailben/stable/20240723
[lldb] Cherry-picking missing commits
2 parents bf56de2 + 453c7b2 commit fbf0ce9

36 files changed

+793
-113
lines changed

lldb/docs/use/tutorial.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ is more convenient to make the basic commands unique down to a letter or two,
168168
and then learn these sequences than to fill the namespace with lots of aliases,
169169
and then have to type them all the way out.
170170

171+
If the alias abbreviation or the full alias command collides with another
172+
existing command, the command resolver will prefer to use the alias over any
173+
other command as far as there is only one alias command match.
174+
171175
However, users are free to customize LLDB's command set however they like, and
172176
since LLDB reads the file ``~/.lldbinit`` at startup, you can store all your
173177
aliases there and they will be generally available to you. Your aliases are

lldb/include/lldb/Core/PluginManager.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define LLDB_CORE_PLUGINMANAGER_H
1111

1212
#include "lldb/Core/Architecture.h"
13+
#include "lldb/Interpreter/Interfaces/ScriptedInterfaceUsages.h"
1314
#include "lldb/Symbol/TypeSystem.h"
1415
#include "lldb/Utility/CompletionRequest.h"
1516
#include "lldb/Utility/FileSpec.h"
@@ -488,6 +489,25 @@ class PluginManager {
488489

489490
static LanguageSet GetAllTypeSystemSupportedLanguagesForExpressions();
490491

492+
// Scripted Interface
493+
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
494+
ScriptedInterfaceCreateInstance create_callback,
495+
lldb::ScriptLanguage language,
496+
ScriptedInterfaceUsages usages);
497+
498+
static bool UnregisterPlugin(ScriptedInterfaceCreateInstance create_callback);
499+
500+
static uint32_t GetNumScriptedInterfaces();
501+
502+
static llvm::StringRef GetScriptedInterfaceNameAtIndex(uint32_t idx);
503+
504+
static llvm::StringRef GetScriptedInterfaceDescriptionAtIndex(uint32_t idx);
505+
506+
static lldb::ScriptLanguage GetScriptedInterfaceLanguageAtIndex(uint32_t idx);
507+
508+
static ScriptedInterfaceUsages
509+
GetScriptedInterfaceUsagesAtIndex(uint32_t idx);
510+
491511
// REPL
492512
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description,
493513
REPLCreateInstance create_callback,

lldb/include/lldb/Interpreter/CommandInterpreter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ class CommandInterpreter : public Broadcaster,
295295
StringList *matches = nullptr,
296296
StringList *descriptions = nullptr) const;
297297

298+
CommandObject *
299+
GetAliasCommandObject(llvm::StringRef cmd, StringList *matches = nullptr,
300+
StringList *descriptions = nullptr) const;
301+
298302
/// Determine whether a root level, built-in command with this name exists.
299303
bool CommandExists(llvm::StringRef cmd) const;
300304

lldb/include/lldb/Interpreter/Interfaces/ScriptedInterface.h

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

12+
#include "ScriptedInterfaceUsages.h"
13+
1214
#include "lldb/Core/StructuredDataImpl.h"
1315
#include "lldb/Utility/LLDBLog.h"
1416
#include "lldb/Utility/Log.h"
@@ -68,6 +70,11 @@ class ScriptedInterface {
6870
return true;
6971
}
7072

73+
static bool CreateInstance(lldb::ScriptLanguage language,
74+
ScriptedInterfaceUsages usages) {
75+
return false;
76+
}
77+
7178
protected:
7279
StructuredData::GenericSP m_object_instance_sp;
7380
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//===-- ScriptedInterfaceUsages.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_SCRIPTEDINTERFACEUSAGES_H
10+
#define LLDB_INTERPRETER_SCRIPTEDINTERFACEUSAGES_H
11+
12+
#include "lldb/lldb-types.h"
13+
14+
#include "lldb/Utility/Stream.h"
15+
#include "llvm/ADT/StringRef.h"
16+
17+
namespace lldb_private {
18+
class ScriptedInterfaceUsages {
19+
public:
20+
ScriptedInterfaceUsages() = default;
21+
ScriptedInterfaceUsages(const std::vector<llvm::StringRef> ci_usages,
22+
const std::vector<llvm::StringRef> sbapi_usages)
23+
: m_command_interpreter_usages(ci_usages), m_sbapi_usages(sbapi_usages) {}
24+
25+
const std::vector<llvm::StringRef> &GetCommandInterpreterUsages() const {
26+
return m_command_interpreter_usages;
27+
}
28+
29+
const std::vector<llvm::StringRef> &GetSBAPIUsages() const {
30+
return m_sbapi_usages;
31+
}
32+
33+
enum class UsageKind { CommandInterpreter, API };
34+
35+
void Dump(Stream &s, UsageKind kind) const;
36+
37+
private:
38+
std::vector<llvm::StringRef> m_command_interpreter_usages;
39+
std::vector<llvm::StringRef> m_sbapi_usages;
40+
};
41+
} // namespace lldb_private
42+
43+
#endif // LLDB_INTERPRETER_SCRIPTEDINTERFACEUSAGES_H

lldb/include/lldb/Target/ThreadPlanPython.h renamed to lldb/include/lldb/Target/ScriptedThreadPlan.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
//===-- ThreadPlanPython.h --------------------------------------------*- C++
2-
//-*-===//
1+
//===-- ScriptedThreadPlan.h ------------------------------------*- C++ -*-===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
54
// See https://llvm.org/LICENSE.txt for license information.
65
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
76
//
87
//===----------------------------------------------------------------------===//
98

10-
#ifndef LLDB_TARGET_THREADPLANPYTHON_H
11-
#define LLDB_TARGET_THREADPLANPYTHON_H
9+
#ifndef LLDB_TARGET_SCRIPTEDTHREADPLAN_H
10+
#define LLDB_TARGET_SCRIPTEDTHREADPLAN_H
1211

1312
#include <string>
1413

@@ -27,13 +26,10 @@
2726

2827
namespace lldb_private {
2928

30-
// ThreadPlanPython:
31-
//
32-
33-
class ThreadPlanPython : public ThreadPlan {
29+
class ScriptedThreadPlan : public ThreadPlan {
3430
public:
35-
ThreadPlanPython(Thread &thread, const char *class_name,
36-
const StructuredDataImpl &args_data);
31+
ScriptedThreadPlan(Thread &thread, const char *class_name,
32+
const StructuredDataImpl &args_data);
3733

3834
void GetDescription(Stream *s, lldb::DescriptionLevel level) override;
3935

@@ -52,15 +48,14 @@ class ThreadPlanPython : public ThreadPlan {
5248
void DidPush() override;
5349

5450
bool IsPlanStale() override;
55-
56-
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
5751

52+
bool DoWillResume(lldb::StateType resume_state, bool current_plan) override;
5853

5954
protected:
6055
bool DoPlanExplainsStop(Event *event_ptr) override;
6156

6257
lldb::StateType GetPlanRunState() override;
63-
58+
6459
ScriptInterpreter *GetScriptInterpreter();
6560

6661
private:
@@ -73,10 +68,10 @@ class ThreadPlanPython : public ThreadPlan {
7368
bool m_stop_others;
7469
lldb::ScriptedThreadPlanInterfaceSP m_interface;
7570

76-
ThreadPlanPython(const ThreadPlanPython &) = delete;
77-
const ThreadPlanPython &operator=(const ThreadPlanPython &) = delete;
71+
ScriptedThreadPlan(const ScriptedThreadPlan &) = delete;
72+
const ScriptedThreadPlan &operator=(const ScriptedThreadPlan &) = delete;
7873
};
7974

8075
} // namespace lldb_private
8176

82-
#endif // LLDB_TARGET_THREADPLANPYTHON_H
77+
#endif // LLDB_TARGET_SCRIPTEDTHREADPLAN_H

lldb/include/lldb/lldb-private-interfaces.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Value;
2525
} // namespace llvm
2626

2727
namespace lldb_private {
28+
class ScriptedInterfaceUsages;
2829
typedef lldb::ABISP (*ABICreateInstance)(lldb::ProcessSP process_sp,
2930
const ArchSpec &arch);
3031
typedef std::unique_ptr<Architecture> (*ArchitectureCreateInstance)(
@@ -125,6 +126,8 @@ typedef lldb::REPLSP (*REPLCreateInstance)(Status &error,
125126
lldb::LanguageType language,
126127
Debugger *debugger, Target *target,
127128
const char *repl_options);
129+
typedef bool (*ScriptedInterfaceCreateInstance)(lldb::ScriptLanguage language,
130+
ScriptedInterfaceUsages usages);
128131
typedef int (*ComparisonFunction)(const void *, const void *);
129132
typedef void (*DebuggerInitializeCallback)(Debugger &debugger);
130133
/// Trace

lldb/source/API/SBStructuredData.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ lldb::SBError SBStructuredData::SetFromJSON(lldb::SBStream &stream) {
8686
StructuredData::ParseJSON(stream.GetData());
8787
m_impl_up->SetObjectSP(json_obj);
8888

89-
if (!json_obj || json_obj->GetType() != eStructuredDataTypeDictionary)
89+
static constexpr StructuredDataType unsupported_type[] = {
90+
eStructuredDataTypeInvalid,
91+
eStructuredDataTypeGeneric,
92+
};
93+
94+
if (!json_obj || llvm::is_contained(unsupported_type, json_obj->GetType()))
9095
error.SetErrorString("Invalid Syntax");
9196
return error;
9297
}

lldb/source/API/SBThreadPlan.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
#include "lldb/Symbol/SymbolContext.h"
2222
#include "lldb/Target/Process.h"
2323
#include "lldb/Target/Queue.h"
24+
#include "lldb/Target/ScriptedThreadPlan.h"
2425
#include "lldb/Target/StopInfo.h"
2526
#include "lldb/Target/SystemRuntime.h"
2627
#include "lldb/Target/Target.h"
2728
#include "lldb/Target/Thread.h"
2829
#include "lldb/Target/ThreadPlan.h"
29-
#include "lldb/Target/ThreadPlanPython.h"
3030
#include "lldb/Target/ThreadPlanStepInRange.h"
3131
#include "lldb/Target/ThreadPlanStepInstruction.h"
3232
#include "lldb/Target/ThreadPlanStepOut.h"
@@ -66,8 +66,8 @@ SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) {
6666

6767
Thread *thread = sb_thread.get();
6868
if (thread)
69-
m_opaque_wp = std::make_shared<ThreadPlanPython>(*thread, class_name,
70-
StructuredDataImpl());
69+
m_opaque_wp = std::make_shared<ScriptedThreadPlan>(*thread, class_name,
70+
StructuredDataImpl());
7171
}
7272

7373
SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name,
@@ -76,8 +76,8 @@ SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name,
7676

7777
Thread *thread = sb_thread.get();
7878
if (thread)
79-
m_opaque_wp = std::make_shared<ThreadPlanPython>(*thread, class_name,
80-
*args_data.m_impl_up);
79+
m_opaque_wp = std::make_shared<ScriptedThreadPlan>(*thread, class_name,
80+
*args_data.m_impl_up);
8181
}
8282

8383
// Assignment operator

lldb/source/Commands/CommandObjectCommands.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,13 @@ rather than using a positional placeholder:"
322322
323323
(lldb) command alias bl3 breakpoint set -f %1 -l 3
324324
325-
Always sets a breakpoint on line 3 of whatever file is indicated.)");
325+
Always sets a breakpoint on line 3 of whatever file is indicated.
326+
327+
)"
328+
329+
"If the alias abbreviation or the full alias command collides with another \
330+
existing command, the command resolver will prefer to use the alias over any \
331+
other command as far as there is only one alias command match.");
326332

327333
CommandArgumentEntry arg1;
328334
CommandArgumentEntry arg2;

0 commit comments

Comments
 (0)