diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2015-07-03 16:57:06 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2015-07-03 16:57:06 +0000 |
| commit | 5e95aa85bb660d45e9905ef1d7180b2678280660 (patch) | |
| tree | 3c2e41c3be19b7fc7666ed45a5f91ec3b6e35f2a /include/lldb/Host | |
| parent | 12bd4897ff0678fa663e09d78ebc22dd255ceb86 (diff) | |
Notes
Diffstat (limited to 'include/lldb/Host')
24 files changed, 693 insertions, 74 deletions
diff --git a/include/lldb/Host/Editline.h b/include/lldb/Host/Editline.h index 9fce193efc9f..697be4cd8e77 100644 --- a/include/lldb/Host/Editline.h +++ b/include/lldb/Host/Editline.h @@ -171,17 +171,13 @@ namespace lldb_private { uint32_t GetCurrentLine(); - /// Hides the current input session in preparation for output - void - Hide(); - - /// Prepare to return to editing after a call to Hide() - void - Refresh(); - /// Interrupt the current edit as if ^C was pressed bool Interrupt(); + + /// Cancel this edit and oblitarate all trace of it + bool + Cancel(); /// Register a callback for the tab key void @@ -207,6 +203,9 @@ namespace lldb_private { bool GetLines (int first_line_number, StringList &lines, bool &interrupted); + void + PrintAsync (Stream *stream, const char *s, size_t len); + private: /// Sets the lowest line number for multi-line editing sessions. A value of zero suppresses @@ -335,7 +334,6 @@ namespace lldb_private { bool m_multiline_enabled = false; std::vector<EditLineStringType> m_input_lines; EditorStatus m_editor_status; - bool m_editor_getting_char = false; bool m_color_prompts = true; int m_terminal_width = 0; int m_base_line_number = 0; @@ -359,6 +357,8 @@ namespace lldb_private { const char * m_fix_indentation_callback_chars = nullptr; CompleteCallbackType m_completion_callback = nullptr; void * m_completion_callback_baton = nullptr; + + Mutex m_output_mutex; }; } diff --git a/include/lldb/Host/File.h b/include/lldb/Host/File.h index 8219cc06fdc2..5747cb5adcfd 100644 --- a/include/lldb/Host/File.h +++ b/include/lldb/Host/File.h @@ -470,7 +470,7 @@ public: GetPermissions(Error &error) const; static uint32_t - GetPermissions (const char *path, Error &error); + GetPermissions(const FileSpec &file_spec, Error &error); //------------------------------------------------------------------ diff --git a/include/lldb/Host/FileSpec.h b/include/lldb/Host/FileSpec.h index 173d948e687b..d0338d41db1b 100644 --- a/include/lldb/Host/FileSpec.h +++ b/include/lldb/Host/FileSpec.h @@ -11,6 +11,8 @@ #define liblldb_FileSpec_h_ #if defined(__cplusplus) +#include <functional> + #include "lldb/lldb-private.h" #include "lldb/Core/ConstString.h" #include "lldb/Core/STLUtils.h" @@ -78,6 +80,12 @@ public: //------------------------------------------------------------------ explicit FileSpec (const char *path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative); + explicit FileSpec (const char *path, bool resolve_path, ArchSpec arch); + + explicit FileSpec(const std::string &path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative); + + explicit FileSpec(const std::string &path, bool resolve_path, ArchSpec arch); + //------------------------------------------------------------------ /// Copy constructor /// @@ -259,7 +267,7 @@ public: /// The stream to which to dump the object description. //------------------------------------------------------------------ void - Dump (Stream *s) const; + Dump(Stream *s) const; //------------------------------------------------------------------ /// Existence test. @@ -359,16 +367,25 @@ public: IsSourceImplementationFile () const; //------------------------------------------------------------------ - /// Returns true if the filespec represents path that is relative - /// path to the current working directory. + /// Returns true if the filespec represents a relative path. /// /// @return - /// \b true if the filespec represents a current working - /// directory relative path, \b false otherwise. + /// \b true if the filespec represents a relative path, + /// \b false otherwise. //------------------------------------------------------------------ bool - IsRelativeToCurrentWorkingDirectory () const; - + IsRelative() const; + + //------------------------------------------------------------------ + /// Returns true if the filespec represents an absolute path. + /// + /// @return + /// \b true if the filespec represents an absolute path, + /// \b false otherwise. + //------------------------------------------------------------------ + bool + IsAbsolute() const; + TimeValue GetModificationTime () const; @@ -408,6 +425,20 @@ public: std::string GetPath (bool denormalize = true) const; + const char * + GetCString(bool denormalize = true) const; + + //------------------------------------------------------------------ + /// Extract the full path to the file. + /// + /// Extract the directory and path into an llvm::SmallVectorImpl<> + /// + /// @return + /// Returns a std::string with the directory and filename + /// concatenated. + //------------------------------------------------------------------ + void GetPath(llvm::SmallVectorImpl<char> &path, bool denormalize = true) const; + //------------------------------------------------------------------ /// Extract the extension of the file. /// @@ -530,6 +561,45 @@ public: lldb::DataBufferSP MemoryMapFileContents (off_t offset = 0, size_t length = SIZE_MAX) const; + + //------------------------------------------------------------------ + /// Memory map part of, or the entire contents of, a file only if + /// the file is local (not on a network mount). + /// + /// Returns a shared pointer to a data buffer that contains all or + /// part of the contents of a file. The data will be memory mapped + /// if the file is local and will lazily page in data from the file + /// as memory is accessed. If the data is memory mapped, 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 + /// truncated. The final number of bytes that get mapped can be + /// verified using the DataBuffer::GetByteSize() function on the return + /// shared data pointer object contents. + /// + /// If the file is on a network mount the data will be read into a + /// heap buffer immediately so that accesses to the data won't later + /// cause a crash if we touch a page that isn't paged in and the + /// network mount has been disconnected or gone away. + /// + /// @param[in] offset + /// The offset in bytes from the beginning of the file where + /// memory mapping should begin. + /// + /// @param[in] length + /// The size in bytes that should be mapped starting \a offset + /// bytes into the file. If \a length is \c SIZE_MAX, map + /// as many bytes as possible. + /// + /// @return + /// 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. + //------------------------------------------------------------------ + lldb::DataBufferSP + MemoryMapFileContentsIfLocal(off_t file_offset, size_t file_size) const; + //------------------------------------------------------------------ /// Read part of, or the entire contents of, a file into a heap based data buffer. /// @@ -579,9 +649,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); - + //------------------------------------------------------------------ + /// Normalize a pathname by collapsing redundant separators and + /// up-level references. + //------------------------------------------------------------------ + void + NormalizePath (); //------------------------------------------------------------------ /// Run through the input string, replaying the effect of any ".." and produce @@ -613,6 +686,15 @@ public: void SetFile (const char *path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative); + void + SetFile(const char *path, bool resolve_path, ArchSpec arch); + + void + SetFile(const std::string &path, bool resolve_path, PathSyntax syntax = ePathSyntaxHostNative); + + void + SetFile(const std::string &path, bool resolve_path, ArchSpec arch); + bool IsResolved () const { @@ -668,10 +750,25 @@ public: FileSpec CopyByRemovingLastPathComponent () const; - + void - AppendPathComponent (const char *new_path); - + PrependPathComponent(const char *new_path); + + void + PrependPathComponent(const std::string &new_path); + + void + PrependPathComponent(const FileSpec &new_path); + + void + AppendPathComponent(const char *new_path); + + void + AppendPathComponent(const std::string &new_path); + + void + AppendPathComponent(const FileSpec &new_path); + void RemoveLastPathComponent (); @@ -706,8 +803,7 @@ public: typedef EnumerateDirectoryResult (*EnumerateDirectoryCallbackType) (void *baton, FileType file_type, - const FileSpec &spec -); + const FileSpec &spec); static EnumerateDirectoryResult EnumerateDirectory (const char *dir_path, @@ -717,6 +813,11 @@ public: EnumerateDirectoryCallbackType callback, void *callback_baton); + typedef std::function <EnumerateDirectoryResult(FileType file_type, const FileSpec &spec)> DirectoryCallback; + + static EnumerateDirectoryResult + ForEachItemInDirectory (const char *dir_path, DirectoryCallback const &callback); + protected: //------------------------------------------------------------------ // Member variables diff --git a/include/lldb/Host/FileSystem.h b/include/lldb/Host/FileSystem.h index adcbfc9d590d..bea1ec80172e 100644 --- a/include/lldb/Host/FileSystem.h +++ b/include/lldb/Host/FileSystem.h @@ -24,19 +24,36 @@ 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 MakeDirectory(const FileSpec &file_spec, uint32_t mode); + static Error DeleteDirectory(const FileSpec &file_spec, bool recurse); - static Error GetFilePermissions(const char *path, uint32_t &file_permissions); - static Error SetFilePermissions(const char *path, uint32_t file_permissions); + static Error GetFilePermissions(const FileSpec &file_spec, + uint32_t &file_permissions); + static Error SetFilePermissions(const FileSpec &file_spec, + 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 Error Hardlink(const FileSpec &src, const FileSpec &dst); + static Error Symlink(const FileSpec &src, const FileSpec &dst); + static Error Readlink(const FileSpec &src, FileSpec &dst); + static Error Unlink(const FileSpec &file_spec); static bool CalculateMD5(const FileSpec &file_spec, uint64_t &low, uint64_t &high); + static bool CalculateMD5(const FileSpec &file_spec, + uint64_t offset, + uint64_t length, + uint64_t &low, + uint64_t &high); + + static bool CalculateMD5AsString(const FileSpec &file_spec, std::string& digest_str); + static bool CalculateMD5AsString(const FileSpec &file_spec, + uint64_t offset, + uint64_t length, + std::string& digest_str); + + /// Return \b true if \a spec is on a locally mounted file system, \b false otherwise. + static bool IsLocal(const FileSpec &spec); }; } diff --git a/include/lldb/Host/Host.h b/include/lldb/Host/Host.h index 9a68c698c826..caf33634057d 100644 --- a/include/lldb/Host/Host.h +++ b/include/lldb/Host/Host.h @@ -133,9 +133,6 @@ public: static const char * GetSignalAsCString (int signo); - static void - WillTerminate (); - typedef void (*ThreadLocalStorageCleanupCallback) (void *p); static lldb::thread_key_t @@ -236,12 +233,16 @@ public: GetProcessInfo (lldb::pid_t pid, ProcessInstanceInfo &proc_info); #if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined (__NetBSD__) +#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__) + static short GetPosixspawnFlags(const ProcessLaunchInfo &launch_info); static Error LaunchProcessPosixSpawn(const char *exe_path, const ProcessLaunchInfo &launch_info, lldb::pid_t &pid); static bool AddPosixSpawnFileAction(void *file_actions, const FileAction *info, Log *log, Error &error); -#endif + +#endif // !defined(__ANDROID__) && !defined(__ANDROID_NDK__) +#endif // defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined(__NetBSD__) static const lldb_private::UnixSignalsSP& GetUnixSignals (); @@ -249,14 +250,33 @@ public: static Error LaunchProcess (ProcessLaunchInfo &launch_info); + //------------------------------------------------------------------ + /// Perform expansion of the command-line for this launch info + /// This can potentially involve wildcard expansion + // environment variable replacement, and whatever other + // argument magic the platform defines as part of its typical + // user experience + //------------------------------------------------------------------ + static Error + ShellExpandArguments (ProcessLaunchInfo &launch_info); + + static Error + RunShellCommand(const char *command, // Shouldn't be NULL + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + 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, + bool run_in_default_shell = true); + static Error - RunShellCommand (const char *command, // Shouldn't be NULL - const char *working_dir, // Pass NULL to use the current working directory - int *status_ptr, // Pass NULL if you don't want the process exit status - 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, - bool run_in_default_shell = true); + RunShellCommand(const Args& args, + const FileSpec &working_dir, // Pass empty FileSpec to use the current working directory + int *status_ptr, // Pass NULL if you don't want the process exit status + 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, + bool run_in_default_shell = true); static lldb::DataBufferSP GetAuxvData (lldb_private::Process *process); @@ -268,9 +288,6 @@ public: OpenFileInExternalEditor (const FileSpec &file_spec, uint32_t line_no); - static void - Backtrace (Stream &strm, uint32_t max_frames); - static size_t GetEnvironment (StringList &env); }; diff --git a/include/lldb/Host/HostInfo.h b/include/lldb/Host/HostInfo.h index cbbf6cd2d49c..6bb009997896 100644 --- a/include/lldb/Host/HostInfo.h +++ b/include/lldb/Host/HostInfo.h @@ -38,8 +38,13 @@ #include "lldb/Host/windows/HostInfoWindows.h" #define HOST_INFO_TYPE HostInfoWindows #elif defined(__linux__) +#if defined(__ANDROID_NDK__) +#include "lldb/Host/android/HostInfoAndroid.h" +#define HOST_INFO_TYPE HostInfoAndroid +#else #include "lldb/Host/linux/HostInfoLinux.h" #define HOST_INFO_TYPE HostInfoLinux +#endif #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #include "lldb/Host/freebsd/HostInfoFreeBSD.h" #define HOST_INFO_TYPE HostInfoFreeBSD diff --git a/include/lldb/Host/HostInfoBase.h b/include/lldb/Host/HostInfoBase.h index 5a8a06329500..6a5f784ebba3 100644 --- a/include/lldb/Host/HostInfoBase.h +++ b/include/lldb/Host/HostInfoBase.h @@ -115,7 +115,9 @@ class HostInfoBase protected: static bool ComputeSharedLibraryDirectory(FileSpec &file_spec); static bool ComputeSupportExeDirectory(FileSpec &file_spec); - static bool ComputeTempFileDirectory(FileSpec &file_spec); + static bool ComputeProcessTempFileDirectory(FileSpec &file_spec); + static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec); + static bool ComputeTempFileBaseDirectory(FileSpec &file_spec); static bool ComputeHeaderDirectory(FileSpec &file_spec); static bool ComputeSystemPluginsDirectory(FileSpec &file_spec); static bool ComputeClangDirectory(FileSpec &file_spec); diff --git a/include/lldb/Host/LockFile.h b/include/lldb/Host/LockFile.h new file mode 100644 index 000000000000..a89560481874 --- /dev/null +++ b/include/lldb/Host/LockFile.h @@ -0,0 +1,27 @@ +//===-- LockFile.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_LockFile_h_ +#define liblldb_Host_LockFile_h_ + +#if defined(_WIN32) +#include "lldb/Host/windows/LockFileWindows.h" +namespace lldb_private +{ +typedef LockFileWindows LockFile; +} +#else +#include "lldb/Host/posix/LockFilePosix.h" +namespace lldb_private +{ +typedef LockFilePosix LockFile; +} +#endif + +#endif // liblldb_Host_LockFile_h_ diff --git a/include/lldb/Host/LockFileBase.h b/include/lldb/Host/LockFileBase.h new file mode 100644 index 000000000000..35dd7d817c59 --- /dev/null +++ b/include/lldb/Host/LockFileBase.h @@ -0,0 +1,73 @@ +//===-- LockFileBase.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_LockFileBase_h_ +#define liblldb_Host_LockFileBase_h_ + +#include "lldb/Core/Error.h" + +#include <functional> + +namespace lldb_private +{ + +class LockFileBase +{ +public: + virtual ~LockFileBase () = default; + + bool + IsLocked () const; + + Error + WriteLock (const uint64_t start, const uint64_t len); + Error + TryWriteLock (const uint64_t start, const uint64_t len); + + Error + ReadLock (const uint64_t start, const uint64_t len); + Error + TryReadLock (const uint64_t start, const uint64_t len); + + Error + Unlock (); + +protected: + using Locker = std::function<Error (const uint64_t, const uint64_t)>; + + LockFileBase (int fd); + + virtual bool + IsValidFile () const; + + virtual Error + DoWriteLock (const uint64_t start, const uint64_t len) = 0; + virtual Error + DoTryWriteLock (const uint64_t start, const uint64_t len) = 0; + + virtual Error + DoReadLock (const uint64_t start, const uint64_t len) = 0; + virtual Error + DoTryReadLock (const uint64_t start, const uint64_t len) = 0; + + virtual Error + DoUnlock () = 0; + + Error + DoLock (const Locker &locker, const uint64_t start, const uint64_t len); + + int m_fd; // not owned. + bool m_locked; + uint64_t m_start; + uint64_t m_len; +}; + +} + +#endif diff --git a/include/lldb/Host/PipeBase.h b/include/lldb/Host/PipeBase.h index 5ef2bb530281..8680a252d8b6 100644 --- a/include/lldb/Host/PipeBase.h +++ b/include/lldb/Host/PipeBase.h @@ -40,6 +40,8 @@ class PipeBase virtual int GetWriteFileDescriptor() const = 0; virtual int ReleaseReadFileDescriptor() = 0; virtual int ReleaseWriteFileDescriptor() = 0; + virtual void CloseReadFileDescriptor() = 0; + virtual void CloseWriteFileDescriptor() = 0; // Close both descriptors virtual void Close() = 0; diff --git a/include/lldb/Host/Socket.h b/include/lldb/Host/Socket.h index ee85f85fcaf2..f4599b5ab87b 100644 --- a/include/lldb/Host/Socket.h +++ b/include/lldb/Host/Socket.h @@ -56,7 +56,12 @@ public: // 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, bool child_processes_inherit, Socket *&socket, Predicate<uint16_t>* predicate); + static Error TcpListen( + llvm::StringRef host_and_port, + bool child_processes_inherit, + Socket *&socket, + Predicate<uint16_t>* predicate, + int backlog = 5); static Error TcpConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket); static Error UdpConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&send_socket, Socket *&recv_socket); static Error UnixDomainConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket); diff --git a/include/lldb/Host/Time.h b/include/lldb/Host/Time.h new file mode 100644 index 000000000000..1481d381053d --- /dev/null +++ b/include/lldb/Host/Time.h @@ -0,0 +1,26 @@ +//===-- Time.h --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Include system time headers, adding missing functions as necessary + +#ifndef liblldb_Host_Time_h_ +#define liblldb_Host_Time_h_ + +#ifdef __ANDROID_NDK__ +#include <android/api-level.h> +#endif + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 +#include <time64.h> +extern time_t timegm(struct tm* t); +#else +#include <time.h> +#endif + +#endif // liblldb_Host_Time_h_ diff --git a/include/lldb/Host/XML.h b/include/lldb/Host/XML.h new file mode 100644 index 000000000000..e3547d834635 --- /dev/null +++ b/include/lldb/Host/XML.h @@ -0,0 +1,234 @@ +//===-- XML.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_XML_h_ +#define liblldb_XML_h_ + +// C Includes + +#if defined( LIBXML2_DEFINED ) +#include <libxml/xmlreader.h> +#endif + +// C++ Includes + +#include <functional> +#include <string> +#include <vector> + +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private.h" +#include "llvm/ADT/StringRef.h" +#include "lldb/Core/StreamString.h" +#include "lldb/Core/StructuredData.h" + + +namespace lldb_private { + +#if defined( LIBXML2_DEFINED ) + typedef xmlNodePtr XMLNodeImpl; + typedef xmlDocPtr XMLDocumentImpl; +#else + typedef void * XMLNodeImpl; + typedef void * XMLDocumentImpl; +#endif + + class XMLNode; + + typedef std::vector<std::string> NamePath; + typedef std::function <bool(const XMLNode &node)> NodeCallback; + typedef std::function <bool(const llvm::StringRef &name, const llvm::StringRef &value)> AttributeCallback; + + class XMLNode + { + public: + XMLNode(); + + XMLNode(XMLNodeImpl node); + + ~XMLNode(); + + explicit operator bool() const + { + return IsValid(); + } + + void + Clear(); + + bool + IsValid() const; + + bool + IsElement () const; + + llvm::StringRef + GetName() const; + + bool + GetElementText (std::string &text) const; + + bool + GetElementTextAsUnsigned (uint64_t &value, uint64_t fail_value = 0, int base = 0) const; + + bool + GetElementTextAsFloat (double &value, double fail_value = 0.0) const; + + bool + NameIs (const char *name) const; + + XMLNode + GetParent() const; + + XMLNode + GetSibling() const; + + XMLNode + GetChild () const; + + llvm::StringRef + GetAttributeValue(const char *name, const char *fail_value = NULL) const; + + XMLNode + FindFirstChildElementWithName (const char *name) const; + + XMLNode + GetElementForPath (const NamePath &path); + + //---------------------------------------------------------------------- + // Iterate through all sibling nodes of any type + //---------------------------------------------------------------------- + void + ForEachSiblingNode (NodeCallback const &callback) const; + + //---------------------------------------------------------------------- + // Iterate through only the sibling nodes that are elements + //---------------------------------------------------------------------- + void + ForEachSiblingElement (NodeCallback const &callback) const; + + //---------------------------------------------------------------------- + // Iterate through only the sibling nodes that are elements and whose + // name matches \a name. + //---------------------------------------------------------------------- + void + ForEachSiblingElementWithName (const char *name, NodeCallback const &callback) const; + + void + ForEachChildNode (NodeCallback const &callback) const; + + void + ForEachChildElement (NodeCallback const &callback) const; + + void + ForEachChildElementWithName (const char *name, NodeCallback const &callback) const; + + void + ForEachAttribute (AttributeCallback const &callback) const; + + protected: + XMLNodeImpl m_node; + }; + + class XMLDocument + { + public: + + XMLDocument (); + + ~XMLDocument (); + + explicit operator bool() const + { + return IsValid(); + } + + bool + IsValid() const; + + void + Clear(); + + bool + ParseFile (const char *path); + + bool + ParseMemory (const char *xml, size_t xml_length, const char *url = "untitled.xml"); + + //---------------------------------------------------------------------- + // If \a name is NULL, just get the root element node, else only return + // a value XMLNode if the name of the root element matches \a name. + //---------------------------------------------------------------------- + XMLNode + GetRootElement(const char *required_name = nullptr); + + const std::string & + GetErrors() const; + + static void + ErrorCallback (void *ctx, const char *format, ...); + + static bool + XMLEnabled (); + + protected: + XMLDocumentImpl m_document; + StreamString m_errors; + }; + + class ApplePropertyList + { + public: + ApplePropertyList(); + + ApplePropertyList(const char *path); + + ~ApplePropertyList(); + + bool + ParseFile (const char *path); + + const std::string & + GetErrors() const; + + explicit operator bool() const + { + return IsValid(); + } + + bool + IsValid() const; + + XMLNode + GetValueNode (const char *key) const; + + bool + GetValueAsString (const char *key, std::string &value) const; + + StructuredData::ObjectSP + GetStructuredData(); + + protected: + + // Using a node returned from GetValueNode() extract its value as a + // string (if possible). Array and dictionary nodes will return false + // as they have no string value. Boolean nodes will return true and + // \a value will be "true" or "false" as the string value comes from + // the element name itself. All other nodes will return the text + // content of the XMLNode. + static bool + ExtractStringFromValueNode (const XMLNode &node, std::string &value); + + XMLDocument m_xml_doc; + XMLNode m_dict_node; + }; +} // namespace lldb_private + +#endif // liblldb_XML_h_ diff --git a/include/lldb/Host/common/NativeBreakpointList.h b/include/lldb/Host/common/NativeBreakpointList.h index 51617330d075..aba2f8a74cdc 100644 --- a/include/lldb/Host/common/NativeBreakpointList.h +++ b/include/lldb/Host/common/NativeBreakpointList.h @@ -42,6 +42,9 @@ namespace lldb_private Error GetBreakpoint (lldb::addr_t addr, NativeBreakpointSP &breakpoint_sp); + Error + RemoveTrapsFromBuffer(lldb::addr_t addr, void *buf, size_t size) const; + private: typedef std::map<lldb::addr_t, NativeBreakpointSP> BreakpointMap; diff --git a/include/lldb/Host/common/NativeProcessProtocol.h b/include/lldb/Host/common/NativeProcessProtocol.h index 83c14a5ab37a..f6a685aae147 100644 --- a/include/lldb/Host/common/NativeProcessProtocol.h +++ b/include/lldb/Host/common/NativeProcessProtocol.h @@ -16,6 +16,7 @@ #include "lldb/lldb-types.h" #include "lldb/Core/Error.h" #include "lldb/Host/Mutex.h" +#include "llvm/ADT/StringRef.h" #include "NativeBreakpointList.h" #include "NativeWatchpointList.h" @@ -90,13 +91,16 @@ namespace lldb_private GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info); virtual Error - ReadMemory (lldb::addr_t addr, void *buf, lldb::addr_t size, lldb::addr_t &bytes_read) = 0; + ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) = 0; virtual Error - WriteMemory (lldb::addr_t addr, const void *buf, lldb::addr_t size, lldb::addr_t &bytes_written) = 0; + ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) = 0; virtual Error - AllocateMemory (lldb::addr_t size, uint32_t permissions, lldb::addr_t &addr) = 0; + WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) = 0; + + virtual Error + AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) = 0; virtual Error DeallocateMemory (lldb::addr_t addr) = 0; @@ -283,6 +287,16 @@ namespace lldb_private bool UnregisterNativeDelegate (NativeDelegate &native_delegate); + // Called before termination of NativeProcessProtocol's instance. + virtual void + Terminate (); + + virtual Error + GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec) = 0; + + virtual Error + GetFileLoadAddress(const llvm::StringRef& file_name, lldb::addr_t& load_addr) = 0; + protected: lldb::pid_t m_pid; diff --git a/include/lldb/Host/common/NativeRegisterContext.h b/include/lldb/Host/common/NativeRegisterContext.h index e9c03e3c20a4..098f148f95d0 100644 --- a/include/lldb/Host/common/NativeRegisterContext.h +++ b/include/lldb/Host/common/NativeRegisterContext.h @@ -99,14 +99,26 @@ public: virtual Error ClearAllHardwareWatchpoints (); + virtual Error + IsWatchpointHit(uint32_t wp_index, bool &is_hit); + + virtual Error + GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr); + + virtual Error + IsWatchpointVacant (uint32_t wp_index, bool &is_vacant); + + virtual lldb::addr_t + GetWatchpointAddress (uint32_t wp_index); + virtual bool HardwareSingleStep (bool enable); virtual Error - ReadRegisterValueFromMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, lldb::addr_t src_len, RegisterValue ®_value); + ReadRegisterValueFromMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, size_t src_len, RegisterValue ®_value); virtual Error - WriteRegisterValueToMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, lldb::addr_t dst_len, const RegisterValue ®_value); + WriteRegisterValueToMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, size_t dst_len, const RegisterValue ®_value); //------------------------------------------------------------------ // Subclasses should not override these @@ -129,6 +141,9 @@ public: lldb::addr_t GetPC (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS); + virtual lldb::addr_t + GetPCfromBreakpointLocation (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS); + Error SetPC (lldb::addr_t pc); diff --git a/include/lldb/Host/common/SoftwareBreakpoint.h b/include/lldb/Host/common/SoftwareBreakpoint.h index 1fed19eca612..83b3d18aa768 100644 --- a/include/lldb/Host/common/SoftwareBreakpoint.h +++ b/include/lldb/Host/common/SoftwareBreakpoint.h @@ -17,6 +17,8 @@ namespace lldb_private { class SoftwareBreakpoint : public NativeBreakpoint { + friend class NativeBreakpointList; + public: static Error CreateSoftwareBreakpoint (NativeProcessProtocol &process, lldb::addr_t addr, size_t size_hint, NativeBreakpointSP &breakpoint_spn); diff --git a/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h b/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h index 660b9d169bfc..bcbb6014b116 100644 --- a/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h +++ b/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h @@ -38,23 +38,25 @@ class ConnectionFileDescriptor : public Connection ConnectionFileDescriptor(int fd, bool owns_fd); + ConnectionFileDescriptor(Socket* socket); + virtual ~ConnectionFileDescriptor(); - virtual bool IsConnected() const; + bool IsConnected() const override; - virtual lldb::ConnectionStatus Connect(const char *s, Error *error_ptr); + lldb::ConnectionStatus Connect(const char *s, Error *error_ptr) override; - virtual lldb::ConnectionStatus Disconnect(Error *error_ptr); + lldb::ConnectionStatus Disconnect(Error *error_ptr) override; - virtual size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec, lldb::ConnectionStatus &status, Error *error_ptr); + size_t Read(void *dst, size_t dst_len, uint32_t timeout_usec, lldb::ConnectionStatus &status, Error *error_ptr) override; - virtual size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Error *error_ptr); + size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Error *error_ptr) override; - virtual std::string GetURI(); + std::string GetURI() override; lldb::ConnectionStatus BytesAvailable(uint32_t timeout_usec, Error *error_ptr); - bool InterruptRead(); + bool InterruptRead() override; lldb::IOObjectSP GetReadObject() @@ -104,6 +106,8 @@ class ConnectionFileDescriptor : public Connection std::string m_uri; private: + void InitializeSocket(Socket* socket); + DISALLOW_COPY_AND_ASSIGN(ConnectionFileDescriptor); }; diff --git a/include/lldb/Host/posix/Fcntl.h b/include/lldb/Host/posix/Fcntl.h new file mode 100644 index 000000000000..3e3a472f0a20 --- /dev/null +++ b/include/lldb/Host/posix/Fcntl.h @@ -0,0 +1,25 @@ +//===-- Fcntl.h -------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This file defines fcntl functions & structures + +#ifndef liblldb_Host_posix_Fcntl_h_ +#define liblldb_Host_posix_Fcntl_h_ + +#ifdef __ANDROID_NDK__ +#include <android/api-level.h> +#endif + +#include <fcntl.h> + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 +#define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6) +#endif + +#endif // liblldb_Host_posix_Fcntl_h_ diff --git a/include/lldb/Host/posix/HostProcessPosix.h b/include/lldb/Host/posix/HostProcessPosix.h index 8c1b0599e114..c9534991361b 100644 --- a/include/lldb/Host/posix/HostProcessPosix.h +++ b/include/lldb/Host/posix/HostProcessPosix.h @@ -29,13 +29,13 @@ class HostProcessPosix : public HostNativeProcessBase virtual Error Signal(int signo) const; static Error Signal(lldb::process_t process, int signo); - virtual Error Terminate(); - virtual Error GetMainModule(FileSpec &file_spec) const; + Error Terminate() override; + Error GetMainModule(FileSpec &file_spec) const override; - virtual lldb::pid_t GetProcessId() const; - virtual bool IsRunning() const; + lldb::pid_t GetProcessId() const override; + bool IsRunning() const override; - virtual HostThread StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals); + HostThread StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals) override; }; } diff --git a/include/lldb/Host/posix/HostThreadPosix.h b/include/lldb/Host/posix/HostThreadPosix.h index e0eaedf73be2..8839b8d4068b 100644 --- a/include/lldb/Host/posix/HostThreadPosix.h +++ b/include/lldb/Host/posix/HostThreadPosix.h @@ -24,8 +24,8 @@ class HostThreadPosix : public HostNativeThreadBase HostThreadPosix(lldb::thread_t thread); virtual ~HostThreadPosix(); - virtual Error Join(lldb::thread_result_t *result); - virtual Error Cancel(); + Error Join(lldb::thread_result_t *result) override; + Error Cancel() override; Error Detach(); }; diff --git a/include/lldb/Host/posix/LockFilePosix.h b/include/lldb/Host/posix/LockFilePosix.h new file mode 100644 index 000000000000..999397ec2bb5 --- /dev/null +++ b/include/lldb/Host/posix/LockFilePosix.h @@ -0,0 +1,42 @@ +//===-- LockFilePosix.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_posix_LockFilePosix_h_ +#define liblldb_Host_posix_LockFilePosix_h_ + +#include "lldb/Host/LockFileBase.h" + +namespace lldb_private { + +class LockFilePosix : public LockFileBase +{ +public: + explicit LockFilePosix (int fd); + ~LockFilePosix (); + +protected: + Error + DoWriteLock (const uint64_t start, const uint64_t len) override; + + Error + DoTryWriteLock (const uint64_t start, const uint64_t len) override; + + Error + DoReadLock (const uint64_t start, const uint64_t len) override; + + Error + DoTryReadLock (const uint64_t start, const uint64_t len) override; + + Error + DoUnlock () override; +}; + +} // namespace lldb_private + +#endif // liblldb_Host_posix_LockFilePosix_h_ diff --git a/include/lldb/Host/posix/PipePosix.h b/include/lldb/Host/posix/PipePosix.h index fbdac66149d6..710b77d34bdc 100644 --- a/include/lldb/Host/posix/PipePosix.h +++ b/include/lldb/Host/posix/PipePosix.h @@ -16,7 +16,7 @@ namespace lldb_private { //---------------------------------------------------------------------- -/// @class PipePosix PipePosix .h "lldb/Host/posix/PipePosix.h" +/// @class PipePosix PipePosix.h "lldb/Host/posix/PipePosix.h" /// @brief A posix-based implementation of Pipe, a class that abtracts /// unix style pipes. /// @@ -28,6 +28,11 @@ public: static int kInvalidDescriptor; PipePosix(); + PipePosix(int read_fd, int write_fd); + PipePosix(const PipePosix &) = delete; + PipePosix(PipePosix &&pipe_posix); + PipePosix &operator=(const PipePosix &) = delete; + PipePosix &operator=(PipePosix &&pipe_posix); ~PipePosix() override; @@ -55,6 +60,11 @@ public: ReleaseReadFileDescriptor() override; int ReleaseWriteFileDescriptor() override; + void + CloseReadFileDescriptor() override; + void + CloseWriteFileDescriptor() override; + // Close both descriptors void @@ -69,11 +79,6 @@ public: ReadWithTimeout(void *buf, size_t size, const std::chrono::microseconds &timeout, size_t &bytes_read) override; private: - void - CloseReadFileDescriptor(); - void - CloseWriteFileDescriptor(); - int m_fds[2]; }; diff --git a/include/lldb/Host/posix/ProcessLauncherPosix.h b/include/lldb/Host/posix/ProcessLauncherPosix.h index c0e2a36e4e5e..a5e57ccb26ed 100644 --- a/include/lldb/Host/posix/ProcessLauncherPosix.h +++ b/include/lldb/Host/posix/ProcessLauncherPosix.h @@ -18,7 +18,7 @@ namespace lldb_private class ProcessLauncherPosix : public ProcessLauncher { public: - virtual HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Error &error); + HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Error &error) override; }; } |
