LLDB mainline
IOHandler.cpp
Go to the documentation of this file.
1//===-- IOHandler.cpp -----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11#if defined(__APPLE__)
12#include <deque>
13#endif
14#include <string>
15
16#include "lldb/Core/Debugger.h"
17#include "lldb/Host/Config.h"
18#include "lldb/Host/File.h"
22#include "lldb/Utility/Status.h"
25#include "lldb/lldb-forward.h"
26
27#if LLDB_ENABLE_LIBEDIT
28#include "lldb/Host/Editline.h"
29#endif
32#include "llvm/ADT/StringRef.h"
33
34#ifdef _WIN32
36#endif
37
38#include <memory>
39#include <mutex>
40#include <optional>
41
42#include <cassert>
43#include <cctype>
44#include <cerrno>
45#include <clocale>
46#include <cstdint>
47#include <cstdio>
48#include <cstring>
49#include <type_traits>
50
51using namespace lldb;
52using namespace lldb_private;
53using llvm::StringRef;
54
56 : IOHandler(debugger, type,
57 FileSP(), // Adopt STDIN from top input reader
58 LockableStreamFileSP(), // Adopt STDOUT from top input reader
59 LockableStreamFileSP(), // Adopt STDERR from top input reader
60 0 // Flags
61
62 ) {}
63
65 const lldb::FileSP &input_sp,
66 const lldb::LockableStreamFileSP &output_sp,
67 const lldb::LockableStreamFileSP &error_sp, uint32_t flags)
68 : m_debugger(debugger), m_input_sp(input_sp), m_output_sp(output_sp),
69 m_error_sp(error_sp), m_popped(false), m_flags(flags), m_type(type),
70 m_user_data(nullptr), m_done(false), m_active(false) {
71 // If any files are not specified, then adopt them from the top input reader.
75}
76
77IOHandler::~IOHandler() = default;
78
80 return (m_input_sp ? m_input_sp->GetDescriptor() : -1);
81}
82
84 return (m_output_sp ? m_output_sp->GetUnlockedFile().GetDescriptor() : -1);
85}
86
88 return (m_error_sp ? m_error_sp->GetUnlockedFile().GetDescriptor() : -1);
89}
90
92
94
96
98 return GetInputFileSP() ? GetInputFileSP()->GetIsInteractive() : false;
99}
100
102 return GetInputFileSP() ? GetInputFileSP()->GetIsRealTerminal() : false;
103}
104
106
107void IOHandler::WaitForPop() { m_popped.WaitForValueEqualTo(true); }
108
109void IOHandler::PrintAsync(const char *s, size_t len, bool is_stdout) {
110 lldb::LockableStreamFileSP stream_sp = is_stdout ? m_output_sp : m_error_sp;
111 LockedStreamFile locked_Stream = stream_sp->Lock();
112 locked_Stream.Write(s, len);
113}
114
115bool IOHandlerStack::PrintAsync(const char *s, size_t len, bool is_stdout) {
116 std::lock_guard<std::recursive_mutex> guard(m_mutex);
117 if (!m_top)
118 return false;
119 m_top->PrintAsync(s, len, is_stdout);
120 return true;
121}
122
123IOHandlerConfirm::IOHandlerConfirm(Debugger &debugger, llvm::StringRef prompt,
124 bool default_response)
126 debugger, IOHandler::Type::Confirm,
127 nullptr, // nullptr editline_name means no history loaded/saved
128 llvm::StringRef(), // No prompt
129 llvm::StringRef(), // No continuation prompt
130 false, // Multi-line
131 false, // Don't colorize the prompt (i.e. the confirm message.)
132 0, *this),
133 m_default_response(default_response), m_user_response(default_response) {
134 StreamString prompt_stream;
135 prompt_stream.PutCString(prompt);
137 prompt_stream.PutCString(": [Y/n] ");
138 else
139 prompt_stream.PutCString(": [y/N] ");
140
141 SetPrompt(prompt_stream.GetString());
142}
143
145
147 CompletionRequest &request) {
148 if (request.GetRawCursorPos() != 0)
149 return;
150 request.AddCompletion(m_default_response ? "y" : "n");
151}
152
154 std::string &line) {
155 const llvm::StringRef input = llvm::StringRef(line).rtrim();
156 if (input.empty()) {
157 // User just hit enter, set the response to the default
159 io_handler.SetIsDone(true);
160 return;
161 }
162
163 if (input.size() == 1) {
164 switch (input[0]) {
165 case 'y':
166 case 'Y':
167 m_user_response = true;
168 io_handler.SetIsDone(true);
169 return;
170 case 'n':
171 case 'N':
172 m_user_response = false;
173 io_handler.SetIsDone(true);
174 return;
175 default:
176 break;
177 }
178 }
179
180 if (input.equals_insensitive("yes")) {
181 m_user_response = true;
182 io_handler.SetIsDone(true);
183 } else if (input.equals_insensitive("no")) {
184 m_user_response = false;
185 io_handler.SetIsDone(true);
186 }
187}
188
189std::optional<std::string>
191 llvm::StringRef line) {
192 return io_handler.GetDebugger()
195}
196
198 CompletionRequest &request) {
199 switch (m_completion) {
200 case Completion::None:
201 break;
203 io_handler.GetDebugger().GetCommandInterpreter().HandleCompletion(request);
204 break;
207 io_handler.GetDebugger().GetCommandInterpreter(),
208 lldb::eVariablePathCompletion, request, nullptr);
209 break;
210 }
211}
212
214 Debugger &debugger, IOHandler::Type type,
215 const char *editline_name, // Used for saving history files
216 llvm::StringRef prompt, llvm::StringRef continuation_prompt,
217 bool multi_line, bool color, uint32_t line_number_start,
218 IOHandlerDelegate &delegate)
220 debugger, type,
221 FileSP(), // Inherit input from top input reader
222 LockableStreamFileSP(), // Inherit output from top input reader
223 LockableStreamFileSP(), // Inherit error from top input reader
224 0, // Flags
225 editline_name, // Used for saving history files
226 prompt, continuation_prompt, multi_line, color, line_number_start,
227 delegate) {}
228
230 Debugger &debugger, IOHandler::Type type, const lldb::FileSP &input_sp,
231 const lldb::LockableStreamFileSP &output_sp,
232 const lldb::LockableStreamFileSP &error_sp, uint32_t flags,
233 const char *editline_name, // Used for saving history files
234 llvm::StringRef prompt, llvm::StringRef continuation_prompt,
235 bool multi_line, bool color, uint32_t line_number_start,
236 IOHandlerDelegate &delegate)
237 : IOHandler(debugger, type, input_sp, output_sp, error_sp, flags),
238#if LLDB_ENABLE_LIBEDIT
239 m_editline_up(),
240#endif
242 m_current_lines_ptr(nullptr), m_base_line_number(line_number_start),
243 m_curr_line_idx(UINT32_MAX), m_multi_line(multi_line), m_color(color),
244 m_interrupt_exits(true) {
245 SetPrompt(prompt);
246
247#if LLDB_ENABLE_LIBEDIT
248 // To use Editline, we need an input, output, and error stream. Not all valid
249 // files will have a FILE* stream. Don't use Editline if the input is not a
250 // real terminal.
251 const bool use_editline =
252 m_input_sp && m_input_sp->GetIsRealTerminal() && // Input
253 m_output_sp && m_output_sp->GetUnlockedFile().GetStream() && // Output
254 m_error_sp && m_error_sp->GetUnlockedFile().GetStream(); // Error
255 if (use_editline) {
256 m_editline_up = std::make_unique<Editline>(
257 editline_name, m_input_sp ? m_input_sp->GetStream() : nullptr,
259 m_editline_up->SetIsInputCompleteCallback(
260 [this](Editline *editline, StringList &lines) {
261 return this->IsInputCompleteCallback(editline, lines);
262 });
263
264 m_editline_up->SetAutoCompleteCallback([this](CompletionRequest &request) {
265 this->AutoCompleteCallback(request);
266 });
267 m_editline_up->SetRedrawCallback([this]() { this->RedrawCallback(); });
268
269 if (debugger.GetAutosuggestionMode() != eAutosuggestionOff) {
270 m_editline_up->SetSuggestionCallback([this](llvm::StringRef line) {
271 return this->SuggestionCallback(line);
272 });
273 m_editline_up->SetSuggestionAnsiPrefix(ansi::FormatAnsiTerminalCodes(
274 debugger.GetAutosuggestionAnsiPrefix()));
275 m_editline_up->SetSuggestionAnsiSuffix(ansi::FormatAnsiTerminalCodes(
276 debugger.GetAutosuggestionAnsiSuffix()));
277 }
278 // See if the delegate supports fixing indentation
279 const char *indent_chars = delegate.IOHandlerGetFixIndentationCharacters();
280 if (indent_chars) {
281 // The delegate does support indentation, hook it up so when any
282 // indentation character is typed, the delegate gets a chance to fix it
283 FixIndentationCallbackType f = [this](Editline *editline,
284 const StringList &lines,
285 int cursor_position) {
286 return this->FixIndentationCallback(editline, lines, cursor_position);
287 };
288 m_editline_up->SetFixIndentationCallback(std::move(f), indent_chars);
289 }
290 }
291#endif
293 SetPrompt(prompt);
294 SetContinuationPrompt(continuation_prompt);
295}
296
298#if LLDB_ENABLE_LIBEDIT
299 m_editline_up.reset();
300#endif
301}
302
305 m_delegate.IOHandlerActivated(*this, GetIsInteractive());
306}
307
310 m_delegate.IOHandlerDeactivated(*this);
311}
312
314#if LLDB_ENABLE_LIBEDIT
315 if (m_editline_up)
316 m_editline_up->TerminalSizeChanged();
317#endif
318}
319
320// Split out a line from the buffer, if there is a full one to get.
321static std::optional<std::string> SplitLine(std::string &line_buffer) {
322 size_t pos = line_buffer.find('\n');
323 if (pos == std::string::npos)
324 return std::nullopt;
325 std::string line =
326 std::string(StringRef(line_buffer.c_str(), pos).rtrim("\n\r"));
327 line_buffer = line_buffer.substr(pos + 1);
328 return line;
329}
330
331// If the final line of the file ends without a end-of-line, return
332// it as a line anyway.
333static std::optional<std::string> SplitLineEOF(std::string &line_buffer) {
334 if (llvm::all_of(line_buffer, llvm::isSpace))
335 return std::nullopt;
336 std::string line = std::move(line_buffer);
337 line_buffer.clear();
338 return line;
339}
340
341bool IOHandlerEditline::GetLine(std::string &line, bool &interrupted) {
342#if LLDB_ENABLE_LIBEDIT
343 if (m_editline_up) {
344 return m_editline_up->GetLine(line, interrupted);
345 }
346#endif
347
348 line.clear();
349
350 if (GetIsInteractive()) {
351 const char *prompt = nullptr;
352
353 if (m_multi_line && m_curr_line_idx > 0)
354 prompt = GetContinuationPrompt();
355
356 if (prompt == nullptr)
357 prompt = GetPrompt();
358
359 if (prompt && prompt[0]) {
360 if (m_output_sp) {
361 LockedStreamFile locked_stream = m_output_sp->Lock();
362 locked_stream.PutCString(prompt);
363 }
364 }
365 }
366
367 std::optional<std::string> got_line = SplitLine(m_line_buffer);
368
369 if (!got_line && !m_input_sp) {
370 // No more input file, we are done...
371 SetIsDone(true);
372 return false;
373 }
374
375 FILE *in = m_input_sp ? m_input_sp->GetStream() : nullptr;
376 char buffer[256];
377
378 if (!got_line && !in && m_input_sp) {
379 // there is no FILE*, fall back on just reading bytes from the stream.
380 while (!got_line) {
381 size_t bytes_read = sizeof(buffer);
382 Status error = m_input_sp->Read((void *)buffer, bytes_read);
383 if (error.Success() && !bytes_read) {
384 got_line = SplitLineEOF(m_line_buffer);
385 break;
386 }
387 if (error.Fail())
388 break;
389 m_line_buffer += StringRef(buffer, bytes_read);
390 got_line = SplitLine(m_line_buffer);
391 }
392 }
393
394 if (!got_line && in) {
395 while (!got_line) {
396 char *r = fgets(buffer, sizeof(buffer), in);
397 if (r == nullptr) {
398 if (feof(in)) {
399 got_line = SplitLineEOF(m_line_buffer);
400 break;
401 }
402 if (ferror(in) && errno == EINTR)
403 continue;
404#ifdef _WIN32
405 // ReadFile on Windows is supposed to set ERROR_OPERATION_ABORTED
406 // according to the docs on MSDN. However, this has evidently been a
407 // known bug since Windows 8. Therefore, we can't detect if a signal
408 // interrupted in the fgets. So pressing ctrl-c causes the repl to end
409 // and the process to exit. A temporary workaround is just to attempt
410 // to fgets twice until this bug is fixed.
411 if (GetLastError() == ERROR_OPERATION_ABORTED) {
412 clearerr(in);
413 continue;
414 }
415#endif
416 break;
417 }
418 m_line_buffer += buffer;
419 got_line = SplitLine(m_line_buffer);
420 }
421 }
422
423 if (got_line) {
424 line = *got_line;
425 }
426
427 return (bool)got_line;
428}
429
430#if LLDB_ENABLE_LIBEDIT
431bool IOHandlerEditline::IsInputCompleteCallback(Editline *editline,
432 StringList &lines) {
433 return m_delegate.IOHandlerIsInputComplete(*this, lines);
434}
435
436int IOHandlerEditline::FixIndentationCallback(Editline *editline,
437 const StringList &lines,
438 int cursor_position) {
439 return m_delegate.IOHandlerFixIndentation(*this, lines, cursor_position);
440}
441
442std::optional<std::string>
443IOHandlerEditline::SuggestionCallback(llvm::StringRef line) {
444 // In tab-mode, we just display what tab would complete if the user
445 // would tab.
446 if (m_debugger.GetAutosuggestionMode() == eAutosuggestionTabMode) {
447 CompletionResult result;
448 CompletionRequest request(line, line.size(), result);
449 m_delegate.IOHandlerComplete(*this, request);
450 StringList matches;
451 result.GetMatches(matches);
452 std::string longest_prefix = matches.LongestCommonPrefix();
453 llvm::StringRef cursor_arg_prefix = request.GetCursorArgumentPrefix();
454 if (longest_prefix.size() > cursor_arg_prefix.size())
455 return longest_prefix.substr(cursor_arg_prefix.size());
456 return std::nullopt;
457 }
458 return m_delegate.IOHandlerSuggestion(*this, line);
459}
460
461void IOHandlerEditline::AutoCompleteCallback(CompletionRequest &request) {
462 m_delegate.IOHandlerComplete(*this, request);
463}
464
465void IOHandlerEditline::RedrawCallback() {
466 m_debugger.RedrawStatusline(std::nullopt);
467}
468
469#endif
470
472#if LLDB_ENABLE_LIBEDIT
473 if (m_editline_up) {
474 return m_editline_up->GetPrompt();
475 } else {
476#endif
477 if (m_prompt.empty())
478 return nullptr;
479#if LLDB_ENABLE_LIBEDIT
480 }
481#endif
482 return m_prompt.c_str();
483}
484
485bool IOHandlerEditline::SetPrompt(llvm::StringRef prompt) {
486 m_prompt = std::string(prompt);
487
488#if LLDB_ENABLE_LIBEDIT
489 if (m_editline_up) {
490 m_editline_up->SetPrompt(m_prompt.empty() ? nullptr : m_prompt.c_str());
491 m_editline_up->SetPromptAnsiPrefix(
492 ansi::FormatAnsiTerminalCodes(m_debugger.GetPromptAnsiPrefix()));
493 m_editline_up->SetPromptAnsiSuffix(
494 ansi::FormatAnsiTerminalCodes(m_debugger.GetPromptAnsiSuffix()));
495 }
496#endif
497 return true;
498}
499
500bool IOHandlerEditline::SetUseColor(bool use_color) {
501 m_color = use_color;
502
503#if LLDB_ENABLE_LIBEDIT
504 if (m_editline_up) {
505 m_editline_up->UseColor(use_color);
506 m_editline_up->SetSuggestionAnsiPrefix(ansi::FormatAnsiTerminalCodes(
507 m_debugger.GetAutosuggestionAnsiPrefix()));
508 m_editline_up->SetSuggestionAnsiSuffix(ansi::FormatAnsiTerminalCodes(
509 m_debugger.GetAutosuggestionAnsiSuffix()));
510 }
511#endif
512 return true;
513}
514
516 return (m_continuation_prompt.empty() ? nullptr
517 : m_continuation_prompt.c_str());
518}
519
520void IOHandlerEditline::SetContinuationPrompt(llvm::StringRef prompt) {
521 m_continuation_prompt = std::string(prompt);
522
523#if LLDB_ENABLE_LIBEDIT
524 if (m_editline_up)
525 m_editline_up->SetContinuationPrompt(m_continuation_prompt.empty()
526 ? nullptr
527 : m_continuation_prompt.c_str());
528#endif
529}
530
532 m_base_line_number = line;
533}
534
536#if LLDB_ENABLE_LIBEDIT
537 if (m_editline_up)
538 return m_editline_up->GetCurrentLine();
539#endif
540 return m_curr_line_idx;
541}
542
544#if LLDB_ENABLE_LIBEDIT
545 if (m_editline_up)
546 return m_editline_up->GetInputAsStringList();
547#endif
548 // When libedit is not used, the current lines can be gotten from
549 // `m_current_lines_ptr`, which is updated whenever a new line is processed.
550 // This doesn't happen when libedit is used, in which case
551 // `m_current_lines_ptr` is only updated when the full input is terminated.
552
554 return *m_current_lines_ptr;
555 return StringList();
556}
557
558bool IOHandlerEditline::GetLines(StringList &lines, bool &interrupted) {
559 m_current_lines_ptr = &lines;
560
561 bool success = false;
562#if LLDB_ENABLE_LIBEDIT
563 if (m_editline_up) {
564 return m_editline_up->GetLines(m_base_line_number, lines, interrupted);
565 } else {
566#endif
567 bool done = false;
569
570 while (!done) {
571 // Show line numbers if we are asked to
572 std::string line;
574 if (m_output_sp) {
575 LockedStreamFile locked_stream = m_output_sp->Lock();
576 locked_stream.Printf("%u%s",
577 m_base_line_number + (uint32_t)lines.GetSize(),
578 GetPrompt() == nullptr ? " " : "");
579 }
580 }
581
582 m_curr_line_idx = lines.GetSize();
583
584 bool interrupted = false;
585 if (GetLine(line, interrupted) && !interrupted) {
586 lines.AppendString(line);
587 done = m_delegate.IOHandlerIsInputComplete(*this, lines);
588 } else {
589 done = true;
590 }
591 }
592 success = lines.GetSize() > 0;
593#if LLDB_ENABLE_LIBEDIT
594 }
595#endif
596 return success;
597}
598
599// Each IOHandler gets to run until it is done. It should read data from the
600// "in" and place output into "out" and "err and return when done.
602 std::string line;
603 while (IsActive()) {
604 bool interrupted = false;
605 if (m_multi_line) {
606 StringList lines;
607 if (GetLines(lines, interrupted)) {
608 if (interrupted) {
610 m_delegate.IOHandlerInputInterrupted(*this, line);
611
612 } else {
613 line = lines.CopyList();
614 m_delegate.IOHandlerInputComplete(*this, line);
615 }
616 } else {
617 m_done = true;
618 }
619 } else {
620 if (GetLine(line, interrupted)) {
621 if (interrupted)
622 m_delegate.IOHandlerInputInterrupted(*this, line);
623 else
624 m_delegate.IOHandlerInputComplete(*this, line);
625 } else {
626 m_done = true;
627 }
628 }
629 }
630}
631
633#if LLDB_ENABLE_LIBEDIT
634 if (m_editline_up)
635 m_editline_up->Cancel();
636#endif
637}
638
640 // Let the delgate handle it first
641 if (m_delegate.IOHandlerInterrupt(*this))
642 return true;
643
644#if LLDB_ENABLE_LIBEDIT
645 if (m_editline_up)
646 return m_editline_up->Interrupt();
647#endif
648 return false;
649}
650
652#if LLDB_ENABLE_LIBEDIT
653 if (m_editline_up)
654 m_editline_up->Interrupt();
655#endif
656}
657
658void IOHandlerEditline::PrintAsync(const char *s, size_t len, bool is_stdout) {
659#if LLDB_ENABLE_LIBEDIT
660 if (m_editline_up) {
661 lldb::LockableStreamFileSP stream_sp = is_stdout ? m_output_sp : m_error_sp;
662 m_editline_up->PrintAsync(stream_sp, s, len);
663 } else
664#endif
665 {
666#ifdef _WIN32
667 const char *prompt = GetPrompt();
668 if (prompt) {
669 // Back up over previous prompt using Windows API
670 CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
671 HANDLE console_handle = GetStdHandle(STD_OUTPUT_HANDLE);
672 GetConsoleScreenBufferInfo(console_handle, &screen_buffer_info);
673 COORD coord = screen_buffer_info.dwCursorPosition;
674 coord.X -= strlen(prompt);
675 if (coord.X < 0)
676 coord.X = 0;
677 SetConsoleCursorPosition(console_handle, coord);
678 }
679#endif
680 IOHandler::PrintAsync(s, len, is_stdout);
681#ifdef _WIN32
682 if (prompt)
683 IOHandler::PrintAsync(prompt, strlen(prompt), is_stdout);
684#endif
685 }
686}
687
689#if LLDB_ENABLE_LIBEDIT
690 if (m_editline_up)
691 m_editline_up->Refresh();
692#endif
693}
static llvm::raw_ostream & error(Stream &strm)
static std::optional< std::string > SplitLine(std::string &line_buffer)
static std::optional< std::string > SplitLineEOF(std::string &line_buffer)
void * HANDLE
static bool InvokeCommonCompletionCallbacks(CommandInterpreter &interpreter, uint32_t completion_mask, lldb_private::CompletionRequest &request, SearchFilter *searcher)
std::optional< std::string > GetAutoSuggestionForCommand(llvm::StringRef line)
Returns the auto-suggestion string that should be added to the given command line.
void HandleCompletion(CompletionRequest &request)
"lldb/Utility/ArgCompletionRequest.h"
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
void GetMatches(StringList &matches) const
Adds all collected completion matches to the given list.
A class to manage flag bits.
Definition Debugger.h:100
llvm::StringRef GetAutosuggestionAnsiPrefix() const
Definition Debugger.cpp:631
CommandInterpreter & GetCommandInterpreter()
Definition Debugger.h:182
llvm::StringRef GetAutosuggestionAnsiSuffix() const
Definition Debugger.cpp:637
AutosuggestionMode GetAutosuggestionMode() const
Definition Debugger.cpp:624
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in, lldb::LockableStreamFileSP &out, lldb::LockableStreamFileSP &err)
Instances of Editline provide an abstraction over libedit's EditLine facility.
Definition Editline.h:155
IOHandlerConfirm(Debugger &debugger, llvm::StringRef prompt, bool default_response)
void IOHandlerInputComplete(IOHandler &io_handler, std::string &data) override
Called when a line or lines have been retrieved.
void IOHandlerComplete(IOHandler &io_handler, CompletionRequest &request) override
A delegate class for use with IOHandler subclasses.
Definition IOHandler.h:184
virtual void IOHandlerComplete(IOHandler &io_handler, CompletionRequest &request)
virtual const char * IOHandlerGetFixIndentationCharacters()
Definition IOHandler.h:203
virtual bool IOHandlerIsInputComplete(IOHandler &io_handler, StringList &lines)
Called to determine whether typing enter after the last line in lines should end input.
Definition IOHandler.h:260
virtual std::optional< std::string > IOHandlerSuggestion(IOHandler &io_handler, llvm::StringRef line)
virtual int IOHandlerFixIndentation(IOHandler &io_handler, const StringList &lines, int cursor_position)
Called when a new line is created or one of an identified set of indentation characters is typed.
Definition IOHandler.h:227
void PrintAsync(const char *s, size_t len, bool is_stdout) override
bool SetPrompt(llvm::StringRef prompt) override
bool GetLine(std::string &line, bool &interrupted)
void TerminalSizeChanged() override
bool GetLines(StringList &lines, bool &interrupted)
void SetBaseLineNumber(uint32_t line)
IOHandlerEditline(Debugger &debugger, IOHandler::Type type, const char *editline_name, llvm::StringRef prompt, llvm::StringRef continuation_prompt, bool multi_line, bool color, uint32_t line_number_start, IOHandlerDelegate &delegate)
void SetContinuationPrompt(llvm::StringRef prompt)
IOHandlerDelegate & m_delegate
Definition IOHandler.h:429
bool SetUseColor(bool use_color) override
const char * GetPrompt() override
uint32_t GetCurrentLineIndex() const
StringList GetCurrentLines() const
bool PrintAsync(const char *s, size_t len, bool is_stdout)
std::recursive_mutex m_mutex
Definition IOHandler.h:542
virtual void PrintAsync(const char *s, size_t len, bool is_stdout)
Predicate< bool > m_popped
Definition IOHandler.h:166
virtual void Activate()
Definition IOHandler.h:87
bool GetIsRealTerminal()
Check if the input is coming from a real terminal.
lldb::FileSP GetInputFileSP()
Definition IOHandler.cpp:91
Debugger & GetDebugger()
Definition IOHandler.h:130
virtual void Deactivate()
Definition IOHandler.h:89
lldb::LockableStreamFileSP m_output_sp
Definition IOHandler.h:164
lldb::LockableStreamFileSP m_error_sp
Definition IOHandler.h:165
IOHandler(Debugger &debugger, IOHandler::Type type)
Definition IOHandler.cpp:55
bool GetIsInteractive()
Check if the input is being supplied interactively by a user.
Definition IOHandler.cpp:97
lldb::FileSP m_input_sp
Definition IOHandler.h:163
lldb::LockableStreamFileSP GetErrorStreamFileSP()
Definition IOHandler.cpp:95
lldb::LockableStreamFileSP GetOutputStreamFileSP()
Definition IOHandler.cpp:93
void SetIsDone(bool b)
Definition IOHandler.h:81
An error handling class.
Definition Status.h:118
llvm::StringRef GetString() const
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition Stream.h:111
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
std::string CopyList(const char *item_preamble=nullptr, const char *items_sep="\n") const
void AppendString(const std::string &s)
std::string LongestCommonPrefix()
#define UINT32_MAX
std::string FormatAnsiTerminalCodes(llvm::StringRef format, bool do_color=true)
llvm::unique_function< int(Editline *, StringList &, int)> FixIndentationCallbackType
Definition Editline.h:97
A class that represents a running process on the host machine.
@ eBroadcastOnChange
Only broadcast if the value changes when the value is modified.
Definition Predicate.h:30
@ eAutosuggestionTabMode
Show the prefix that tab completion would insert for the current line.
@ eAutosuggestionOff
Do not show any autosuggestion.
@ eVariablePathCompletion
std::shared_ptr< lldb_private::LockableStreamFile > LockableStreamFileSP
std::shared_ptr< lldb_private::File > FileSP