2010-06-09 00:52:24 +08:00
|
|
|
//===-- ProcessGDBRemote.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_ProcessGDBRemote_h_
|
|
|
|
#define liblldb_ProcessGDBRemote_h_
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
|
|
|
|
// C++ Includes
|
|
|
|
#include <list>
|
2011-02-12 14:28:37 +08:00
|
|
|
#include <vector>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
// Other libraries and framework includes
|
|
|
|
#include "lldb/Core/ArchSpec.h"
|
|
|
|
#include "lldb/Core/Broadcaster.h"
|
|
|
|
#include "lldb/Core/Error.h"
|
|
|
|
#include "lldb/Core/InputReader.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
2010-08-10 07:31:02 +08:00
|
|
|
#include "lldb/Core/StringList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/ThreadSafeValue.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
#include "GDBRemoteCommunicationClient.h"
|
2010-07-10 04:39:50 +08:00
|
|
|
#include "Utility/StringExtractor.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "GDBRemoteRegisterContext.h"
|
|
|
|
|
|
|
|
class ThreadGDBRemote;
|
|
|
|
|
|
|
|
class ProcessGDBRemote : public lldb_private::Process
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Constructors and Destructors
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
static Process*
|
|
|
|
CreateInstance (lldb_private::Target& target, lldb_private::Listener &listener);
|
|
|
|
|
|
|
|
static void
|
|
|
|
Initialize();
|
|
|
|
|
|
|
|
static void
|
|
|
|
Terminate();
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
GetPluginNameStatic();
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
GetPluginDescriptionStatic();
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Constructors and Destructors
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
ProcessGDBRemote(lldb_private::Target& target, lldb_private::Listener &listener);
|
|
|
|
|
|
|
|
virtual
|
|
|
|
~ProcessGDBRemote();
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Check if a given Process
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual bool
|
2011-07-18 04:36:25 +08:00
|
|
|
CanDebug (lldb_private::Target &target,
|
|
|
|
bool plugin_specified_by_name);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-09 06:40:15 +08:00
|
|
|
// virtual uint32_t
|
|
|
|
// ListProcessesMatchingName (const char *name, lldb_private::StringList &matches, std::vector<lldb::pid_t> &pids);
|
2010-08-10 07:31:02 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Creating a new process, or attaching to an existing one
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual lldb_private::Error
|
|
|
|
WillLaunch (lldb_private::Module* module);
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DoLaunch (lldb_private::Module* module,
|
|
|
|
char const *argv[], // Can be NULL
|
|
|
|
char const *envp[], // Can be NULL
|
2010-09-01 02:35:14 +08:00
|
|
|
uint32_t flags,
|
2010-06-09 00:52:24 +08:00
|
|
|
const char *stdin_path, // Can be NULL
|
Added a new variant of SBTarget::Launch() that deprectates the old one that
takes separate file handles for stdin, stdout, and stder and also allows for
the working directory to be specified.
Added support to "process launch" to a new option: --working-dir=PATH. We
can now set the working directory. If this is not set, it defaults to that
of the process that has LLDB loaded. Added the working directory to the
host LaunchInNewTerminal function to allows the current working directory
to be set in processes that are spawned in their own terminal. Also hooked this
up to the lldb_private::Process and all mac plug-ins. The linux plug-in had its
API changed, but nothing is making use of it yet. Modfied "debugserver" and
"darwin-debug" to also handle the current working directory options and modified
the code in LLDB that spawns these tools to pass the info along.
Fixed ProcessGDBRemote to properly pass along all file handles for stdin, stdout
and stderr.
After clearing the default values for the stdin/out/err file handles for
process to be NULL, we had a crasher in UserSettingsController::UpdateStringVariable
which is now fixed. Also fixed the setting of boolean values to be able to
be set as "true", "yes", "on", "1" for true (case insensitive) and "false", "no",
"off", or "0" for false.
Fixed debugserver to properly handle files for STDIN, STDOUT and STDERR that are not
already opened. Previous to this fix debugserver would only correctly open and dupe
file handles for the slave side of a pseudo terminal. It now correctly handles
getting STDIN for the inferior from a file, and spitting STDOUT and STDERR out to
files. Also made sure the file handles were correctly opened with the NOCTTY flag
for terminals.
llvm-svn: 124060
2011-01-23 13:56:20 +08:00
|
|
|
const char *stdout_path, // Can be NULL
|
|
|
|
const char *stderr_path, // Can be NULL
|
|
|
|
const char *working_dir); // Can be NULL
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
DidLaunch ();
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
2010-11-18 13:57:03 +08:00
|
|
|
WillAttachToProcessWithID (lldb::pid_t pid);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
virtual lldb_private::Error
|
2010-11-18 13:57:03 +08:00
|
|
|
WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-02-04 09:58:07 +08:00
|
|
|
virtual lldb_private::Error
|
|
|
|
DoConnectRemote (const char *remote_url);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb_private::Error
|
|
|
|
WillLaunchOrAttach ();
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
2010-07-10 04:39:50 +08:00
|
|
|
DoAttachToProcessWithID (lldb::pid_t pid);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
virtual lldb_private::Error
|
2010-07-10 04:39:50 +08:00
|
|
|
DoAttachToProcessWithName (const char *process_name, bool wait_for_launch);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
virtual void
|
|
|
|
DidAttach ();
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// PluginInterface protocol
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual const char *
|
|
|
|
GetPluginName();
|
|
|
|
|
|
|
|
virtual const char *
|
|
|
|
GetShortPluginName();
|
|
|
|
|
|
|
|
virtual uint32_t
|
|
|
|
GetPluginVersion();
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Process Control
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual lldb_private::Error
|
|
|
|
WillResume ();
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DoResume ();
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
2010-11-17 10:32:00 +08:00
|
|
|
DoHalt (bool &caused_stop);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
WillDetach ();
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DoDetach ();
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DoSignal (int signal);
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DoDestroy ();
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
RefreshStateAfterStop();
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Process Queries
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual bool
|
|
|
|
IsAlive ();
|
|
|
|
|
|
|
|
virtual lldb::addr_t
|
|
|
|
GetImageInfoAddress();
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Process Memory
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual size_t
|
|
|
|
DoReadMemory (lldb::addr_t addr, void *buf, size_t size, lldb_private::Error &error);
|
|
|
|
|
|
|
|
virtual size_t
|
|
|
|
DoWriteMemory (lldb::addr_t addr, const void *buf, size_t size, lldb_private::Error &error);
|
|
|
|
|
|
|
|
virtual lldb::addr_t
|
|
|
|
DoAllocateMemory (size_t size, uint32_t permissions, lldb_private::Error &error);
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DoDeallocateMemory (lldb::addr_t ptr);
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// Process STDIO
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
virtual size_t
|
|
|
|
GetSTDOUT (char *buf, size_t buf_size, lldb_private::Error &error);
|
|
|
|
|
|
|
|
virtual size_t
|
|
|
|
GetSTDERR (char *buf, size_t buf_size, lldb_private::Error &error);
|
|
|
|
|
|
|
|
virtual size_t
|
|
|
|
PutSTDIN (const char *buf, size_t buf_size, lldb_private::Error &error);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Process Breakpoints
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
virtual lldb_private::Error
|
|
|
|
EnableBreakpoint (lldb_private::BreakpointSite *bp_site);
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DisableBreakpoint (lldb_private::BreakpointSite *bp_site);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Process Watchpoints
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
virtual lldb_private::Error
|
|
|
|
EnableWatchpoint (lldb_private::WatchpointLocation *wp_loc);
|
|
|
|
|
|
|
|
virtual lldb_private::Error
|
|
|
|
DisableWatchpoint (lldb_private::WatchpointLocation *wp_loc);
|
|
|
|
|
2011-01-22 09:33:44 +08:00
|
|
|
virtual bool
|
|
|
|
StartNoticingNewThreads();
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
StopNoticingNewThreads();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class ThreadGDBRemote;
|
2011-03-22 12:00:09 +08:00
|
|
|
friend class GDBRemoteCommunicationClient;
|
2010-06-09 00:52:24 +08:00
|
|
|
friend class GDBRemoteRegisterContext;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Accessors
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool
|
|
|
|
IsRunning ( lldb::StateType state )
|
|
|
|
{
|
|
|
|
return state == lldb::eStateRunning || IsStepping(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsStepping ( lldb::StateType state)
|
|
|
|
{
|
|
|
|
return state == lldb::eStateStepping;
|
|
|
|
}
|
|
|
|
bool
|
|
|
|
CanResume ( lldb::StateType state)
|
|
|
|
{
|
|
|
|
return state == lldb::eStateStopped;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HasExited (lldb::StateType state)
|
|
|
|
{
|
|
|
|
return state == lldb::eStateExited;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ProcessIDIsValid ( ) const;
|
|
|
|
|
2010-11-16 13:07:41 +08:00
|
|
|
// static void
|
|
|
|
// STDIOReadThreadBytesReceived (void *baton, const void *src, size_t src_len);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-11-16 13:07:41 +08:00
|
|
|
// void
|
|
|
|
// AppendSTDOUT (const char* s, size_t len);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
Clear ( );
|
|
|
|
|
|
|
|
lldb_private::Flags &
|
|
|
|
GetFlags ()
|
|
|
|
{
|
|
|
|
return m_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
const lldb_private::Flags &
|
|
|
|
GetFlags () const
|
|
|
|
{
|
|
|
|
return m_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
UpdateThreadListIfNeeded ();
|
|
|
|
|
|
|
|
lldb_private::Error
|
2011-04-12 13:54:46 +08:00
|
|
|
StartDebugserverProcess (const char *debugserver_url);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
KillDebugserverProcess ();
|
|
|
|
|
|
|
|
void
|
2011-01-29 15:10:55 +08:00
|
|
|
BuildDynamicRegisterInfo (bool force);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-03-22 12:00:09 +08:00
|
|
|
GDBRemoteCommunicationClient &
|
2010-06-09 00:52:24 +08:00
|
|
|
GetGDBRemote()
|
|
|
|
{
|
|
|
|
return m_gdb_comm;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
/// Broadcaster event bits definitions.
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
eBroadcastBitAsyncContinue = (1 << 0),
|
|
|
|
eBroadcastBitAsyncThreadShouldExit = (1 << 1)
|
|
|
|
};
|
|
|
|
|
|
|
|
lldb_private::Flags m_flags; // Process specific flags (see eFlags enums)
|
|
|
|
lldb_private::Mutex m_stdio_mutex; // Multithreaded protection for stdio
|
2011-03-22 12:00:09 +08:00
|
|
|
GDBRemoteCommunicationClient m_gdb_comm;
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::pid_t m_debugserver_pid;
|
2010-08-21 10:22:51 +08:00
|
|
|
lldb::thread_t m_debugserver_thread;
|
2011-06-03 06:22:38 +08:00
|
|
|
StringExtractorGDBRemote m_last_stop_packet;
|
2010-06-09 00:52:24 +08:00
|
|
|
GDBRemoteDynamicRegisterInfo m_register_info;
|
|
|
|
lldb_private::Broadcaster m_async_broadcaster;
|
|
|
|
lldb::thread_t m_async_thread;
|
2011-02-12 14:28:37 +08:00
|
|
|
typedef std::vector<lldb::tid_t> tid_collection;
|
|
|
|
typedef std::vector< std::pair<lldb::tid_t,int> > tid_sig_collection;
|
2011-05-15 09:25:55 +08:00
|
|
|
typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
|
2011-02-12 14:28:37 +08:00
|
|
|
tid_collection m_continue_c_tids; // 'c' for continue
|
|
|
|
tid_sig_collection m_continue_C_tids; // 'C' for continue with signal
|
|
|
|
tid_collection m_continue_s_tids; // 's' for step
|
|
|
|
tid_sig_collection m_continue_S_tids; // 'S' for step with signal
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::addr_t m_dispatch_queue_offsets_addr;
|
|
|
|
size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory
|
|
|
|
bool m_waiting_for_attach;
|
2011-01-22 09:33:44 +08:00
|
|
|
std::vector<lldb::user_id_t> m_thread_observation_bps;
|
2011-05-15 09:25:55 +08:00
|
|
|
MMapMap m_addr_to_mmap_size;
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
StartAsyncThread ();
|
|
|
|
|
|
|
|
void
|
|
|
|
StopAsyncThread ();
|
|
|
|
|
|
|
|
static void *
|
|
|
|
AsyncThread (void *arg);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
MonitorDebugserverProcess (void *callback_baton,
|
|
|
|
lldb::pid_t pid,
|
|
|
|
int signo, // Zero for no signal
|
|
|
|
int exit_status); // Exit value of process if signal is zero
|
|
|
|
|
|
|
|
lldb::StateType
|
|
|
|
SetThreadStopInfo (StringExtractor& stop_packet);
|
|
|
|
|
|
|
|
void
|
|
|
|
DidLaunchOrAttach ();
|
|
|
|
|
|
|
|
lldb_private::Error
|
|
|
|
ConnectToDebugserver (const char *host_port);
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GetDispatchQueueNameForThread (lldb::addr_t thread_dispatch_qaddr,
|
|
|
|
std::string &dispatch_queue_name);
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
AttachInputReaderCallback (void *baton,
|
|
|
|
lldb_private::InputReader *reader,
|
|
|
|
lldb::InputReaderAction notification,
|
|
|
|
const char *bytes,
|
|
|
|
size_t bytes_len);
|
|
|
|
|
2011-01-23 07:43:18 +08:00
|
|
|
lldb_private::Error
|
|
|
|
InterruptIfRunning (bool discard_thread_plans,
|
|
|
|
bool catch_stop_event,
|
|
|
|
lldb::EventSP &stop_event_sp);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
private:
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
// For ProcessGDBRemote only
|
|
|
|
//------------------------------------------------------------------
|
2011-01-22 09:33:44 +08:00
|
|
|
static bool
|
|
|
|
NewThreadNotifyBreakpointHit (void *baton,
|
|
|
|
lldb_private::StoppointCallbackContext *context,
|
|
|
|
lldb::user_id_t break_id,
|
|
|
|
lldb::user_id_t break_loc_id);
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // liblldb_ProcessGDBRemote_h_
|