30 changes: 13 additions & 17 deletions lldb/source/Host/common/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#endif

#if defined (__linux__) || defined (__FreeBSD__) || defined (__FreeBSD_kernel__) || defined (__APPLE__) || defined(__NetBSD__)
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
#include <spawn.h>
#endif
#include <sys/wait.h>
Expand Down Expand Up @@ -111,7 +111,7 @@ Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, vo
return ThreadLauncher::LaunchThread(thread_name, MonitorChildProcessThreadFunction, info_ptr, NULL);
}

#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
//------------------------------------------------------------------
// Scoped class that will disable thread canceling when it is
// constructed, and exception safely restore the previous value it
Expand All @@ -126,7 +126,6 @@ class ScopedPThreadCancelDisabler
int err = ::pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &m_old_state);
if (err != 0)
m_old_state = -1;

}

~ScopedPThreadCancelDisabler()
Expand All @@ -139,7 +138,7 @@ class ScopedPThreadCancelDisabler
private:
int m_old_state; // Save the old cancelability state.
};
#endif
#endif // __ANDROID_NDK__

static thread_result_t
MonitorChildProcessThreadFunction (void *arg)
Expand Down Expand Up @@ -173,15 +172,14 @@ MonitorChildProcessThreadFunction (void *arg)
log->Printf("%s ::wait_pid (pid = %" PRIi32 ", &status, options = %i)...", function, pid, options);

// Wait for all child processes
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
::pthread_testcancel ();
#endif
// Get signals from all children with same process group of pid
const ::pid_t wait_pid = ::waitpid (pid, &status, options);
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
::pthread_testcancel ();
#endif

