summaryrefslogtreecommitdiff
path: root/include/lldb/Host
diff options
context:
space:
mode:
Diffstat (limited to 'include/lldb/Host')
-rw-r--r--include/lldb/Host/Editline.h209
-rw-r--r--include/lldb/Host/File.h56
-rw-r--r--include/lldb/Host/FileSpec.h2
-rw-r--r--include/lldb/Host/Host.h27
-rw-r--r--include/lldb/Host/HostGetOpt.h20
-rw-r--r--include/lldb/Host/SocketAddress.h21
6 files changed, 320 insertions, 15 deletions
diff --git a/include/lldb/Host/Editline.h b/include/lldb/Host/Editline.h
new file mode 100644
index 000000000000..b92de1052f29
--- /dev/null
+++ b/include/lldb/Host/Editline.h
@@ -0,0 +1,209 @@
+//===-- Editline.h ----------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_Editline_h_
+#define liblldb_Editline_h_
+#if defined(__cplusplus)
+
+#include "lldb/lldb-private.h"
+
+#include <stdio.h>
+#ifdef _WIN32
+#include "lldb/Host/windows/editlinewin.h"
+#else
+#include <histedit.h>
+#endif
+
+#include <string>
+#include <vector>
+
+#include "lldb/Host/Condition.h"
+#include "lldb/Host/FileSpec.h"
+#include "lldb/Host/Mutex.h"
+
+namespace lldb_private {
+
+//----------------------------------------------------------------------
+/// @class Editline Editline.h "lldb/Host/Editline.h"
+/// @brief A class that encapsulates editline functionality.
+//----------------------------------------------------------------------
+class Editline
+{
+public:
+ typedef LineStatus (*LineCompletedCallbackType) (
+ Editline *editline,
+ StringList &lines,
+ uint32_t line_idx,
+ Error &error,
+ void *baton);
+
+ typedef int (*CompleteCallbackType) (
+ const char *current_line,
+ const char *cursor,
+ const char *last_char,
+ int skip_first_n_matches,
+ int max_matches,
+ StringList &matches,
+ void *baton);
+
+ typedef int (*GetCharCallbackType) (
+ ::EditLine *,
+ char *c);
+
+ Editline(const char *prog, // Used for the history file and for editrc program name
+ const char *prompt,
+ FILE *fin,
+ FILE *fout,
+ FILE *ferr);
+
+ ~Editline();
+
+ Error
+ GetLine (std::string &line);
+
+ Error
+ GetLines (const std::string &end_line, StringList &lines);
+
+ bool
+ LoadHistory ();
+
+ bool
+ SaveHistory ();
+
+ FILE *
+ GetInputFile ();
+
+ FILE *
+ GetOutputFile ();
+
+ FILE *
+ GetErrorFile ();
+
+ bool
+ GettingLine () const
+ {
+ return m_getting_line;
+ }
+
+ void
+ Hide ();
+
+ void
+ Refresh();
+
+ void
+ Interrupt ();
+
+ void
+ SetAutoCompleteCallback (CompleteCallbackType callback,
+ void *baton)
+ {
+ m_completion_callback = callback;
+ m_completion_callback_baton = baton;
+ }
+
+ void
+ SetLineCompleteCallback (LineCompletedCallbackType callback,
+ void *baton)
+ {
+ m_line_complete_callback = callback;
+ m_line_complete_callback_baton = baton;
+ }
+
+ size_t
+ Push (const char *bytes, size_t len);
+
+ // Cache bytes and use them for input without using a FILE. Calling this function
+ // will set the getc callback in the editline
+ size_t
+ SetInputBuffer (const char *c, size_t len);
+
+ static int
+ GetCharFromInputFileCallback (::EditLine *e, char *c);
+
+ void
+ SetGetCharCallback (GetCharCallbackType callback);
+
+ const char *
+ GetPrompt();
+
+ void
+ SetPrompt (const char *p);
+
+private:
+
+ Error
+ PrivateGetLine(std::string &line);
+
+ FileSpec
+ GetHistoryFile();
+
+ unsigned char
+ HandleCompletion (int ch);
+
+ int
+ GetChar (char *c);
+
+
+ static unsigned char
+ CallbackEditPrevLine (::EditLine *e, int ch);
+
+ static unsigned char
+ CallbackEditNextLine (::EditLine *e, int ch);
+
+ static unsigned char
+ CallbackComplete (::EditLine *e, int ch);
+
+ static const char *
+ GetPromptCallback (::EditLine *e);
+
+ static Editline *
+ GetClientData (::EditLine *e);
+
+ static FILE *
+ GetFilePointer (::EditLine *e, int fd);
+
+ static int
+ GetCharInputBufferCallback (::EditLine *e, char *c);
+
+ enum class Command
+ {
+ None = 0,
+ EditPrevLine,
+ EditNextLine,
+ };
+ ::EditLine *m_editline;
+ ::History *m_history;
+ ::HistEvent m_history_event;
+ std::string m_program;
+ std::string m_prompt;
+ std::string m_lines_prompt;
+ std::string m_getc_buffer;
+ Mutex m_getc_mutex;
+ Condition m_getc_cond;
+ CompleteCallbackType m_completion_callback;
+ void *m_completion_callback_baton;
+// Mutex m_gets_mutex; // Make sure only one thread
+ LineCompletedCallbackType m_line_complete_callback;
+ void *m_line_complete_callback_baton;
+ Command m_lines_command;
+ uint32_t m_lines_curr_line;
+ uint32_t m_lines_max_line;
+ bool m_prompt_with_line_numbers;
+ bool m_getting_line;
+ bool m_got_eof; // Set to true when we detect EOF
+ bool m_interrupted;
+
+ DISALLOW_COPY_AND_ASSIGN(Editline);
+};
+
+} // namespace lldb_private
+
+#endif // #if defined(__cplusplus)
+#endif // liblldb_Host_h_
diff --git a/include/lldb/Host/File.h b/include/lldb/Host/File.h
index 607efa029c09..814d96059f37 100644
--- a/include/lldb/Host/File.h
+++ b/include/lldb/Host/File.h
@@ -51,7 +51,10 @@ public:
m_descriptor (kInvalidDescriptor),
m_stream (kInvalidStream),
m_options (0),
- m_owned (false)
+ m_own_stream (false),
+ m_own_descriptor (false),
+ m_is_interactive (eLazyBoolCalculate),
+ m_is_real_terminal (eLazyBoolCalculate)
{
}
@@ -59,7 +62,10 @@ public:
m_descriptor (kInvalidDescriptor),
m_stream (fh),
m_options (0),
- m_owned (transfer_ownership)
+ m_own_stream (transfer_ownership),
+ m_own_descriptor (false),
+ m_is_interactive (eLazyBoolCalculate),
+ m_is_real_terminal (eLazyBoolCalculate)
{
}
@@ -111,13 +117,15 @@ public:
uint32_t options,
uint32_t permissions = lldb::eFilePermissionsFileDefault);
- File (int fd, bool tranfer_ownership) :
+ File (int fd, bool transfer_ownership) :
m_descriptor (fd),
m_stream (kInvalidStream),
m_options (0),
- m_owned (tranfer_ownership)
+ m_own_stream (false),
+ m_own_descriptor (transfer_ownership)
{
}
+
//------------------------------------------------------------------
/// Destructor.
///
@@ -458,6 +466,32 @@ public:
static uint32_t
GetPermissions (const char *path, Error &error);
+
+ //------------------------------------------------------------------
+ /// Return true if this file is interactive.
+ ///
+ /// @return
+ /// True if this file is a terminal (tty or pty), false
+ /// otherwise.
+ //------------------------------------------------------------------
+ bool
+ GetIsInteractive ();
+
+ //------------------------------------------------------------------
+ /// Return true if this file from a real terminal.
+ ///
+ /// Just knowing a file is a interactive isn't enough, we also need
+ /// to know if the terminal has a width and height so we can do
+ /// cursor movement and other terminal maninpulations by sending
+ /// escape sequences.
+ ///
+ /// @return
+ /// True if this file is a terminal (tty, not a pty) that has
+ /// a non-zero width and height, false otherwise.
+ //------------------------------------------------------------------
+ bool
+ GetIsRealTerminal ();
+
//------------------------------------------------------------------
/// Output printf formatted output to the stream.
///
@@ -476,6 +510,12 @@ public:
size_t
PrintfVarArg(const char *format, va_list args);
+
+ void
+ SetOptions (uint32_t options)
+ {
+ m_options = options;
+ }
protected:
@@ -491,13 +531,19 @@ protected:
return m_stream != kInvalidStream;
}
+ void
+ CalculateInteractiveAndTerminal ();
+
//------------------------------------------------------------------
// Member variables
//------------------------------------------------------------------
int m_descriptor;
FILE *m_stream;
uint32_t m_options;
- bool m_owned;
+ bool m_own_stream;
+ bool m_own_descriptor;
+ LazyBool m_is_interactive;
+ LazyBool m_is_real_terminal;
};
} // namespace lldb_private
diff --git a/include/lldb/Host/FileSpec.h b/include/lldb/Host/FileSpec.h
index 086c8f200567..dfc4e4ae0fe3 100644
--- a/include/lldb/Host/FileSpec.h
+++ b/include/lldb/Host/FileSpec.h
@@ -534,7 +534,7 @@ public:
/// as many bytes as possible.
///
/// @return
- /// A shared pointer to the memeory mapped data. This shared
+ /// A shared pointer to the memory mapped data. This shared
/// pointer can contain a NULL DataBuffer pointer, so the contained
/// pointer must be checked prior to using it.
//------------------------------------------------------------------
diff --git a/include/lldb/Host/Host.h b/include/lldb/Host/Host.h
index fe0f6f62b3bc..862b1ed79432 100644
--- a/include/lldb/Host/Host.h
+++ b/include/lldb/Host/Host.h
@@ -202,6 +202,23 @@ public:
GetTargetTriple ();
//------------------------------------------------------------------
+ /// Gets the name of the distribution (i.e. distributor id).
+ ///
+ /// On Linux, this will return the equivalent of lsb_release -i.
+ /// Android will return 'android'. Other systems may return
+ /// nothing.
+ ///
+ /// @return
+ /// A ConstString reference containing the OS distribution id.
+ /// The return string will be all lower case, with whitespace
+ /// replaced with underscores. The return string will be
+ /// empty (result.AsCString() will return NULL) if the distribution
+ /// cannot be obtained.
+ //------------------------------------------------------------------
+ static const ConstString &
+ GetDistributionId ();
+
+ //------------------------------------------------------------------
/// Get the process ID for the calling process.
///
/// @return
@@ -459,7 +476,15 @@ public:
static bool
GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info);
-
+
+#if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__)
+ static short
+ GetPosixspawnFlags (ProcessLaunchInfo &launch_info);
+
+ static Error
+ LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t &pid);
+#endif
+
static lldb::pid_t
LaunchApplication (const FileSpec &app_file_spec);
diff --git a/include/lldb/Host/HostGetOpt.h b/include/lldb/Host/HostGetOpt.h
new file mode 100644
index 000000000000..6fb7b51dddba
--- /dev/null
+++ b/include/lldb/Host/HostGetOpt.h
@@ -0,0 +1,20 @@
+//===-- GetOpt.h ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#pragma once
+
+#ifndef _MSC_VER
+
+#include <unistd.h>
+#include <getopt.h>
+
+#else
+
+#include <lldb/Host/windows/GetOptInc.h>
+
+#endif \ No newline at end of file
diff --git a/include/lldb/Host/SocketAddress.h b/include/lldb/Host/SocketAddress.h
index 5e79e94fa9ec..4dc62102103a 100644
--- a/include/lldb/Host/SocketAddress.h
+++ b/include/lldb/Host/SocketAddress.h
@@ -18,7 +18,6 @@
#include <winsock2.h>
#include <WS2tcpip.h>
typedef ADDRESS_FAMILY sa_family_t;
-typedef USHORT in_port_t;
#else
#include <sys/socket.h>
#include <netdb.h>
@@ -103,7 +102,7 @@ public:
//------------------------------------------------------------------
// Get the port if the socket address for the family has a port
//------------------------------------------------------------------
- in_port_t
+ uint16_t
GetPort () const;
//------------------------------------------------------------------
@@ -111,7 +110,7 @@ public:
// The family must be set correctly prior to calling this function.
//------------------------------------------------------------------
bool
- SetPort (in_port_t port);
+ SetPort (uint16_t port);
//------------------------------------------------------------------
// Set the socket address according to the first match from a call
@@ -121,10 +120,12 @@ public:
// address.
//------------------------------------------------------------------
bool
- SetAddress (const struct addrinfo *hints_ptr, // Optional hints where the family, protocol and other things can be specified.
- const char *host, // Hostname ("foo.bar.com" or "foo" or IP address string ("123.234.12.1" or "2001:0db8:85a3:0000:0000:8a2e:0370:7334")
- const char *service, // Protocol name ("tcp", "http", etc) or a raw port number string ("81")
- struct addrinfo *addr_info_ptr); // If non-NULL, this will get filled in with the match
+ getaddrinfo (const char *host, // Hostname ("foo.bar.com" or "foo" or IP address string ("123.234.12.1" or "2001:0db8:85a3:0000:0000:8a2e:0370:7334")
+ const char *service, // Protocol name ("tcp", "http", etc) or a raw port number string ("81")
+ int ai_family = PF_UNSPEC,
+ int ai_socktype = 0,
+ int ai_protocol = 0,
+ int ai_flags = 0);
//------------------------------------------------------------------
// Quick way to set the SocketAddress to localhost given the family.
@@ -133,7 +134,11 @@ public:
//------------------------------------------------------------------
bool
SetToLocalhost (sa_family_t family,
- in_port_t port);
+ uint16_t port);
+
+ bool
+ SetToAnyAddress (sa_family_t family,
+ uint16_t port);
//------------------------------------------------------------------
// Returns true if there is a valid socket address in this object.