https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/170795
>From 60cb07b17688241060c1c71c97fb1d752774a544 Mon Sep 17 00:00:00 2001 From: John Harrison <[email protected]> Date: Thu, 4 Dec 2025 18:18:53 -0800 Subject: [PATCH 1/2] [lldb-dap] Add an introductory message on startup. This adds an introductory message to try to inform users on how the debug console works and adds a little more information on the current target/process, similiar to the lldb driver. Here is an example of the introduction: ``` To get started with the lldb-dap debug console try "<variable>", "help [<cmd-name>]", or "apropos <search-word>". For more information visit https://github.com/llvm/llvm-project/blob/main/lldb/tools/lldb-dap/README.md Executable binary set to 'a.out' (arm64-apple-macosx15.0.0). Attached to process 1234. ``` We may want to change the URL for more information to a page under lldb.llvm.org but that does not yet exist. --- .../ConfigurationDoneRequestHandler.cpp | 2 ++ .../tools/lldb-dap/Handler/RequestHandler.cpp | 21 +++++++++++++++++++ lldb/tools/lldb-dap/Handler/RequestHandler.h | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/lldb/tools/lldb-dap/Handler/ConfigurationDoneRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/ConfigurationDoneRequestHandler.cpp index 1bfe7b7f6ef5c..5ef44cba4ebcc 100644 --- a/lldb/tools/lldb-dap/Handler/ConfigurationDoneRequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/ConfigurationDoneRequestHandler.cpp @@ -50,6 +50,8 @@ ConfigurationDoneRequestHandler::Run(const ConfigurationDoneArguments &) const { /// lldb-dap specific editor extension. SendExtraCapabilities(dap); + PrintIntroductionMessage(); + // Clients can request a baseline of currently existing threads after // we acknowledge the configurationDone request. // Client requests the baseline of currently existing threads after diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index d67437ad5b3ae..3841db45eae8b 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -17,6 +17,7 @@ #include "RunInTerminal.h" #include "lldb/API/SBDefines.h" #include "lldb/API/SBEnvironment.h" +#include "lldb/API/SBStream.h" #include "llvm/Support/Error.h" #include <mutex> @@ -261,6 +262,26 @@ void BaseRequestHandler::PrintWelcomeMessage() const { #endif } +void BaseRequestHandler::PrintIntroductionMessage() const { + lldb::SBStream msg; + msg.Print("To get started with the lldb-dap debug console try " + "\"<variable>\", \"help [<cmd-name>]\", or \"apropos " + "<search-word>\".\r\nFor more information visit " + "https://github.com/llvm/llvm-project/blob/main/lldb/tools/" + "lldb-dap/README.md\r\n"); + if (dap.target && dap.target.GetExecutable()) { + char path[PATH_MAX] = {0}; + dap.target.GetExecutable().GetPath(path, sizeof(path)); + msg.Printf("Executable binary set to '%s' (%s).\r\n", path, + dap.target.GetTriple()); + } + if (dap.target.GetProcess()) { + msg.Printf("Attached to process %llu.\r\n", + dap.target.GetProcess().GetProcessID()); + } + dap.SendOutput(OutputType::Console, {msg.GetData(), msg.GetSize()}); +} + bool BaseRequestHandler::HasInstructionGranularity( const llvm::json::Object &arguments) const { if (std::optional<llvm::StringRef> value = arguments.getString("granularity")) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.h b/lldb/tools/lldb-dap/Handler/RequestHandler.h index 5d235352b7738..c0b1722d26a9b 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.h +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.h @@ -64,6 +64,10 @@ class BaseRequestHandler { /// LLDB_DAP_WELCOME_MESSAGE is defined. void PrintWelcomeMessage() const; + /// Prints an introduction to the debug console and information about the + /// debug session. + void PrintIntroductionMessage() const; + // Takes a LaunchRequest object and launches the process, also handling // runInTerminal if applicable. It doesn't do any of the additional // initialization and bookkeeping stuff that is needed for `request_launch`. >From 03e2d3b839cdc6a3a41060ae202f9e5abd184512 Mon Sep 17 00:00:00 2001 From: John Harrison <[email protected]> Date: Fri, 5 Dec 2025 13:33:05 -0800 Subject: [PATCH 2/2] Adjusting the message, moving part of it to the PrintWelcomeMessage function and switched to using llvm::raw_ostream instead of lldb::SBStream. --- .../tools/lldb-dap/Handler/RequestHandler.cpp | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp index 3841db45eae8b..512896be564aa 100644 --- a/lldb/tools/lldb-dap/Handler/RequestHandler.cpp +++ b/lldb/tools/lldb-dap/Handler/RequestHandler.cpp @@ -17,8 +17,8 @@ #include "RunInTerminal.h" #include "lldb/API/SBDefines.h" #include "lldb/API/SBEnvironment.h" -#include "lldb/API/SBStream.h" #include "llvm/Support/Error.h" +#include "llvm/Support/raw_ostream.h" #include <mutex> #if !defined(_WIN32) @@ -260,26 +260,48 @@ void BaseRequestHandler::PrintWelcomeMessage() const { #ifdef LLDB_DAP_WELCOME_MESSAGE dap.SendOutput(OutputType::Console, LLDB_DAP_WELCOME_MESSAGE); #endif + + std::string message; + llvm::raw_string_ostream OS(message); + OS << "To get started with the lldb-dap debug console try "; + + switch (dap.repl_mode) { + case ReplMode::Auto: + OS << "\"<variable>\", \"<lldb-cmd>\" or \"help [<cmd-name>]\" for more " + "information.\r\n"; + OS << "Use '" << dap.configuration.commandEscapePrefix + << "' to prefix commands that may conflict with local variables.\r\n"; + break; + case ReplMode::Command: + OS << "\"<lldb-cmd>\" or \"help [<cmd-name>]\" for more information.\r\n"; + break; + case ReplMode::Variable: + OS << "\"<variable>\" or \"" << dap.configuration.commandEscapePrefix + << "help [<cmd-name>]\" for more information.\r\n"; + break; + } + + OS << "For more information visit " + "https://github.com/llvm/llvm-project/blob/main/lldb/tools/" + "lldb-dap/README.md#debug-console\r\n"; + + dap.SendOutput(OutputType::Console, message); } void BaseRequestHandler::PrintIntroductionMessage() const { - lldb::SBStream msg; - msg.Print("To get started with the lldb-dap debug console try " - "\"<variable>\", \"help [<cmd-name>]\", or \"apropos " - "<search-word>\".\r\nFor more information visit " - "https://github.com/llvm/llvm-project/blob/main/lldb/tools/" - "lldb-dap/README.md\r\n"); + std::string msg; + llvm::raw_string_ostream os(msg); if (dap.target && dap.target.GetExecutable()) { char path[PATH_MAX] = {0}; dap.target.GetExecutable().GetPath(path, sizeof(path)); - msg.Printf("Executable binary set to '%s' (%s).\r\n", path, - dap.target.GetTriple()); + os << llvm::formatv("Executable binary set to '{0}' ({1}).\r\n", path, + dap.target.GetTriple()); } if (dap.target.GetProcess()) { - msg.Printf("Attached to process %llu.\r\n", - dap.target.GetProcess().GetProcessID()); + os << llvm::formatv("Attached to process {0}\r\n", + dap.target.GetProcess().GetProcessID()); } - dap.SendOutput(OutputType::Console, {msg.GetData(), msg.GetSize()}); + dap.SendOutput(OutputType::Console, msg); } bool BaseRequestHandler::HasInstructionGranularity( _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
