diff options
author | Ed Maste <emaste@FreeBSD.org> | 2015-02-09 01:44:09 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2015-02-09 01:44:09 +0000 |
commit | 12bd4897ff0678fa663e09d78ebc22dd255ceb86 (patch) | |
tree | a8f4b3abea3e6937e60728991c736e6e3d322fc1 /include/lldb/Host | |
parent | 205afe679855a4ce8149cdaa94d3f0868ce796dc (diff) | |
download | src-12bd4897ff0678fa663e09d78ebc22dd255ceb86.tar.gz src-12bd4897ff0678fa663e09d78ebc22dd255ceb86.zip |
Import LLDB as of upstream SVN 228549 (git 39760838)vendor/lldb/lldb-r228549
Notes
Notes:
svn path=/vendor/lldb/dist/; revision=278425
svn path=/vendor/lldb/lldb-r228549/; revision=278426; tag=vendor/lldb/lldb-r228549
Diffstat (limited to 'include/lldb/Host')
-rw-r--r-- | include/lldb/Host/File.h | 3 | ||||
-rw-r--r-- | include/lldb/Host/Host.h | 3 | ||||
-rw-r--r-- | include/lldb/Host/PipeBase.h | 2 | ||||
-rw-r--r-- | include/lldb/Host/Socket.h | 31 | ||||
-rw-r--r-- | include/lldb/Host/SocketAddress.h | 7 | ||||
-rw-r--r-- | include/lldb/Host/StringConvert.h | 45 | ||||
-rw-r--r-- | include/lldb/Host/common/NativeBreakpoint.h | 66 | ||||
-rw-r--r-- | include/lldb/Host/common/NativeBreakpointList.h | 53 | ||||
-rw-r--r-- | include/lldb/Host/common/NativeProcessProtocol.h | 349 | ||||
-rw-r--r-- | include/lldb/Host/common/NativeRegisterContext.h | 197 | ||||
-rw-r--r-- | include/lldb/Host/common/NativeRegisterContextRegisterInfo.h | 47 | ||||
-rw-r--r-- | include/lldb/Host/common/NativeThreadProtocol.h | 82 | ||||
-rw-r--r-- | include/lldb/Host/common/NativeWatchpointList.h | 47 | ||||
-rw-r--r-- | include/lldb/Host/common/SoftwareBreakpoint.h | 51 | ||||
-rw-r--r-- | include/lldb/Host/posix/ConnectionFileDescriptorPosix.h | 6 | ||||
-rw-r--r-- | include/lldb/Host/posix/PipePosix.h | 2 |
16 files changed, 977 insertions, 14 deletions
diff --git a/include/lldb/Host/File.h b/include/lldb/Host/File.h index 2738679b5e03..8219cc06fdc2 100644 --- a/include/lldb/Host/File.h +++ b/include/lldb/Host/File.h @@ -42,7 +42,8 @@ public: eOpenOptionNonBlocking = (1u << 4), // File reads eOpenOptionCanCreate = (1u << 5), // Create file if doesn't already exist eOpenOptionCanCreateNewOnly = (1u << 6), // Can create file only if it doesn't already exist - eOpenoptionDontFollowSymlinks = (1u << 7) + eOpenoptionDontFollowSymlinks = (1u << 7), + eOpenOptionCloseOnExec = (1u << 8) // Close the file when executing a new process }; static mode_t diff --git a/include/lldb/Host/Host.h b/include/lldb/Host/Host.h index ce12689fc047..9a68c698c826 100644 --- a/include/lldb/Host/Host.h +++ b/include/lldb/Host/Host.h @@ -246,9 +246,6 @@ public: static const lldb_private::UnixSignalsSP& GetUnixSignals (); - static lldb::pid_t - LaunchApplication (const FileSpec &app_file_spec); - static Error LaunchProcess (ProcessLaunchInfo &launch_info); diff --git a/include/lldb/Host/PipeBase.h b/include/lldb/Host/PipeBase.h index 8cad2507d32c..5ef2bb530281 100644 --- a/include/lldb/Host/PipeBase.h +++ b/include/lldb/Host/PipeBase.h @@ -14,6 +14,7 @@ #include <string> #include "lldb/Core/Error.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" namespace lldb_private @@ -25,6 +26,7 @@ class PipeBase virtual Error CreateNew(bool child_process_inherit) = 0; virtual Error CreateNew(llvm::StringRef name, bool child_process_inherit) = 0; + virtual Error CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl<char>& name) = 0; virtual Error OpenAsReader(llvm::StringRef name, bool child_process_inherit) = 0; diff --git a/include/lldb/Host/Socket.h b/include/lldb/Host/Socket.h index 77069ae35f79..ee85f85fcaf2 100644 --- a/include/lldb/Host/Socket.h +++ b/include/lldb/Host/Socket.h @@ -70,22 +70,35 @@ public: 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; + // returns port number or 0 if error + static uint16_t GetLocalPortNumber (const NativeSocket& socket); + + // returns port number or 0 if error + uint16_t GetLocalPortNumber () const; + + // returns ip address string or empty string if error + std::string GetLocalIPAddress () const; + + // must be connected + // returns port number or 0 if error + uint16_t GetRemotePortNumber () const; + + // must be connected + // returns ip address string or empty string if error + std::string GetRemoteIPAddress () const; NativeSocket GetNativeSocket () const { return m_socket; } - SocketProtocol GetSocketProtocol() const { return m_protocol; } + 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 Error PreDisconnect (); + virtual Error Close (); - virtual bool IsValid() const { return m_socket != kInvalidSocketValue; } - virtual WaitableHandle GetWaitableHandle(); + virtual bool IsValid () const { return m_socket != kInvalidSocketValue; } + virtual WaitableHandle GetWaitableHandle (); -protected: static bool DecodeHostAndPort (llvm::StringRef host_and_port, std::string &host_str, @@ -93,7 +106,7 @@ protected: int32_t& port, Error *error_ptr); - +protected: SocketProtocol m_protocol; NativeSocket m_socket; SocketAddress m_udp_send_sockaddr; // Send address used for UDP connections. diff --git a/include/lldb/Host/SocketAddress.h b/include/lldb/Host/SocketAddress.h index 3598a42a82d0..9666f56489f6 100644 --- a/include/lldb/Host/SocketAddress.h +++ b/include/lldb/Host/SocketAddress.h @@ -31,6 +31,7 @@ typedef ADDRESS_FAMILY sa_family_t; // C++ Includes // Other libraries and framework includes // Project includes +#include <string> namespace lldb_private { @@ -100,6 +101,12 @@ public: SetFamily (sa_family_t family); //------------------------------------------------------------------ + // Get the address + //------------------------------------------------------------------ + std::string + GetIPAddress () const; + + //------------------------------------------------------------------ // Get the port if the socket address for the family has a port //------------------------------------------------------------------ uint16_t diff --git a/include/lldb/Host/StringConvert.h b/include/lldb/Host/StringConvert.h new file mode 100644 index 000000000000..3cc260cf2be1 --- /dev/null +++ b/include/lldb/Host/StringConvert.h @@ -0,0 +1,45 @@ +//===-- StringConvert.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_StringConvert_h_ +#define liblldb_StringConvert_h_ + +// C Includes +#include <stdint.h> + +// C++ Includes + +// Other libraries and framework includes +// Project includes + +namespace lldb_private { + +namespace StringConvert { + +//---------------------------------------------------------------------- +/// @namespace StringConvert StringConvert.h "lldb/Host/StringConvert.h" +/// @brief Utility classes for converting strings into Integers +//---------------------------------------------------------------------- + +int32_t +ToSInt32 (const char *s, int32_t fail_value = 0, int base = 0, bool *success_ptr = nullptr); + +uint32_t +ToUInt32 (const char *s, uint32_t fail_value = 0, int base = 0, bool *success_ptr = nullptr); + +int64_t +ToSInt64 (const char *s, int64_t fail_value = 0, int base = 0, bool *success_ptr = nullptr); + +uint64_t +ToUInt64 (const char *s, uint64_t fail_value = 0, int base = 0, bool *success_ptr = nullptr); + +} // namespace StringConvert +} // namespace lldb_private + +#endif diff --git a/include/lldb/Host/common/NativeBreakpoint.h b/include/lldb/Host/common/NativeBreakpoint.h new file mode 100644 index 000000000000..367003b94e35 --- /dev/null +++ b/include/lldb/Host/common/NativeBreakpoint.h @@ -0,0 +1,66 @@ +//===-- NativeBreakpoint.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_NativeBreakpoint_h_ +#define liblldb_NativeBreakpoint_h_ + +#include "lldb/lldb-types.h" + +namespace lldb_private +{ + class NativeBreakpointList; + + class NativeBreakpoint + { + friend class NativeBreakpointList; + + public: + // The assumption is that derived breakpoints are enabled when created. + NativeBreakpoint (lldb::addr_t addr); + + virtual + ~NativeBreakpoint (); + + Error + Enable (); + + Error + Disable (); + + lldb::addr_t + GetAddress () const { return m_addr; } + + bool + IsEnabled () const { return m_enabled; } + + virtual bool + IsSoftwareBreakpoint () const = 0; + + protected: + const lldb::addr_t m_addr; + int32_t m_ref_count; + + virtual Error + DoEnable () = 0; + + virtual Error + DoDisable () = 0; + + private: + bool m_enabled; + + // ----------------------------------------------------------- + // interface for NativeBreakpointList + // ----------------------------------------------------------- + void AddRef (); + int32_t DecRef (); + }; +} + +#endif // ifndef liblldb_NativeBreakpoint_h_ diff --git a/include/lldb/Host/common/NativeBreakpointList.h b/include/lldb/Host/common/NativeBreakpointList.h new file mode 100644 index 000000000000..51617330d075 --- /dev/null +++ b/include/lldb/Host/common/NativeBreakpointList.h @@ -0,0 +1,53 @@ +//===-- NativeBreakpointList.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_NativeBreakpointList_h_ +#define liblldb_NativeBreakpointList_h_ + +#include "lldb/lldb-private-forward.h" +#include "lldb/Core/Error.h" +#include "lldb/Host/Mutex.h" +// #include "lldb/Host/NativeBreakpoint.h" + +#include <functional> +#include <map> + +namespace lldb_private +{ + class NativeBreakpointList + { + public: + typedef std::function<Error (lldb::addr_t addr, size_t size_hint, bool hardware, NativeBreakpointSP &breakpoint_sp)> CreateBreakpointFunc; + + NativeBreakpointList (); + + Error + AddRef (lldb::addr_t addr, size_t size_hint, bool hardware, CreateBreakpointFunc create_func); + + Error + DecRef (lldb::addr_t addr); + + Error + EnableBreakpoint (lldb::addr_t addr); + + Error + DisableBreakpoint (lldb::addr_t addr); + + Error + GetBreakpoint (lldb::addr_t addr, NativeBreakpointSP &breakpoint_sp); + + private: + typedef std::map<lldb::addr_t, NativeBreakpointSP> BreakpointMap; + + Mutex m_mutex; + BreakpointMap m_breakpoints; + }; +} + +#endif // ifndef liblldb_NativeBreakpointList_h_ diff --git a/include/lldb/Host/common/NativeProcessProtocol.h b/include/lldb/Host/common/NativeProcessProtocol.h new file mode 100644 index 000000000000..83c14a5ab37a --- /dev/null +++ b/include/lldb/Host/common/NativeProcessProtocol.h @@ -0,0 +1,349 @@ +//===-- NativeProcessProtocol.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_NativeProcessProtocol_h_ +#define liblldb_NativeProcessProtocol_h_ + +#include <vector> + +#include "lldb/lldb-private-forward.h" +#include "lldb/lldb-types.h" +#include "lldb/Core/Error.h" +#include "lldb/Host/Mutex.h" + +#include "NativeBreakpointList.h" +#include "NativeWatchpointList.h" + +namespace lldb_private +{ + class MemoryRegionInfo; + class ResumeActionList; + + //------------------------------------------------------------------ + // NativeProcessProtocol + //------------------------------------------------------------------ + class NativeProcessProtocol : + public std::enable_shared_from_this<NativeProcessProtocol> + { + friend class SoftwareBreakpoint; + + 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); + + public: + virtual ~NativeProcessProtocol () + { + } + + virtual Error + Resume (const ResumeActionList &resume_actions) = 0; + + virtual Error + Halt () = 0; + + virtual Error + Detach () = 0; + + //------------------------------------------------------------------ + /// Sends a process a UNIX signal \a signal. + /// + /// @return + /// Returns an error object. + //------------------------------------------------------------------ + virtual Error + Signal (int signo) = 0; + + //------------------------------------------------------------------ + /// Tells a process to interrupt all operations as if by a Ctrl-C. + /// + /// The default implementation will send a local host's equivalent of + /// a SIGSTOP to the process via the NativeProcessProtocol::Signal() + /// operation. + /// + /// @return + /// Returns an error object. + //------------------------------------------------------------------ + virtual Error + Interrupt (); + + virtual Error + Kill () = 0; + + //---------------------------------------------------------------------- + // Memory and memory region functions + //---------------------------------------------------------------------- + + virtual Error + 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; + + 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 () const; + + virtual size_t + UpdateThreads () = 0; + + virtual bool + GetArchitecture (ArchSpec &arch) const = 0; + + //---------------------------------------------------------------------- + // Breakpoint functions + //---------------------------------------------------------------------- + virtual Error + SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware) = 0; + + virtual Error + RemoveBreakpoint (lldb::addr_t addr); + + virtual Error + EnableBreakpoint (lldb::addr_t addr); + + virtual Error + DisableBreakpoint (lldb::addr_t addr); + + //---------------------------------------------------------------------- + // Watchpoint functions + //---------------------------------------------------------------------- + virtual const NativeWatchpointList::WatchpointMap& + GetWatchpointMap () const; + + virtual uint32_t + GetMaxWatchpoints () const; + + virtual Error + SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware); + + virtual Error + RemoveWatchpoint (lldb::addr_t addr); + + //---------------------------------------------------------------------- + // Accessors + //---------------------------------------------------------------------- + lldb::pid_t + GetID() const + { + return m_pid; + } + + lldb::StateType + GetState () const; + + 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; + } + + bool + GetByteOrder (lldb::ByteOrder &byte_order) const; + + //---------------------------------------------------------------------- + // Exit Status + //---------------------------------------------------------------------- + virtual bool + GetExitStatus (lldb_private::ExitType *exit_type, int *status, std::string &exit_description); + + virtual bool + SetExitStatus (lldb_private::ExitType exit_type, int status, const char *exit_description, bool bNotifyStateChange); + + //---------------------------------------------------------------------- + // Access to threads + //---------------------------------------------------------------------- + NativeThreadProtocolSP + GetThreadAtIndex (uint32_t idx); + + NativeThreadProtocolSP + GetThreadByID (lldb::tid_t tid); + + void + SetCurrentThreadID (lldb::tid_t tid) + { + m_current_thread_id = tid; + } + + lldb::tid_t + GetCurrentThreadID () + { + return m_current_thread_id; + } + + NativeThreadProtocolSP + GetCurrentThread () + { + return GetThreadByID (m_current_thread_id); + } + + //---------------------------------------------------------------------- + // Access to inferior stdio + //---------------------------------------------------------------------- + virtual + int GetTerminalFileDescriptor () + { + return m_terminal_fd; + } + + //---------------------------------------------------------------------- + // Stop id interface + //---------------------------------------------------------------------- + + uint32_t + GetStopID () const; + + // --------------------------------------------------------------------- + // Callbacks for low-level process state changes + // --------------------------------------------------------------------- + class NativeDelegate + { + public: + virtual + ~NativeDelegate () {} + + virtual void + InitializeDelegate (NativeProcessProtocol *process) = 0; + + virtual void + ProcessStateChanged (NativeProcessProtocol *process, lldb::StateType state) = 0; + + virtual void + DidExec (NativeProcessProtocol *process) = 0; + }; + + //------------------------------------------------------------------ + /// Register a native delegate. + /// + /// Clients can register nofication callbacks by passing in a + /// NativeDelegate impl and passing it into this function. + /// + /// Note: it is required that the lifetime of the + /// native_delegate outlive the NativeProcessProtocol. + /// + /// @param[in] native_delegate + /// A NativeDelegate impl to be called when certain events + /// happen within the NativeProcessProtocol or related threads. + /// + /// @return + /// true if the delegate was registered successfully; + /// false if the delegate was already registered. + /// + /// @see NativeProcessProtocol::NativeDelegate. + //------------------------------------------------------------------ + bool + RegisterNativeDelegate (NativeDelegate &native_delegate); + + //------------------------------------------------------------------ + /// Unregister a native delegate previously registered. + /// + /// @param[in] native_delegate + /// A NativeDelegate impl previously registered with this process. + /// + /// @return Returns \b true if the NativeDelegate was + /// successfully removed from the process, \b false otherwise. + /// + /// @see NativeProcessProtocol::NativeDelegate + //------------------------------------------------------------------ + bool + UnregisterNativeDelegate (NativeDelegate &native_delegate); + + protected: + lldb::pid_t m_pid; + + std::vector<NativeThreadProtocolSP> m_threads; + lldb::tid_t m_current_thread_id; + mutable Mutex m_threads_mutex; + + lldb::StateType m_state; + mutable Mutex m_state_mutex; + + lldb_private::ExitType m_exit_type; + int m_exit_status; + std::string m_exit_description; + Mutex m_delegates_mutex; + std::vector<NativeDelegate*> m_delegates; + NativeBreakpointList m_breakpoint_list; + NativeWatchpointList m_watchpoint_list; + int m_terminal_fd; + uint32_t m_stop_id; + + // ----------------------------------------------------------- + // Internal interface for state handling + // ----------------------------------------------------------- + void + SetState (lldb::StateType state, bool notify_delegates = true); + + // Derived classes need not implement this. It can be used as a + // hook to clear internal caches that should be invalidated when + // stop ids change. + // + // Note this function is called with the state mutex obtained + // by the caller. + virtual void + DoStopIDBumped (uint32_t newBumpId); + + // ----------------------------------------------------------- + // Internal interface for software breakpoints + // ----------------------------------------------------------- + Error + SetSoftwareBreakpoint (lldb::addr_t addr, uint32_t size_hint); + + virtual Error + GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint, size_t &actual_opcode_size, const uint8_t *&trap_opcode_bytes) = 0; + + // ----------------------------------------------------------- + /// Notify the delegate that an exec occurred. + /// + /// Provide a mechanism for a delegate to clear out any exec- + /// sensitive data. + // ----------------------------------------------------------- + void + NotifyDidExec (); + + NativeThreadProtocolSP + GetThreadByIDUnlocked (lldb::tid_t tid); + + private: + + void + SynchronouslyNotifyProcessStateChanged (lldb::StateType state); + }; +} + +#endif // #ifndef liblldb_NativeProcessProtocol_h_ diff --git a/include/lldb/Host/common/NativeRegisterContext.h b/include/lldb/Host/common/NativeRegisterContext.h new file mode 100644 index 000000000000..e9c03e3c20a4 --- /dev/null +++ b/include/lldb/Host/common/NativeRegisterContext.h @@ -0,0 +1,197 @@ +//===-- NativeRegisterContext.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_NativeRegisterContext_h_ +#define liblldb_NativeRegisterContext_h_ + +// C Includes +// C++ Includes +// Other libraries and framework includes +// Project includes +#include "lldb/lldb-private.h" +#include "lldb/Host/common/NativeWatchpointList.h" + +namespace lldb_private { + +class NativeThreadProtocol; + +class NativeRegisterContext: + public std::enable_shared_from_this<NativeRegisterContext> +{ +public: + //------------------------------------------------------------------ + // Constructors and Destructors + //------------------------------------------------------------------ + NativeRegisterContext (NativeThreadProtocol &thread, uint32_t concrete_frame_idx); + + virtual + ~NativeRegisterContext (); + + // void + // InvalidateIfNeeded (bool force); + + //------------------------------------------------------------------ + // Subclasses must override these functions + //------------------------------------------------------------------ + // virtual void + // InvalidateAllRegisters () = 0; + + virtual uint32_t + GetRegisterCount () const = 0; + + virtual uint32_t + GetUserRegisterCount () const = 0; + + virtual const RegisterInfo * + GetRegisterInfoAtIndex (uint32_t reg) const = 0; + + const char * + GetRegisterSetNameForRegisterAtIndex (uint32_t reg_index) const; + + virtual uint32_t + GetRegisterSetCount () const = 0; + + virtual const RegisterSet * + GetRegisterSet (uint32_t set_index) const = 0; + + virtual Error + ReadRegister (const RegisterInfo *reg_info, RegisterValue ®_value) = 0; + + virtual Error + WriteRegister (const RegisterInfo *reg_info, const RegisterValue ®_value) = 0; + + virtual Error + ReadAllRegisterValues (lldb::DataBufferSP &data_sp) = 0; + + virtual Error + WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) = 0; + + uint32_t + ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) const; + + //------------------------------------------------------------------ + // Subclasses can override these functions if desired + //------------------------------------------------------------------ + virtual uint32_t + NumSupportedHardwareBreakpoints (); + + virtual uint32_t + SetHardwareBreakpoint (lldb::addr_t addr, size_t size); + + virtual bool + ClearHardwareBreakpoint (uint32_t hw_idx); + + virtual uint32_t + NumSupportedHardwareWatchpoints (); + + virtual uint32_t + SetHardwareWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags); + + virtual bool + ClearHardwareWatchpoint (uint32_t hw_index); + + virtual Error + ClearAllHardwareWatchpoints (); + + 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); + + virtual Error + WriteRegisterValueToMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, lldb::addr_t dst_len, const RegisterValue ®_value); + + //------------------------------------------------------------------ + // Subclasses should not override these + //------------------------------------------------------------------ + virtual lldb::tid_t + GetThreadID() const; + + virtual NativeThreadProtocol & + GetThread () + { + return m_thread; + } + + const RegisterInfo * + GetRegisterInfoByName (const char *reg_name, uint32_t start_idx = 0); + + const RegisterInfo * + GetRegisterInfo (uint32_t reg_kind, uint32_t reg_num); + + lldb::addr_t + GetPC (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS); + + Error + SetPC (lldb::addr_t pc); + + lldb::addr_t + GetSP (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS); + + Error + SetSP (lldb::addr_t sp); + + lldb::addr_t + GetFP (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS); + + Error + SetFP (lldb::addr_t fp); + + const char * + GetRegisterName (uint32_t reg); + + lldb::addr_t + GetReturnAddress (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS); + + lldb::addr_t + GetFlags (lldb::addr_t fail_value = 0); + + lldb::addr_t + ReadRegisterAsUnsigned (uint32_t reg, lldb::addr_t fail_value); + + lldb::addr_t + ReadRegisterAsUnsigned (const RegisterInfo *reg_info, lldb::addr_t fail_value); + + Error + WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval); + + Error + WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval); + + // uint32_t + // GetStopID () const + // { + // return m_stop_id; + // } + + // void + // SetStopID (uint32_t stop_id) + // { + // m_stop_id = stop_id; + // } + +protected: + //------------------------------------------------------------------ + // Classes that inherit from RegisterContext can see and modify these + //------------------------------------------------------------------ + NativeThreadProtocol &m_thread; // The thread that this register context belongs to. + uint32_t m_concrete_frame_idx; // The concrete frame index for this register context + // uint32_t m_stop_id; // The stop ID that any data in this context is valid for + +private: + //------------------------------------------------------------------ + // For RegisterContext only + //------------------------------------------------------------------ + DISALLOW_COPY_AND_ASSIGN (NativeRegisterContext); +}; + +} // namespace lldb_private + +#endif // liblldb_NativeRegisterContext_h_ diff --git a/include/lldb/Host/common/NativeRegisterContextRegisterInfo.h b/include/lldb/Host/common/NativeRegisterContextRegisterInfo.h new file mode 100644 index 000000000000..b2a29de4e5a4 --- /dev/null +++ b/include/lldb/Host/common/NativeRegisterContextRegisterInfo.h @@ -0,0 +1,47 @@ +//===-- NativeRegisterContextRegisterInfo.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_NativeRegisterContextRegisterInfo_h +#define lldb_NativeRegisterContextRegisterInfo_h + +#include <memory> + +#include "NativeRegisterContext.h" +#include "Plugins/Process/Utility/RegisterInfoInterface.h" + +namespace lldb_private +{ + class NativeRegisterContextRegisterInfo: public NativeRegisterContext + { + public: + /// + /// Construct a NativeRegisterContextRegisterInfo, taking ownership + /// of the register_info_interface pointer. + /// + NativeRegisterContextRegisterInfo (NativeThreadProtocol &thread, + uint32_t concrete_frame_idx, + RegisterInfoInterface *register_info_interface); + + uint32_t + GetRegisterCount () const override; + + uint32_t + GetUserRegisterCount () const override; + + const RegisterInfo * + GetRegisterInfoAtIndex (uint32_t reg_index) const override; + + const RegisterInfoInterface& + GetRegisterInfoInterface () const; + + private: + std::unique_ptr<RegisterInfoInterface> m_register_info_interface_up; + }; +} +#endif diff --git a/include/lldb/Host/common/NativeThreadProtocol.h b/include/lldb/Host/common/NativeThreadProtocol.h new file mode 100644 index 000000000000..954ffb36a94f --- /dev/null +++ b/include/lldb/Host/common/NativeThreadProtocol.h @@ -0,0 +1,82 @@ +//===-- NativeThreadProtocol.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_NativeThreadProtocol_h_ +#define liblldb_NativeThreadProtocol_h_ + +#include <memory> + +#include "lldb/lldb-private-forward.h" +#include "lldb/lldb-types.h" +#include "lldb/Host/Debug.h" + +namespace lldb_private +{ + //------------------------------------------------------------------ + // NativeThreadProtocol + //------------------------------------------------------------------ + class NativeThreadProtocol: + public std::enable_shared_from_this<NativeThreadProtocol> + { + public: + NativeThreadProtocol (NativeProcessProtocol *process, lldb::tid_t tid); + + virtual ~NativeThreadProtocol() + { + } + + virtual std::string + GetName() = 0; + + virtual lldb::StateType + GetState () = 0; + + virtual NativeRegisterContextSP + GetRegisterContext () = 0; + + virtual Error + ReadRegister (uint32_t reg, RegisterValue ®_value); + + virtual Error + WriteRegister (uint32_t reg, const RegisterValue ®_value); + + virtual Error + SaveAllRegisters (lldb::DataBufferSP &data_sp); + + virtual Error + RestoreAllRegisters (lldb::DataBufferSP &data_sp); + + virtual bool + GetStopReason (ThreadStopInfo &stop_info, std::string& description) = 0; + + lldb::tid_t + GetID() const + { + return m_tid; + } + + NativeProcessProtocolSP + GetProcess (); + + // --------------------------------------------------------------------- + // Thread-specific watchpoints + // --------------------------------------------------------------------- + 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; + + protected: + NativeProcessProtocolWP m_process_wp; + lldb::tid_t m_tid; + }; +} + +#endif // #ifndef liblldb_NativeThreadProtocol_h_ diff --git a/include/lldb/Host/common/NativeWatchpointList.h b/include/lldb/Host/common/NativeWatchpointList.h new file mode 100644 index 000000000000..7b310e5a0db0 --- /dev/null +++ b/include/lldb/Host/common/NativeWatchpointList.h @@ -0,0 +1,47 @@ +//===-- NativeWatchpointList.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_NativeWatchpointList_h_ +#define liblldb_NativeWatchpointList_h_ + +#include "lldb/lldb-private-forward.h" +#include "lldb/Core/Error.h" + +#include <map> + +namespace lldb_private +{ + struct NativeWatchpoint + { + lldb::addr_t m_addr; + size_t m_size; + uint32_t m_watch_flags; + bool m_hardware; + }; + + class NativeWatchpointList + { + public: + Error + Add (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware); + + Error + Remove (lldb::addr_t addr); + + using WatchpointMap = std::map<lldb::addr_t, NativeWatchpoint>; + + const WatchpointMap& + GetWatchpointMap () const; + + private: + WatchpointMap m_watchpoints; + }; +} + +#endif // ifndef liblldb_NativeWatchpointList_h_ diff --git a/include/lldb/Host/common/SoftwareBreakpoint.h b/include/lldb/Host/common/SoftwareBreakpoint.h new file mode 100644 index 000000000000..1fed19eca612 --- /dev/null +++ b/include/lldb/Host/common/SoftwareBreakpoint.h @@ -0,0 +1,51 @@ +//===-- SoftwareBreakpoint.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_SoftwareBreakpoint_h_ +#define liblldb_SoftwareBreakpoint_h_ + +#include "lldb/lldb-private-forward.h" +#include "NativeBreakpoint.h" + +namespace lldb_private +{ + class SoftwareBreakpoint : public NativeBreakpoint + { + public: + static Error + CreateSoftwareBreakpoint (NativeProcessProtocol &process, lldb::addr_t addr, size_t size_hint, NativeBreakpointSP &breakpoint_spn); + + SoftwareBreakpoint (NativeProcessProtocol &process, lldb::addr_t addr, const uint8_t *saved_opcodes, const uint8_t *trap_opcodes, size_t opcode_size); + + protected: + Error + DoEnable () override; + + Error + DoDisable () override; + + bool + IsSoftwareBreakpoint () const override; + + private: + /// Max number of bytes that a software trap opcode sequence can occupy. + static const size_t MAX_TRAP_OPCODE_SIZE = 8; + + NativeProcessProtocol &m_process; + uint8_t m_saved_opcodes [MAX_TRAP_OPCODE_SIZE]; + uint8_t m_trap_opcodes [MAX_TRAP_OPCODE_SIZE]; + const size_t m_opcode_size; + + static Error + EnableSoftwareBreakpoint (NativeProcessProtocol &process, lldb::addr_t addr, size_t bp_opcode_size, const uint8_t *bp_opcode_bytes, uint8_t *saved_opcode_bytes); + + }; +} + +#endif // #ifndef liblldb_SoftwareBreakpoint_h_ diff --git a/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h b/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h index 4d326d71fa75..660b9d169bfc 100644 --- a/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h +++ b/include/lldb/Host/posix/ConnectionFileDescriptorPosix.h @@ -50,6 +50,8 @@ class ConnectionFileDescriptor : public Connection virtual size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Error *error_ptr); + virtual std::string GetURI(); + lldb::ConnectionStatus BytesAvailable(uint32_t timeout_usec, Error *error_ptr); bool InterruptRead(); @@ -75,7 +77,7 @@ class ConnectionFileDescriptor : public Connection void CloseCommandPipe(); - lldb::ConnectionStatus SocketListen(const char *host_and_port, Error *error_ptr); + lldb::ConnectionStatus SocketListenAndAccept(const char *host_and_port, Error *error_ptr); lldb::ConnectionStatus ConnectTCP(const char *host_and_port, Error *error_ptr); @@ -99,6 +101,8 @@ class ConnectionFileDescriptor : public Connection bool m_waiting_for_accept; bool m_child_processes_inherit; + std::string m_uri; + private: DISALLOW_COPY_AND_ASSIGN(ConnectionFileDescriptor); }; diff --git a/include/lldb/Host/posix/PipePosix.h b/include/lldb/Host/posix/PipePosix.h index 0ab3ff7f6775..fbdac66149d6 100644 --- a/include/lldb/Host/posix/PipePosix.h +++ b/include/lldb/Host/posix/PipePosix.h @@ -36,6 +36,8 @@ public: Error CreateNew(llvm::StringRef name, bool child_process_inherit) override; Error + CreateWithUniqueName(llvm::StringRef prefix, bool child_process_inherit, llvm::SmallVectorImpl<char>& name) override; + Error OpenAsReader(llvm::StringRef name, bool child_process_inherit) override; Error OpenAsWriterWithTimeout(llvm::StringRef name, bool child_process_inherit, const std::chrono::microseconds &timeout) override; |