diff options
Diffstat (limited to 'include/lldb/Host')
27 files changed, 821 insertions, 607 deletions
diff --git a/include/lldb/Host/Condition.h b/include/lldb/Host/Condition.h index 2f1858b75a56..7431315c37a0 100644 --- a/include/lldb/Host/Condition.h +++ b/include/lldb/Host/Condition.h @@ -25,7 +25,7 @@ class TimeValue; /// /// A class that wraps up a pthread condition (pthread_cond_t). The /// class will create a pthread condition when an instance is -/// constructed, and detroy it when it is destructed. It also provides +/// constructed, and destroy it when it is destructed. It also provides /// access to the standard pthread condition calls. //---------------------------------------------------------------------- class Condition diff --git a/include/lldb/Host/Config.h b/include/lldb/Host/Config.h index 80616b747cf5..af6b98a7912a 100644 --- a/include/lldb/Host/Config.h +++ b/include/lldb/Host/Config.h @@ -18,7 +18,7 @@ #include "lldb/Host/linux/Config.h" -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) || defined(__NetBSD__) #include "lldb/Host/freebsd/Config.h" diff --git a/include/lldb/Host/Debug.h b/include/lldb/Host/Debug.h index 2cb758e1b733..87dffb9865c2 100644 --- a/include/lldb/Host/Debug.h +++ b/include/lldb/Host/Debug.h @@ -10,14 +10,11 @@ #ifndef liblldb_Debug_h_ #define liblldb_Debug_h_ -#include "lldb/lldb-private.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/StreamString.h" -#include "lldb/Host/Mutex.h" #include <vector> +#include "lldb/lldb-private.h" namespace lldb_private { - + //------------------------------------------------------------------ // Tells a thread what it needs to do when the process is resumed. //------------------------------------------------------------------ @@ -27,7 +24,7 @@ namespace lldb_private { lldb::StateType state; // Valid values are eStateStopped/eStateSuspended, eStateRunning, and eStateStepping. int signal; // When resuming this thread, resume it with this signal if this value is > 0 }; - + //------------------------------------------------------------------ // A class that contains instructions for all threads for // NativeProcessProtocol::Resume(). Each thread can either run, stay @@ -43,15 +40,14 @@ namespace lldb_private { m_signal_handled () { } - + ResumeActionList (lldb::StateType default_action, int signal) : m_actions(), m_signal_handled () { SetDefaultThreadActionIfNeeded (default_action, signal); } - - + ResumeActionList (const ResumeAction *actions, size_t num_actions) : m_actions (), m_signal_handled () @@ -62,7 +58,7 @@ namespace lldb_private { m_signal_handled.assign (num_actions, false); } } - + ~ResumeActionList() { } @@ -72,14 +68,14 @@ namespace lldb_private { { return m_actions.empty(); } - + void Append (const ResumeAction &action) { m_actions.push_back (action); m_signal_handled.push_back (false); } - + void AppendAction (lldb::tid_t tid, lldb::StateType state, @@ -88,25 +84,25 @@ namespace lldb_private { ResumeAction action = { tid, state, signal }; Append (action); } - + void AppendResumeAll () { AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateRunning); } - + void AppendSuspendAll () { AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateStopped); } - + void AppendStepAll () { AppendAction (LLDB_INVALID_THREAD_ID, lldb::eStateStepping); } - + const ResumeAction * GetActionForThread (lldb::tid_t tid, bool default_ok) const { @@ -120,7 +116,7 @@ namespace lldb_private { return GetActionForThread (LLDB_INVALID_THREAD_ID, false); return NULL; } - + size_t NumActionsWithState (lldb::StateType state) const { @@ -133,7 +129,7 @@ namespace lldb_private { } return count; } - + bool SetDefaultThreadActionIfNeeded (lldb::StateType action, int signal) { @@ -147,7 +143,7 @@ namespace lldb_private { } return false; } - + void SetSignalHandledForThread (lldb::tid_t tid) const { @@ -161,26 +157,26 @@ namespace lldb_private { } } } - + const ResumeAction * GetFirst() const { return m_actions.data(); } - + size_t GetSize () const { return m_actions.size(); } - + void Clear() { m_actions.clear(); m_signal_handled.clear(); } - + protected: std::vector<ResumeAction> m_actions; mutable std::vector<bool> m_signal_handled; @@ -191,13 +187,13 @@ namespace lldb_private { lldb::StopReason reason; union { - // eStopTypeSignal + // eStopReasonSignal struct { uint32_t signo; } signal; - - // eStopTypeException + + // eStopReasonException struct { uint64_t type; @@ -206,201 +202,5 @@ namespace lldb_private { } exception; } details; }; - - //------------------------------------------------------------------ - // NativeThreadProtocol - //------------------------------------------------------------------ - class NativeThreadProtocol { - - public: - NativeThreadProtocol (NativeProcessProtocol *process, lldb::tid_t tid) : - m_process (process), - m_tid (tid) - { - } - - virtual ~NativeThreadProtocol() - { - } - virtual const char *GetName() = 0; - virtual lldb::StateType GetState () = 0; - virtual Error ReadRegister (uint32_t reg, RegisterValue ®_value) = 0; - virtual Error WriteRegister (uint32_t reg, const RegisterValue ®_value) = 0; - virtual Error SaveAllRegisters (lldb::DataBufferSP &data_sp) = 0; - virtual Error RestoreAllRegisters (lldb::DataBufferSP &data_sp) = 0; - virtual bool GetStopReason (ThreadStopInfo &stop_info) = 0; - - lldb::tid_t - GetID() const - { - return m_tid; - } - protected: - NativeProcessProtocol *m_process; - lldb::tid_t m_tid; - }; - - - //------------------------------------------------------------------ - // NativeProcessProtocol - //------------------------------------------------------------------ - class NativeProcessProtocol { - public: - - static NativeProcessProtocol * - CreateInstance (lldb::pid_t pid); - - // lldb_private::Host calls should be used to launch a process for debugging, and - // then the process should be attached to. When attaching to a process - // lldb_private::Host calls should be used to locate the process to attach to, - // and then this function should be called. - NativeProcessProtocol (lldb::pid_t pid) : - m_pid (pid), - m_threads(), - m_threads_mutex (Mutex::eMutexTypeRecursive), - m_state (lldb::eStateInvalid), - m_exit_status(0), - m_exit_description() - { - } - - public: - virtual ~NativeProcessProtocol () - { - } - - virtual Error Resume (const ResumeActionList &resume_actions) = 0; - virtual Error Halt () = 0; - virtual Error Detach () = 0; - virtual Error Signal (int signo) = 0; - virtual Error Kill () = 0; - - virtual Error ReadMemory (lldb::addr_t addr, void *buf, lldb::addr_t size, lldb::addr_t &bytes_read) = 0; - virtual Error WriteMemory (lldb::addr_t addr, const void *buf, lldb::addr_t size, lldb::addr_t &bytes_written) = 0; - virtual Error AllocateMemory (lldb::addr_t size, uint32_t permissions, lldb::addr_t &addr) = 0; - virtual Error DeallocateMemory (lldb::addr_t addr) = 0; - - virtual lldb::addr_t GetSharedLibraryInfoAddress () = 0; - - virtual bool IsAlive () = 0; - virtual size_t UpdateThreads () = 0; - virtual bool GetArchitecture (ArchSpec &arch) = 0; - - //---------------------------------------------------------------------- - // Breakpoint functions - //---------------------------------------------------------------------- - virtual Error SetBreakpoint (lldb::addr_t addr, size_t size, bool hardware) = 0; - virtual Error RemoveBreakpoint (lldb::addr_t addr, size_t size) = 0; - - //---------------------------------------------------------------------- - // Watchpoint functions - //---------------------------------------------------------------------- - virtual uint32_t GetMaxWatchpoints () = 0; - virtual Error SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) = 0; - virtual Error RemoveWatchpoint (lldb::addr_t addr) = 0; - - - //---------------------------------------------------------------------- - // Accessors - //---------------------------------------------------------------------- - lldb::pid_t - GetID() const - { - return m_pid; - } - - lldb::StateType - GetState () const - { - return m_state; - } - - bool - IsRunning () const - { - return m_state == lldb::eStateRunning || IsStepping(); - } - - bool - IsStepping () const - { - return m_state == lldb::eStateStepping; - } - - bool - CanResume () const - { - return m_state == lldb::eStateStopped; - } - - - void - SetState (lldb::StateType state) - { - m_state = state; - } - - //---------------------------------------------------------------------- - // Exit Status - //---------------------------------------------------------------------- - virtual bool - GetExitStatus (int *status) - { - if (m_state == lldb::eStateExited) - { - *status = m_exit_status; - return true; - } - *status = 0; - return false; - } - virtual bool - SetExitStatus (int status, const char *exit_description) - { - // Exit status already set - if (m_state == lldb::eStateExited) - return false; - m_state = lldb::eStateExited; - m_exit_status = status; - if (exit_description && exit_description[0]) - m_exit_description = exit_description; - else - m_exit_description.clear(); - return true; - } - - //---------------------------------------------------------------------- - // Access to threads - //---------------------------------------------------------------------- - lldb::NativeThreadProtocolSP - GetThreadAtIndex (uint32_t idx) - { - Mutex::Locker locker(m_threads_mutex); - if (idx < m_threads.size()) - return m_threads[idx]; - return lldb::NativeThreadProtocolSP(); - } - - lldb::NativeThreadProtocolSP - GetThreadByID (lldb::tid_t tid) - { - Mutex::Locker locker(m_threads_mutex); - for (auto thread_sp : m_threads) - { - if (thread_sp->GetID() == tid) - return thread_sp; - } - return lldb::NativeThreadProtocolSP(); - } - - protected: - lldb::pid_t m_pid; - std::vector<lldb::NativeThreadProtocolSP> m_threads; - mutable Mutex m_threads_mutex; - lldb::StateType m_state; - int m_exit_status; - std::string m_exit_description; - }; - } #endif // #ifndef liblldb_Debug_h_ diff --git a/include/lldb/Host/DynamicLibrary.h b/include/lldb/Host/DynamicLibrary.h deleted file mode 100644 index 1fcc7d1883cf..000000000000 --- a/include/lldb/Host/DynamicLibrary.h +++ /dev/null @@ -1,51 +0,0 @@ -//===-- DynamicLibrary.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_DynamicLibrary_h_ -#define liblldb_DynamicLibrary_h_ - -#include "lldb/Host/FileSpec.h" -#include "lldb/Host/Host.h" - -namespace lldb_private { - -class DynamicLibrary -{ -public: - DynamicLibrary (const FileSpec& spec, uint32_t options = Host::eDynamicLibraryOpenOptionLazy | - Host::eDynamicLibraryOpenOptionLocal | - Host::eDynamicLibraryOpenOptionLimitGetSymbol); - - ~DynamicLibrary (); - - template <typename T = void*> - T GetSymbol (const char* name) - { - Error err; - if (!m_handle) - return (T)NULL; - void* symbol = Host::DynamicLibraryGetSymbol (m_handle, name, err); - if (!symbol) - return (T)NULL; - return (T)symbol; - } - - bool - IsValid (); - -private: - lldb_private::FileSpec m_filespec; - void* m_handle; - - DISALLOW_COPY_AND_ASSIGN (DynamicLibrary); -}; - -} // namespace lldb_private - -#endif // liblldb_DynamicLibrary_h_ diff --git a/include/lldb/Host/Editline.h b/include/lldb/Host/Editline.h index b92de1052f29..5cba8465d654 100644 --- a/include/lldb/Host/Editline.h +++ b/include/lldb/Host/Editline.h @@ -23,9 +23,11 @@ #include <string> #include <vector> +#include "lldb/Core/ConnectionFileDescriptor.h" #include "lldb/Host/Condition.h" #include "lldb/Host/FileSpec.h" #include "lldb/Host/Mutex.h" +#include "lldb/Host/Predicate.h" namespace lldb_private { @@ -33,6 +35,10 @@ namespace lldb_private { /// @class Editline Editline.h "lldb/Host/Editline.h" /// @brief A class that encapsulates editline functionality. //---------------------------------------------------------------------- +class EditlineHistory; + +typedef std::shared_ptr<EditlineHistory> EditlineHistorySP; + class Editline { public: @@ -58,6 +64,7 @@ public: Editline(const char *prog, // Used for the history file and for editrc program name const char *prompt, + bool configure_for_multiline, FILE *fin, FILE *fout, FILE *ferr); @@ -65,10 +72,13 @@ public: ~Editline(); Error - GetLine (std::string &line); + GetLine (std::string &line, + bool &interrupted); Error - GetLines (const std::string &end_line, StringList &lines); + GetLines (const std::string &end_line, + StringList &lines, + bool &interrupted); bool LoadHistory (); @@ -97,7 +107,7 @@ public: void Refresh(); - void + bool Interrupt (); void @@ -118,11 +128,6 @@ public: 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); @@ -135,21 +140,21 @@ public: void SetPrompt (const char *p); - + + void + ShowLineNumbers (bool enable, uint32_t line_offset) + { + m_prompt_with_line_numbers = enable; + m_line_offset = line_offset; + } + 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); @@ -169,9 +174,6 @@ private: static FILE * GetFilePointer (::EditLine *e, int fd); - static int - GetCharInputBufferCallback (::EditLine *e, char *c); - enum class Command { None = 0, @@ -179,22 +181,19 @@ private: EditNextLine, }; ::EditLine *m_editline; - ::History *m_history; - ::HistEvent m_history_event; - std::string m_program; + EditlineHistorySP m_history_sp; std::string m_prompt; std::string m_lines_prompt; - std::string m_getc_buffer; - Mutex m_getc_mutex; - Condition m_getc_cond; + lldb_private::Predicate<bool> m_getting_char; 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_line_offset; uint32_t m_lines_curr_line; uint32_t m_lines_max_line; + ConnectionFileDescriptor m_file; bool m_prompt_with_line_numbers; bool m_getting_line; bool m_got_eof; // Set to true when we detect EOF diff --git a/include/lldb/Host/Endian.h b/include/lldb/Host/Endian.h index 610f3ce95c41..1ae3c40b5ca4 100644 --- a/include/lldb/Host/Endian.h +++ b/include/lldb/Host/Endian.h @@ -20,7 +20,7 @@ namespace endian { { uint32_t num; uint8_t bytes[sizeof(uint32_t)]; - } const endianTest = { (uint16_t)0x01020304 }; + } const endianTest = { 0x01020304 }; inline ByteOrder InlHostByteOrder() { return (ByteOrder)endianTest.bytes[0]; } diff --git a/include/lldb/Host/File.h b/include/lldb/Host/File.h index 814d96059f37..2738679b5e03 100644 --- a/include/lldb/Host/File.h +++ b/include/lldb/Host/File.h @@ -16,6 +16,7 @@ #include <sys/types.h> #include "lldb/lldb-private.h" +#include "lldb/Host/IOObject.h" namespace lldb_private { @@ -26,7 +27,7 @@ namespace lldb_private { /// A file class that divides abstracts the LLDB core from host file /// functionality. //---------------------------------------------------------------------- -class File +class File : public IOObject { public: static int kInvalidDescriptor; @@ -48,22 +49,22 @@ public: ConvertOpenOptionsForPOSIXOpen (uint32_t open_options); File() : + IOObject(eFDTypeFile, false), m_descriptor (kInvalidDescriptor), m_stream (kInvalidStream), m_options (0), m_own_stream (false), - m_own_descriptor (false), m_is_interactive (eLazyBoolCalculate), m_is_real_terminal (eLazyBoolCalculate) { } File (FILE *fh, bool transfer_ownership) : + IOObject(eFDTypeFile, false), m_descriptor (kInvalidDescriptor), m_stream (fh), m_options (0), m_own_stream (transfer_ownership), - m_own_descriptor (false), m_is_interactive (eLazyBoolCalculate), m_is_real_terminal (eLazyBoolCalculate) { @@ -118,11 +119,11 @@ public: uint32_t permissions = lldb::eFilePermissionsFileDefault); File (int fd, bool transfer_ownership) : + IOObject(eFDTypeFile, transfer_ownership), m_descriptor (fd), m_stream (kInvalidStream), m_options (0), - m_own_stream (false), - m_own_descriptor (transfer_ownership) + m_own_stream (false) { } @@ -222,6 +223,10 @@ public: int GetDescriptor() const; + WaitableHandle + GetWaitableHandle(); + + void SetDescriptor(int fd, bool transfer_ownership); @@ -331,7 +336,7 @@ public: /// /// @param[in/out] offset /// The offset to seek to within the file relative to the - /// end of the file which gets filled in the the resulting + /// end of the file which gets filled in with the resulting /// absolute file offset. /// /// @param[in] error_ptr @@ -482,7 +487,7 @@ public: /// /// 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 + /// cursor movement and other terminal manipulations by sending /// escape sequences. /// /// @return @@ -541,7 +546,6 @@ protected: FILE *m_stream; uint32_t m_options; bool m_own_stream; - bool m_own_descriptor; LazyBool m_is_interactive; LazyBool m_is_real_terminal; }; diff --git a/include/lldb/Host/FileCache.h b/include/lldb/Host/FileCache.h new file mode 100644 index 000000000000..779ff983de98 --- /dev/null +++ b/include/lldb/Host/FileCache.h @@ -0,0 +1,45 @@ +//===-- FileCache.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_Host_FileCache_h +#define liblldb_Host_FileCache_h + +#include <stdint.h> + +#include "lldb/lldb-forward.h" +#include "lldb/lldb-types.h" + +#include "lldb/Core/Error.h" +#include "lldb/Host/FileSpec.h" + +namespace lldb_private +{ +class FileCache +{ + private: + FileCache() {} + + typedef std::map<lldb::user_id_t, lldb::FileSP> FDToFileMap; + + public: + static FileCache &GetInstance(); + + lldb::user_id_t OpenFile(const FileSpec &file_spec, uint32_t flags, uint32_t mode, Error &error); + bool CloseFile(lldb::user_id_t fd, Error &error); + + uint64_t WriteFile(lldb::user_id_t fd, uint64_t offset, const void *src, uint64_t src_len, Error &error); + uint64_t ReadFile(lldb::user_id_t fd, uint64_t offset, void *dst, uint64_t dst_len, Error &error); + + private: + static FileCache *m_instance; + + FDToFileMap m_cache; +}; +} + +#endif diff --git a/include/lldb/Host/FileSpec.h b/include/lldb/Host/FileSpec.h index dfc4e4ae0fe3..ef73bb2ede0f 100644 --- a/include/lldb/Host/FileSpec.h +++ b/include/lldb/Host/FileSpec.h @@ -51,6 +51,13 @@ public: eFileTypeOther } FileType; + enum PathSyntax + { + ePathSyntaxPosix, + ePathSyntaxWindows, + ePathSyntaxHostNative + }; + FileSpec(); //------------------------------------------------------------------ @@ -69,7 +76,7 @@ public: /// /// @see FileSpec::SetFile (const char *path, bool resolve) //------------------------------------------------------------------ - explicit FileSpec (const char *path, bool resolve_path); + explicit FileSpec (const char *path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative); //------------------------------------------------------------------ /// Copy constructor @@ -249,7 +256,7 @@ public: /// by a directory delimiter, and the filename. /// /// @param[in] s - /// The stream to which to dump the object descripton. + /// The stream to which to dump the object description. //------------------------------------------------------------------ void Dump (Stream *s) const; @@ -263,6 +270,15 @@ public: bool Exists () const; + //------------------------------------------------------------------ + /// Check if a file is readable by the current user + /// + /// @return + /// \b true if the file exists on disk and is readable, \b false + /// otherwise. + //------------------------------------------------------------------ + bool + Readable () const; //------------------------------------------------------------------ /// Expanded existence test. @@ -291,6 +307,9 @@ public: uint64_t GetByteSize() const; + PathSyntax + GetPathSyntax() const; + //------------------------------------------------------------------ /// Directory string get accessor. /// @@ -375,7 +394,7 @@ public: /// still NULL terminated). //------------------------------------------------------------------ size_t - GetPath (char *path, size_t max_path_length) const; + GetPath (char *path, size_t max_path_length, bool denormalize = true) const; //------------------------------------------------------------------ /// Extract the full path to the file. @@ -387,7 +406,7 @@ public: /// concatenated. //------------------------------------------------------------------ std::string - GetPath () const; + GetPath (bool denormalize = true) const; //------------------------------------------------------------------ /// Extract the extension of the file. @@ -486,7 +505,7 @@ public: /// Returns a shared pointer to a data buffer that contains all or /// part of the contents of a file. The data is memory mapped and /// will lazily page in data from the file as memory is accessed. - /// The data that is mappped will start \a offset bytes into the + /// The data that is mapped will start \a offset bytes into the /// file, and \a length bytes will be mapped. If \a length is /// greater than the number of bytes available in the file starting /// at \a offset, the number of bytes will be appropriately @@ -504,7 +523,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. //------------------------------------------------------------------ @@ -559,8 +578,12 @@ public: //------------------------------------------------------------------ lldb::DataBufferSP ReadFileContentsAsCString(Error *error_ptr = NULL); + + static void Normalize(llvm::SmallVectorImpl<char> &path, PathSyntax syntax = ePathSyntaxHostNative); + static void DeNormalize(llvm::SmallVectorImpl<char> &path, PathSyntax syntax = ePathSyntaxHostNative); + //------------------------------------------------------------------ - /// Change the file specificed with a new path. + /// Change the file specified with a new path. /// /// Update the contents of this object with a new path. The path will /// be split up into a directory and filename and stored as uniqued @@ -574,7 +597,7 @@ public: /// the static FileSpec::Resolve. //------------------------------------------------------------------ void - SetFile (const char *path, bool resolve_path); + SetFile (const char *path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative); bool IsResolved () const @@ -617,27 +640,14 @@ public: ReadFileLines (STLStringArray &lines); //------------------------------------------------------------------ - /// Resolves user name and links in \a src_path, and writes the output - /// to \a dst_path. Note if the path pointed to by \a src_path does not - /// exist, the contents of \a src_path will be copied to \a dst_path - /// unchanged. + /// Resolves user name and links in \a path, and overwrites the input + /// argument with the resolved path. /// - /// @param[in] src_path - /// Input path to be resolved. - /// - /// @param[in] dst_path - /// Buffer to store the resolved path. - /// - /// @param[in] dst_len - /// Size of the buffer pointed to by dst_path. - /// - /// @result - /// The number of characters required to write the resolved path. If the - /// resolved path doesn't fit in dst_len, dst_len-1 characters will - /// be written to \a dst_path, but the actual required length will still be returned. + /// @param[in] path + /// Input path to be resolved, in the form of a llvm::SmallString or similar. //------------------------------------------------------------------ - static size_t - Resolve (const char *src_path, char *dst_path, size_t dst_len); + static void + Resolve (llvm::SmallVectorImpl<char> &path); FileSpec CopyByAppendingPathComponent (const char *new_path) const; @@ -665,18 +675,9 @@ public: /// /// @param[in] dst_path /// Buffer to store the resolved path. - /// - /// @param[in] dst_len - /// Size of the buffer pointed to by dst_path. - /// - /// @result - /// The number of characters required to write the resolved path, or 0 if - /// the user name could not be found. If the - /// resolved path doesn't fit in dst_len, dst_len-1 characters will - /// be written to \a dst_path, but the actual required length will still be returned. //------------------------------------------------------------------ - static size_t - ResolveUsername (const char *src_path, char *dst_path, size_t dst_len); + static void + ResolveUsername (llvm::SmallVectorImpl<char> &path); static size_t ResolvePartialUsername (const char *partial_name, StringList &matches); @@ -709,6 +710,7 @@ protected: ConstString m_directory; ///< The uniqued directory path ConstString m_filename; ///< The uniqued filename path mutable bool m_is_resolved; ///< True if this path has been resolved. + PathSyntax m_syntax; ///< The syntax that this path uses (e.g. Windows / Posix) }; //---------------------------------------------------------------------- diff --git a/include/lldb/Host/FileSystem.h b/include/lldb/Host/FileSystem.h new file mode 100644 index 000000000000..adcbfc9d590d --- /dev/null +++ b/include/lldb/Host/FileSystem.h @@ -0,0 +1,43 @@ +//===-- FileSystem.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_Host_FileSystem_h +#define liblldb_Host_FileSystem_h + +#include <stdint.h> + +#include "lldb/lldb-types.h" + +#include "lldb/Core/Error.h" +#include "lldb/Host/FileSpec.h" + +namespace lldb_private +{ +class FileSystem +{ + public: + static FileSpec::PathSyntax GetNativePathSyntax(); + + static Error MakeDirectory(const char *path, uint32_t mode); + static Error DeleteDirectory(const char *path, bool recurse); + + static Error GetFilePermissions(const char *path, uint32_t &file_permissions); + static Error SetFilePermissions(const char *path, uint32_t file_permissions); + static lldb::user_id_t GetFileSize(const FileSpec &file_spec); + static bool GetFileExists(const FileSpec &file_spec); + + static Error Symlink(const char *src, const char *dst); + static Error Readlink(const char *path, char *buf, size_t buf_len); + static Error Unlink(const char *path); + + static bool CalculateMD5(const FileSpec &file_spec, uint64_t &low, uint64_t &high); +}; +} + +#endif diff --git a/include/lldb/Host/Host.h b/include/lldb/Host/Host.h index 862b1ed79432..19ed7b01e80f 100644 --- a/include/lldb/Host/Host.h +++ b/include/lldb/Host/Host.h @@ -17,11 +17,16 @@ #include <string> #include "lldb/lldb-private.h" +#include "lldb/lldb-private-forward.h" #include "lldb/Core/StringList.h" #include "lldb/Host/File.h" +#include "lldb/Host/FileSpec.h" namespace lldb_private { +class FileAction; +class ProcessLaunchInfo; + //---------------------------------------------------------------------- /// @class Host Host.h "lldb/Host/Host.h" /// @brief A class that provides host computer information. @@ -32,6 +37,10 @@ namespace lldb_private { class Host { public: + + /// A value of std::numeric_limits<uint32_t>::max() is used if there is no practical limit. + static const uint32_t MAX_THREAD_NAME_LENGTH; + typedef bool (*MonitorChildProcessCallback) (void *callback_baton, lldb::pid_t pid, bool exited, @@ -48,11 +57,11 @@ public: /// thread so the callback function must be thread safe. /// /// When the callback gets called, the return value indicates if - /// minotoring should stop. If \b true is returned from \a callback + /// monitoring should stop. If \b true is returned from \a callback /// the information will be removed. If \b false is returned then /// monitoring will continue. If the child process exits, the /// monitoring will automatically stop after the callback returned - /// ragardless of the callback return value. + /// regardless of the callback return value. /// /// @param[in] callback /// A function callback to call when a child receives a signal @@ -83,68 +92,6 @@ public: lldb::pid_t pid, bool monitor_signals); - //------------------------------------------------------------------ - /// Get the host page size. - /// - /// @return - /// The size in bytes of a VM page on the host system. - //------------------------------------------------------------------ - static size_t - GetPageSize(); - - //------------------------------------------------------------------ - /// Returns the endianness of the host system. - /// - /// @return - /// Returns the endianness of the host system as a lldb::ByteOrder - /// enumeration. - //------------------------------------------------------------------ - static lldb::ByteOrder - GetByteOrder (); - - //------------------------------------------------------------------ - /// Returns the number of CPUs on this current host. - /// - /// @return - /// Number of CPUs on this current host, or zero if the number - /// of CPUs can't be determined on this host. - //------------------------------------------------------------------ - static uint32_t - GetNumberCPUS (); - - static bool - GetOSVersion (uint32_t &major, - uint32_t &minor, - uint32_t &update); - - static bool - GetOSBuildString (std::string &s); - - static bool - GetOSKernelDescription (std::string &s); - - static bool - GetHostname (std::string &s); - - static const char * - GetUserName (uint32_t uid, std::string &user_name); - - static const char * - GetGroupName (uint32_t gid, std::string &group_name); - - static uint32_t - GetUserID (); - - static uint32_t - GetGroupID (); - - static uint32_t - GetEffectiveUserID (); - - static uint32_t - GetEffectiveGroupID (); - - enum SystemLogType { eSystemLogWarning, @@ -158,67 +105,6 @@ public: SystemLog (SystemLogType type, const char *format, va_list args); //------------------------------------------------------------------ - /// Gets the host architecture. - /// - /// @return - /// A const architecture object that represents the host - /// architecture. - //------------------------------------------------------------------ - enum SystemDefaultArchitecture - { - eSystemDefaultArchitecture, // The overall default architecture that applications will run on this host - eSystemDefaultArchitecture32, // If this host supports 32 bit programs, return the default 32 bit arch - eSystemDefaultArchitecture64 // If this host supports 64 bit programs, return the default 64 bit arch - }; - - static const ArchSpec & - GetArchitecture (SystemDefaultArchitecture arch_kind = eSystemDefaultArchitecture); - - //------------------------------------------------------------------ - /// Gets the host vendor string. - /// - /// @return - /// A const string object containing the host vendor name. - //------------------------------------------------------------------ - static const ConstString & - GetVendorString (); - - //------------------------------------------------------------------ - /// Gets the host Operating System (OS) string. - /// - /// @return - /// A const string object containing the host OS name. - //------------------------------------------------------------------ - static const ConstString & - GetOSString (); - - //------------------------------------------------------------------ - /// Gets the host target triple as a const string. - /// - /// @return - /// A const string object containing the host target triple. - //------------------------------------------------------------------ - static const ConstString & - 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 @@ -259,7 +145,7 @@ public: /// /// This function call lets the current host OS do any thread /// specific initialization that it needs, including naming the - /// thread. No cleanup routine is exptected to be called + /// thread. No cleanup routine is expected to be called /// /// @param[in] name /// The current thread's name in the current process. @@ -357,16 +243,6 @@ public: SetShortThreadName (lldb::pid_t pid, lldb::tid_t tid, const char *name, size_t len); //------------------------------------------------------------------ - /// Gets the FileSpec of the current process (the process that - /// that is running the LLDB code). - /// - /// @return - /// \b A file spec with the program name. - //------------------------------------------------------------------ - static FileSpec - GetProgramFileSpec (); - - //------------------------------------------------------------------ /// Given an address in the current process (the process that /// is running the LLDB code), return the name of the module that /// it comes from. This can be useful when you need to know the @@ -383,8 +259,6 @@ public: //------------------------------------------------------------------ static FileSpec GetModuleFileSpecForHostAddress (const void *host_addr); - - //------------------------------------------------------------------ /// If you have an executable that is in a bundle and want to get @@ -410,7 +284,7 @@ public: //------------------------------------------------------------------ /// When executable files may live within a directory, where the /// directory represents an executable bundle (like the MacOSX - /// app bundles), the locate the executable within the containing + /// app bundles), then locate the executable within the containing /// bundle. /// /// @param[in,out] file @@ -426,28 +300,6 @@ public: ResolveExecutableInBundle (FileSpec &file); //------------------------------------------------------------------ - /// Find a resource files that are related to LLDB. - /// - /// Operating systems have different ways of storing shared - /// libraries and related resources. This function abstracts the - /// access to these paths. - /// - /// @param[in] path_type - /// The type of LLDB resource path you are looking for. If the - /// enumeration ends with "Dir", then only the \a file_spec's - /// directory member gets filled in. - /// - /// @param[in] file_spec - /// A file spec that gets filled in with the appriopriate path. - /// - /// @return - /// \b true if \a resource_path was resolved, \a false otherwise. - //------------------------------------------------------------------ - static bool - GetLLDBPath (PathType path_type, - FileSpec &file_spec); - - //------------------------------------------------------------------ /// Set a string that can be displayed if host application crashes. /// /// Some operating systems have the ability to print a description @@ -477,14 +329,19 @@ public: static bool GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info); -#if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) +#if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined (__NetBSD__) static short GetPosixspawnFlags (ProcessLaunchInfo &launch_info); static Error LaunchProcessPosixSpawn (const char *exe_path, ProcessLaunchInfo &launch_info, ::pid_t &pid); + + static bool AddPosixSpawnFileAction(void *file_actions, const FileAction *info, Log *log, Error &error); #endif + static const lldb_private::UnixSignalsSP& + GetUnixSignals (); + static lldb::pid_t LaunchApplication (const FileSpec &app_file_spec); @@ -503,6 +360,9 @@ public: static lldb::DataBufferSP GetAuxvData (lldb_private::Process *process); + static lldb::DataBufferSP + GetAuxvData (lldb::pid_t pid); + static lldb::TargetSP GetDummyTarget (Debugger &debugger); @@ -515,79 +375,6 @@ public: static size_t GetEnvironment (StringList &env); - - enum DynamicLibraryOpenOptions - { - eDynamicLibraryOpenOptionLazy = (1u << 0), // Lazily resolve symbols in this dynamic library - eDynamicLibraryOpenOptionLocal = (1u << 1), // Only open a shared library with local access (hide it from the global symbol namespace) - eDynamicLibraryOpenOptionLimitGetSymbol = (1u << 2) // DynamicLibraryGetSymbol calls on this handle will only return matches from this shared library - }; - static void * - DynamicLibraryOpen (const FileSpec &file_spec, - uint32_t options, - Error &error); - - static Error - DynamicLibraryClose (void *dynamic_library_handle); - - static void * - DynamicLibraryGetSymbol (void *dynamic_library_handle, - const char *symbol_name, - Error &error); - - static Error - MakeDirectory (const char* path, uint32_t mode); - - static Error - GetFilePermissions (const char* path, uint32_t &file_permissions); - - static Error - SetFilePermissions (const char* path, uint32_t file_permissions); - - static Error - Symlink (const char *src, const char *dst); - - static Error - Readlink (const char *path, char *buf, size_t buf_len); - - static Error - Unlink (const char *path); - - static lldb::user_id_t - OpenFile (const FileSpec& file_spec, - uint32_t flags, - uint32_t mode, - Error &error); - - static bool - CloseFile (lldb::user_id_t fd, - Error &error); - - static uint64_t - WriteFile (lldb::user_id_t fd, - uint64_t offset, - const void* src, - uint64_t src_len, - Error &error); - - static uint64_t - ReadFile (lldb::user_id_t fd, - uint64_t offset, - void* dst, - uint64_t dst_len, - Error &error); - - static lldb::user_id_t - GetFileSize (const FileSpec& file_spec); - - static bool - GetFileExists (const FileSpec& file_spec); - - static bool - CalculateMD5 (const FileSpec& file_spec, - uint64_t &low, - uint64_t &high); - }; } // namespace lldb_private diff --git a/include/lldb/Host/HostGetOpt.h b/include/lldb/Host/HostGetOpt.h index f4b2c87be230..761c1a118600 100644 --- a/include/lldb/Host/HostGetOpt.h +++ b/include/lldb/Host/HostGetOpt.h @@ -10,11 +10,15 @@ #ifndef _MSC_VER +#ifdef _WIN32 +#define _BSD_SOURCE // Required so that getopt.h defines optreset +#endif + #include <unistd.h> #include <getopt.h> #else -#include <lldb/Host/windows/GetOptInc.h> +#include <lldb/Host/windows/getopt/GetOptInc.h> #endif diff --git a/include/lldb/Host/HostInfo.h b/include/lldb/Host/HostInfo.h new file mode 100644 index 000000000000..cbbf6cd2d49c --- /dev/null +++ b/include/lldb/Host/HostInfo.h @@ -0,0 +1,61 @@ +//===-- HostInfoBase.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_Host_HostInfo_h_ +#define lldb_Host_HostInfo_h_ + +//---------------------------------------------------------------------- +/// @class HostInfo HostInfo.h "lldb/Host/HostInfo.h" +/// @brief A class that provides host computer information. +/// +/// HostInfo is a class that answers information about the host operating +/// system. Note that HostInfo is NOT intended to be used to manipulate or +/// control the operating system. +/// +/// HostInfo is implemented in an OS-specific class (for example +/// HostInfoWindows) in a separate file, and then typedefed to HostInfo here. +/// Users of the class reference it as HostInfo::method(). +/// +/// Not all hosts provide the same functionality. It is important that methods +/// only be implemented at the lowest level at which they make sense. It should +/// be up to the clients of the class to ensure that they not attempt to call a +/// method which doesn't make sense for a particular platform. For example, +/// when implementing a method that only makes sense on a posix-compliant +/// system, implement it on HostInfoPosix, and not on HostInfoBase with a +/// default implementation. This way, users of HostInfo are required to think +/// about the implications of calling a particular method and if used in a +/// context where the method doesn't make sense, will generate a compiler error. +/// +//---------------------------------------------------------------------- + +#if defined(_WIN32) +#include "lldb/Host/windows/HostInfoWindows.h" +#define HOST_INFO_TYPE HostInfoWindows +#elif defined(__linux__) +#include "lldb/Host/linux/HostInfoLinux.h" +#define HOST_INFO_TYPE HostInfoLinux +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#include "lldb/Host/freebsd/HostInfoFreeBSD.h" +#define HOST_INFO_TYPE HostInfoFreeBSD +#elif defined(__APPLE__) +#include "lldb/Host/macosx/HostInfoMacOSX.h" +#define HOST_INFO_TYPE HostInfoMacOSX +#else +#include "lldb/Host/posix/HostInfoPosix.h" +#define HOST_INFO_TYPE HostInfoPosix +#endif + +namespace lldb_private +{ +typedef HOST_INFO_TYPE HostInfo; +} + +#undef HOST_INFO_TYPE + +#endif diff --git a/include/lldb/Host/HostInfoBase.h b/include/lldb/Host/HostInfoBase.h new file mode 100644 index 000000000000..f890dbc0b01b --- /dev/null +++ b/include/lldb/Host/HostInfoBase.h @@ -0,0 +1,119 @@ +//===-- HostInfoBase.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_Host_HostInfoBase_h_ +#define lldb_Host_HostInfoBase_h_ + +#include "lldb/Core/ArchSpec.h" +#include "lldb/Host/FileSpec.h" +#include "lldb/lldb-enumerations.h" + +#include "llvm/ADT/StringRef.h" + +#include <stdint.h> + +#include <string> + +namespace lldb_private +{ + +class FileSpec; + +class HostInfoBase +{ + private: + // Static class, unconstructable. + HostInfoBase() {} + ~HostInfoBase() {} + + public: + static void Initialize(); + + //------------------------------------------------------------------ + /// Returns the number of CPUs on this current host. + /// + /// @return + /// Number of CPUs on this current host, or zero if the number + /// of CPUs can't be determined on this host. + //------------------------------------------------------------------ + static uint32_t GetNumberCPUS(); + + //------------------------------------------------------------------ + /// Gets the host vendor string. + /// + /// @return + /// A const string object containing the host vendor name. + //------------------------------------------------------------------ + static llvm::StringRef GetVendorString(); + + //------------------------------------------------------------------ + /// Gets the host Operating System (OS) string. + /// + /// @return + /// A const string object containing the host OS name. + //------------------------------------------------------------------ + static llvm::StringRef GetOSString(); + + //------------------------------------------------------------------ + /// Gets the host target triple as a const string. + /// + /// @return + /// A const string object containing the host target triple. + //------------------------------------------------------------------ + static llvm::StringRef GetTargetTriple(); + + //------------------------------------------------------------------ + /// Gets the host architecture. + /// + /// @return + /// A const architecture object that represents the host + /// architecture. + //------------------------------------------------------------------ + enum ArchitectureKind + { + eArchKindDefault, // The overall default architecture that applications will run on this host + eArchKind32, // If this host supports 32 bit programs, return the default 32 bit arch + eArchKind64 // If this host supports 64 bit programs, return the default 64 bit arch + }; + + static const ArchSpec &GetArchitecture(ArchitectureKind arch_kind = eArchKindDefault); + + //------------------------------------------------------------------ + /// Find a resource files that are related to LLDB. + /// + /// Operating systems have different ways of storing shared + /// libraries and related resources. This function abstracts the + /// access to these paths. + /// + /// @param[in] path_type + /// The type of LLDB resource path you are looking for. If the + /// enumeration ends with "Dir", then only the \a file_spec's + /// directory member gets filled in. + /// + /// @param[in] file_spec + /// A file spec that gets filled in with the appropriate path. + /// + /// @return + /// \b true if \a resource_path was resolved, \a false otherwise. + //------------------------------------------------------------------ + static bool GetLLDBPath(lldb::PathType type, FileSpec &file_spec); + + protected: + static bool ComputeSharedLibraryDirectory(FileSpec &file_spec); + static bool ComputeSupportExeDirectory(FileSpec &file_spec); + static bool ComputeTempFileDirectory(FileSpec &file_spec); + static bool ComputeHeaderDirectory(FileSpec &file_spec); + static bool ComputeSystemPluginsDirectory(FileSpec &file_spec); + static bool ComputeUserPluginsDirectory(FileSpec &file_spec); + + static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64); +}; +} + +#endif diff --git a/include/lldb/Host/HostProcess.h b/include/lldb/Host/HostProcess.h new file mode 100644 index 000000000000..2c10709ce942 --- /dev/null +++ b/include/lldb/Host/HostProcess.h @@ -0,0 +1,44 @@ +//===-- HostProcess.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_Host_HostProcess_h_ +#define lldb_Host_HostProcess_h_ + +//---------------------------------------------------------------------- +/// @class HostInfo HostInfo.h "lldb/Host/HostProcess.h" +/// @brief A class that represents a running process on the host machine. +/// +/// HostProcess allows querying and manipulation of processes running on the +/// host machine. It is not intended to be represent a process which is +/// being debugged, although the native debug engine of a platform may likely +/// back inferior processes by a HostProcess. +/// +/// HostProcess is implemented using static polymorphism so that on any given +/// platform, an instance of HostProcess will always be able to bind statically +/// to the concrete Process implementation for that platform. See HostInfo +/// for more details. +/// +//---------------------------------------------------------------------- + +#if defined(_WIN32) +#include "lldb/Host/windows/HostProcessWindows.h" +#define HOST_PROCESS_TYPE HostProcessWindows +#else +#include "lldb/Host/posix/HostProcessPosix.h" +#define HOST_PROCESS_TYPE HostProcessPosix +#endif + +namespace lldb_private +{ + typedef HOST_PROCESS_TYPE HostProcess; +} + +#undef HOST_PROCESS_TYPE + +#endif diff --git a/include/lldb/Host/IOObject.h b/include/lldb/Host/IOObject.h new file mode 100644 index 000000000000..532b1fd1bfce --- /dev/null +++ b/include/lldb/Host/IOObject.h @@ -0,0 +1,61 @@ +//===-- IOObject.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_Host_Common_IOObject_h_ +#define liblldb_Host_Common_IOObject_h_ + +#include <stdarg.h> +#include <stdio.h> +#include <sys/types.h> + +#include "lldb/lldb-private.h" + +namespace lldb_private { + +class IOObject +{ +public: + typedef enum + { + eFDTypeFile, // Other FD requiring read/write + eFDTypeSocket, // Socket requiring send/recv + } FDType; + + // TODO: On Windows this should be a HANDLE, and wait should use + // WaitForMultipleObjects + typedef int WaitableHandle; + static const WaitableHandle kInvalidHandleValue; + + IOObject(FDType type, bool should_close) + : m_fd_type(type) + , m_should_close_fd(should_close) + { + } + virtual ~IOObject() {} + + virtual Error Read (void *buf, size_t &num_bytes) = 0; + virtual Error Write (const void *buf, size_t &num_bytes) = 0; + virtual bool IsValid() const = 0; + virtual Error Close() = 0; + + FDType GetFdType() const { return m_fd_type; } + + virtual WaitableHandle GetWaitableHandle() = 0; + +protected: + FDType m_fd_type; + bool m_should_close_fd; // True if this class should close the file descriptor when it goes away. + +private: + DISALLOW_COPY_AND_ASSIGN (IOObject); +}; + +} + +#endif diff --git a/include/lldb/Host/OptionParser.h b/include/lldb/Host/OptionParser.h index ca83eeb1ed77..5aa7db5d34bf 100644 --- a/include/lldb/Host/OptionParser.h +++ b/include/lldb/Host/OptionParser.h @@ -16,18 +16,17 @@ struct option; namespace lldb_private { -typedef struct Option +struct OptionDefinition; + +struct Option { - // name of long option - const char *name; - // one of no_argument, required_argument, and optional_argument: - // whether option takes an argument - int has_arg; + // The definition of the option that this refers to. + const OptionDefinition *definition; // if not NULL, set *flag to val when option found int *flag; // if flag not NULL, value to set *flag to; else return value int val; -} Option; +}; class OptionParser { diff --git a/include/lldb/Host/Pipe.h b/include/lldb/Host/Pipe.h new file mode 100644 index 000000000000..b36c85cfbe87 --- /dev/null +++ b/include/lldb/Host/Pipe.h @@ -0,0 +1,83 @@ +//===-- Pipe.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_Pipe_h_ +#define liblldb_Pipe_h_ +#if defined(__cplusplus) + +#include <stdarg.h> +#include <stdio.h> +#include <sys/types.h> + +#include "lldb/lldb-private.h" + +namespace lldb_private { + +//---------------------------------------------------------------------- +/// @class Pipe Pipe.h "lldb/Host/Pipe.h" +/// @brief A class that abtracts unix style pipes. +/// +/// A class that abstracts the LLDB core from host pipe functionality. +//---------------------------------------------------------------------- +class Pipe +{ +public: + static int kInvalidDescriptor; + + Pipe(); + + ~Pipe(); + + bool + Open(); + + bool + IsValid() const; + + bool + ReadDescriptorIsValid() const; + + bool + WriteDescriptorIsValid() const; + + int + GetReadFileDescriptor() const; + + int + GetWriteFileDescriptor() const; + + // Close both descriptors + void + Close(); + + bool + CloseReadFileDescriptor(); + + bool + CloseWriteFileDescriptor(); + + int + ReleaseReadFileDescriptor(); + + int + ReleaseWriteFileDescriptor(); + + size_t + Read (void *buf, size_t size); + + size_t + Write (const void *buf, size_t size); +private: + int m_fds[2]; +}; + +} // namespace lldb_private + +#endif // #if defined(__cplusplus) +#endif // liblldb_Pipe_h_ diff --git a/include/lldb/Host/Predicate.h b/include/lldb/Host/Predicate.h index 6ddf20b67c69..f0e83ea5894b 100644 --- a/include/lldb/Host/Predicate.h +++ b/include/lldb/Host/Predicate.h @@ -78,7 +78,7 @@ public: //------------------------------------------------------------------ /// Destructor. /// - /// Destrory the condition, mutex, and T objects. + /// Destroy the condition, mutex, and T objects. //------------------------------------------------------------------ ~Predicate () { @@ -112,7 +112,7 @@ public: /// The new value to set. /// /// @param[in] broadcast_type - /// A value indicating when and if to broadast. See the + /// A value indicating when and if to broadcast. See the /// PredicateBroadcastType enumeration for details. /// /// @see Predicate::Broadcast() @@ -140,7 +140,7 @@ public: /// The bits to set in \a m_value. /// /// @param[in] broadcast_type - /// A value indicating when and if to broadast. See the + /// A value indicating when and if to broadcast. See the /// PredicateBroadcastType enumeration for details. /// /// @see Predicate::Broadcast() @@ -168,7 +168,7 @@ public: /// The bits to clear in \a m_value. /// /// @param[in] broadcast_type - /// A value indicating when and if to broadast. See the + /// A value indicating when and if to broadcast. See the /// PredicateBroadcastType enumeration for details. /// /// @see Predicate::Broadcast() @@ -464,7 +464,7 @@ public: protected: //---------------------------------------------------------------------- - // pthread condition and mutex variable to controll access and allow + // pthread condition and mutex variable to control access and allow // blocking between the main thread and the spotlight index thread. //---------------------------------------------------------------------- T m_value; ///< The templatized value T that we are protecting access to @@ -477,7 +477,7 @@ private: /// Broadcast if needed. /// /// Check to see if we need to broadcast to our condition variable - /// depedning on the \a old_value and on the \a broadcast_type. + /// depending on the \a old_value and on the \a broadcast_type. /// /// If \a broadcast_type is eBroadcastNever, no broadcast will be /// sent. diff --git a/include/lldb/Host/Socket.h b/include/lldb/Host/Socket.h new file mode 100644 index 000000000000..0f3aa073001c --- /dev/null +++ b/include/lldb/Host/Socket.h @@ -0,0 +1,103 @@ +//===-- Socket.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_Host_Socket_h_ +#define liblldb_Host_Socket_h_ + +#include <string> + +#include "lldb/lldb-private.h" + +#include "lldb/Core/Error.h" +#include "lldb/Host/IOObject.h" +#include "lldb/Host/Predicate.h" +#include "lldb/Host/SocketAddress.h" + +#ifdef _WIN32 +#include "lldb/Host/windows/windows.h" +#include <winsock2.h> +#include <ws2tcpip.h> +#endif + +namespace llvm +{ + class StringRef; +} + +namespace lldb_private { + +#if defined(_MSC_VER) + typedef SOCKET NativeSocket; +#else + typedef int NativeSocket; +#endif + +class Socket : public IOObject +{ +public: + typedef enum + { + ProtocolTcp, + ProtocolUdp, + ProtocolUnixDomain + } SocketProtocol; + + static const NativeSocket kInvalidSocketValue; + + Socket(NativeSocket socket, SocketProtocol protocol, bool should_close); + ~Socket(); + + // Initialize a Tcp Socket object in listening mode. listen and accept are implemented + // separately because the caller may wish to manipulate or query the socket after it is + // initialized, but before entering a blocking accept. + static Error TcpListen(llvm::StringRef host_and_port, Socket *&socket, Predicate<uint16_t>* predicate); + static Error TcpConnect(llvm::StringRef host_and_port, Socket *&socket); + static Error UdpConnect(llvm::StringRef host_and_port, Socket *&send_socket, Socket *&recv_socket); + static Error UnixDomainConnect(llvm::StringRef host_and_port, Socket *&socket); + static Error UnixDomainAccept(llvm::StringRef host_and_port, Socket *&socket); + + // Blocks on a listening socket until a connection is received. This method assumes that + // |this->m_socket| is a listening socket, created via either TcpListen() or via the native + // constructor that takes a NativeSocket, which itself was created via a call to |listen()| + Error BlockingAccept(llvm::StringRef host_and_port, Socket *&socket); + + int GetOption (int level, int option_name, int &option_value); + int SetOption (int level, int option_name, int option_value); + + static uint16_t GetPortNumber(const NativeSocket& socket); + uint16_t GetPortNumber () const; + + NativeSocket GetNativeSocket () const { return m_socket; } + SocketProtocol GetSocketProtocol() const { return m_protocol; } + + virtual Error Read (void *buf, size_t &num_bytes); + virtual Error Write (const void *buf, size_t &num_bytes); + + virtual Error PreDisconnect(); + virtual Error Close(); + + virtual bool IsValid() const { return m_socket != kInvalidSocketValue; } + virtual WaitableHandle GetWaitableHandle(); + +protected: + static bool + DecodeHostAndPort (llvm::StringRef host_and_port, + std::string &host_str, + std::string &port_str, + int32_t& port, + Error *error_ptr); + + + SocketProtocol m_protocol; + NativeSocket m_socket; + SocketAddress m_udp_send_sockaddr; // Send address used for UDP connections. +}; +} + +#endif diff --git a/include/lldb/Host/SocketAddress.h b/include/lldb/Host/SocketAddress.h index 4dc62102103a..3598a42a82d0 100644 --- a/include/lldb/Host/SocketAddress.h +++ b/include/lldb/Host/SocketAddress.h @@ -16,7 +16,7 @@ #ifdef _WIN32 #include "lldb/Host/windows/windows.h" #include <winsock2.h> -#include <WS2tcpip.h> +#include <ws2tcpip.h> typedef ADDRESS_FAMILY sa_family_t; #else #include <sys/socket.h> @@ -82,7 +82,7 @@ public: GetLength () const; //------------------------------------------------------------------ - // Get the mex length for the the largest socket address supported. + // Get the max length for the largest socket address supported. //------------------------------------------------------------------ static socklen_t GetMaxLength (); @@ -203,7 +203,7 @@ public: // Conversion operators to allow getting the contents of this class // as a pointer to the appropriate structure. This allows an instance // of this class to be used in calls that take one of the sockaddr - // structure variants without having to manally use the correct + // structure variants without having to manually use the correct // accessor function. //------------------------------------------------------------------ diff --git a/include/lldb/Host/Symbols.h b/include/lldb/Host/Symbols.h index 652a614e6355..d6c86333d709 100644 --- a/include/lldb/Host/Symbols.h +++ b/include/lldb/Host/Symbols.h @@ -50,7 +50,7 @@ public: // Locate the object and symbol file given a module specification. // // Locating the file can try to download the file from a corporate build - // respository, or using any other means necessary to locate both the + // repository, or using any other means necessary to locate both the // unstripped object file and the debug symbols. // The force_lookup argument controls whether the external program is called // unconditionally to find the symbol file, or if the user's settings are diff --git a/include/lldb/Host/Terminal.h b/include/lldb/Host/Terminal.h index 5ea88c515637..4a6017fc2eee 100644 --- a/include/lldb/Host/Terminal.h +++ b/include/lldb/Host/Terminal.h @@ -101,7 +101,7 @@ public: /// /// @param[in] save_process_group /// If \b true, save the process group settings, else do not - /// save the process group setttings for a TTY. + /// save the process group settings for a TTY. /// /// @return /// Returns \b true if \a fd describes a TTY and if the state diff --git a/include/lldb/Host/TimeValue.h b/include/lldb/Host/TimeValue.h index ba230045307f..1792d343a6a6 100644 --- a/include/lldb/Host/TimeValue.h +++ b/include/lldb/Host/TimeValue.h @@ -15,11 +15,7 @@ #ifndef _MSC_VER #include <sys/time.h> -// BEGIN: MinGW work around -#if !defined(_STRUCT_TIMESPEC) && !defined(HAVE_STRUCT_TIMESPEC) -#include <pthread.h> -#endif -// END: MinGW work around + #endif // C++ Includes diff --git a/include/lldb/Host/freebsd/HostInfoFreeBSD.h b/include/lldb/Host/freebsd/HostInfoFreeBSD.h new file mode 100644 index 000000000000..1404a4b1525c --- /dev/null +++ b/include/lldb/Host/freebsd/HostInfoFreeBSD.h @@ -0,0 +1,29 @@ +//===-- HostInfoFreeBSD.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_Host_freebsd_HostInfoFreeBSD_h_ +#define lldb_Host_freebsd_HostInfoFreeBSD_h_ + +#include "lldb/Host/FileSpec.h" +#include "lldb/Host/posix/HostInfoPosix.h" + +namespace lldb_private +{ + +class HostInfoFreeBSD : public HostInfoPosix +{ + public: + static bool GetOSVersion(uint32_t &major, uint32_t &minor, uint32_t &update); + static bool GetOSBuildString(std::string &s); + static bool GetOSKernelDescription(std::string &s); + static FileSpec GetProgramFileSpec(); +}; +} + +#endif diff --git a/include/lldb/Host/posix/HostInfoPosix.h b/include/lldb/Host/posix/HostInfoPosix.h new file mode 100644 index 000000000000..6e0dcbe48021 --- /dev/null +++ b/include/lldb/Host/posix/HostInfoPosix.h @@ -0,0 +1,40 @@ +//===-- HostInfoPosix.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_Host_posix_HostInfoPosix_h_ +#define lldb_Host_posix_HostInfoPosix_h_ + +#include "lldb/Host/HostInfoBase.h" + +namespace lldb_private +{ + +class HostInfoPosix : public HostInfoBase +{ + friend class HostInfoBase; + + public: + static size_t GetPageSize(); + static bool GetHostname(std::string &s); + static const char *LookupUserName(uint32_t uid, std::string &user_name); + static const char *LookupGroupName(uint32_t gid, std::string &group_name); + + static uint32_t GetUserID(); + static uint32_t GetGroupID(); + static uint32_t GetEffectiveUserID(); + static uint32_t GetEffectiveGroupID(); + + protected: + static bool ComputeSupportExeDirectory(FileSpec &file_spec); + static bool ComputeHeaderDirectory(FileSpec &file_spec); + static bool ComputePythonDirectory(FileSpec &file_spec); +}; +} + +#endif diff --git a/include/lldb/Host/posix/HostProcessPosix.h b/include/lldb/Host/posix/HostProcessPosix.h new file mode 100644 index 000000000000..aa003ee4845e --- /dev/null +++ b/include/lldb/Host/posix/HostProcessPosix.h @@ -0,0 +1,46 @@ +//===-- HostProcessPosix.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_Host_HostProcesPosix_h_ +#define lldb_Host_HostProcesPosix_h_ + +#include "lldb/lldb-types.h" +#include "lldb/Core/Error.h" +#include "lldb/Target/ProcessLaunchInfo.h" + +namespace lldb_private +{ + +class FileSpec; + +class HostProcessPosix +{ + public: + static const lldb::pid_t kInvalidProcessId; + + HostProcessPosix(); + ~HostProcessPosix(); + + Error Signal(int signo) const; + static Error Signal(lldb::pid_t pid, int signo); + + Error Create(lldb::pid_t pid); + Error Terminate(int signo); + Error GetMainModule(FileSpec &file_spec) const; + + lldb::pid_t GetProcessId() const; + bool IsRunning() const; + + private: + + lldb::pid_t m_pid; +}; +} + +#endif |
