Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lldb/tools/lldb-dap/tool/lldb-dap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef int socklen_t;
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <termios.h>
#include <unistd.h>
#endif

Expand Down Expand Up @@ -121,6 +122,15 @@ class LLDBDAPOptTable : public llvm::opt::GenericOptTable {
};
} // anonymous namespace

#define ESCAPE "\x1b"
#define CSI ESCAPE "["
// Move the cursor to 0,0
#define ANSI_CURSOR_HOME CSI "H"
// Clear the screen buffer
#define ANSI_ERASE_SCREEN CSI "2J"
// Clear the scroll back buffer
#define ANSI_ERASE_SCROLLBACK CSI "3J"

static void PrintHelp(LLDBDAPOptTable &table, llvm::StringRef tool_name) {
std::string usage_str = tool_name.str() + " options";
table.printHelp(llvm::outs(), usage_str.c_str(), "LLDB DAP", false);
Expand Down Expand Up @@ -261,6 +271,14 @@ static llvm::Error LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
files.push_back(files.back());
if (llvm::Error err = SetupIORedirection(files))
return err;
} else if ((isatty(STDIN_FILENO) != 0) &&
llvm::StringRef(getenv("TERM")).starts_with_insensitive("xterm")) {
// Clear the screen.
llvm::outs() << ANSI_CURSOR_HOME ANSI_ERASE_SCREEN ANSI_ERASE_SCROLLBACK;
// VSCode will reuse the same terminal for the same debug configuration
// between runs. Clear the input buffer prior to starting the new process so
// prior input is not carried forward to the new debug session.
tcflush(STDIN_FILENO, TCIFLUSH);
}

RunInTerminalLauncherCommChannel comm_channel(comm_file);
Expand Down
Loading