@@ -17,12 +17,29 @@ namespace lldb_dap {
1717
1818bool RunLLDBCommands (lldb::SBDebugger &debugger, llvm::StringRef prefix,
1919 const llvm::ArrayRef<std::string> &commands,
20- llvm::raw_ostream &strm, bool parse_command_directives) {
20+ llvm::raw_ostream &strm, bool parse_command_directives,
21+ bool echo_commands) {
2122 if (commands.empty ())
2223 return true ;
2324
2425 bool did_print_prefix = false ;
2526
27+ // We only need the prompt when echoing commands.
28+ std::string prompt_string;
29+ if (echo_commands) {
30+ prompt_string = " (lldb) " ;
31+
32+ // Get the current prompt from settings.
33+ if (const lldb::SBStructuredData prompt = debugger.GetSetting (" prompt" )) {
34+ const size_t prompt_length = prompt.GetStringValue (nullptr , 0 );
35+
36+ if (prompt_length != 0 ) {
37+ prompt_string.resize (prompt_length + 1 );
38+ prompt.GetStringValue (prompt_string.data (), prompt_string.length ());
39+ }
40+ }
41+ }
42+
2643 lldb::SBCommandInterpreter interp = debugger.GetCommandInterpreter ();
2744 for (llvm::StringRef command : commands) {
2845 lldb::SBCommandReturnObject result;
@@ -60,7 +77,10 @@ bool RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
6077 strm << prefix << " \n " ;
6178 did_print_prefix = true ;
6279 }
63- strm << " (lldb) " << command << " \n " ;
80+
81+ if (echo_commands)
82+ strm << prompt_string.c_str () << command << ' \n ' ;
83+
6484 auto output_len = result.GetOutputSize ();
6585 if (output_len) {
6686 const char *output = result.GetOutput ();
@@ -81,23 +101,16 @@ bool RunLLDBCommands(lldb::SBDebugger &debugger, llvm::StringRef prefix,
81101std::string RunLLDBCommands (lldb::SBDebugger &debugger, llvm::StringRef prefix,
82102 const llvm::ArrayRef<std::string> &commands,
83103 bool &required_command_failed,
84- bool parse_command_directives) {
104+ bool parse_command_directives, bool echo_commands ) {
85105 required_command_failed = false ;
86106 std::string s;
87107 llvm::raw_string_ostream strm (s);
88- required_command_failed = !RunLLDBCommands (debugger, prefix, commands, strm,
89- parse_command_directives);
108+ required_command_failed =
109+ !RunLLDBCommands (debugger, prefix, commands, strm,
110+ parse_command_directives, echo_commands);
90111 return s;
91112}
92113
93- std::string
94- RunLLDBCommandsVerbatim (lldb::SBDebugger &debugger, llvm::StringRef prefix,
95- const llvm::ArrayRef<std::string> &commands) {
96- bool required_command_failed = false ;
97- return RunLLDBCommands (debugger, prefix, commands, required_command_failed,
98- /* parse_command_directives=*/ false );
99- }
100-
101114bool ThreadHasStopReason (lldb::SBThread &thread) {
102115 switch (thread.GetStopReason ()) {
103116 case lldb::eStopReasonTrace:
0 commit comments