2014-06-30 21:05:18 +00:00
|
|
|
//===-- NativeProcessLinux.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_NativeProcessLinux_H_
|
|
|
|
|
#define liblldb_NativeProcessLinux_H_
|
|
|
|
|
|
|
|
|
|
// C++ Includes
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
|
|
// Other libraries and framework includes
|
|
|
|
|
#include "lldb/Core/ArchSpec.h"
|
|
|
|
|
#include "lldb/lldb-types.h"
|
|
|
|
|
#include "lldb/Host/Debug.h"
|
2015-05-29 19:52:29 +00:00
|
|
|
#include "lldb/Host/FileSpec.h"
|
2014-09-09 20:54:56 +00:00
|
|
|
#include "lldb/Host/HostThread.h"
|
2014-06-30 21:05:18 +00:00
|
|
|
#include "lldb/Host/Mutex.h"
|
|
|
|
|
#include "lldb/Target/MemoryRegionInfo.h"
|
|
|
|
|
|
2015-02-03 01:51:38 +00:00
|
|
|
#include "lldb/Host/common/NativeProcessProtocol.h"
|
2015-05-11 10:03:10 +00:00
|
|
|
#include "NativeThreadLinux.h"
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-03-31 09:52:22 +00:00
|
|
|
namespace lldb_private {
|
2014-06-30 21:05:18 +00:00
|
|
|
class Error;
|
|
|
|
|
class Module;
|
|
|
|
|
class Scalar;
|
|
|
|
|
|
2015-03-31 09:52:22 +00:00
|
|
|
namespace process_linux {
|
2014-06-30 21:05:18 +00:00
|
|
|
/// @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
|
|
|
|
|
{
|
2015-07-09 11:51:11 +00:00
|
|
|
friend Error
|
|
|
|
|
NativeProcessProtocol::Launch (ProcessLaunchInfo &launch_info,
|
|
|
|
|
NativeDelegate &native_delegate,
|
2015-07-21 13:20:32 +00:00
|
|
|
MainLoop &mainloop,
|
2015-07-09 11:51:11 +00:00
|
|
|
NativeProcessProtocolSP &process_sp);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-07-09 11:51:11 +00:00
|
|
|
friend Error
|
|
|
|
|
NativeProcessProtocol::Attach (lldb::pid_t pid,
|
2015-07-21 13:20:32 +00:00
|
|
|
NativeProcessProtocol::NativeDelegate &native_delegate,
|
|
|
|
|
MainLoop &mainloop,
|
|
|
|
|
NativeProcessProtocolSP &process_sp);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-07-09 11:51:11 +00:00
|
|
|
public:
|
2014-06-30 21:05:18 +00:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
// NativeProcessProtocol Interface
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
Error
|
|
|
|
|
Resume (const ResumeActionList &resume_actions) override;
|
|
|
|
|
|
|
|
|
|
Error
|
|
|
|
|
Halt () override;
|
|
|
|
|
|
|
|
|
|
Error
|
|
|
|
|
Detach () override;
|
|
|
|
|
|
|
|
|
|
Error
|
|
|
|
|
Signal (int signo) override;
|
|
|
|
|
|
2015-02-03 01:51:00 +00:00
|
|
|
Error
|
|
|
|
|
Interrupt () override;
|
|
|
|
|
|
2014-06-30 21:05:18 +00:00
|
|
|
Error
|
|
|
|
|
Kill () override;
|
|
|
|
|
|
|
|
|
|
Error
|
|
|
|
|
GetMemoryRegionInfo (lldb::addr_t load_addr, MemoryRegionInfo &range_info) override;
|
|
|
|
|
|
|
|
|
|
Error
|
2015-04-29 17:24:48 +00:00
|
|
|
ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override;
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
Error
|
2015-04-29 17:24:48 +00:00
|
|
|
ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override;
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
Error
|
2015-04-29 17:24:48 +00:00
|
|
|
WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override;
|
|
|
|
|
|
|
|
|
|
Error
|
|
|
|
|
AllocateMemory(size_t size, uint32_t permissions, lldb::addr_t &addr) override;
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
Error
|
|
|
|
|
DeallocateMemory (lldb::addr_t addr) override;
|
|
|
|
|
|
|
|
|
|
lldb::addr_t
|
|
|
|
|
GetSharedLibraryInfoAddress () override;
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
UpdateThreads () override;
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
GetArchitecture (ArchSpec &arch) const override;
|
|
|
|
|
|
|
|
|
|
Error
|
|
|
|
|
SetBreakpoint (lldb::addr_t addr, uint32_t size, bool hardware) override;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
DoStopIDBumped (uint32_t newBumpId) override;
|
|
|
|
|
|
2015-05-26 11:58:52 +00:00
|
|
|
Error
|
|
|
|
|
GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec) override;
|
|
|
|
|
|
2015-06-18 20:43:56 +00:00
|
|
|
Error
|
|
|
|
|
GetFileLoadAddress(const llvm::StringRef& file_name, lldb::addr_t& load_addr) override;
|
|
|
|
|
|
2015-08-21 09:13:53 +00:00
|
|
|
NativeThreadLinuxSP
|
|
|
|
|
GetThreadByID(lldb::tid_t id);
|
|
|
|
|
|
2014-06-30 21:05:18 +00:00
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
// Interface used by NativeRegisterContext-derived classes.
|
|
|
|
|
// ---------------------------------------------------------------------
|
2015-06-30 17:04:49 +00:00
|
|
|
static Error
|
|
|
|
|
PtraceWrapper(int req,
|
|
|
|
|
lldb::pid_t pid,
|
|
|
|
|
void *addr = nullptr,
|
|
|
|
|
void *data = nullptr,
|
|
|
|
|
size_t data_size = 0,
|
|
|
|
|
long *result = nullptr);
|
2015-03-24 11:15:23 +00:00
|
|
|
|
2014-06-30 21:05:18 +00:00
|
|
|
protected:
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
// NativeProcessProtocol protected interface
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
Error
|
|
|
|
|
GetSoftwareBreakpointTrapOpcode (size_t trap_opcode_size_hint, size_t &actual_opcode_size, const uint8_t *&trap_opcode_bytes) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
2015-07-21 13:20:32 +00:00
|
|
|
MainLoop::SignalHandleUP m_sigchld_handle;
|
2015-03-31 09:52:22 +00:00
|
|
|
ArchSpec m_arch;
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-03-31 09:52:22 +00:00
|
|
|
LazyBool m_supports_mem_region;
|
2014-06-30 21:05:18 +00:00
|
|
|
std::vector<MemoryRegionInfo> m_mem_region_cache;
|
2015-03-31 09:52:22 +00:00
|
|
|
Mutex m_mem_region_cache_mutex;
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-08-20 09:06:12 +00:00
|
|
|
lldb::tid_t m_pending_notification_tid;
|
|
|
|
|
|
2015-04-15 09:47:02 +00:00
|
|
|
// 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;
|
|
|
|
|
|
2014-06-30 21:05:18 +00:00
|
|
|
/// @class LauchArgs
|
|
|
|
|
///
|
|
|
|
|
/// @brief Simple structure to pass data to the thread responsible for
|
|
|
|
|
/// launching a child process.
|
2015-04-20 13:53:49 +00:00
|
|
|
struct LaunchArgs
|
2014-06-30 21:05:18 +00:00
|
|
|
{
|
2015-04-20 13:53:49 +00:00
|
|
|
LaunchArgs(Module *module,
|
2014-06-30 21:05:18 +00:00
|
|
|
char const **argv,
|
|
|
|
|
char const **envp,
|
2015-05-29 19:52:29 +00:00
|
|
|
const FileSpec &stdin_file_spec,
|
|
|
|
|
const FileSpec &stdout_file_spec,
|
|
|
|
|
const FileSpec &stderr_file_spec,
|
|
|
|
|
const FileSpec &working_dir,
|
2015-03-31 09:52:22 +00:00
|
|
|
const ProcessLaunchInfo &launch_info);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
~LaunchArgs();
|
|
|
|
|
|
2015-05-29 19:52:29 +00:00
|
|
|
Module *m_module; // The executable image to launch.
|
|
|
|
|
char const **m_argv; // Process arguments.
|
|
|
|
|
char const **m_envp; // Process environment.
|
|
|
|
|
const FileSpec m_stdin_file_spec; // Redirect stdin if not empty.
|
|
|
|
|
const FileSpec m_stdout_file_spec; // Redirect stdout if not empty.
|
|
|
|
|
const FileSpec m_stderr_file_spec; // Redirect stderr if not empty.
|
|
|
|
|
const FileSpec m_working_dir; // Working directory or empty.
|
2015-03-31 09:52:22 +00:00
|
|
|
const ProcessLaunchInfo &m_launch_info;
|
2014-06-30 21:05:18 +00:00
|
|
|
};
|
|
|
|
|
|
2015-08-09 19:04:41 +00:00
|
|
|
typedef std::function< ::pid_t(Error &)> InitialOperation;
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
// Private Instance Methods
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
NativeProcessLinux ();
|
|
|
|
|
|
|
|
|
|
/// Launches an inferior process ready for debugging. Forms the
|
|
|
|
|
/// implementation of Process::DoLaunch.
|
|
|
|
|
void
|
|
|
|
|
LaunchInferior (
|
2015-07-21 13:20:32 +00:00
|
|
|
MainLoop &mainloop,
|
2014-06-30 21:05:18 +00:00
|
|
|
Module *module,
|
|
|
|
|
char const *argv[],
|
|
|
|
|
char const *envp[],
|
2015-05-29 19:52:29 +00:00
|
|
|
const FileSpec &stdin_file_spec,
|
|
|
|
|
const FileSpec &stdout_file_spec,
|
|
|
|
|
const FileSpec &stderr_file_spec,
|
|
|
|
|
const FileSpec &working_dir,
|
2015-03-31 09:52:22 +00:00
|
|
|
const ProcessLaunchInfo &launch_info,
|
2014-06-30 21:05:18 +00:00
|
|
|
Error &error);
|
|
|
|
|
|
|
|
|
|
/// Attaches to an existing process. Forms the
|
2015-03-13 11:16:03 +00:00
|
|
|
/// implementation of Process::DoAttach
|
2014-06-30 21:05:18 +00:00
|
|
|
void
|
2015-07-21 13:20:32 +00:00
|
|
|
AttachToInferior (MainLoop &mainloop, lldb::pid_t pid, Error &error);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-04-20 13:53:49 +00:00
|
|
|
::pid_t
|
|
|
|
|
Launch(LaunchArgs *args, Error &error);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-04-20 13:53:49 +00:00
|
|
|
::pid_t
|
|
|
|
|
Attach(lldb::pid_t pid, Error &error);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-02-03 01:51:12 +00:00
|
|
|
static Error
|
2014-06-30 21:05:18 +00:00
|
|
|
SetDefaultPtraceOpts(const lldb::pid_t);
|
|
|
|
|
|
|
|
|
|
static bool
|
2015-05-29 19:52:29 +00:00
|
|
|
DupDescriptor(const FileSpec &file_spec, int fd, int flags);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-04-17 14:07:49 +00:00
|
|
|
static void *
|
|
|
|
|
MonitorThread(void *baton);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MonitorCallback(lldb::pid_t pid, bool exited, int signal, int status);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
[NativeProcessLinux] Add back synchronisation of thread create events
Summary:
Without the synchronisation between the two thread creation events the following case could
happen:
- threads A and B are running. A hits a breakpoint. We note that we want to stop B.
- before we could stop it, B creates a new thread C, we get the stop notification for B, but we
don't record C's existence yet.
- we resume B
- before we get the C notification, B stops again (e.g. hits a breakpoint, gets our SIGSTOP,
etc.)
- we see all known threads have stopped, and we notify LLDB
- C notification comes, we note it's existence and resume it
=> we have an inconsistent state (LLDB thinks we've stopped, but C is running)
I resolve this by doing a blocking wait for for the C notification when we get the creation
notification on the parent (B) thread. This way the two events are synchronised, but we don't
need to introduce the intermediate "launching" state which would complicate handling of thread
states as all code would need to be aware of the third possible state.
Test Plan:
This is an obscure corner case, which I had not observed in practise, so I have no
test for it. I have tested that this commit does not regress in existing tests though.
Reviewers: chaoren, vharron
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D9217
llvm-svn: 235969
2015-04-28 07:51:52 +00:00
|
|
|
void
|
|
|
|
|
WaitForNewThread(::pid_t tid);
|
|
|
|
|
|
2014-06-30 21:05:18 +00:00
|
|
|
void
|
2015-08-24 09:22:04 +00:00
|
|
|
MonitorSIGTRAP(const siginfo_t &info, NativeThreadLinux &thread);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-03-19 23:28:10 +00:00
|
|
|
void
|
2015-08-24 09:22:04 +00:00
|
|
|
MonitorTrace(NativeThreadLinux &thread);
|
2015-03-19 23:28:10 +00:00
|
|
|
|
|
|
|
|
void
|
2015-08-24 09:22:04 +00:00
|
|
|
MonitorBreakpoint(NativeThreadLinux &thread);
|
2015-03-19 23:28:10 +00:00
|
|
|
|
|
|
|
|
void
|
2015-08-21 09:13:53 +00:00
|
|
|
MonitorWatchpoint(NativeThreadLinux &thread, uint32_t wp_index);
|
2015-03-19 23:28:10 +00:00
|
|
|
|
2014-06-30 21:05:18 +00:00
|
|
|
void
|
2015-08-24 09:22:04 +00:00
|
|
|
MonitorSignal(const siginfo_t &info, NativeThreadLinux &thread, bool exited);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
2015-04-22 10:00:23 +00:00
|
|
|
bool
|
|
|
|
|
SupportHardwareSingleStepping() const;
|
|
|
|
|
|
|
|
|
|
Error
|
2015-08-24 09:22:04 +00:00
|
|
|
SetupSoftwareSingleStepping(NativeThreadLinux &thread);
|
2015-04-22 10:00:23 +00:00
|
|
|
|
2014-06-30 21:05:18 +00:00
|
|
|
#if 0
|
|
|
|
|
static ::ProcessMessage::CrashReason
|
|
|
|
|
GetCrashReasonForSIGSEGV(const siginfo_t *info);
|
|
|
|
|
|
|
|
|
|
static ::ProcessMessage::CrashReason
|
|
|
|
|
GetCrashReasonForSIGILL(const siginfo_t *info);
|
|
|
|
|
|
|
|
|
|
static ::ProcessMessage::CrashReason
|
|
|
|
|
GetCrashReasonForSIGFPE(const siginfo_t *info);
|
|
|
|
|
|
|
|
|
|
static ::ProcessMessage::CrashReason
|
|
|
|
|
GetCrashReasonForSIGBUS(const siginfo_t *info);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
HasThreadNoLock (lldb::tid_t thread_id);
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
StopTrackingThread (lldb::tid_t thread_id);
|
|
|
|
|
|
2015-08-21 09:13:53 +00:00
|
|
|
NativeThreadLinuxSP
|
2014-06-30 21:05:18 +00:00
|
|
|
AddThread (lldb::tid_t thread_id);
|
|
|
|
|
|
|
|
|
|
Error
|
2015-08-24 09:22:04 +00:00
|
|
|
GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
Error
|
2015-08-24 09:22:04 +00:00
|
|
|
FixupBreakpointPCAsNeeded(NativeThreadLinux &thread);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
/// Writes a siginfo_t structure corresponding to the given thread ID to the
|
|
|
|
|
/// memory region pointed to by @p siginfo.
|
2015-02-03 01:51:12 +00:00
|
|
|
Error
|
|
|
|
|
GetSignalInfo(lldb::tid_t tid, void *siginfo);
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
/// 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.
|
2015-02-03 01:51:12 +00:00
|
|
|
Error
|
2014-06-30 21:05:18 +00:00
|
|
|
GetEventMessage(lldb::tid_t tid, unsigned long *message);
|
|
|
|
|
|
|
|
|
|
/// Resumes the given thread. If @p signo is anything but
|
|
|
|
|
/// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
|
2015-02-03 01:51:12 +00:00
|
|
|
Error
|
2014-06-30 21:05:18 +00:00
|
|
|
Resume(lldb::tid_t tid, uint32_t signo);
|
|
|
|
|
|
|
|
|
|
/// Single steps the given thread. If @p signo is anything but
|
|
|
|
|
/// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
|
2015-02-03 01:51:12 +00:00
|
|
|
Error
|
2014-06-30 21:05:18 +00:00
|
|
|
SingleStep(lldb::tid_t tid, uint32_t signo);
|
|
|
|
|
|
2015-02-03 01:50:42 +00:00
|
|
|
void
|
|
|
|
|
NotifyThreadDeath (lldb::tid_t tid);
|
|
|
|
|
|
2015-03-31 09:52:22 +00:00
|
|
|
Error
|
2014-06-30 21:05:18 +00:00
|
|
|
Detach(lldb::tid_t tid);
|
2015-02-03 01:51:15 +00:00
|
|
|
|
2015-05-06 10:46:34 +00:00
|
|
|
|
2015-05-12 08:35:33 +00:00
|
|
|
// 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).
|
2015-05-06 10:46:34 +00:00
|
|
|
void
|
2015-05-08 08:57:45 +00:00
|
|
|
StopRunningThreads(lldb::tid_t triggering_tid);
|
2015-05-06 10:46:34 +00:00
|
|
|
|
[NativeProcessLinux] Fix removal of temporary breakpoints
Summary:
There was an issue in NPL, where we attempted removal of temporary breakpoints (used to implement
software single stepping), while some threads of the process were running. This is a problem
since we currently always use the main thread's ID in the removal ptrace call. Therefore, if the
main thread was still running, the ptrace call would fail, and the software breakpoint would
remain, causing all kinds of problems. This change removes the breakpoints after all threads have
stopped. This fixes TestExitDuringStep on Android arm and can also potentially help in other
situations, as previously the breakpoint would not get removed if the thread stopped for another
reason.
Test Plan: TestExitDuringStep passes, other tests remain unchanged.
Reviewers: tberghammer
Subscribers: tberghammer, aemerson, lldb-commits
Differential Revision: http://reviews.llvm.org/D9792
llvm-svn: 237448
2015-05-15 13:49:01 +00:00
|
|
|
// Notify the delegate if all threads have stopped.
|
|
|
|
|
void SignalIfAllThreadsStopped();
|
2015-05-06 10:46:34 +00:00
|
|
|
|
2015-08-20 09:06:12 +00:00
|
|
|
// Resume the given thread, optionally passing it the given signal. The type of resume
|
|
|
|
|
// operation (continue, single-step) depends on the state parameter.
|
2015-05-07 08:30:31 +00:00
|
|
|
Error
|
2015-08-24 09:22:04 +00:00
|
|
|
ResumeThread(NativeThreadLinux &thread, lldb::StateType state, int signo);
|
2015-05-06 10:46:34 +00:00
|
|
|
|
|
|
|
|
void
|
2015-08-21 09:13:53 +00:00
|
|
|
ThreadWasCreated(NativeThreadLinux &thread);
|
2015-05-06 10:46:34 +00:00
|
|
|
|
2015-07-21 13:20:32 +00:00
|
|
|
void
|
|
|
|
|
SigchldHandler();
|
2014-06-30 21:05:18 +00:00
|
|
|
};
|
2015-03-31 09:52:22 +00:00
|
|
|
|
|
|
|
|
} // namespace process_linux
|
|
|
|
|
} // namespace lldb_private
|
2014-06-30 21:05:18 +00:00
|
|
|
|
|
|
|
|
#endif // #ifndef liblldb_NativeProcessLinux_H_
|