diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:26:05 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:26:05 +0000 | 
| commit | 14f1b3e8826ce43b978db93a62d1166055db5394 (patch) | |
| tree | 0a00ad8d3498783fe0193f3b656bca17c4c8697d /source/Plugins/Process/Linux/NativeProcessLinux.h | |
| parent | 4ee8c119c71a06dcad1e0fecc8c675e480e59337 (diff) | |
Notes
Diffstat (limited to 'source/Plugins/Process/Linux/NativeProcessLinux.h')
| -rw-r--r-- | source/Plugins/Process/Linux/NativeProcessLinux.h | 297 | 
1 files changed, 123 insertions, 174 deletions
diff --git a/source/Plugins/Process/Linux/NativeProcessLinux.h b/source/Plugins/Process/Linux/NativeProcessLinux.h index d5be06f0cb58..fcb13c8b016b 100644 --- a/source/Plugins/Process/Linux/NativeProcessLinux.h +++ b/source/Plugins/Process/Linux/NativeProcessLinux.h @@ -15,192 +15,151 @@  // Other libraries and framework includes  #include "lldb/Core/ArchSpec.h" -#include "lldb/lldb-types.h"  #include "lldb/Host/Debug.h"  #include "lldb/Host/FileSpec.h"  #include "lldb/Host/HostThread.h"  #include "lldb/Target/MemoryRegionInfo.h" +#include "lldb/lldb-types.h" -#include "lldb/Host/common/NativeProcessProtocol.h"  #include "NativeThreadLinux.h" +#include "lldb/Host/common/NativeProcessProtocol.h"  namespace lldb_private { -    class Error; -    class Scalar; +class Error; +class Scalar;  namespace process_linux { -    /// @class NativeProcessLinux -    /// @brief Manages communication with the inferior (debugee) process. -    /// -    /// Upon construction, this class prepares and launches an inferior process for -    /// debugging. -    /// -    /// Changes in the inferior process state are broadcasted. -    class NativeProcessLinux: public NativeProcessProtocol -    { -        friend Error -        NativeProcessProtocol::Launch (ProcessLaunchInfo &launch_info, -                NativeDelegate &native_delegate, -                MainLoop &mainloop, -                NativeProcessProtocolSP &process_sp); - -        friend Error -        NativeProcessProtocol::Attach (lldb::pid_t pid, -                NativeProcessProtocol::NativeDelegate &native_delegate, -                MainLoop &mainloop, -                NativeProcessProtocolSP &process_sp); +/// @class NativeProcessLinux +/// @brief Manages communication with the inferior (debugee) process. +/// +/// Upon construction, this class prepares and launches an inferior process for +/// debugging. +/// +/// Changes in the inferior process state are broadcasted. +class NativeProcessLinux : public NativeProcessProtocol { +  friend Error NativeProcessProtocol::Launch( +      ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate, +      MainLoop &mainloop, NativeProcessProtocolSP &process_sp); -    public: -        // --------------------------------------------------------------------- -        // NativeProcessProtocol Interface -        // --------------------------------------------------------------------- -        Error -        Resume (const ResumeActionList &resume_actions) override; +  friend Error NativeProcessProtocol::Attach( +      lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate, +      MainLoop &mainloop, NativeProcessProtocolSP &process_sp); -        Error -        Halt () override; +public: +  // --------------------------------------------------------------------- +  // NativeProcessProtocol Interface +  // --------------------------------------------------------------------- +  Error Resume(const ResumeActionList &resume_actions) override; -        Error -        Detach () override; +  Error Halt() override; -        Error -        Signal (int signo) override; +  Error Detach() override; -        Error -        Interrupt () override; +  Error Signal(int signo) override; -        Error -        Kill () override; +  Error Interrupt() override; -        Error -        GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info) override; +  Error Kill() override; -        Error -        ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override; +  Error GetMemoryRegionInfo(lldb::addr_t load_addr, +                            MemoryRegionInfo &range_info) override; -        Error -        ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override; +  Error ReadMemory(lldb::addr_t addr, void *buf, size_t size, +                   size_t &bytes_read) override; -        Error -        WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override; +  Error ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, +                              size_t &bytes_read) override; -        Error -        AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) override; +  Error WriteMemory(lldb::addr_t addr, const void *buf, size_t size, +                    size_t &bytes_written) override; -        Error -        DeallocateMemory (lldb::addr_t addr) override; +  Error AllocateMemory(size_t size, uint32_t permissions, +                       lldb::addr_t &addr) override; -        lldb::addr_t -        GetSharedLibraryInfoAddress () override; +  Error DeallocateMemory(lldb::addr_t addr) override; -        size_t -        UpdateThreads () override; +  lldb::addr_t GetSharedLibraryInfoAddress() override; -        bool -        GetArchitecture (ArchSpec &arch) const override; +  size_t UpdateThreads() override; -        Error -        SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware) override; +  bool GetArchitecture(ArchSpec &arch) const override; -        void -        DoStopIDBumped (uint32_t newBumpId) override; +  Error SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override; -        Error -        GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec) override; +  void DoStopIDBumped(uint32_t newBumpId) override; -        Error -        GetFileLoadAddress(const llvm::StringRef& file_name, lldb::addr_t& load_addr) override; +  Error GetLoadedModuleFileSpec(const char *module_path, +                                FileSpec &file_spec) override; -        NativeThreadLinuxSP -        GetThreadByID(lldb::tid_t id); +  Error GetFileLoadAddress(const llvm::StringRef &file_name, +                           lldb::addr_t &load_addr) override; -        // --------------------------------------------------------------------- -        // Interface used by NativeRegisterContext-derived classes. -        // --------------------------------------------------------------------- -        static Error -        PtraceWrapper(int req, -                      lldb::pid_t pid, -                      void *addr = nullptr, -                      void *data = nullptr, -                      size_t data_size = 0, -                      long *result = nullptr); +  NativeThreadLinuxSP GetThreadByID(lldb::tid_t id); -        bool -        SupportHardwareSingleStepping() const; +  // --------------------------------------------------------------------- +  // Interface used by NativeRegisterContext-derived classes. +  // --------------------------------------------------------------------- +  static Error PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr, +                             void *data = nullptr, size_t data_size = 0, +                             long *result = nullptr); -    protected: -        // --------------------------------------------------------------------- -        // NativeProcessProtocol protected interface -        // --------------------------------------------------------------------- -        Error -        GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint, size_t &actual_opcode_size, const uint8_t *&trap_opcode_bytes) override; +  bool SupportHardwareSingleStepping() const; -    private: +protected: +  // --------------------------------------------------------------------- +  // NativeProcessProtocol protected interface +  // --------------------------------------------------------------------- +  Error +  GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint, +                                  size_t &actual_opcode_size, +                                  const uint8_t *&trap_opcode_bytes) override; -        MainLoop::SignalHandleUP m_sigchld_handle; -        ArchSpec m_arch; +private: +  MainLoop::SignalHandleUP m_sigchld_handle; +  ArchSpec m_arch; -        LazyBool m_supports_mem_region; -        std::vector<MemoryRegionInfo> m_mem_region_cache; +  LazyBool m_supports_mem_region; +  std::vector<MemoryRegionInfo> m_mem_region_cache; -        lldb::tid_t m_pending_notification_tid; +  lldb::tid_t m_pending_notification_tid; -        // List of thread ids stepping with a breakpoint with the address of -        // the relevan breakpoint -        std::map<lldb::tid_t, lldb::addr_t> m_threads_stepping_with_breakpoint; +  // List of thread ids stepping with a breakpoint with the address of +  // the relevan breakpoint +  std::map<lldb::tid_t, lldb::addr_t> m_threads_stepping_with_breakpoint; +  // --------------------------------------------------------------------- +  // Private Instance Methods +  // --------------------------------------------------------------------- +  NativeProcessLinux(); -        // --------------------------------------------------------------------- -        // Private Instance Methods -        // --------------------------------------------------------------------- -        NativeProcessLinux (); +  Error LaunchInferior(MainLoop &mainloop, ProcessLaunchInfo &launch_info); -        Error -        LaunchInferior(MainLoop &mainloop, ProcessLaunchInfo &launch_info); +  /// Attaches to an existing process.  Forms the +  /// implementation of Process::DoAttach +  void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Error &error); -        /// Attaches to an existing process.  Forms the -        /// implementation of Process::DoAttach -        void -        AttachToInferior (MainLoop &mainloop, lldb::pid_t pid, Error &error); +  ::pid_t Attach(lldb::pid_t pid, Error &error); -        ::pid_t -        Attach(lldb::pid_t pid, Error &error); +  static Error SetDefaultPtraceOpts(const lldb::pid_t); -        static void -        ChildFunc(const ProcessLaunchInfo &launch_info) LLVM_ATTRIBUTE_NORETURN; +  static void *MonitorThread(void *baton); -        static Error -        SetDefaultPtraceOpts(const lldb::pid_t); +  void MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status); -        static bool -        DupDescriptor(const FileSpec &file_spec, int fd, int flags); +  void WaitForNewThread(::pid_t tid); -        static void * -        MonitorThread(void *baton); +  void MonitorSIGTRAP(const siginfo_t &info, NativeThreadLinux &thread); -        void -        MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status); +  void MonitorTrace(NativeThreadLinux &thread); -        void -        WaitForNewThread(::pid_t tid); +  void MonitorBreakpoint(NativeThreadLinux &thread); -        void -        MonitorSIGTRAP(const siginfo_t &info, NativeThreadLinux &thread); +  void MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index); -        void -        MonitorTrace(NativeThreadLinux &thread); +  void MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread, +                     bool exited); -        void -        MonitorBreakpoint(NativeThreadLinux &thread); - -        void -        MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index); - -        void -        MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread, bool exited); - -        Error -        SetupSoftwareSingleStepping(NativeThreadLinux &thread); +  Error SetupSoftwareSingleStepping(NativeThreadLinux &thread);  #if 0          static ::ProcessMessage::CrashReason @@ -216,59 +175,49 @@ namespace process_linux {          GetCrashReasonForSIGBUS(const siginfo_t *info);  #endif -        bool -        HasThreadNoLock (lldb::tid_t thread_id); - -        bool -        StopTrackingThread (lldb::tid_t thread_id); +  bool HasThreadNoLock(lldb::tid_t thread_id); -        NativeThreadLinuxSP -        AddThread (lldb::tid_t thread_id); +  bool StopTrackingThread(lldb::tid_t thread_id); -        Error -        GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size); +  NativeThreadLinuxSP AddThread(lldb::tid_t thread_id); -        Error -        FixupBreakpointPCAsNeeded(NativeThreadLinux &thread); +  Error GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size); -        /// Writes a siginfo_t structure corresponding to the given thread ID to the -        /// memory region pointed to by @p siginfo. -        Error -        GetSignalInfo(lldb::tid_t tid, void *siginfo); +  Error FixupBreakpointPCAsNeeded(NativeThreadLinux &thread); -        /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) -        /// corresponding to the given thread ID to the memory pointed to by @p -        /// message. -        Error -        GetEventMessage(lldb::tid_t tid, unsigned long *message); +  /// Writes a siginfo_t structure corresponding to the given thread ID to the +  /// memory region pointed to by @p siginfo. +  Error GetSignalInfo(lldb::tid_t tid, void *siginfo); -        void -        NotifyThreadDeath (lldb::tid_t tid); +  /// Writes the raw event message code (vis-a-vis PTRACE_GETEVENTMSG) +  /// corresponding to the given thread ID to the memory pointed to by @p +  /// message. +  Error GetEventMessage(lldb::tid_t tid, unsigned long *message); -        Error -        Detach(lldb::tid_t tid); +  void NotifyThreadDeath(lldb::tid_t tid); +  Error Detach(lldb::tid_t tid); -        // This method is requests a stop on all threads which are still running. It sets up a -        // deferred delegate notification, which will fire once threads report as stopped. The -        // triggerring_tid will be set as the current thread (main stop reason). -        void -        StopRunningThreads(lldb::tid_t triggering_tid); +  // This method is requests a stop on all threads which are still running. It +  // sets up a +  // deferred delegate notification, which will fire once threads report as +  // stopped. The +  // triggerring_tid will be set as the current thread (main stop reason). +  void StopRunningThreads(lldb::tid_t triggering_tid); -        // Notify the delegate if all threads have stopped. -        void SignalIfAllThreadsStopped(); +  // Notify the delegate if all threads have stopped. +  void SignalIfAllThreadsStopped(); -        // Resume the given thread, optionally passing it the given signal. The type of resume -        // operation (continue, single-step) depends on the state parameter. -        Error -        ResumeThread(NativeThreadLinux &thread, lldb::StateType state, int signo); +  // Resume the given thread, optionally passing it the given signal. The type +  // of resume +  // operation (continue, single-step) depends on the state parameter. +  Error ResumeThread(NativeThreadLinux &thread, lldb::StateType state, +                     int signo); -        void -        ThreadWasCreated(NativeThreadLinux &thread); +  void ThreadWasCreated(NativeThreadLinux &thread); -        void -        SigchldHandler(); -    }; +  void SigchldHandler(); +};  } // namespace process_linux  } // namespace lldb_private  | 
