Skip to content

Commit 30c69c2

Browse files
authored
Merge pull request #10369 from swiftlang/revert-10368-cherrypick-output-error-stream-locking
Revert "Cherrypick commits to synchronize the debugger output and error stream"
2 parents e52baa8 + a1e84c5 commit 30c69c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+599
-786
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,20 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
132132
void SetAsyncExecution(bool async);
133133

134134
lldb::FileSP GetInputFileSP() { return m_input_file_sp; }
135+
136+
lldb::StreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
137+
138+
lldb::StreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
139+
135140
File &GetInputFile() { return *m_input_file_sp; }
136141

137-
lldb::FileSP GetOutputFileSP() {
138-
return m_output_stream_sp->GetUnlockedFileSP();
139-
}
142+
File &GetOutputFile() { return m_output_stream_sp->GetFile(); }
140143

141-
lldb::FileSP GetErrorFileSP() {
142-
return m_error_stream_sp->GetUnlockedFileSP();
143-
}
144+
File &GetErrorFile() { return m_error_stream_sp->GetFile(); }
145+
146+
StreamFile &GetOutputStream() { return *m_output_stream_sp; }
147+
148+
StreamFile &GetErrorStream() { return *m_error_stream_sp; }
144149

145150
repro::DataRecorder *GetInputRecorder();
146151

@@ -156,9 +161,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
156161

157162
void RestoreInputTerminalState();
158163

159-
lldb::StreamUP GetAsyncOutputStream();
164+
lldb::StreamSP GetAsyncOutputStream();
160165

161-
lldb::StreamUP GetAsyncErrorStream();
166+
lldb::StreamSP GetAsyncErrorStream();
162167

163168
CommandInterpreter &GetCommandInterpreter() {
164169
assert(m_command_interpreter_up.get());
@@ -201,8 +206,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
201206
// If any of the streams are not set, set them to the in/out/err stream of
202207
// the top most input reader to ensure they at least have something
203208
void AdoptTopIOHandlerFilesIfInvalid(lldb::FileSP &in,
204-
lldb::LockableStreamFileSP &out,
205-
lldb::LockableStreamFileSP &err);
209+
lldb::StreamFileSP &out,
210+
lldb::StreamFileSP &err);
206211