if (wait_pid == -1)
{
if (errno == EINTR)
Expand Down Expand Up @@ -226,7 +224,7 @@ MonitorChildProcessThreadFunction (void *arg)

// Scope for pthread_cancel_disabler
{
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
ScopedPThreadCancelDisabler pthread_cancel_disabler;
#endif

Expand Down Expand Up @@ -316,6 +314,8 @@ Host::GetCurrentThreadID()
return thread_self;
#elif defined(__FreeBSD__)
return lldb::tid_t(pthread_getthreadid_np());
#elif defined(__ANDROID_NDK__)
return lldb::tid_t(gettid());
#elif defined(__linux__)
return lldb::tid_t(syscall(SYS_gettid));
#else
Expand Down Expand Up @@ -456,7 +456,7 @@ FileSpec
Host::GetModuleFileSpecForHostAddress (const void *host_addr)
{
FileSpec module_filespec;
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
Dl_info info;
if (::dladdr (host_addr, &info))
{
Expand Down Expand Up @@ -694,14 +694,13 @@ Host::RunShellCommand (const char *command,
// systems

#if defined (__APPLE__) || defined (__linux__) || defined (__FreeBSD__) || defined (__GLIBC__) || defined(__NetBSD__)

// this method needs to be visible to macosx/Host.cpp and
// common/Host.cpp.

short
Host::GetPosixspawnFlags(const ProcessLaunchInfo &launch_info)
{
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
short flags = POSIX_SPAWN_SETSIGDEF | POSIX_SPAWN_SETSIGMASK;

#if defined (__APPLE__)
Expand Down Expand Up @@ -745,7 +744,7 @@ Host::GetPosixspawnFlags(const ProcessLaunchInfo &launch_info)
#endif // #if defined (__APPLE__)
return flags;
#else
assert(false *&& "Host::GetPosixspawnFlags() not supported on Android");
assert(false && "Host::GetPosixspawnFlags() not supported on Android");
return 0;
#endif
}
Expand All @@ -754,7 +753,7 @@ Error
Host::LaunchProcessPosixSpawn(const char *exe_path, const ProcessLaunchInfo &launch_info, lldb::pid_t &pid)
{
Error error;
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS));

posix_spawnattr_t attr;
Expand Down Expand Up @@ -954,7 +953,7 @@ Host::LaunchProcessPosixSpawn(const char *exe_path, const ProcessLaunchInfo &lau
bool
Host::AddPosixSpawnFileAction(void *_file_actions, const FileAction *info, Log *log, Error &error)
{
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__ANDROID_NDK__)
if (info == NULL)
return false;

Expand Down Expand Up @@ -1022,7 +1021,6 @@ Host::AddPosixSpawnFileAction(void *_file_actions, const FileAction *info, Log *
return false;
#endif
}

#endif // LaunchProcedssPosixSpawn: Apple, Linux, FreeBSD and other GLIBC systems

#if defined(__linux__) || defined(__FreeBSD__) || defined(__GLIBC__) || defined(__NetBSD__) || defined(_WIN32)
Expand All @@ -1049,11 +1047,9 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info)

return error;
}

#endif // defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)

#ifndef _WIN32

void
Host::Kill(lldb::pid_t pid, int signo)
{
Expand Down
8 changes: 8 additions & 0 deletions lldb/source/Host/common/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
#include "lldb/Host/TimeValue.h"
#include "lldb/Interpreter/Args.h"

#ifdef __ANDROID_NDK__
#include <linux/tcp.h>
#include <bits/error_constants.h>
#include <asm-generic/errno-base.h>
#include <errno.h>
#include <arpa/inet.h>
#endif

#ifndef LLDB_DISABLE_POSIX
#include <arpa/inet.h>
#include <netdb.h>
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Host/linux/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#include "lldb/Target/Process.h"

#include "lldb/Host/Host.h"
#ifdef __ANDROID_NDK__
#include "lldb/Host/android/Android.h"
#endif
#include "lldb/Core/DataBufferHeap.h"
#include "lldb/Core/DataExtractor.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "ObjectContainerBSDArchive.h"

#ifdef _WIN32
#if defined(_WIN32) || defined(__ANDROID_NDK__)
// Defines from ar, missing on Windows
#define ARMAG "!<arch>\n"
#define SARMAG 8
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ PlatformLinux::LaunchNativeProcess (
lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
NativeProcessProtocolSP &process_sp)
{
#if !defined(__linux__)
#if !defined(__linux__) || defined(__ANDROID_NDK__)
return Error("only implemented on Linux hosts");
#else
if (!IsHost ())
Expand Down Expand Up @@ -857,7 +857,7 @@ PlatformLinux::AttachNativeProcess (lldb::pid_t pid,
lldb_private::NativeProcessProtocol::NativeDelegate &native_delegate,
NativeProcessProtocolSP &process_sp)
{
#if !defined(__linux__)
#if !defined(__linux__) || defined(__ANDROID_NDK__)
return Error("only implemented on Linux hosts");
#else
if (!IsHost ())
Expand Down
7 changes: 6 additions & 1 deletion lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
#include <stdint.h>
#include <unistd.h>
#include <linux/unistd.h>
#if defined(__ANDROID_NDK__) && defined (__arm__)
#include <linux/personality.h>
#include <linux/user.h>
#else
#include <sys/personality.h>
#include <sys/user.h>
#endif
#ifndef __ANDROID__
#include <sys/procfs.h>
#endif
Expand All @@ -27,7 +33,6 @@
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/user.h>
#include <sys/wait.h>

#if defined (__arm64__) || defined (__aarch64__)
Expand Down
7 changes: 6 additions & 1 deletion lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
#include <stdint.h>
#include <unistd.h>
#include <elf.h>
#if defined(__ANDROID_NDK__) && defined (__arm__)
#include <linux/personality.h>
#include <linux/user.h>
#else
#include <sys/personality.h>
#include <sys/user.h>
#endif
#ifndef __ANDROID__
#include <sys/procfs.h>
#endif
Expand All @@ -25,7 +31,6 @@
#include <sys/socket.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/user.h>
#include <sys/wait.h>

// C++ Includes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ RegisterContextMacOSXFrameBackchain::ReadRegister (const RegisterInfo *reg_info,
// TOOD: need a better way to detect when "long double" types are
// the same bytes size as "double"
#if !defined(__arm__) && !defined(__arm64__) && !defined(__aarch64__) && !defined(_MSC_VER) && \
!defined(__mips__) && !defined(__powerpc__)
!defined(__mips__) && !defined(__powerpc__) && !defined(__ANDROID_NDK__)
case sizeof (long double):
if (sizeof (long double) == sizeof(uint32_t))
{
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/Utility/PseudoTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ char *ptsname(int fd) { return 0; }

pid_t fork(void) { return 0; }
pid_t setsid(void) { return 0; }
#elif defined(__ANDROID_NDK__)
#include "lldb/Host/android/Android.h"
#endif

using namespace lldb_utility;
Expand Down
2 changes: 2 additions & 0 deletions lldb/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_subdirectory(debugserver)
endif()
add_subdirectory(driver)
if (NOT __ANDROID_NDK__)
add_subdirectory(lldb-mi)
endif()
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "Linux")
add_subdirectory(lldb-gdbserver)
endif()
Expand Down
2 changes: 2 additions & 0 deletions lldb/tools/driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#if defined(_WIN32)
#include <io.h>
#include <fcntl.h>
#elif defined(__ANDROID_NDK__)
#include <errno.h>
#else
#include <unistd.h>
#endif
Expand Down
14 changes: 8 additions & 6 deletions lldb/tools/driver/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,17 @@
#include <termios.h>
#include <unistd.h>

#include <histedit.h>
#include <pthread.h>
#include <sys/time.h>

#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <readline/readline.h>
#else
#include <editline/readline.h>
#endif
#if !defined(__ANDROID_NDK__)
#include <histedit.h>
#if defined(__FreeBSD__) || defined(__NetBSD__)
#include <readline/readline.h>
#else
#include <editline/readline.h>
#endif
#endif

#endif

Expand Down
30 changes: 29 additions & 1 deletion lldb/tools/lldb-gdbserver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
set(LLVM_NO_RTTI 1)

if ( CMAKE_SYSTEM_NAME MATCHES "Linux" )
include_directories(
../../source/Plugins/Process/Linux
../../source/Plugins/Process/POSIX
)
endif ()

if ( CMAKE_SYSTEM_NAME MATCHES "FreeBSD" )
include_directories(
../../source/Plugins/Process/FreeBSD
../../source/Plugins/Process/POSIX
)
endif ()
include_directories(../../source)

include(../../cmake/LLDBDependencies.cmake)

# have to include lldb and lldb-log files since those are not libraries and llgs depends on them
add_lldb_executable(lldb-gdbserver
lldb-gdbserver.cpp
../../source/lldb-log.cpp
../../source/lldb.cpp
)

target_link_libraries(lldb-gdbserver liblldb)
# The Darwin linker doesn't understand --start-group/--end-group.
if (LLVM_COMPILER_IS_GCC_COMPATIBLE AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
target_link_libraries(lldb-gdbserver
-Wl,--start-group ${LLDB_USED_LIBS} -Wl,--end-group)
else()
target_link_libraries(lldb-gdbserver ${LLDB_USED_LIBS})
endif()
target_link_libraries(lldb-gdbserver ${CLANG_USED_LIBS})
llvm_config(lldb-gdbserver ${LLVM_LINK_COMPONENTS})

target_link_libraries(lldb-gdbserver ${LLDB_SYSTEM_LIBS})

set_target_properties(lldb-gdbserver PROPERTIES VERSION ${LLDB_VERSION})

Expand Down