summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/Process')
-rw-r--r--lldb/source/Plugins/Process/MacOSX-User/Makefile17
-rw-r--r--lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.h2
-rw-r--r--lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp11
-rw-r--r--lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h12
-rw-r--r--lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.cpp11
-rw-r--r--lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.h2
-rw-r--r--lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp15
-rw-r--r--lldb/source/Plugins/Process/Utility/Makefile14
-rw-r--r--lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp2
-rw-r--r--lldb/source/Plugins/Process/Utility/UnwindLibUnwind.h2
-rw-r--r--lldb/source/Plugins/Process/Utility/libunwind/include/libunwind.h6
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp9
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h2
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp17
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBServer.cpp1148
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBServerLog.cpp80
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBServerLog.h55
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/Makefile14
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp20
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h8
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp8
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h3
22 files changed, 128 insertions, 1330 deletions
diff --git a/lldb/source/Plugins/Process/MacOSX-User/Makefile b/lldb/source/Plugins/Process/MacOSX-User/Makefile
new file mode 100644
index 00000000000..8fb3e46e6c8
--- /dev/null
+++ b/lldb/source/Plugins/Process/MacOSX-User/Makefile
@@ -0,0 +1,17 @@
+##===- source/Plugins/Process/MacOSX-User/Makefile ---------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LLDB_LEVEL := ../../../..
+LIBRARYNAME := lldbPluginProcessMacOSXUser
+BUILD_ARCHIVE = 1
+
+Source := $(wildcard $(PROJ_SRC_DIR)/source/*.cpp)
+Source += $(wildcard $(PROJ_SRC_DIR)/source/MacOSX/*.cpp)
+
+include $(LLDB_LEVEL)/Makefile
diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.h b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.h
index 1f3aeb07b0a..78e7ed5e68b 100644
--- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.h
+++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachException.h
@@ -131,7 +131,7 @@ public:
enum
{
e_actionForward, // Forward signal to inferior process
- e_actionStop, // Stop when this signal is received
+ e_actionStop // Stop when this signal is received
};
struct Action
{
diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
index 648e9539b8d..b9adb31c8a4 100644
--- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
+++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
@@ -341,7 +341,7 @@ ProcessMacOSX::DoLaunch
}
Error
-ProcessMacOSX::DoAttach (lldb::pid_t attach_pid)
+ProcessMacOSX::DoAttachToProcessWithID (lldb::pid_t attach_pid)
{
Error error;
@@ -493,12 +493,19 @@ ProcessMacOSX::DidAttach ()
}
Error
-ProcessMacOSX::WillAttach (lldb::pid_t pid)
+ProcessMacOSX::WillAttachToProcessWithID (lldb::pid_t pid)
{
return WillLaunchOrAttach ();
}
Error
+ProcessMacOSX::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
+{
+ return WillLaunchOrAttach ();
+}
+
+
+Error
ProcessMacOSX::DoResume ()
{
Error error;
diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h
index 8388d4e46fe..6f1f3362679 100644
--- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h
+++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.h
@@ -22,8 +22,8 @@
#include "lldb/Target/Thread.h"
// Project includes
-#include "MachTask.h"
-#include "MachException.h"
+#include "MacOSX/MachTask.h"
+#include "MacOSX/MachException.h"
typedef enum PDLaunch
{
@@ -33,6 +33,7 @@ typedef enum PDLaunch
#if defined (__arm__)
eLaunchSpringBoard,
#endif
+ kNumPDLaunchTypes
} PDLaunchType;
@@ -99,10 +100,13 @@ public:
DidLaunch ();
virtual lldb_private::Error
- WillAttach (lldb::pid_t pid);
+ WillAttachToProcessWithID (lldb::pid_t pid);
virtual lldb_private::Error
- DoAttach (lldb::pid_t pid);
+ WillAttachToProcessWithName (const char *process_name, bool wait_for_launch);
+
+ virtual lldb_private::Error
+ DoAttachToProcessWithID (lldb::pid_t pid);
virtual void
DidAttach ();
diff --git a/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.cpp b/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.cpp
index bf6b6c2eac4..96bba7e9b99 100644
--- a/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.cpp
@@ -166,6 +166,9 @@ LibUnwindRegisterContext::ReadRegisterValue (uint32_t reg, Scalar &value)
break;
}
break;
+
+ default:
+ break;
}
return false;
}
@@ -197,9 +200,12 @@ LibUnwindRegisterContext::WriteRegisterValue (uint32_t reg, const Scalar &value)
const RegisterInfo *reg_info = GetRegisterInfoAtIndex (reg);
if (reg_info == NULL)
return false;
- unw_word_t reg_value;
+ unw_word_t reg_value = 0;
switch (value.GetType())
{
+ case Scalar::e_void:
+ return false;
+
case Scalar::e_sint: reg_value = value.SInt(); break;
case Scalar::e_uint: reg_value = value.UInt(); break;
case Scalar::e_slong: reg_value = value.SLong(); break;
@@ -294,6 +300,9 @@ LibUnwindRegisterContext::WriteRegisterBytes (uint32_t reg, DataExtractor &data,
default:
return false;
}
+
+ default:
+ return false;
}
return WriteRegisterValue (reg, value);
}
diff --git a/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.h b/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.h
index 4e89b27961f..bd7d8bd3bea 100644
--- a/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.h
+++ b/lldb/source/Plugins/Process/Utility/LibUnwindRegisterContext.h
@@ -17,7 +17,7 @@
#include "lldb/lldb-private.h"
#include "lldb/Target/RegisterContext.h"
-#include "libunwind.h"
+#include "libunwind/include/libunwind.h"
class LibUnwindRegisterContext : public lldb_private::RegisterContext
{
diff --git a/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp b/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp
index e6c7b354abc..902e22c3431 100644
--- a/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp
+++ b/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp
@@ -21,10 +21,11 @@
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
-#include "lldb-enumerations.h"
-#include "libunwind.h"
+#include "lldb/lldb-enumerations.h"
#include "llvm-c/EnhancedDisassembly.h"
+#include "libunwind/include/libunwind.h"
+
using namespace lldb;
namespace lldb_private {
@@ -191,7 +192,15 @@ access_raw (lldb_private::unw_addr_space_t as, lldb_private::unw_word_t addr, ll
static int
-reg_info (lldb_private::unw_addr_space_t as, lldb_private::unw_regnum_t regnum, lldb_private::unw_regtype_t *type, char *buf, size_t buflen, void *arg)
+reg_info
+(
+ lldb_private::unw_addr_space_t as,
+ lldb_private::unw_regnum_t regnum,
+ lldb_private::unw_regtype_t *type,
+ char *buf,
+ size_t buflen,
+ void *arg
+)
{
if (arg == 0)
return -1;
diff --git a/lldb/source/Plugins/Process/Utility/Makefile b/lldb/source/Plugins/Process/Utility/Makefile
new file mode 100644
index 00000000000..f82fa88eddb
--- /dev/null
+++ b/lldb/source/Plugins/Process/Utility/Makefile
@@ -0,0 +1,14 @@
+##===- source/Plugins/Utility/Makefile ---------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LLDB_LEVEL := ../../../..
+LIBRARYNAME := lldbPluginUtility
+BUILD_ARCHIVE = 1
+
+include $(LLDB_LEVEL)/Makefile
diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
index df2f7c07f65..937ae84e3ee 100644
--- a/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
+++ b/lldb/source/Plugins/Process/Utility/RegisterContextMacOSXFrameBackchain.cpp
@@ -18,7 +18,7 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Target/Thread.h"
// Project includes
-#include "StringExtractorGDBRemote.h"
+#include "Utility/StringExtractorGDBRemote.h"
using namespace lldb;
using namespace lldb_private;
diff --git a/lldb/source/Plugins/Process/Utility/UnwindLibUnwind.h b/lldb/source/Plugins/Process/Utility/UnwindLibUnwind.h
index d91f164a2f9..8b3489b80e1 100644
--- a/lldb/source/Plugins/Process/Utility/UnwindLibUnwind.h
+++ b/lldb/source/Plugins/Process/Utility/UnwindLibUnwind.h
@@ -15,7 +15,7 @@
#include <vector>
// Other libraries and framework includes
-#include "libunwind.h"
+#include "libunwind/include/libunwind.h"
// Project includes
#include "lldb/lldb-private.h"
diff --git a/lldb/source/Plugins/Process/Utility/libunwind/include/libunwind.h b/lldb/source/Plugins/Process/Utility/libunwind/include/libunwind.h
index 63cc8ba2366..df7025653ea 100644
--- a/lldb/source/Plugins/Process/Utility/libunwind/include/libunwind.h
+++ b/lldb/source/Plugins/Process/Utility/libunwind/include/libunwind.h
@@ -56,7 +56,7 @@ enum unw_as_type { UNW_LOCAL, UNW_REMOTE };
struct unw_addr_space
{
enum unw_as_type type;
- uint8_t data[];
+ uint8_t data[1];
};
typedef struct unw_addr_space* unw_addr_space_t;
@@ -345,7 +345,7 @@ extern int unw_end_of_prologue_setup(unw_cursor_t*, unw_word_t sta
// architecture independent register numbers
enum {
UNW_REG_IP = -1, // instruction pointer
- UNW_REG_SP = -2, // stack pointer
+ UNW_REG_SP = -2 // stack pointer
};
@@ -502,7 +502,7 @@ enum {
};
-}; // namespace lldb_private
+} // namespace lldb_private
#endif
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index c144fed163b..66c4b241ef3 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -21,7 +21,7 @@
#include "lldb/Host/TimeValue.h"
// Project includes
-#include "StringExtractorGDBRemote.h"
+#include "Utility/StringExtractorGDBRemote.h"
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
@@ -78,7 +78,7 @@ GDBRemoteCommunication::CalculcateChecksum (const char *payload, size_t payload_
// We only need to compute the checksum if we are sending acks
if (m_send_acks)
{
- for (int i = 0; i < payload_length; ++i)
+ for (size_t i = 0; i < payload_length; ++i)
checksum += payload[i];
}
return checksum & 255;
@@ -365,7 +365,10 @@ GDBRemoteCommunication::SendPacketNoLock (const char *payload, size_t payload_le
if (bytes_written == packet.GetSize())
{
if (m_send_acks)
- GetAck (1) == '+';
+ {
+ if (GetAck (1) != '+')
+ return 0;
+ }
}
return bytes_written;
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 051fa445ff1..9351c6a7790 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -26,7 +26,7 @@
#include "lldb/Host/Mutex.h"
#include "lldb/Host/Predicate.h"
-#include "StringExtractorGDBRemote.h"
+#include "Utility/StringExtractorGDBRemote.h"
class ProcessGDBRemote;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index d69b172366d..5af4c9c2035 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -17,11 +17,11 @@
#include "lldb/Core/Scalar.h"
#include "lldb/Core/StreamString.h"
// Project includes
-#include "StringExtractorGDBRemote.h"
+#include "Utility/StringExtractorGDBRemote.h"
#include "ProcessGDBRemote.h"
#include "ThreadGDBRemote.h"
-#include "ARM_GCC_Registers.h"
-#include "ARM_DWARF_Registers.h"
+#include "Utility/ARM_GCC_Registers.h"
+#include "Utility/ARM_DWARF_Registers.h"
using namespace lldb;
using namespace lldb_private;
@@ -171,7 +171,10 @@ GDBRemoteRegisterContext::ReadRegisterValue (uint32_t reg, Scalar &value)
return true;
}
break;
- }
+
+ default:
+ break;
+ }
}
return false;
}
@@ -219,10 +222,10 @@ GDBRemoteRegisterContext::ReadRegisterBytes (uint32_t reg, DataExtractor &data)
else
{
// Get each register individually
- packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg, false);
+ packet_len = ::snprintf (packet, sizeof(packet), "p%x", reg);
assert (packet_len < (sizeof(packet) - 1));
if (gdb_comm.SendPacketAndWaitForResponse(packet, response, 1, false))
- if (response.GetHexBytes ((uint8_t*)m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size), reg_info->byte_size, '\xcc') == reg_info->byte_size)
+ if (response.GetHexBytes (const_cast<uint8_t*>(m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size)), reg_info->byte_size, '\xcc') == reg_info->byte_size)
m_reg_valid[reg] = true;
}
}
@@ -276,7 +279,7 @@ GDBRemoteRegisterContext::WriteRegisterBytes (uint32_t reg, DataExtractor &data,
if (reg_info)
{
// Grab a pointer to where we are going to put this register
- uint8_t *dst = (uint8_t *)m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size);
+ uint8_t *dst = const_cast<uint8_t*>(m_reg_data.PeekData(reg_info->byte_offset, reg_info->byte_size));
if (dst == NULL)
return false;
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBServer.cpp
deleted file mode 100644
index a88ec7b09d4..00000000000
--- a/lldb/source/Plugins/Process/gdb-remote/GDBServer.cpp
+++ /dev/null
@@ -1,1148 +0,0 @@
-//===-- GDBServer.cpp -------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <getopt.h>
-#include <netinet/in.h>
-#include <sys/select.h>
-#include <sys/sysctl.h>
-#include <string>
-#include <vector>
-#include <asl.h>
-
-#include "GDBServerLog.h"
-#include "GDBRemoteSession.h"
-
-using namespace lldb;
-
-//----------------------------------------------------------------------
-// Run loop modes which determine which run loop function will be called
-//----------------------------------------------------------------------
-typedef enum
-{
- eDCGSRunLoopModeInvalid = 0,
- eDCGSRunLoopModeGetStartModeFromRemoteProtocol,
- eDCGSRunLoopModeInferiorAttaching,
- eDCGSRunLoopModeInferiorLaunching,
- eDCGSRunLoopModeInferiorExecuting,
- eDCGSRunLoopModeInferiorKillOrDetach,
- eDCGSRunLoopModeExit
-} GSRunLoopMode;
-
-typedef enum
-{
- eLaunchFlavorDefault = 0,
- eLaunchFlavorPosixSpawn,
-#if defined (__arm__)
- eLaunchFlavorSpringBoard,
-#endif
- eLaunchFlavorForkExec,
-} GSLaunchFlavor;
-
-typedef lldb::shared_ptr<GDBRemoteSession> GDBRemoteSP;
-
-typedef struct HandleBroadcastEventInfo
-{
- TargetSP target_sp;
- GDBRemoteSP remote_sp;
- GSRunLoopMode mode;
-
- Target *
- GetTarget ()
- {
- return target_sp.get();
- }
-
- Process *
- GetProcess()
- {
- if (target_sp.get())
- return target_sp->GetProcess().get();
- return NULL;
- }
-
- GDBRemoteSession *
- GetRemote ()
- {
- return remote_sp.get();
- }
-
-};
-
-
-//----------------------------------------------------------------------
-// Global Variables
-//----------------------------------------------------------------------
-static int g_lockdown_opt = 0;
-static int g_applist_opt = 0;
-static GSLaunchFlavor g_launch_flavor = eLaunchFlavorDefault;
-int g_isatty = 0;
-
-//----------------------------------------------------------------------
-// Run Loop function prototypes
-//----------------------------------------------------------------------
-void GSRunLoopGetStartModeFromRemote (HandleBroadcastEventInfo *info);
-void GSRunLoopInferiorExecuting (HandleBroadcastEventInfo *info);
-
-
-//----------------------------------------------------------------------
-// Get our program path and arguments from the remote connection.
-// We will need to start up the remote connection without a PID, get the
-// arguments, wait for the new process to finish launching and hit its
-// entry point, and then return the run loop mode that should come next.
-//----------------------------------------------------------------------
-void
-GSRunLoopGetStartModeFromRemote (HandleBroadcastEventInfo *info)
-{
- std::string packet;
-
- Target *target = info->GetTarget();
- GDBRemoteSession *remote = info->GetRemote();
- if (target != NULL && remote != NULL)
- {
- // Spin waiting to get the A packet.
- while (1)
- {
- gdb_err_t err = gdb_err;
- GDBRemoteSession::PacketEnum type;
-
- err = remote->HandleReceivedPacket (&type);
-
- // check if we tried to attach to a process
- if (type == GDBRemoteSession::vattach || type == GDBRemoteSession::vattachwait)
- {
- if (err == gdb_success)
- {
- info->mode = eDCGSRunLoopModeInferiorExecuting;
- return;
- }
- else
- {
- Log::STDERR ("error: attach failed.");
- info->mode = eDCGSRunLoopModeExit;
- return;
- }
- }
-
- if (err == gdb_success)
- {
- // If we got our arguments we are ready to launch using the arguments
- // and any environment variables we received.
- if (type == GDBRemoteSession::set_argv)
- {
- info->mode = eDCGSRunLoopModeInferiorLaunching;
- return;
- }
- }
- else if (err == gdb_not_connected)
- {
- Log::STDERR ("error: connection lost.");
- info->mode = eDCGSRunLoopModeExit;
- return;
- }
- else
- {
- // a catch all for any other gdb remote packets that failed
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s Error getting packet.",__FUNCTION__);
- continue;
- }
-
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "#### %s", __FUNCTION__);
- }
- }
- info->mode = eDCGSRunLoopModeExit;
-}
-
-
-//----------------------------------------------------------------------
-// This run loop mode will wait for the process to launch and hit its
-// entry point. It will currently ignore all events except for the
-// process state changed event, where it watches for the process stopped
-// or crash process state.
-//----------------------------------------------------------------------
-GSRunLoopMode
-GSRunLoopLaunchInferior (HandleBroadcastEventInfo *info)
-{
- // The Process stuff takes a c array, the GSContext has a vector...
- // So make up a c array.
- Target *target = info->GetTarget();
- GDBRemoteSession *remote = info->GetRemote();
- Process* process = info->GetProcess();
-
- if (process == NULL)
- return eDCGSRunLoopModeExit;
-
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s Launching '%s'...", __FUNCTION__, target->GetExecutableModule()->GetFileSpec().GetFilename().AsCString());
-
- // Our launch type hasn't been set to anything concrete, so we need to
- // figure our how we are going to launch automatically.
-
- GSLaunchFlavor launch_flavor = g_launch_flavor;
- if (launch_flavor == eLaunchFlavorDefault)
- {
- // Our default launch method is posix spawn
- launch_flavor = eLaunchFlavorPosixSpawn;
-
-#if defined (__arm__)
- // Check if we have an app bundle, if so launch using SpringBoard.
- if (strstr(inferior_argv[0], ".app"))
- {
- launch_flavor = eLaunchFlavorSpringBoard;
- }
-#endif
- }
-
- //ctx.SetLaunchFlavor(launch_flavor);
-
- const char *stdio_file = NULL;
- lldb::pid_t pid = process->Launch (remote->GetARGV(), remote->GetENVP(), stdio_file, stdio_file, stdio_file);
-
- if (pid == LLDB_INVALID_PROCESS_ID)
- {
- Log::STDERR ("error: process launch failed: %s", process->GetError().AsCString());
- }
- else
- {
- if (remote->IsConnected())
- {
- // It we are connected already, the next thing gdb will do is ask
- // whether the launch succeeded, and if not, whether there is an
- // error code. So we need to fetch one packet from gdb before we wait
- // on the stop from the target.
- gdb_err_t err = gdb_err;
- GDBRemoteSession::PacketEnum type;
-
- err = remote->HandleReceivedPacket (&type);
-
- if (err != gdb_success)
- {
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s Error getting packet.", __FUNCTION__);
- return eDCGSRunLoopModeExit;
- }
- if (type != GDBRemoteSession::query_launch_success)
- {
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s Didn't get the expected qLaunchSuccess packet.", __FUNCTION__);
- }
- }
- }
-
- Listener listener("GSRunLoopLaunchInferior");
- listener.StartListeningForEvents (process, Process::eBroadcastBitStateChanged);
- while (process->GetID() != LLDB_INVALID_PROCESS_ID)
- {
- uint32_t event_mask = 0;
- while (listener.WaitForEvent(NULL, &event_mask))
- {
- if (event_mask & Process::eBroadcastBitStateChanged)
- {
- Event event;
- StateType event_state;
- while ((event_state = process->GetNextEvent (&event)))
- if (StateIsStoppedState(event_state))
- {
- GDBServerLog::LogIf (GS_LOG_EVENTS, "%s process %4.4x stopped with state %s", __FUNCTION__, pid, StateAsCString(event_state));
-
- switch (event_state)
- {
- default:
- case eStateInvalid:
- case eStateUnloaded:
- case eStateAttaching:
- case eStateLaunching:
- case eStateSuspended:
- break; // Ignore
-
- case eStateRunning:
- case eStateStepping:
- // Still waiting to stop at entry point...
- break;
-
- case eStateStopped:
- case eStateCrashed:
- return eDCGSRunLoopModeInferiorExecuting;
-
- case eStateDetached:
- case eStateExited:
- pid = LLDB_INVALID_PROCESS_ID;
- return eDCGSRunLoopModeExit;
- }
- }
-
- if (event_state = eStateInvalid)
- break;
- }
- }
- }
-
- return eDCGSRunLoopModeExit;
-}
-
-
-//----------------------------------------------------------------------
-// This run loop mode will wait for the process to launch and hit its
-// entry point. It will currently ignore all events except for the
-// process state changed event, where it watches for the process stopped
-// or crash process state.
-//----------------------------------------------------------------------
-GSRunLoopMode
-GSRunLoopLaunchAttaching (HandleBroadcastEventInfo *info, lldb::pid_t& pid)
-{
- Process* process = info->GetProcess();
-
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s Attaching to pid %i...", __FUNCTION__, pid);
- pid = process->Attach(pid);
-
- if (pid == LLDB_INVALID_PROCESS_ID)
- return eDCGSRunLoopModeExit;
- return eDCGSRunLoopModeInferiorExecuting;
-}
-
-//----------------------------------------------------------------------
-// Watch for signals:
-// SIGINT: so we can halt our inferior. (disabled for now)
-// SIGPIPE: in case our child process dies
-//----------------------------------------------------------------------
-lldb::pid_t g_pid;
-int g_sigpipe_received = 0;
-void
-signal_handler(int signo)
-{
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s (%s)", __FUNCTION__, Host::GetSignalAsCString(signo));
-
- switch (signo)
- {
-// case SIGINT:
-// DNBProcessKill (g_pid, signo);
-// break;
-
- case SIGPIPE:
- g_sigpipe_received = 1;
- break;
- }
-}
-
-// Return the new run loop mode based off of the current process state
-void
-HandleProcessStateChange (HandleBroadcastEventInfo *info, bool initialize)
-{
- Process *process = info->GetProcess();
- if (process == NULL)
- {
- info->mode = eDCGSRunLoopModeExit;
- return;
- }
-
- if (process->GetID() == LLDB_INVALID_PROCESS_ID)
- {
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "#### %s error: pid invalid, exiting...", __FUNCTION__);
- info->mode = eDCGSRunLoopModeExit;
- return;
- }
- StateType pid_state = process->GetState ();
-
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s (info, initialize=%i) pid_state = %s", __FUNCTION__, (int)initialize, StateAsCString(pid_state));
-
- switch (pid_state)
- {
- case eStateInvalid:
- case eStateUnloaded:
- // Something bad happened
- info->mode = eDCGSRunLoopModeExit;
- return;
-
- case eStateAttaching:
- case eStateLaunching:
- info->mode = eDCGSRunLoopModeInferiorExecuting;
- return;
-
- case eStateSuspended:
- case eStateCrashed:
- case eStateStopped:
- if (initialize == false)
- {
- // Compare the last stop count to our current notion of a stop count
- // to make sure we don't notify more than once for a given stop.
- static uint32_t g_prev_stop_id = 0;
- uint32_t stop_id = process->GetStopID();
- bool pid_stop_count_changed = g_prev_stop_id != stop_id;
- if (pid_stop_count_changed)
- {
- info->GetRemote()->FlushSTDIO();
-
- if (stop_id == 1)
- {
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s (&remote, initialize=%i) pid_state = %s pid_stop_count %u (old %u)) Notify??? no, first stop...", __FUNCTION__, (int)initialize, StateAsCString (pid_state), stop_id, g_prev_stop_id);
- }
- else
- {
-
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s (&remote, initialize=%i) pid_state = %s pid_stop_count %u (old %u)) Notify??? YES!!!", __FUNCTION__, (int)initialize, StateAsCString (pid_state), stop_id, g_prev_stop_id);
- info->GetRemote()->NotifyThatProcessStopped ();
- }
- }
- else
- {
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "%s (&remote, initialize=%i) pid_state = %s pid_stop_count %u (old %u)) Notify??? skipping...", __FUNCTION__, (int)initialize, StateAsCString (pid_state), stop_id, g_prev_stop_id);
- }
- }
- info->mode = eDCGSRunLoopModeInferiorExecuting;
- return;
-
- case eStateStepping:
- case eStateRunning:
- info->mode = eDCGSRunLoopModeInferiorExecuting;
- return;
-
- case eStateExited:
- info->GetRemote()->HandlePacket_last_signal (NULL);
- info->mode = eDCGSRunLoopModeExit;
- return;
-
- }
-
- // Catch all...
- info->mode = eDCGSRunLoopModeExit;
-}
-
-bool
-CommunicationHandleBroadcastEvent (Broadcaster *broadcaster, uint32_t event_mask, void *baton)
-{
- HandleBroadcastEventInfo *info = (HandleBroadcastEventInfo *)baton;
- Process *process = info->GetProcess();
-
- if (process == NULL)
- {
- info->mode = eDCGSRunLoopModeExit;
- return true;
- }
-
- if (event_mask & Communication::eBroadcastBitPacketAvailable)
- {
- if (process->IsRunning())
- {
- if (info->GetRemote()->HandleAsyncPacket() == gdb_not_connected)
- info->mode = eDCGSRunLoopModeExit;
- }
- else
- {
- if (info->GetRemote()->HandleReceivedPacket() == gdb_not_connected)
- info->mode = eDCGSRunLoopModeExit;
- }
- }
- if (event_mask & Communication::eBroadcastBitReadThreadDidExit)
- {
- info->mode = eDCGSRunLoopModeExit;
- }
- if (event_mask & Communication::eBroadcastBitDisconnected)
- {
- info->mode = eDCGSRunLoopModeExit;
- }
-
- return true;
-
-}
-
-bool
-ProcessHandleBroadcastEvent (Broadcaster *broadcaster, uint32_t event_mask, void *baton)
-{
- HandleBroadcastEventInfo *info = (HandleBroadcastEventInfo *)baton;
- Process *process = info->GetProcess();
- if (process == NULL)
- {
- info->mode = eDCGSRunLoopModeExit;
- return true;
- }
-
- if (event_mask & Process::eBroadcastBitStateChanged)
- {
- // Consume all available process events with no timeout
- Event event;
- StateType process_state;
- while ((process_state = process->GetNextEvent (&event)) != eStateInvalid)
- {
- if (StateIsStoppedState(process_state))
- info->GetRemote()->FlushSTDIO();
- HandleProcessStateChange (info, false);
-
- if (info->mode != eDCGSRunLoopModeInferiorExecuting)
- break;
- }
- }
- else
- if (event_mask & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitSTDERR))
- {
- info->GetRemote()->FlushSTDIO();
- }
- return true;
-}
-
-// This function handles the case where our inferior program is stopped and
-// we are waiting for gdb remote protocol packets. When a packet occurs that
-// makes the inferior run, we need to leave this function with a new state
-// as the return code.
-void
-GSRunLoopInferiorExecuting (HandleBroadcastEventInfo *info)
-{
- GDBServerLog::LogIf (GS_LOG_MINIMAL, "#### %s", __FUNCTION__);
-
- // Init our mode and set 'is_running' based on the current process state
- HandleProcessStateChange (info, true);
-
- uint32_t desired_mask, acquired_mask;
- Listener listener("GSRunLoopInferiorExecuting");
-
- desired_mask = Communication::eBroadcastBitPacketAvailable |
- Communication::eBroadcastBitReadThreadDidExit |
- Communication::eBroadcastBitDisconnected;
-
- acquired_mask = listener.StartListeningForEvents (&(info->GetRemote()->GetPacketComm()),
- desired_mask,
- CommunicationHandleBroadcastEvent,
- info);
-
- assert (acquired_mask == desired_mask);
- desired_mask = GDBRemotePacket::eBroadcastBitPacketAvailable;
-
- acquired_mask = listener.StartListeningForEvents (&(info->GetRemote()->GetPacketComm()),
- desired_mask,
- CommunicationHandleBroadcastEvent,
- info);
-
- assert (acquired_mask == desired_mask);
-
- desired_mask = Process::eBroadcastBitStateChanged |
- Process::eBroadcastBitSTDOUT |
- Process::eBroadcastBitSTDERR ;
- acquired_mask = listener.StartListeningForEvents (info->GetProcess (),
- desired_mask,
- ProcessHandleBroadcastEvent,
- info);
-
- assert (acquired_mask == desired_mask);
-
- Process *process = info->GetProcess();
-
- while (process->IsAlive())
- {
- if (!info->GetRemote()->IsConnected())
- {
- info->mode = eDCGSRunLoopModeInferiorKillOrDetach;
- break;
- }
-
- // We want to make sure we consume all process state changes and have
- // whomever is notifying us to wait for us to reset the event bit before
- // continuing.
- //ctx.Events().SetResetAckMask (GSContext::event_proc_state_changed);
- uint32_t event_mask = 0;
- Broadcaster *broadcaster = listener.WaitForEvent(NULL, &event_mask);
- if (broadcaster)
- {
- listener.HandleBroadcastEvent(broadcaster, event_mask);
- }
- }
-}
-
-
-//----------------------------------------------------------------------
-// Convenience function to set up the remote listening port
-// Returns 1 for success 0 for failure.
-//----------------------------------------------------------------------
-
-static bool
-StartListening (HandleBroadcastEventInfo *info, int listen_port)
-{
- if (!info->GetRemote()->IsConnected())
- {
- Log::STDOUT ("Listening to port %i...\n", listen_port);
- char connect_url[256];
- snprintf(connect_url, sizeof(connect_url), "listen://%i", listen_port);
-
- Communication &comm = info->remote_sp->GetPacketComm();
- comm.SetConnection (new ConnectionFileDescriptor);
-
- if (comm.Connect (connect_url))
- {
- if (comm.StartReadThread())
- return true;
-
- Log::STDERR ("Failed to start the communication read thread.\n", connect_url);
- comm.Disconnect();
- }
- else
- {
- Log::STDERR ("Failed to connection to %s.\n", connect_url);
- }
- return false;
- }
- return true;
-}
-
-//----------------------------------------------------------------------
-// ASL Logging callback that can be registered with DNBLogSetLogDCScriptInterpreter::Type
-//----------------------------------------------------------------------
-//void
-//ASLLogDCScriptInterpreter::Type(void *baton, uint32_t flags, const char *format, va_list args)
-//{
-// if (format == NULL)
-// return;
-// static aslmsg g_aslmsg = NULL;
-// if (g_aslmsg == NULL)
-// {
-// g_aslmsg = ::asl_new (ASL_TYPE_MSG);
-// char asl_key_sender[PATH_MAX];
-// snprintf(asl_key_sender, sizeof(asl_key_sender), "com.apple.dc-gdbserver-%g", dc_gdbserverVersionNumber);
-// ::asl_set (g_aslmsg, ASL_KEY_SENDER, asl_key_sender);
-// }
-//
-// int asl_level;
-// if (flags & DNBLOG_FLAG_FATAL) asl_level = ASL_LEVEL_CRIT;
-// else if (flags & DNBLOG_FLAG_ERROR) asl_level = ASL_LEVEL_ERR;
-// else if (flags & DNBLOG_FLAG_WARNING) asl_level = ASL_LEVEL_WARNING;
-// else if (flags & DNBLOG_FLAG_VERBOSE) asl_level = ASL_LEVEL_WARNING; //ASL_LEVEL_INFO;
-// else asl_level = ASL_LEVEL_WARNING; //ASL_LEVEL_DEBUG;
-//
-// ::asl_vlog (NULL, g_aslmsg, asl_level, format, args);
-//}
-
-//----------------------------------------------------------------------
-// FILE based Logging callback that can be registered with
-// DNBLogSetLogDCScriptInterpreter::Type
-//----------------------------------------------------------------------
-void
-FileLogDCScriptInterpreter::Type(void *baton, uint32_t flags, const char *format, va_list args)
-{
- if (baton == NULL || format == NULL)
- return;
-
- ::vfprintf ((FILE *)baton, format, args);
- ::fprintf ((FILE *)baton, "\n");
-}
-
-//----------------------------------------------------------------------
-// option descriptors for getopt_long()
-//----------------------------------------------------------------------
-static struct option g_long_options[] =
-{
- { "arch", required_argument, NULL, 'c' },
- { "attach", required_argument, NULL, 'a' },
- { "debug", no_argument, NULL, 'g' },
- { "verbose", no_argument, NULL, 'v' },
- { "lockdown", no_argument, &g_lockdown_opt, 1 }, // short option "-k"
- { "applist", no_argument, &g_applist_opt, 1 }, // short option "-t"
- { "log-file", required_argument, NULL, 'l' },
- { "log-flags", required_argument, NULL, 'f' },
- { "launch", required_argument, NULL, 'x' }, // Valid values are "auto", "posix-spawn", "fork-exec", "springboard" (arm only)
- { "waitfor", required_argument, NULL, 'w' }, // Wait for a process whose namet starts with ARG
- { "waitfor-interval", required_argument, NULL, 'i' }, // Time in usecs to wait between sampling the pid list when waiting for a process by name
- { "waitfor-duration", required_argument, NULL, 'd' }, // The time in seconds to wait for a process to show up by name
- { NULL, 0, NULL, 0 }
-};
-
-extern const double dc_gdbserverVersionNumber;
-int
-main (int argc, char *argv[])
-{
- Initialize();
- Host::ThreadCreated ("[main]");
-
- g_isatty = ::isatty (STDIN_FILENO);
-
-// signal (SIGINT, signal_handler);
- signal (SIGPIPE, signal_handler);
-
- Log *log = GDBServerLog::GetLogIfAllCategoriesSet(GS_LOG_ALL);
- const char *this_exe_name = argv[0];
- int i;
- int attach_pid = LLDB_INVALID_PROCESS_ID;
- for (i=0; i<argc; i++)
- GDBServerLog::LogIf(GS_LOG_DEBUG, "argv[%i] = %s", i, argv[i]);
-
- FILE* log_file = NULL;
- uint32_t log_flags = 0;
- // Parse our options
- int ch;
- int long_option_index = 0;
- int debug = 0;
- std::string waitfor_pid_name; // Wait for a process that starts with this name
- std::string attach_pid_name;
- useconds_t waitfor_interval = 1000; // Time in usecs between process lists polls when waiting for a process by name, default 1 msec.
- useconds_t waitfor_duration = 0; // Time in seconds to wait for a process by name, 0 means wait forever.
- ArchSpec arch;
- GSRunLoopMode start_mode = eDCGSRunLoopModeExit;
-
- while ((ch = getopt_long(argc, argv, "a:c:d:gi:vktl:f:w:x:", g_long_options, &long_option_index)) != -1)
- {
-// DNBLogDebug("option: ch == %c (0x%2.2x) --%s%c%s\n",
-// ch, (uint8_t)ch,
-// g_long_options[long_option_index].name,
-// g_long_options[long_option_index].has_arg ? '=' : ' ',
-// optarg ? optarg : "");
- switch (ch)
- {
- case 0: // Any optional that auto set themselves will return 0
- break;
-
- case 'c':
- arch.SetArch(optarg);
- if (!arch.IsValid())
- {
- Log::STDERR ("error: invalid arch string '%s'\n", optarg);
- exit (8);
- }
- break;
-
- case 'a':
- if (optarg && optarg[0])
- {
- if (isdigit(optarg[0]))
- {
- char *end = NULL;
- attach_pid = strtoul(optarg, &end, 0);
- if (end == NULL || *end != '\0')
- {
- Log::STDERR ("error: invalid pid option '%s'\n", optarg);
- exit (4);
- }
- }
- else
- {
- attach_pid_name = optarg;
- }
- start_mode = eDCGSRunLoopModeInferiorAttaching;
- }
- break;
-
- // --waitfor=NAME
- case 'w':
- if (optarg && optarg[0])
- {
- waitfor_pid_name = optarg;
- start_mode = eDCGSRunLoopModeInferiorAttaching;
- }
- break;
-
- // --waitfor-interval=USEC
- case 'i':
- if (optarg && optarg[0])
- {
- char *end = NULL;
- waitfor_interval = strtoul(optarg, &end, 0);
- if (end == NULL || *end != '\0')
- {
- Log::STDERR ("error: invalid waitfor-interval option value '%s'.\n", optarg);
- exit (6);
- }
- }
- break;
-
- // --waitfor-duration=SEC
- case 'd':
- if (optarg && optarg[0])
- {
- char *end = NULL;
- waitfor_duration = strtoul(optarg, &end, 0);
- if (end == NULL || *end != '\0')
- {
- Log::STDERR ("error: invalid waitfor-duration option value '%s'.\n", optarg);
- exit (7);
- }
- }
- break;
-
- case 'x':
- if (optarg && optarg[0])
- {
- if (strcasecmp(optarg, "auto") == 0)
- g_launch_flavor = eLaunchFlavorDefault;
- else if (strcasestr(optarg, "posix") == optarg)
- g_launch_flavor = eLaunchFlavorPosixSpawn;
- else if (strcasestr(optarg, "fork") == optarg)
- g_launch_flavor = eLaunchFlavorForkExec;
-#if defined (__arm__)
- else if (strcasestr(optarg, "spring") == optarg)
- g_launch_flavor = eLaunchFlavorSpringBoard;
-#endif
- else
- {
- Log::STDERR ("error: invalid TYPE for the --launch=TYPE (-x TYPE) option: '%s'\n", optarg);
- Log::STDERR ("Valid values TYPE are:\n");
- Log::STDERR (" auto Auto-detect the best launch method to use.\n");
- Log::STDERR (" posix Launch the executable using posix_spawn.\n");
- Log::STDERR (" fork Launch the executable using fork and exec.\n");
-#if defined (__arm__)
- Log::STDERR (" spring Launch the executable through Springboard.\n");
-#endif
- exit (5);
- }
- }
- break;
-
- case 'l': // Set Log File
- if (optarg && optarg[0])
- {
- if (strcasecmp(optarg, "stdout") == 0)
- log_file = stdout;
- else if (strcasecmp(optarg, "stderr") == 0)
- log_file = stderr;
- else
- log_file = fopen(optarg, "w+");
-
- if (log_file == NULL)
- {
- const char *errno_str = strerror(errno);
- Log::STDERR ("Failed to open log file '%s' for writing: errno = %i (%s)", optarg, errno, errno_str ? errno_str : "unknown error");
- }
- }
- break;
-
- case 'f': // Log Flags
- if (optarg && optarg[0])
- log_flags = strtoul(optarg, NULL, 0);
- break;
-
- case 'g':
- debug = 1;
- //DNBLogSetDebug(1);
- break;
-
- case 't':
- g_applist_opt = 1;
- break;
-
- case 'k':
- g_lockdown_opt = 1;
- break;
-
- case 'v':
- //DNBLogSetVerbose(1);
- break;
- }
- }
-
- // Skip any options we consumed with getopt_long
- argc -= optind;
- argv += optind;
-
- // It is ok for us to set NULL as the logfile (this will disable any logging)
-
-// if (log_file != NULL)
-// {
-// DNBLogSetLogDCScriptInterpreter::Type(FileLogDCScriptInterpreter::Type, log_file);
-// // If our log file was set, yet we have no log flags, log everything!
-// if (log_flags == 0)
-// log_flags = LOG_ALL | LOG_DCGS_ALL;
-//
-// DNBLogSetLogMask (log_flags);
-// }
-// else
-// {
-// // Enable DNB logging
-// DNBLogSetLogDCScriptInterpreter::Type(ASLLogDCScriptInterpreter::Type, NULL);
-// DNBLogSetLogMask (log_flags);
-//
-// }
-
- // as long as we're dropping remotenub in as a replacement for gdbserver,
- // explicitly note that this is not gdbserver.
-
- Log::STDOUT ("debugserver-%g \n", dc_gdbserverVersionNumber);
- int listen_port = -1;
- if (g_lockdown_opt == 0 && g_applist_opt == 0)
- {
- // Make sure we at least have port
- if (argc < 1)
- {
- Log::STDERR ("Usage: %s host:port [program-name program-arg1 program-arg2 ...]\n", this_exe_name);
- exit (1);
- }
- // accept 'localhost:' prefix on port number
-
- std::string host_str;
- std::string port_str(argv[0]);
-
- // We just used the host:port arg...
- argc--;
- argv++;
-
- size_t port_idx = port_str.find(':');
- if (port_idx != std::string::npos)
- {
- host_str.assign(port_str, 0, port_idx);
- port_str.erase(0, port_idx + 1);
- }
-
- if (port_str.empty())
- {
- Log::STDERR ("error: no port specified\nUsage: %s host:port [program-name program-arg1 program-arg2 ...]\n", this_exe_name);
- exit (2);
- }
- else if (port_str.find_first_not_of("0123456789") != std::string::npos)
- {
- Log::STDERR ("error: port must be an integer: %s\nUsage: %s host:port [program-name program-arg1 program-arg2 ...]\n", port_str.c_str(), this_exe_name);
- exit (3);
- }
- //DNBLogDebug("host_str = '%s' port_str = '%s'", host_str.c_str(), port_str.c_str());
- listen_port = atoi (port_str.c_str());
- }
-
-
- // We must set up some communications now.
-
- FileSpec exe_spec;
- if (argv[0])
- exe_spec.SetFile (argv[0]);
-
- HandleBroadcastEventInfo info;
- info.target_sp = TargetList::SharedList().CreateTarget(&exe_spec, &arch);
- ProcessSP process_sp (info.target_sp->CreateProcess ());
- info.remote_sp.reset (new GDBRemoteSession (process_sp));
-
- info.remote_sp->SetLog (log);
- StreamString sstr;
- sstr.Printf("ConnectionFileDescriptor(%s)", argv[0]);
-
- if (info.remote_sp.get() == NULL)
- {
- Log::STDERR ("error: failed to create a GDBRemoteSession class\n");
- return -1;
- }
-
-
-
- // If we know we're waiting to attach, we don't need any of this other info.
- if (start_mode != eDCGSRunLoopModeInferiorAttaching)
- {
- if (argc == 0 || g_lockdown_opt)
- {
- if (g_lockdown_opt != 0)
- {
- // Work around for SIGPIPE crashes due to posix_spawn issue. We have to close
- // STDOUT and STDERR, else the first time we try and do any, we get SIGPIPE and
- // die as posix_spawn is doing bad things with our file descriptors at the moment.
- int null = open("/dev/null", O_RDWR);
- dup2(null, STDOUT_FILENO);
- dup2(null, STDERR_FILENO);
- }
- else if (g_applist_opt != 0)
- {
-// // List all applications we are able to see
-// std::string applist_plist;
-// int err = ListApplications(applist_plist, false, false);
-// if (err == 0)
-// {
-// fputs (applist_plist.c_str(), stdout);
-// }
-// else
-// {
-// Log::STDERR ("error: ListApplications returned error %i\n", err);
-// }
-// // Exit with appropriate error if we were asked to list the applications
-// // with no other args were given (and we weren't trying to do this over
-// // lockdown)
-// return err;
- return 0;
- }
-
- //DNBLogDebug("Get args from remote protocol...");
- start_mode = eDCGSRunLoopModeGetStartModeFromRemoteProtocol;
- }
- else
- {
- start_mode = eDCGSRunLoopModeInferiorLaunching;
- // Fill in the argv array in the context from the rest of our args.
- // Skip the name of this executable and the port number
- info.remote_sp->SetArguments (argc, argv);
- }
- }
-
- if (start_mode == eDCGSRunLoopModeExit)
- return -1;
-
- info.mode = start_mode;
-
- while (info.mode != eDCGSRunLoopModeExit)
- {
- switch (info.mode)
- {
- case eDCGSRunLoopModeGetStartModeFromRemoteProtocol:
- #if defined (__arm__)
- if (g_lockdown_opt)
- {
- if (!info.remote_sp->GetCommunication()->IsConnected())
- {
- if (info.remote_sp->GetCommunication()->ConnectToService () != gdb_success)
- {
- Log::STDERR ("Failed to get connection from a remote gdb process.\n");
- info.mode = eDCGSRunLoopModeExit;
- }
- else if (g_applist_opt != 0)
- {
- // List all applications we are able to see
- std::string applist_plist;
- if (ListApplications(applist_plist, false, false) == 0)
- {
- //DNBLogDebug("Task list: %s", applist_plist.c_str());
-
- info.remote_sp->GetCommunication()->Write(applist_plist.c_str(), applist_plist.size());
- // Issue a read that will never yield any data until the other side
- // closes the socket so this process doesn't just exit and cause the
- // socket to close prematurely on the other end and cause data loss.
- std::string buf;
- info.remote_sp->GetCommunication()->Read(buf);
- }
- info.remote_sp->GetCommunication()->Disconnect(false);
- info.mode = eDCGSRunLoopModeExit;
- break;
- }
- else
- {
- // Start watching for remote packets
- info.remote_sp->StartReadRemoteDataThread();
- }
- }
- }
- else
-#endif
- {
- if (StartListening (&info, listen_port))
- Log::STDOUT ("Got a connection, waiting for process information for launching or attaching.\n");
- else
- info.mode = eDCGSRunLoopModeExit;
- }
-
- if (info.mode != eDCGSRunLoopModeExit)
- GSRunLoopGetStartModeFromRemote (&info);
- break;
-
- case eDCGSRunLoopModeInferiorAttaching:
- if (!waitfor_pid_name.empty())
- {
- // Set our end wait time if we are using a waitfor-duration
- // option that may have been specified
-
- TimeValue attach_timeout_abstime;
- if (waitfor_duration != 0)
- {
- attach_timeout_abstime = TimeValue::Now();
- attach_timeout_abstime.OffsetWithSeconds (waitfor_duration);
- }
- GSLaunchFlavor launch_flavor = g_launch_flavor;
- if (launch_flavor == eLaunchFlavorDefault)
- {
- // Our default launch method is posix spawn
- launch_flavor = eLaunchFlavorPosixSpawn;
-
-#if defined (__arm__)
- // Check if we have an app bundle, if so launch using SpringBoard.
- if (waitfor_pid_name.find (".app") != std::string::npos)
- {
- launch_flavor = eLaunchFlavorSpringBoard;
- }
-#endif
- }
-
- //ctx.SetLaunchFlavor(launch_flavor);
-
-
- lldb::pid_t pid = info.GetProcess()->Attach (waitfor_pid_name.c_str());
- if (pid == LLDB_INVALID_PROCESS_ID)
- {
- info.GetRemote()->GetLaunchError() = info.GetProcess()->GetError();
- Log::STDERR ("error: failed to attach to process named: \"%s\" %s", waitfor_pid_name.c_str(), info.GetRemote()->GetLaunchError().AsCString());
- info.mode = eDCGSRunLoopModeExit;
- }
- else
- {
- info.mode = eDCGSRunLoopModeInferiorExecuting;
- }
- }
- else if (attach_pid != LLDB_INVALID_PROCESS_ID)
- {
- Log::STDOUT ("Attaching to process %i...\n", attach_pid);
- info.mode = GSRunLoopLaunchAttaching (&info, attach_pid);
- if (info.mode != eDCGSRunLoopModeInferiorExecuting)
- {
- const char *error_str = info.GetRemote()->GetLaunchError().AsCString();
- Log::STDERR ("error: failed to attach process %i: %s\n", attach_pid, error_str ? error_str : "unknown error.");
- info.mode = eDCGSRunLoopModeExit;
- }
- }
- else if (!attach_pid_name.empty ())
- {
- lldb::pid_t pid = info.GetProcess()->Attach (waitfor_pid_name.c_str());
- if (pid == LLDB_INVALID_PROCESS_ID)
- {
- info.GetRemote()->GetLaunchError() = info.GetProcess()->GetError();
- Log::STDERR ("error: failed to attach to process named: \"%s\" %s", waitfor_pid_name.c_str(), info.GetRemote()->GetLaunchError().AsCString());
- info.mode = eDCGSRunLoopModeExit;
- }
- else
- {
- info.mode = eDCGSRunLoopModeInferiorExecuting;
- }
- }
- else
- {
- Log::STDERR ("error: asked to attach with empty name and invalid PID.");
- info.mode = eDCGSRunLoopModeExit;
- }
-
- if (info.mode != eDCGSRunLoopModeExit)
- {
- if (StartListening (&info, listen_port))
- Log::STDOUT ("Got a connection, waiting for debugger instructions for process %d.\n", attach_pid);
- else
- info.mode = eDCGSRunLoopModeExit;
- }
- break;
-
- case eDCGSRunLoopModeInferiorLaunching:
- info.mode = GSRunLoopLaunchInferior (&info);
-
- if (info.mode == eDCGSRunLoopModeInferiorExecuting)
- {
- if (StartListening (&info, listen_port))
- Log::STDOUT ("Got a connection, waiting for debugger instructions for task \"%s\".\n", argv[0]);
- else
- info.mode = eDCGSRunLoopModeExit;
- }
- else
- {
- Log::STDERR ("error: failed to launch process %s: %s\n", argv[0], info.GetRemote()->GetLaunchError().AsCString());
- }
- break;
-
- case eDCGSRunLoopModeInferiorExecuting:
- GSRunLoopInferiorExecuting (&info);
- break;
-
- case eDCGSRunLoopModeInferiorKillOrDetach:
- {
- Process *process = info.GetProcess();
- if (process && process->IsAlive())
- {
- process->Kill(SIGCONT);
- process->Kill(SIGKILL);
- }
- }
- info.mode = eDCGSRunLoopModeExit;
- break;
-
- default:
- info.mode = eDCGSRunLoopModeExit;
- case eDCGSRunLoopModeExit:
- break;
- }
- }
-
- return 0;
-}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBServerLog.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBServerLog.cpp
deleted file mode 100644
index 2d4116ebe7b..00000000000
--- a/lldb/source/Plugins/Process/gdb-remote/GDBServerLog.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-//===-- GDBServerLog.cpp ----------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//----------------------------------------------------------------------
-//
-// GDBServerLog.cpp
-// liblldb
-//
-// Created by Greg Clayton on 6/19/09.
-//
-//
-//----------------------------------------------------------------------
-
-#include "GDBServerLog.h"
-
-using namespace lldb;
-
-static Log *
-LogAccessor (bool get, Log *log)
-{
- static Log* g_log = NULL; // Leak for now as auto_ptr was being cleaned up
- // by global constructors before other threads
- // were done with it.
- if (get)
- {
-// // Debug code below for enabling logging by default
-// if (g_log == NULL)
-// {
-// g_log = new Log("/dev/stdout", false);
-// g_log->GetMask().SetAllFlagBits(GS_LOG_ALL);
-// g_log->GetOptions().Set(LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_THREAD_NAME);
-// }
- }
- else
- {
- if (g_log)
- delete g_log;
- g_log = log;
- }
-
- return g_log;
-}
-
-Log *
-GDBServerLog::GetLogIfAllCategoriesSet (uint32_t mask)
-{
- Log *log = LogAccessor (true, NULL);
- if (log && mask)
- {
- uint32_t log_mask = log->GetMask().GetAllFlagBits();
- if ((log_mask & mask) != mask)
- return NULL;
- }
- return log;
-}
-
-void
-GDBServerLog::SetLog (Log *log)
-{
- LogAccessor (false, log);
-}
-
-
-void
-GDBServerLog::LogIf (uint32_t mask, const char *format, ...)
-{
- Log *log = GDBServerLog::GetLogIfAllCategoriesSet (mask);
- if (log)
- {
- va_list args;
- va_start (args, format);
- log->VAPrintf (format, args);
- va_end (args);
- }
-}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBServerLog.h b/lldb/source/Plugins/Process/gdb-remote/GDBServerLog.h
deleted file mode 100644
index 3dec8088cef..00000000000
--- a/lldb/source/Plugins/Process/gdb-remote/GDBServerLog.h
+++ /dev/null
@@ -1,55 +0,0 @@
-//===-- GDBServerLog.h ------------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//----------------------------------------------------------------------
-//
-// GDBServerLog.h
-// liblldb
-//
-// Created by Greg Clayton on 6/19/09.
-//
-//
-//----------------------------------------------------------------------
-
-#ifndef liblldb_GDBServerLog_h_
-#define liblldb_GDBServerLog_h_
-
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-
-#include "lldb/Core/Log.h"
-
-// Project includes
-#define GS_LOG_VERBOSE (1u << 0)
-#define GS_LOG_DEBUG (1u << 1)
-#define GS_LOG_PACKETS (1u << 2)
-#define GS_LOG_EVENTS (1u << 3)
-#define GS_LOG_MINIMAL (1u << 4)
-#define GS_LOG_ALL (UINT32_MAX)
-#define GS_LOG_DEFAULT (GS_LOG_VERBOSE |\
- GS_LOG_PACKETS)
-
-namespace lldb {
-
-class GDBServerLog
-{
-public:
- static Log *
- GetLog (uint32_t mask = 0);
-
- static void
- SetLog (Log *log);
-
- static void
- LogIf (uint32_t mask, const char *format, ...);
-};
-
-} // namespace lldb
-
-#endif // liblldb_GDBServerLog_h_
diff --git a/lldb/source/Plugins/Process/gdb-remote/Makefile b/lldb/source/Plugins/Process/gdb-remote/Makefile
new file mode 100644
index 00000000000..8a9b6107787
--- /dev/null
+++ b/lldb/source/Plugins/Process/gdb-remote/Makefile
@@ -0,0 +1,14 @@
+##===- source/Plugins/Process/gdb-remote/Makefile -------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LLDB_LEVEL := ../../../..
+LIBRARYNAME := lldbPluginProcessGDBRemote
+BUILD_ARCHIVE = 1
+
+include $(LLDB_LEVEL)/Makefile
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index f58613b62f1..fcf00270514 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -46,12 +46,11 @@
// Project includes
#include "lldb/Host/Host.h"
-#include "StringExtractorGDBRemote.h"
+#include "Utility/StringExtractorGDBRemote.h"
#include "GDBRemoteRegisterContext.h"
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
#include "ThreadGDBRemote.h"
-#include "libunwind.h"
#include "MacOSXLibunwindCallbacks.h"
#if defined (__i386__) || defined (__x86_64__)
@@ -116,28 +115,29 @@ ProcessGDBRemote::CanDebug(Target &target)
ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) :
Process (target, listener),
m_dynamic_loader_ap (),
- m_byte_order (eByteOrderHost),
m_flags (0),
m_stdio_communication ("gdb-remote.stdio"),
m_stdio_mutex (Mutex::eMutexTypeRecursive),
m_stdout_data (),
m_arch_spec (),
+ m_byte_order (eByteOrderHost),
m_gdb_comm(),
m_debugserver_pid (LLDB_INVALID_PROCESS_ID),
m_debugserver_monitor (0),
+ m_last_stop_packet (),
m_register_info (),
- m_curr_tid (LLDB_INVALID_THREAD_ID),
- m_curr_tid_run (LLDB_INVALID_THREAD_ID),
m_async_broadcaster ("lldb.process.gdb-remote.async-broadcaster"),
m_async_thread (LLDB_INVALID_HOST_THREAD),
+ m_curr_tid (LLDB_INVALID_THREAD_ID),
+ m_curr_tid_run (LLDB_INVALID_THREAD_ID),
m_z0_supported (1),
m_continue_packet(),
m_dispatch_queue_offsets_addr (LLDB_INVALID_ADDRESS),
+ m_packet_timeout (1),
+ m_max_memory_size (512),
m_libunwind_target_type (UNW_TARGET_UNSPECIFIED),
m_libunwind_addr_space (NULL),
- m_waiting_for_attach (false),
- m_packet_timeout (1),
- m_max_memory_size (512)
+ m_waiting_for_attach (false)
{
}
@@ -616,7 +616,7 @@ ProcessGDBRemote::DidLaunch ()
}
Error
-ProcessGDBRemote::DoAttach (lldb::pid_t attach_pid)
+ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid)
{
Error error;
// Clear out and clean up from any current state
@@ -716,7 +716,7 @@ ProcessGDBRemote::AttachInputReaderCallback
}
Error
-ProcessGDBRemote::DoAttach (const char *process_name, bool wait_for_launch)
+ProcessGDBRemote::DoAttachToProcessWithName (const char *process_name, bool wait_for_launch)
{
Error error;
// Clear out and clean up from any current state
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index cd5bab0194f..79872b4db4c 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -26,9 +26,9 @@
#include "lldb/Target/Thread.h"
#include "GDBRemoteCommunication.h"
-#include "StringExtractor.h"
+#include "Utility/StringExtractor.h"
#include "GDBRemoteRegisterContext.h"
-#include "libunwind.h"
+#include "libunwind/include/libunwind.h"
class ThreadGDBRemote;
@@ -94,10 +94,10 @@ public:
WillLaunchOrAttach ();
virtual lldb_private::Error
- DoAttach (lldb::pid_t pid);
+ DoAttachToProcessWithID (lldb::pid_t pid);
virtual lldb_private::Error
- DoAttach (const char *process_name, bool wait_for_launch);
+ DoAttachToProcessWithName (const char *process_name, bool wait_for_launch);
virtual void
DidAttach ();
diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
index 37485edf4e5..4eae1e6d41b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.cpp
@@ -22,7 +22,7 @@
#include "LibUnwindRegisterContext.h"
#include "ProcessGDBRemote.h"
#include "ProcessGDBRemoteLog.h"
-#include "StringExtractorGDBRemote.h"
+#include "Utility/StringExtractorGDBRemote.h"
#include "UnwindLibUnwind.h"
#include "UnwindMacOSXFrameBackchain.h"
@@ -104,6 +104,9 @@ ThreadGDBRemote::WillResume (StateType resume_state)
else
GetGDBProcess().m_continue_packet.Printf(";s:%4.4x", GetID());
break;
+
+ default:
+ break;
}
Thread::WillResume(resume_state);
return true;
@@ -272,8 +275,7 @@ ThreadGDBRemote::GetRawStopReason (StopInfo *stop_info)
if (m_stop_info_stop_id != m_process.GetStopID())
{
char packet[256];
- const int packet_len = snprintf(packet, sizeof(packet), "qThreadStopInfo%x", GetID());
- assert (packet_len < (sizeof(packet) - 1));
+ ::snprintf(packet, sizeof(packet), "qThreadStopInfo%x", GetID());
StringExtractorGDBRemote stop_packet;
if (GetGDBProcess().GetGDBRemote().SendPacketAndWaitForResponse(packet, stop_packet, 1, false))
{
diff --git a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
index 3fa4ae09a2a..d40c2e1f6ab 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ThreadGDBRemote.h
@@ -14,8 +14,7 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"
-#include "MachException.h"
-#include "libunwind.h"
+#include "libunwind/include/libunwind.h"
class StringExtractor;
class ProcessGDBRemote;
OpenPOWER on IntegriCloud