207212
/// Run the given IO handler and return immediately.
208213
void RunIOHandlerAsync(const lldb::IOHandlerSP &reader_sp,
@@ -657,14 +662,6 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
657662

658663
void PrintProgress(const ProgressEventData &data);
659664

660-
/// Except for Debugger and IOHandler, GetOutputStreamSP and GetErrorStreamSP
661-
/// should not be used directly. Use GetAsyncOutputStream and
662-
/// GetAsyncErrorStream instead.
663-
/// @{
664-
lldb::LockableStreamFileSP GetOutputStreamSP() { return m_output_stream_sp; }
665-
lldb::LockableStreamFileSP GetErrorStreamSP() { return m_error_stream_sp; }
666-
/// @}
667-
668665
void PushIOHandler(const lldb::IOHandlerSP &reader_sp,
669666
bool cancel_top_handler = true);
670667

@@ -705,9 +702,8 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
705702

706703
// these should never be NULL
707704
lldb::FileSP m_input_file_sp;
708-
lldb::LockableStreamFileSP m_output_stream_sp;
709-
lldb::LockableStreamFileSP m_error_stream_sp;
710-
LockableStreamFile::Mutex m_output_mutex;
705+
lldb::StreamFileSP m_output_stream_sp;
706+
lldb::StreamFileSP m_error_stream_sp;
711707

712708
/// Used for shadowing the input file when capturing a reproducer.
713709
repro::DataRecorder *m_input_recorder;

lldb/include/lldb/Core/IOHandler.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ namespace lldb_private {
3232
class Debugger;
3333
} // namespace lldb_private
3434

35+
namespace curses {
36+
class Application;
37+
typedef std::unique_ptr<Application> ApplicationAP;
38+
} // namespace curses
39+
3540
namespace lldb_private {
3641

3742
class IOHandler {
@@ -53,9 +58,8 @@ class IOHandler {
5358
IOHandler(Debugger &debugger, IOHandler::Type type);
5459

5560
IOHandler(Debugger &debugger, IOHandler::Type type,
56-
const lldb::FileSP &input_sp,
57-
const lldb::LockableStreamFileSP &output_sp,
58-
const lldb::LockableStreamFileSP &error_sp, uint32_t flags);
61+
const lldb::FileSP &input_sp, const lldb::StreamFileSP &output_sp,
62+
const lldb::StreamFileSP &error_sp, uint32_t flags);
5963

6064
virtual ~IOHandler();
6165

@@ -113,11 +117,17 @@ class IOHandler {
113117

114118
int GetErrorFD();
115119

120+
FILE *GetInputFILE();
121+
122+
FILE *GetOutputFILE();
123+
124+
FILE *GetErrorFILE();
125+
116126
lldb::FileSP GetInputFileSP();
117127

118-
lldb::LockableStreamFileSP GetOutputStreamFileSP();
128+
lldb::StreamFileSP GetOutputStreamFileSP();
119129

120-
lldb::LockableStreamFileSP GetErrorStreamFileSP();
130+
lldb::StreamFileSP GetErrorStreamFileSP();
121131

122132
Debugger &GetDebugger() { return m_debugger; }
123133

@@ -150,11 +160,14 @@ class IOHandler {
150160

151161
virtual void PrintAsync(const char *s, size_t len, bool is_stdout);
152162

163+
std::recursive_mutex &GetOutputMutex() { return m_output_mutex; }
164+
153165
protected:
154166
Debugger &m_debugger;
155167
lldb::FileSP m_input_sp;
156-
lldb::LockableStreamFileSP m_output_sp;
157-
lldb::LockableStreamFileSP m_error_sp;
168+
lldb::StreamFileSP m_output_sp;
169+
lldb::StreamFileSP m_error_sp;
170+
std::recursive_mutex m_output_mutex;
158171
Predicate<bool> m_popped;
159172
Flags m_flags;
160173
Type m_type;
@@ -322,8 +335,8 @@ class IOHandlerEditline : public IOHandler {
322335

323336
IOHandlerEditline(Debugger &debugger, IOHandler::Type type,
324337
const lldb::FileSP &input_sp,
325-
const lldb::LockableStreamFileSP &output_sp,
326-
const lldb::LockableStreamFileSP &error_sp, uint32_t flags,
338+
const lldb::StreamFileSP &output_sp,
339+
const lldb::StreamFileSP &error_sp, uint32_t flags,
327340
const char *editline_name, // Used for saving history files
328341
llvm::StringRef prompt, llvm::StringRef continuation_prompt,
329342
bool multi_line, bool color,
@@ -337,10 +350,9 @@ class IOHandlerEditline : public IOHandler {
337350
IOHandlerDelegate &) = delete;
338351

339352
IOHandlerEditline(Debugger &, IOHandler::Type, const lldb::FileSP &,
340-
const lldb::LockableStreamFileSP &,
341-
const lldb::LockableStreamFileSP &, uint32_t, const char *,
342-
const char *, const char *, bool, bool, uint32_t,
343-
IOHandlerDelegate &) = delete;
353+
const lldb::StreamFileSP &, const lldb::StreamFileSP &,
354+
uint32_t, const char *, const char *, const char *, bool,
355+
bool, uint32_t, IOHandlerDelegate &) = delete;
344356

345357
~IOHandlerEditline() override;
346358

lldb/include/lldb/Core/IOHandlerCursesGUI.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
#include "lldb/Core/IOHandler.h"
1313

1414
namespace lldb_private {
15-
namespace curses {
16-
class Application;
17-
} // namespace curses
1815

1916
class IOHandlerCursesGUI : public IOHandler {
2017
public:
@@ -37,7 +34,7 @@ class IOHandlerCursesGUI : public IOHandler {
3734
void TerminalSizeChanged() override;
3835

3936
protected:
40-
std::unique_ptr<curses::Application> m_app_up;
37+
curses::ApplicationAP m_app_ap;
4138
};
4239

4340
} // namespace lldb_private

lldb/include/lldb/Core/StreamAsynchronousIO.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@
1818
namespace lldb_private {
1919
class Debugger;
2020

21-
/// A stream meant for asynchronously printing output. Output is buffered until
22-
/// the stream is flushed or destroyed. Printing is handled by the currently
23-
/// active IOHandler, or the debugger's output or error stream if there is none.
2421
class StreamAsynchronousIO : public Stream {
2522
public:
26-
enum ForSTDOUT : bool {
27-
STDOUT = true,
28-
STDERR = false,
29-
};
30-
31-
StreamAsynchronousIO(Debugger &debugger, ForSTDOUT for_stdout);
23+
StreamAsynchronousIO(Debugger &debugger, bool for_stdout, bool colors);
3224

3325
~StreamAsynchronousIO() override;
3426

@@ -40,7 +32,7 @@ class StreamAsynchronousIO : public Stream {
4032
private:
4133
Debugger &m_debugger;
4234
std::string m_data;
43-
ForSTDOUT m_for_stdout;
35+
bool m_for_stdout;
4436
};
4537

4638
} // namespace lldb_private

lldb/include/lldb/Host/Editline.h

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <sstream>
3535
#include <vector>
3636

37-
#include "lldb/Host/StreamFile.h"
3837
#include "lldb/lldb-private.h"
3938

4039
#if !defined(_WIN32) && !defined(__ANDROID__)
@@ -152,9 +151,8 @@ using namespace line_editor;
152151
/// facility. Both single- and multi-line editing are supported.
153152
class Editline {
154153
public:
155-
Editline(const char *editor_name, FILE *input_file,
156-
lldb::LockableStreamFileSP output_stream_sp,
157-
lldb::LockableStreamFileSP error_stream_sp, bool color);
154+
Editline(const char *editor_name, FILE *input_file, FILE *output_file,
155+
FILE *error_file, std::recursive_mutex &output_mutex);
158156

159157
~Editline();
160158

@@ -214,23 +212,19 @@ class Editline {
214212
}
215213

216214
void SetPromptAnsiPrefix(std::string prefix) {
217-
if (m_color)
218-
m_prompt_ansi_prefix = std::move(prefix);
215+
m_prompt_ansi_prefix = std::move(prefix);
219216
}
220217

221218
void SetPromptAnsiSuffix(std::string suffix) {
222-
if (m_color)
223-
m_prompt_ansi_suffix = std::move(suffix);
219+
m_prompt_ansi_suffix = std::move(suffix);
224220
}
225221

226222
void SetSuggestionAnsiPrefix(std::string prefix) {
227-
if (m_color)
228-
m_suggestion_ansi_prefix = std::move(prefix);
223+
m_suggestion_ansi_prefix = std::move(prefix);
229224
}
230225

231226
void SetSuggestionAnsiSuffix(std::string suffix) {
232-
if (m_color)
233-
m_suggestion_ansi_suffix = std::move(suffix);
227+
m_suggestion_ansi_suffix = std::move(suffix);
234228
}
235229

236230
/// Prompts for and reads a single line of user input.
@@ -239,8 +233,7 @@ class Editline {
239233
/// Prompts for and reads a multi-line batch of user input.
240234
bool GetLines(int first_line_number, StringList &lines, bool &interrupted);
241235

242-
void PrintAsync(lldb::LockableStreamFileSP stream_sp, const char *s,
243-
size_t len);
236+
void PrintAsync(Stream *stream, const char *s, size_t len);
244237

245238
/// Convert the current input lines into a UTF8 StringList
246239
StringList GetInputAsStringList(int line_count = UINT32_MAX);
@@ -395,11 +388,8 @@ class Editline {
395388
volatile std::sig_atomic_t m_terminal_size_has_changed = 0;
396389
std::string m_editor_name;
397390
FILE *m_input_file;
398-
lldb::LockableStreamFileSP m_output_stream_sp;
399-
lldb::LockableStreamFileSP m_error_stream_sp;
400-
401-
std::optional<LockedStreamFile> m_locked_output;
402-
391+
FILE *m_output_file;
392+
FILE *m_error_file;
403393
ConnectionFileDescriptor m_input_connection;
404394

405395
IsInputCompleteCallbackType m_is_input_complete_callback;
@@ -410,13 +400,13 @@ class Editline {
410400
CompleteCallbackType m_completion_callback;
411401
SuggestionCallbackType m_suggestion_callback;
412402

413-
bool m_color;
414403
std::string m_prompt_ansi_prefix;
415404
std::string m_prompt_ansi_suffix;
416405
std::string m_suggestion_ansi_prefix;
417406
std::string m_suggestion_ansi_suffix;
418407

419408
std::size_t m_previous_autosuggestion_size = 0;
409+
std::recursive_mutex &m_output_mutex;
420410
};
421411
}
422412

lldb/include/lldb/Host/File.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,6 @@ class File : public IOObject {
377377

378378
class NativeFile : public File {
379379
public:
380-
enum TransferOwnership : bool {
381-
Owned = true,
382-
Unowned = false,
383-
};
384-
385380
NativeFile() : m_descriptor(kInvalidDescriptor), m_stream(kInvalidStream) {}
386381

387382
NativeFile(FILE *fh, bool transfer_ownership)

lldb/include/lldb/Host/StreamFile.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@
1313
#include "lldb/Utility/Stream.h"
1414
#include "lldb/lldb-defines.h"
1515
#include "lldb/lldb-enumerations.h"
16-
#include "lldb/lldb-forward.h"
1716

1817
#include <cstdint>
1918
#include <cstdio>
20-
#include <memory>
21-
#include <mutex>
2219

2320
namespace lldb_private {
2421

@@ -55,55 +52,6 @@ class StreamFile : public Stream {
5552
const StreamFile &operator=(const StreamFile &) = delete;
5653
};
5754

58-
class LockableStreamFile;
59-
class LockedStreamFile : public StreamFile {
60-
public:
61-
~LockedStreamFile() { Flush(); }
62-
63-
LockedStreamFile(LockedStreamFile &&other)
64-
: StreamFile(other.m_file_sp), m_lock(std::move(other.m_lock)) {}
65-
66-
private:
67-
LockedStreamFile(std::shared_ptr<File> file, std::recursive_mutex &mutex)
68-
: StreamFile(file), m_lock(mutex) {}
69-
70-
friend class LockableStreamFile;
71-
72-
std::unique_lock<std::recursive_mutex> m_lock;
73-
};
74-
75-
class LockableStreamFile {
76-
public:
77-
using Mutex = std::recursive_mutex;
78-
79-
LockableStreamFile(std::shared_ptr<StreamFile> stream_file_sp, Mutex &mutex)
80-
: m_file_sp(stream_file_sp->GetFileSP()), m_mutex(mutex) {}
81-
LockableStreamFile(StreamFile &stream_file, Mutex &mutex)
82-
: m_file_sp(stream_file.GetFileSP()), m_mutex(mutex) {}
83-
LockableStreamFile(FILE *fh, bool transfer_ownership, Mutex &mutex)
84-
: m_file_sp(std::make_shared<NativeFile>(fh, transfer_ownership)),
85-
m_mutex(mutex) {}
86-
LockableStreamFile(std::shared_ptr<File> file_sp, Mutex &mutex)
87-
: m_file_sp(file_sp), m_mutex(mutex) {}
88-
89-
LockedStreamFile Lock() { return LockedStreamFile(m_file_sp, m_mutex); }
90-
91-
/// Unsafe accessors to get the underlying File without a lock. Exists for
92-
/// legacy reasons.
93-
/// @{
94-
File &GetUnlockedFile() { return *m_file_sp; }
95-
std::shared_ptr<File> GetUnlockedFileSP() { return m_file_sp; }
96-
/// @}
97-
98-
protected:
99-
std::shared_ptr<File> m_file_sp;
100-
Mutex &m_mutex;
101-
102-
private:
103-
LockableStreamFile(const LockableStreamFile &) = delete;
104-
const LockableStreamFile &operator=(const LockableStreamFile &) = delete;
105-
};
106-
10755
} // namespace lldb_private
10856

10957
#endif // LLDB_HOST_STREAMFILE_H

0 commit comments

Comments
 (0)