Skip to content

Commit

Permalink
[lldb-dap] Add a CMake variable for defining a welcome message (llvm#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
walter-erquinigo authored Jan 19, 2024
1 parent c17aa14 commit 8bef2f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
6 changes: 6 additions & 0 deletions lldb/tools/lldb-dap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ add_lldb_tool(lldb-dap
Support
)

if(LLDB_DAP_WELCOME_MESSAGE)
target_compile_definitions(lldb-dap
PRIVATE
-DLLDB_DAP_WELCOME_MESSAGE=\"${LLDB_DAP_WELCOME_MESSAGE}\")
endif()

if(LLDB_BUILD_FRAMEWORK)
# In the build-tree, we know the exact path to the framework directory.
# The installed framework can be in different locations.
Expand Down
20 changes: 16 additions & 4 deletions lldb/tools/lldb-dap/lldb-dap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ typedef void (*RequestCallback)(const llvm::json::Object &command);

enum LaunchMethod { Launch, Attach, AttachForSuspendedLaunch };

/// Prints a welcome message on the editor if the preprocessor variable
/// LLDB_DAP_WELCOME_MESSAGE is defined.
static void PrintWelcomeMessage() {
#ifdef LLDB_DAP_WELCOME_MESSAGE
g_dap.SendOutput(OutputType::Console, LLDB_DAP_WELCOME_MESSAGE);
#endif
}

lldb::SBValueList *GetTopLevelScope(int64_t variablesReference) {
switch (variablesReference) {
case VARREF_LOCALS:
Expand Down Expand Up @@ -657,6 +665,8 @@ void request_attach(const llvm::json::Object &request) {
g_dap.SetFrameFormat(GetString(arguments, "customFrameFormat"));
g_dap.SetThreadFormat(GetString(arguments, "customThreadFormat"));

PrintWelcomeMessage();

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

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

PrintWelcomeMessage();

// This is a hack for loading DWARF in .o files on Mac where the .o files
// in the debug map of the main executable have relative paths which require
// the lldb-dap binary to have its working directory set to that relative
// root for the .o files in order to be able to load debug info.
// in the debug map of the main executable have relative paths which
// require the lldb-dap binary to have its working directory set to that
// relative root for the .o files in order to be able to load debug info.
if (!debuggerRoot.empty())
llvm::sys::fs::set_current_path(debuggerRoot);

Expand Down

0 comments on commit 8bef2f2

Please sign in to comment.