2010-06-09 00:52:24 +08:00
|
|
|
//===-- IOChannel.h ---------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef lldb_IOChannel_h_
|
|
|
|
#define lldb_IOChannel_h_
|
|
|
|
|
2013-10-15 23:46:40 +08:00
|
|
|
#include <thread>
|
|
|
|
#include <mutex>
|
|
|
|
#include <atomic>
|
|
|
|
#include <condition_variable>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
#include <string>
|
|
|
|
#include <queue>
|
|
|
|
#include "Driver.h"
|
|
|
|
|
|
|
|
class IOChannel : public lldb::SBBroadcaster
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
eBroadcastBitHasUserInput = (1 << 0),
|
|
|
|
eBroadcastBitUserInterrupt = (1 << 1),
|
|
|
|
eBroadcastBitThreadShouldExit = (1 << 2),
|
|
|
|
eBroadcastBitThreadDidExit = (1 << 3),
|
|
|
|
eBroadcastBitThreadDidStart = (1 << 4),
|
|
|
|
eBroadcastBitsSTDOUT = (1 << 5),
|
|
|
|
eBroadcastBitsSTDERR = (1 << 6),
|
|
|
|
eBroadcastBitsSTDIN = (1 << 7),
|
|
|
|
eAllEventBits = 0xffffffff
|
|
|
|
};
|
2013-05-07 06:10:33 +08:00
|
|
|
|
|
|
|
enum LibeditGetInputResult
|
|
|
|
{
|
|
|
|
eLibeditGetInputEOF = 0,
|
|
|
|
eLibeditGetInputValid = 1,
|
|
|
|
eLibeditGetInputEmpty = 2,
|
|
|
|
eLibeditGetInputResultError = 4,
|
|
|
|
eLibeditGetInputResultUnknown = 0xffffffff
|
|
|
|
};
|
2010-06-09 00:52:24 +08:00
|
|
|
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
IOChannel (FILE *editline_in,
|
|
|
|
FILE *editline_out,
|
2010-06-09 00:52:24 +08:00
|
|
|
FILE *out,
|
|
|
|
FILE *err,
|
|
|
|
Driver *driver = NULL);
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~IOChannel ();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Start ();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Stop ();
|
|
|
|
|
2013-10-15 23:46:40 +08:00
|
|
|
static lldb::thread_result_t
|
2010-06-09 00:52:24 +08:00
|
|
|
IOReadThread (void *);
|
|
|
|
|
|
|
|
void
|
|
|
|
Run ();
|
|
|
|
|
|
|
|
void
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
OutWrite (const char *buffer, size_t len, bool asynchronous);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
ErrWrite (const char *buffer, size_t len, bool asynchronous);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-05-07 06:10:33 +08:00
|
|
|
LibeditGetInputResult
|
2010-06-09 00:52:24 +08:00
|
|
|
LibeditGetInput (std::string &);
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
LibeditOutputBytesReceived (void *baton, const void *src,size_t src_len);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
SetPrompt ();
|
|
|
|
|
|
|
|
void
|
|
|
|
RefreshPrompt ();
|
|
|
|
|
|
|
|
void
|
|
|
|
AddCommandToQueue (const char *command);
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetCommandFromQueue (std::string &cmd);
|
|
|
|
|
|
|
|
int
|
|
|
|
CommandQueueSize () const;
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearCommandQueue ();
|
|
|
|
|
|
|
|
bool
|
|
|
|
CommandQueueIsEmpty () const;
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GetPrompt ();
|
|
|
|
|
2012-06-01 09:03:40 +08:00
|
|
|
bool
|
|
|
|
EditLineHasCharacters ();
|
|
|
|
|
2012-05-10 05:03:07 +08:00
|
|
|
void
|
|
|
|
EraseCharsBeforeCursor ();
|
|
|
|
|
2010-07-10 04:39:50 +08:00
|
|
|
static unsigned char
|
|
|
|
ElCompletionFn (EditLine *e, int ch);
|
2013-02-23 06:56:55 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
ElResize();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-30 02:35:42 +08:00
|
|
|
protected:
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
IsGettingCommand () const;
|
|
|
|
|
2010-09-30 02:35:42 +08:00
|
|
|
void
|
|
|
|
SetGettingCommand (bool new_value);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
private:
|
|
|
|
|
2013-10-15 23:46:40 +08:00
|
|
|
std::recursive_mutex m_output_mutex;
|
|
|
|
std::condition_variable_any m_output_cond;
|
2010-09-30 02:35:42 +08:00
|
|
|
struct timeval m_enter_elgets_time;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Driver *m_driver;
|
|
|
|
lldb::thread_t m_read_thread;
|
|
|
|
bool m_read_thread_should_exit;
|
|
|
|
FILE *m_out_file;
|
|
|
|
FILE *m_err_file;
|
2013-09-26 02:45:59 +08:00
|
|
|
FILE *m_editline_out;
|
2010-06-09 00:52:24 +08:00
|
|
|
std::queue<std::string> m_command_queue;
|
|
|
|
const char *m_completion_key;
|
|
|
|
|
|
|
|
EditLine *m_edit_line;
|
|
|
|
History *m_history;
|
|
|
|
HistEvent m_history_event;
|
|
|
|
bool m_getting_command;
|
This patch captures and serializes all output being written by the
command line driver, including the lldb prompt being output by
editline, the asynchronous process output & error messages, and
asynchronous messages written by target stop-hooks.
As part of this it introduces a new Stream class,
StreamAsynchronousIO. A StreamAsynchronousIO object is created with a
broadcaster, who will eventually broadcast the stream's data for a
listener to handle, and an event type indicating what type of event
the broadcaster will broadcast. When the Write method is called on a
StreamAsynchronousIO object, the data is appended to an internal
string. When the Flush method is called on a StreamAsynchronousIO
object, it broadcasts it's data string and clears the string.
Anything in lldb-core that needs to generate asynchronous output for
the end-user should use the StreamAsynchronousIO objects.
I have also added a new notification type for InputReaders, to let
them know that a asynchronous output has been written. This is to
allow the input readers to, for example, refresh their prompts and
lines, if desired. I added the case statements to all the input
readers to catch this notification, but I haven't added any code for
handling them yet (except to the IOChannel input reader).
llvm-svn: 130721
2011-05-03 04:41:46 +08:00
|
|
|
bool m_expecting_prompt;
|
2013-09-26 02:45:59 +08:00
|
|
|
bool m_output_flushed;
|
|
|
|
std::string m_prompt_str; // for accumlating the prompt as it gets written out by editline
|
2011-05-04 04:53:11 +08:00
|
|
|
bool m_refresh_request_pending;
|
2010-07-10 04:39:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void
|
|
|
|
HistorySaveLoad (bool save);
|
2010-07-10 04:39:50 +08:00
|
|
|
|
|
|
|
unsigned char
|
|
|
|
HandleCompletion (EditLine *e, int ch);
|
2010-06-09 00:52:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // lldb_IOChannel_h_
|