Skip to content

Commit 8bef2f2

Browse files
[lldb-dap] Add a CMake variable for defining a welcome message (#78811)
lldb-dap instances managed by other extensions benefit from having a welcome message with, for example, a basic user guide or a troubleshooting message. This PR adds a cmake variable for defining such message in a simple way. This message appears upon initialization but before initCommands are executed, as they might cause a failure and prevent the message from being displayed.
1 parent c17aa14 commit 8bef2f2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ add_lldb_tool(lldb-dap
4646
Support
4747
)
4848

49+
if(LLDB_DAP_WELCOME_MESSAGE)
50+
target_compile_definitions(lldb-dap
51+
PRIVATE
52+
-DLLDB_DAP_WELCOME_MESSAGE=\"${LLDB_DAP_WELCOME_MESSAGE}\")
53+
endif()
54+
4955
if(LLDB_BUILD_FRAMEWORK)
5056
# In the build-tree, we know the exact path to the framework directory.
5157
# The installed framework can be in different locations.

lldb/tools/lldb-dap/lldb-dap.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ typedef void (*RequestCallback)(const llvm::json::Object &command);
108108

109109
enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };
110110

111+
/// Prints a welcome message on the editor if the preprocessor variable
112+
/// LLDB_DAP_WELCOME_MESSAGE is defined.
113+
static void PrintWelcomeMessage() {
114+
#ifdef LLDB_DAP_WELCOME_MESSAGE
115+
g_dap.SendOutput(OutputType::Console, LLDB_DAP_WELCOME_MESSAGE);
116+
#endif
117+
}
118+
111119
lldb::SBValueList *GetTopLevelScope(int64_t variablesReference) {
112120
switch (variablesReference) {
113121
case VARREF_LOCALS:
@@ -657,6 +665,8 @@ void request_attach(const llvm::json::Object &request) {
657665
g_dap.SetFrameFormat(GetString(arguments, "customFrameFormat"));
658666
g_dap.SetThreadFormat(GetString(arguments, "customThreadFormat"));
659667

668+
PrintWelcomeMessage();
669+
660670
// This is a hack for loading DWARF in .o files on Mac where the .o files
661671
// in the debug map of the main executable have relative paths which require
662672
// the lldb-dap binary to have its working directory set to that relative
@@ -666,7 +676,7 @@ void request_attach(const llvm::json::Object &request) {
666676

667677
// Run any initialize LLDB commands the user specified in the launch.json
668678
if (llvm::Error err = g_dap.RunInitCommands()) {
669-
response["success"] = false;
679+
kkkk response["success"] = false;
670680
EmplaceSafeString(response, "message", llvm::toString(std::move(err)));
671681
g_dap.SendJSON(llvm::json::Value(std::move(response)));
672682
return;
@@ -1838,10 +1848,12 @@ void request_launch(const llvm::json::Object &request) {
18381848
g_dap.SetFrameFormat(GetString(arguments, "customFrameFormat"));
18391849
g_dap.SetThreadFormat(GetString(arguments, "customThreadFormat"));
18401850

1851+
PrintWelcomeMessage();
1852+
18411853
// This is a hack for loading DWARF in .o files on Mac where the .o files
1842-
// in the debug map of the main executable have relative paths which require
1843-
// the lldb-dap binary to have its working directory set to that relative
1844-
// root for the .o files in order to be able to load debug info.
1854+
// in the debug map of the main executable have relative paths which
1855+
// require the lldb-dap binary to have its working directory set to that
1856+
// relative root for the .o files in order to be able to load debug info.
18451857
if (!debuggerRoot.empty())
18461858
llvm::sys::fs::set_current_path(debuggerRoot);
18471859

0 commit comments

Comments
 (0)