diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2013-11-06 16:48:53 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2013-11-06 16:48:53 +0000 |
| commit | f21a844f60ae6c74fcf1fddca32461acce3c1ee0 (patch) | |
| tree | 56d79f94966870db1cecd65a7264510a25fd1cba /include/lldb/Host | |
| parent | 37d22554be9f5a677dad2a95b7ef22fe59c66a8a (diff) | |
Notes
Diffstat (limited to 'include/lldb/Host')
| -rw-r--r-- | include/lldb/Host/Condition.h | 6 | ||||
| -rw-r--r-- | include/lldb/Host/Config.h | 6 | ||||
| -rw-r--r-- | include/lldb/Host/File.h | 55 | ||||
| -rw-r--r-- | include/lldb/Host/FileSpec.h | 17 | ||||
| -rw-r--r-- | include/lldb/Host/Host.h | 56 | ||||
| -rw-r--r-- | include/lldb/Host/Mutex.h | 6 | ||||
| -rw-r--r-- | include/lldb/Host/OptionParser.h | 53 | ||||
| -rw-r--r-- | include/lldb/Host/ProcessRunLock.h | 81 | ||||
| -rw-r--r-- | include/lldb/Host/SocketAddress.h | 9 | ||||
| -rw-r--r-- | include/lldb/Host/Symbols.h | 1 | ||||
| -rw-r--r-- | include/lldb/Host/Terminal.h | 3 | ||||
| -rw-r--r-- | include/lldb/Host/TimeValue.h | 24 |
12 files changed, 224 insertions, 93 deletions
diff --git a/include/lldb/Host/Condition.h b/include/lldb/Host/Condition.h index 98439ee2ebdfd..2f1858b75a565 100644 --- a/include/lldb/Host/Condition.h +++ b/include/lldb/Host/Condition.h @@ -12,7 +12,7 @@ #if defined(__cplusplus) -#include <pthread.h> +#include "lldb/lldb-types.h" #include "lldb/Host/Mutex.h" namespace lldb_private { @@ -105,7 +105,7 @@ protected: //------------------------------------------------------------------ // Member variables //------------------------------------------------------------------ - pthread_cond_t m_condition; ///< The condition variable. + lldb::condition_t m_condition; ///< The condition variable. //------------------------------------------------------------------ /// Get accessor to the pthread condition object. @@ -113,7 +113,7 @@ protected: /// @return /// A pointer to the condition variable owned by this object. //------------------------------------------------------------------ - pthread_cond_t * + lldb::condition_t * GetCondition (); }; diff --git a/include/lldb/Host/Config.h b/include/lldb/Host/Config.h index 2d5d39baac3dc..80616b747cf5f 100644 --- a/include/lldb/Host/Config.h +++ b/include/lldb/Host/Config.h @@ -14,7 +14,7 @@ #include "lldb/Host/macosx/Config.h" -#elif defined(__linux__) +#elif defined(__linux__) || defined(__GNU__) #include "lldb/Host/linux/Config.h" @@ -26,6 +26,10 @@ #include "lldb/Host/mingw/Config.h" +#elif defined(_MSC_VER) + +#include "lldb/Host/msvc/Config.h" + #else #error undefined platform diff --git a/include/lldb/Host/File.h b/include/lldb/Host/File.h index df7fe92cccba8..7ca582402b32b 100644 --- a/include/lldb/Host/File.h +++ b/include/lldb/Host/File.h @@ -11,7 +11,9 @@ #define liblldb_File_h_ #if defined(__cplusplus) +#include <stdarg.h> #include <stdio.h> +#include <sys/types.h> #include "lldb/lldb-private.h" @@ -41,17 +43,20 @@ public: eOpenOptionCanCreateNewOnly = (1u << 6) // Can create file only if it doesn't already exist }; + static mode_t + ConvertOpenOptionsForPOSIXOpen (uint32_t open_options); + enum Permissions { - ePermissionsUserRead = (1u << 0), - ePermissionsUserWrite = (1u << 1), - ePermissionsUserExecute = (1u << 2), - ePermissionsGroupRead = (1u << 3), + ePermissionsUserRead = (1u << 8), + ePermissionsUserWrite = (1u << 7), + ePermissionsUserExecute = (1u << 6), + ePermissionsGroupRead = (1u << 5), ePermissionsGroupWrite = (1u << 4), - ePermissionsGroupExecute = (1u << 5), - ePermissionsWorldRead = (1u << 6), - ePermissionsWorldWrite = (1u << 7), - ePermissionsWorldExecute = (1u << 8), + ePermissionsGroupExecute = (1u << 3), + ePermissionsWorldRead = (1u << 2), + ePermissionsWorldWrite = (1u << 1), + ePermissionsWorldExecute = (1u << 0), ePermissionsUserRW = (ePermissionsUserRead | ePermissionsUserWrite | 0 ), ePermissionsUserRX = (ePermissionsUserRead | 0 | ePermissionsUserExecute ), @@ -117,6 +122,27 @@ public: uint32_t options, uint32_t permissions = ePermissionsDefault); + //------------------------------------------------------------------ + /// Constructor with FileSpec. + /// + /// Takes a FileSpec pointing to a file which can be just a filename, or a full + /// path. If \a path is not NULL or empty, this function will call + /// File::Open (const char *path, uint32_t options, uint32_t permissions). + /// + /// @param[in] path + /// The FileSpec for this file. + /// + /// @param[in] options + /// Options to use when opening (see File::OpenOptions) + /// + /// @param[in] permissions + /// Options to use when opening (see File::Permissions) + /// + /// @see File::Open (const char *path, uint32_t options, uint32_t permissions) + //------------------------------------------------------------------ + File (const FileSpec& filespec, + uint32_t options, + uint32_t permissions = ePermissionsDefault); File (int fd, bool tranfer_ownership) : m_descriptor (fd), @@ -451,6 +477,19 @@ public: //------------------------------------------------------------------ Error Sync (); + + //------------------------------------------------------------------ + /// Get the permissions for a this file. + /// + /// @return + /// Bits logical OR'ed together from the permission bits defined + /// in lldb_private::File::Permissions. + //------------------------------------------------------------------ + uint32_t + GetPermissions(Error &error) const; + + static uint32_t + GetPermissions (const char *path, Error &error); //------------------------------------------------------------------ /// Output printf formatted output to the stream. diff --git a/include/lldb/Host/FileSpec.h b/include/lldb/Host/FileSpec.h index c58be9ec09d5e..dfc6b711ae4a6 100644 --- a/include/lldb/Host/FileSpec.h +++ b/include/lldb/Host/FileSpec.h @@ -177,7 +177,7 @@ public: /// A pointer to this object if either the directory or filename /// is valid, NULL otherwise. //------------------------------------------------------------------ - operator bool() const; + explicit operator bool() const; //------------------------------------------------------------------ /// Logical NOT operator. @@ -624,6 +624,21 @@ public: static size_t Resolve (const char *src_path, char *dst_path, size_t dst_len); + FileSpec + CopyByAppendingPathComponent (const char *new_path) const; + + FileSpec + CopyByRemovingLastPathComponent () const; + + void + AppendPathComponent (const char *new_path); + + void + RemoveLastPathComponent (); + + const char* + GetLastPathComponent () const; + //------------------------------------------------------------------ /// Resolves the user name at the beginning of \a src_path, and writes the output /// to \a dst_path. Note, \a src_path can contain other path components after the diff --git a/include/lldb/Host/Host.h b/include/lldb/Host/Host.h index 547bdd5d637b1..1d667dee5a200 100644 --- a/include/lldb/Host/Host.h +++ b/include/lldb/Host/Host.h @@ -18,6 +18,7 @@ #include "lldb/lldb-private.h" #include "lldb/Core/StringList.h" +#include "lldb/Host/File.h" namespace lldb_private { @@ -209,6 +210,9 @@ public: static lldb::pid_t GetCurrentProcessID (); + static void + Kill(lldb::pid_t pid, int signo); + //------------------------------------------------------------------ /// Get the thread ID for the calling thread in the current process. /// @@ -264,6 +268,17 @@ public: lldb::thread_result_t *thread_result_ptr, Error *error); + typedef void (*ThreadLocalStorageCleanupCallback) (void *p); + + static lldb::thread_key_t + ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback); + + static void* + ThreadLocalStorageGet(lldb::thread_key_t key); + + static void + ThreadLocalStorageSet(lldb::thread_key_t key, void *value); + //------------------------------------------------------------------ /// Gets the name of a thread in a process. /// @@ -458,7 +473,7 @@ public: int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit std::string *command_output, // Pass NULL if you don't want the command output uint32_t timeout_sec, - const char *shell = "/bin/bash"); + const char *shell = LLDB_DEFAULT_SHELL); static lldb::DataBufferSP GetAuxvData (lldb_private::Process *process); @@ -494,6 +509,45 @@ public: DynamicLibraryGetSymbol (void *dynamic_library_handle, const char *symbol_name, Error &error); + + static uint32_t + MakeDirectory (const char* path, mode_t mode); + + static lldb::user_id_t + OpenFile (const FileSpec& file_spec, + uint32_t flags, + mode_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/Mutex.h b/include/lldb/Host/Mutex.h index 63f759efe3668..496dd0496c130 100644 --- a/include/lldb/Host/Mutex.h +++ b/include/lldb/Host/Mutex.h @@ -11,7 +11,7 @@ #define liblldb_Mutex_h_ #if defined(__cplusplus) -#include <pthread.h> +#include "lldb/lldb-types.h" #include <assert.h> #ifdef LLDB_CONFIGURATION_DEBUG @@ -238,7 +238,7 @@ protected: //------------------------------------------------------------------ // TODO: Hide the mutex in the implementation file in case we ever need to port to an // architecture that doesn't have pthread mutexes. - pthread_mutex_t m_mutex; ///< The pthread mutex object. + lldb::mutex_t m_mutex; ///< The OS mutex object. private: //------------------------------------------------------------------ @@ -247,7 +247,7 @@ private: /// @return /// A pointer to the pthread mutex object owned by this object. //------------------------------------------------------------------ - pthread_mutex_t * + lldb::mutex_t * GetMutex(); Mutex(const Mutex&); diff --git a/include/lldb/Host/OptionParser.h b/include/lldb/Host/OptionParser.h new file mode 100644 index 0000000000000..410e4d9f94687 --- /dev/null +++ b/include/lldb/Host/OptionParser.h @@ -0,0 +1,53 @@ +//===-- OptionParser.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_OptionParser_h_ +#define liblldb_OptionParser_h_ + +namespace lldb_private { + +typedef 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; + // 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 +{ +public: + enum OptionArgument + { + eNoArgument = 0, + eRequiredArgument, + eOptionalArgument + }; + + static void Prepare(); + + static void EnableError(bool error); + + static int Parse(int argc, char * const argv [], + const char *optstring, + const Option *longopts, int *longindex); + + static char* GetOptionArgument(); + static int GetOptionIndex(); + static int GetOptionErrorCause(); +}; + +} + +#endif // liblldb_OptionParser_h_ diff --git a/include/lldb/Host/ProcessRunLock.h b/include/lldb/Host/ProcessRunLock.h index f563be73fce07..eca1ad375fc6b 100644 --- a/include/lldb/Host/ProcessRunLock.h +++ b/include/lldb/Host/ProcessRunLock.h @@ -11,9 +11,9 @@ #define liblldb_ProcessRunLock_h_ #if defined(__cplusplus) +#include "lldb/lldb-defines.h" #include "lldb/Host/Mutex.h" #include "lldb/Host/Condition.h" -#include <pthread.h> #include <stdint.h> #include <time.h> @@ -32,75 +32,14 @@ namespace lldb_private { class ProcessRunLock { public: - ProcessRunLock () : - m_rwlock(), - m_running(false) - { - int err = ::pthread_rwlock_init(&m_rwlock, NULL); (void)err; -//#if LLDB_CONFIGURATION_DEBUG -// assert(err == 0); -//#endif - } - - ~ProcessRunLock () - { - int err = ::pthread_rwlock_destroy (&m_rwlock); (void)err; -//#if LLDB_CONFIGURATION_DEBUG -// assert(err == 0); -//#endif - } - - bool - ReadTryLock () - { - ::pthread_rwlock_rdlock (&m_rwlock); - if (m_running == false) - { - return true; - } - ::pthread_rwlock_unlock (&m_rwlock); - return false; - } - - bool - ReadUnlock () - { - return ::pthread_rwlock_unlock (&m_rwlock) == 0; - } - - bool - SetRunning() - { - ::pthread_rwlock_wrlock (&m_rwlock); - m_running = true; - ::pthread_rwlock_unlock (&m_rwlock); - return true; - } - - bool - TrySetRunning() - { - bool r; - - if (::pthread_rwlock_trywrlock (&m_rwlock) == 0) - { - r = !m_running; - m_running = true; - ::pthread_rwlock_unlock (&m_rwlock); - return r; - } - return false; - } - - bool - SetStopped () - { - ::pthread_rwlock_wrlock (&m_rwlock); - m_running = false; - ::pthread_rwlock_unlock (&m_rwlock); - return true; - } - + ProcessRunLock(); + ~ProcessRunLock(); + bool ReadTryLock (); + bool ReadUnlock (); + bool SetRunning (); + bool TrySetRunning (); + bool SetStopped (); +public: class ProcessRunLocker { public: @@ -153,7 +92,7 @@ public: }; protected: - pthread_rwlock_t m_rwlock; + lldb::rwlock_t m_rwlock; bool m_running; private: DISALLOW_COPY_AND_ASSIGN(ProcessRunLock); diff --git a/include/lldb/Host/SocketAddress.h b/include/lldb/Host/SocketAddress.h index e63b238c79944..5e79e94fa9ecc 100644 --- a/include/lldb/Host/SocketAddress.h +++ b/include/lldb/Host/SocketAddress.h @@ -12,9 +12,18 @@ // C Includes #include <stdint.h> + +#ifdef _WIN32 +#include "lldb/Host/windows/windows.h" +#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> #include <netinet/in.h> +#endif #if defined(__FreeBSD__) #include <sys/types.h> diff --git a/include/lldb/Host/Symbols.h b/include/lldb/Host/Symbols.h index 9db68e1ecf157..652a614e6355e 100644 --- a/include/lldb/Host/Symbols.h +++ b/include/lldb/Host/Symbols.h @@ -12,7 +12,6 @@ // C Includes #include <stdint.h> -#include <sys/time.h> // C++ Includes // Other libraries and framework includes diff --git a/include/lldb/Host/Terminal.h b/include/lldb/Host/Terminal.h index b334717c796bb..5ea88c5156376 100644 --- a/include/lldb/Host/Terminal.h +++ b/include/lldb/Host/Terminal.h @@ -12,6 +12,7 @@ #if defined(__cplusplus) #include "lldb/lldb-private.h" +#include "lldb/Host/Config.h" struct termios; @@ -173,7 +174,9 @@ protected: //------------------------------------------------------------------ Terminal m_tty; ///< A terminal int m_tflags; ///< Cached tflags information. +#ifdef LLDB_CONFIG_TERMIOS_SUPPORTED std::unique_ptr<struct termios> m_termios_ap; ///< Cached terminal state information. +#endif lldb::pid_t m_process_group;///< Cached process group information. }; diff --git a/include/lldb/Host/TimeValue.h b/include/lldb/Host/TimeValue.h index 8c43d6d0e5ff6..ba230045307f1 100644 --- a/include/lldb/Host/TimeValue.h +++ b/include/lldb/Host/TimeValue.h @@ -12,6 +12,7 @@ // C Includes #include <stdint.h> +#ifndef _MSC_VER #include <sys/time.h> // BEGIN: MinGW work around @@ -19,6 +20,7 @@ #include <pthread.h> #endif // END: MinGW work around +#endif // C++ Includes // Other libraries and framework includes @@ -40,7 +42,7 @@ public: TimeValue(); TimeValue(const TimeValue& rhs); TimeValue(const struct timespec& ts); - TimeValue(const struct timeval& tv); + explicit TimeValue(uint32_t seconds, uint32_t nanos = 0); ~TimeValue(); //------------------------------------------------------------------ @@ -64,9 +66,6 @@ public: struct timespec GetAsTimeSpec () const; - struct timeval - GetAsTimeVal () const; - bool IsValid () const; @@ -85,6 +84,23 @@ public: void Dump (Stream *s, uint32_t width = 0) const; + /// Returns only the seconds component of the TimeValue. The nanoseconds + /// portion is ignored. No rounding is performed. + /// @brief Retrieve the seconds component + uint32_t seconds() const { return m_nano_seconds / NanoSecPerSec; } + + /// Returns only the nanoseconds component of the TimeValue. The seconds + /// portion is ignored. + /// @brief Retrieve the nanoseconds component. + uint32_t nanoseconds() const { return m_nano_seconds % NanoSecPerSec; } + + /// Returns only the fractional portion of the TimeValue rounded down to the + /// nearest microsecond (divide by one thousand). + /// @brief Retrieve the fractional part as microseconds; + uint32_t microseconds() const { + return (m_nano_seconds % NanoSecPerSec) / NanoSecPerMicroSec; + } + protected: //------------------------------------------------------------------ // Classes that inherit from TimeValue can see and modify these |
