From: Vince Harron Date: Tue, 12 May 2015 01:10:56 +0000 (+0000) Subject: Get lldb-server building on android-9 X-Git-Tag: llvmorg-3.7.0-rc1~4860 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b33567189ea25fbdd454d9c4cc75cb2850a821f;p=platform%2Fupstream%2Fllvm.git Get lldb-server building on android-9 Build lldb-server with an android-9 sysroot. llvm-svn: 237078 --- diff --git a/lldb/cmake/platforms/Android.cmake b/lldb/cmake/platforms/Android.cmake index 725895a..2af8de7 100644 --- a/lldb/cmake/platforms/Android.cmake +++ b/lldb/cmake/platforms/Android.cmake @@ -85,12 +85,21 @@ if( NOT CMAKE_C_COMPILER ) set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_DIR}/bin/${ANDROID_TOOLCHAIN_NAME}-ranlib${EXECUTABLE_SUFFIX}" CACHE PATH "ranlib" ) endif() -set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT} -pie -fPIE -funwind-tables -fsigned-char -no-canonical-prefixes" ) +set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT} -funwind-tables -fsigned-char -no-canonical-prefixes" ) # TODO: different ARM abi have different flags such as neon, vfpv etc if( X86 ) set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) +elseif( ANDROID_ABI STREQUAL "armeabi" ) + # 64 bit atomic operations used in c++ libraries require armv7-a instructions + # armv5te and armv6 were tried but do not work. + set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a" ) endif() +# PIE is required for API 21+ so we enable it +# unfortunately, it is not supported before API 14 so we need to do something else there +# see http://llvm.org/pr23457 +set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -pie -fPIE" ) + # linker flags set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) diff --git a/lldb/include/lldb/Host/Time.h b/lldb/include/lldb/Host/Time.h new file mode 100644 index 0000000..1da1449 --- /dev/null +++ b/lldb/include/lldb/Host/Time.h @@ -0,0 +1,26 @@ +//===-- Time.h --------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Include system time headers, adding missing functions as necessary + +#ifndef liblldb_Host_Time_h_ +#define liblldb_Host_Time_h_ + +#ifdef __ANDROID_NDK__ +#include +#endif + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 +#include +static time_t timegm(struct tm* t); +#else +#include +#endif + +#endif // liblldb_Host_Time_h_ diff --git a/lldb/include/lldb/Host/android/Android.h b/lldb/include/lldb/Host/android/Android.h index df2f735..8efc1a5 100644 --- a/lldb/include/lldb/Host/android/Android.h +++ b/lldb/include/lldb/Host/android/Android.h @@ -16,9 +16,6 @@ #define _isatty isatty #define SYS_tgkill __NR_tgkill -#define PT_DETACH PTRACE_DETACH - -typedef int __ptrace_request; namespace std { diff --git a/lldb/include/lldb/Host/linux/Personality.h b/lldb/include/lldb/Host/linux/Personality.h new file mode 100644 index 0000000..48fc2e2 --- /dev/null +++ b/lldb/include/lldb/Host/linux/Personality.h @@ -0,0 +1,25 @@ +//===-- Personality.h -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This file defines personality functions & structures + +#ifndef liblldb_Host_linux_Personality_h_ +#define liblldb_Host_linux_Personality_h_ + +#ifdef __ANDROID_NDK__ +#include +#endif + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 +#include +#else +#include +#endif + +#endif // liblldb_Host_linux_Personality_h_ diff --git a/lldb/include/lldb/Host/linux/Ptrace.h b/lldb/include/lldb/Host/linux/Ptrace.h new file mode 100644 index 0000000..b28bb37 --- /dev/null +++ b/lldb/include/lldb/Host/linux/Ptrace.h @@ -0,0 +1,66 @@ +//===-- Ptrace.h ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This file defines ptrace functions & structures + +#ifndef liblldb_Host_linux_Ptrace_h_ +#define liblldb_Host_linux_Ptrace_h_ + +#include + +#ifdef __ANDROID_NDK__ +#define PT_DETACH PTRACE_DETACH +typedef int __ptrace_request; +#endif + +#define DEBUG_PTRACE_MAXBYTES 20 + +// Support ptrace extensions even when compiled without required kernel support +#ifndef PT_GETREGS + #ifndef PTRACE_GETREGS + #define PTRACE_GETREGS 12 + #endif +#endif +#ifndef PT_SETREGS + #ifndef PTRACE_SETREGS + #define PTRACE_SETREGS 13 + #endif +#endif +#ifndef PT_GETFPREGS + #ifndef PTRACE_GETFPREGS + #define PTRACE_GETFPREGS 14 + #endif +#endif +#ifndef PT_SETFPREGS + #ifndef PTRACE_SETFPREGS + #define PTRACE_SETFPREGS 15 + #endif +#endif +#ifndef PTRACE_GETREGSET + #define PTRACE_GETREGSET 0x4204 +#endif +#ifndef PTRACE_SETREGSET + #define PTRACE_SETREGSET 0x4205 +#endif +#ifndef PTRACE_GET_THREAD_AREA + #define PTRACE_GET_THREAD_AREA 25 +#endif +#ifndef PTRACE_ARCH_PRCTL + #define PTRACE_ARCH_PRCTL 30 +#endif +#ifndef ARCH_GET_FS + #define ARCH_SET_GS 0x1001 + #define ARCH_SET_FS 0x1002 + #define ARCH_GET_FS 0x1003 + #define ARCH_GET_GS 0x1004 +#endif + +#define LLDB_PTRACE_NT_ARM_TLS 0x401 // ARM TLS register + +#endif // liblldb_Host_linux_Ptrace_h_ diff --git a/lldb/include/lldb/Host/linux/Signalfd.h b/lldb/include/lldb/Host/linux/Signalfd.h new file mode 100644 index 0000000..cf50e87 --- /dev/null +++ b/lldb/include/lldb/Host/linux/Signalfd.h @@ -0,0 +1,54 @@ +//===-- Signalfd.h ----------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This file defines signalfd functions & structures + +#ifndef liblldb_Host_linux_Signalfd_h_ +#define liblldb_Host_linux_Signalfd_h_ + +#ifdef __ANDROID_NDK__ +#include +#endif + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 + +#include +#include + +#define SFD_CLOEXEC O_CLOEXEC +#define SFD_NONBLOCK O_NONBLOCK + +struct signalfd_siginfo { + __u32 ssi_signo; + __s32 ssi_errno; + __s32 ssi_code; + __u32 ssi_pid; + __u32 ssi_uid; + __s32 ssi_fd; + __u32 ssi_tid; + __u32 ssi_band; + __u32 ssi_overrun; + __u32 ssi_trapno; + __s32 ssi_status; + __s32 ssi_int; + __u64 ssi_ptr; + __u64 ssi_utime; + __u64 ssi_stime; + __u64 ssi_addr; + __u16 ssi_addr_lsb; + __u8 __pad[46]; +}; + +int signalfd (int fd, const sigset_t *mask, int flags); + +#else +#include +#endif + +#endif // liblldb_Host_linux_Signalfd_h_ diff --git a/lldb/include/lldb/Host/posix/Fcntl.h b/lldb/include/lldb/Host/posix/Fcntl.h new file mode 100644 index 0000000..3e3a472 --- /dev/null +++ b/lldb/include/lldb/Host/posix/Fcntl.h @@ -0,0 +1,25 @@ +//===-- Fcntl.h -------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This file defines fcntl functions & structures + +#ifndef liblldb_Host_posix_Fcntl_h_ +#define liblldb_Host_posix_Fcntl_h_ + +#ifdef __ANDROID_NDK__ +#include +#endif + +#include + +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 +#define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6) +#endif + +#endif // liblldb_Host_posix_Fcntl_h_ diff --git a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp index 9c45e27..de62139 100644 --- a/lldb/source/DataFormatters/CXXFormatterFunctions.cpp +++ b/lldb/source/DataFormatters/CXXFormatterFunctions.cpp @@ -29,10 +29,13 @@ #include "lldb/Utility/ProcessStructReader.h" #include + #if __ANDROID_NDK__ #include #endif +#include "lldb/Host/Time.h" + using namespace lldb; using namespace lldb_private; using namespace lldb_private::formatters; diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 5f55477..a13defa 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -104,6 +104,7 @@ else() if (__ANDROID_NDK__) add_host_subdirectory(android android/HostInfoAndroid.cpp + android/LibcGlue.cpp android/ProcessLauncherAndroid.cpp linux/Host.cpp linux/HostInfoLinux.cpp diff --git a/lldb/source/Host/android/LibcGlue.cpp b/lldb/source/Host/android/LibcGlue.cpp new file mode 100644 index 0000000..d443a92 --- /dev/null +++ b/lldb/source/Host/android/LibcGlue.cpp @@ -0,0 +1,39 @@ +//===-- LibcGlue.cpp --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This files adds functions missing from libc on earlier versions of Android + +#include + +#if __ANDROID_API__ < 21 + +#include +#include +#include +#include +#include + +#include "lldb/Host/Time.h" + +time_t timegm(struct tm* t) +{ + return (time_t) timegm64(t); +} + +int signalfd (int fd, const sigset_t *mask, int flags) +{ + return syscall(__NR_signalfd4, fd, mask, _NSIG / 8, flags); +} + +int posix_openpt(int flags) +{ + return open("/dev/ptmx", flags); +} + +#endif diff --git a/lldb/source/Host/posix/HostInfoPosix.cpp b/lldb/source/Host/posix/HostInfoPosix.cpp index debff52..160bd23 100644 --- a/lldb/source/Host/posix/HostInfoPosix.cpp +++ b/lldb/source/Host/posix/HostInfoPosix.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -47,9 +48,31 @@ HostInfoPosix::GetHostname(std::string &s) return false; } +#ifdef __ANDROID_NDK__ +#include +#endif +#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 +#define USE_GETPWUID +#endif + +#ifdef USE_GETPWUID +static std::mutex s_getpwuid_lock; +#endif + const char * HostInfoPosix::LookupUserName(uint32_t uid, std::string &user_name) { +#ifdef USE_GETPWUID + // getpwuid_r is missing from android-9 + // make getpwuid thread safe with a mutex + std::lock_guard lock(s_getpwuid_lock); + struct passwd *user_info_ptr = ::getpwuid(uid); + if (user_info_ptr) + { + user_name.assign(user_info_ptr->pw_name); + return user_name.c_str(); + } +#else struct passwd user_info; struct passwd *user_info_ptr = &user_info; char user_buffer[PATH_MAX]; @@ -62,8 +85,9 @@ HostInfoPosix::LookupUserName(uint32_t uid, std::string &user_name) return user_name.c_str(); } } +#endif user_name.clear(); - return NULL; + return nullptr; } const char * diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp index 4e4bbd8..5491efe 100644 --- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -54,10 +54,8 @@ // System includes - They have to be included after framework includes because they define some // macros which collide with variable names in other modules #include -#include -#include #include -#include + #include #include #include @@ -68,52 +66,10 @@ #include #endif -#ifdef __ANDROID__ -#define __ptrace_request int -#define PT_DETACH PTRACE_DETACH -#endif - -#define DEBUG_PTRACE_MAXBYTES 20 - -// Support ptrace extensions even when compiled without required kernel support -#ifndef PT_GETREGS -#ifndef PTRACE_GETREGS - #define PTRACE_GETREGS 12 -#endif -#endif -#ifndef PT_SETREGS -#ifndef PTRACE_SETREGS - #define PTRACE_SETREGS 13 -#endif -#endif -#ifndef PT_GETFPREGS -#ifndef PTRACE_GETFPREGS - #define PTRACE_GETFPREGS 14 -#endif -#endif -#ifndef PT_SETFPREGS -#ifndef PTRACE_SETFPREGS - #define PTRACE_SETFPREGS 15 -#endif -#endif -#ifndef PTRACE_GETREGSET - #define PTRACE_GETREGSET 0x4204 -#endif -#ifndef PTRACE_SETREGSET - #define PTRACE_SETREGSET 0x4205 -#endif -#ifndef PTRACE_GET_THREAD_AREA - #define PTRACE_GET_THREAD_AREA 25 -#endif -#ifndef PTRACE_ARCH_PRCTL - #define PTRACE_ARCH_PRCTL 30 -#endif -#ifndef ARCH_GET_FS - #define ARCH_SET_GS 0x1001 - #define ARCH_SET_FS 0x1002 - #define ARCH_GET_FS 0x1003 - #define ARCH_GET_GS 0x1004 -#endif +#include "lldb/Host/linux/Personality.h" +#include "lldb/Host/linux/Ptrace.h" +#include "lldb/Host/linux/Signalfd.h" +#include "lldb/Host/android/Android.h" #define LLDB_PERSONALITY_GET_CURRENT_SETTINGS 0xffffffff diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp index 4b29a09..b8f2a3f 100644 --- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp +++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp @@ -41,8 +41,12 @@ // System includes - They have to be included after framework includes because they define some // macros which collide with variable names in other modules -#include -#include + +#include "lldb/Host/linux/Personality.h" +#include "lldb/Host/linux/Ptrace.h" +#include "lldb/Host/linux/Signalfd.h" +#include "lldb/Host/android/Android.h" + #include #include #include @@ -50,37 +54,8 @@ #include #include -#ifdef __ANDROID__ -#define __ptrace_request int -#define PT_DETACH PTRACE_DETACH -#endif - -#define DEBUG_PTRACE_MAXBYTES 20 - -// Support ptrace extensions even when compiled without required kernel support -#ifndef PTRACE_GETREGSET - #define PTRACE_GETREGSET 0x4204 -#endif -#ifndef PTRACE_SETREGSET - #define PTRACE_SETREGSET 0x4205 -#endif -#ifndef PTRACE_GET_THREAD_AREA - #define PTRACE_GET_THREAD_AREA 25 -#endif -#ifndef PTRACE_ARCH_PRCTL - #define PTRACE_ARCH_PRCTL 30 -#endif -#ifndef ARCH_GET_FS - #define ARCH_SET_GS 0x1001 - #define ARCH_SET_FS 0x1002 - #define ARCH_GET_FS 0x1003 - #define ARCH_GET_GS 0x1004 -#endif - #define LLDB_PERSONALITY_GET_CURRENT_SETTINGS 0xffffffff -#define LLDB_PTRACE_NT_ARM_TLS 0x401 // ARM TLS register - // Support hardware breakpoints in case it has not been defined #ifndef TRAP_HWBKPT #define TRAP_HWBKPT 4 diff --git a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp index 798818b..09f72cb 100644 --- a/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp +++ b/lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp @@ -33,6 +33,8 @@ #include "Plugins/Process/Linux/ProcessMonitor.h" #include "POSIXThread.h" +#include "lldb/Host/posix/Fcntl.h" + using namespace lldb; using namespace lldb_private; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 064b60a..89d9876 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -259,7 +259,7 @@ GDBRemoteCommunication::SendPacketNoLock (const char *payload, size_t payload_le strm.Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written, (int)binary_start_offset, packet_data); const uint8_t *p; // Print binary data exactly as sent - for (p = (uint8_t*)packet_data + binary_start_offset; *p != '#'; ++p) + for (p = (const uint8_t*)packet_data + binary_start_offset; *p != '#'; ++p) strm.Printf("\\x%2.2x", *p); // Print the checksum strm.Printf("%*s", (int)3, p); @@ -822,7 +822,11 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *hostname, // connect to us.. error = StartListenThread ("127.0.0.1", 0); if (error.Fail()) + { + if (log) + log->Printf ("GDBRemoteCommunication::%s() unable to start listen thread: %s", __FUNCTION__, error.AsCString()); return error; + } ConnectionFileDescriptor *connection = (ConnectionFileDescriptor *)GetConnection (); // Wait for 10 seconds to resolve the bound port @@ -839,6 +843,8 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *hostname, else { error.SetErrorString ("failed to bind to port 0 on 127.0.0.1"); + if (log) + log->Printf ("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__, error.AsCString()); return error; } } @@ -957,6 +963,13 @@ GDBRemoteCommunication::StartDebugserverProcess (const char *hostname, { error.SetErrorStringWithFormat ("unable to locate " DEBUGSERVER_BASENAME ); } + + if (error.Fail()) + { + if (log) + log->Printf ("GDBRemoteCommunication::%s() failed: %s", __FUNCTION__, error.AsCString()); + } + return error; } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index e8b39ea..0cc528f 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -396,6 +396,10 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerCommon::Handle_qUserName (StringExtractorGDBRemote &packet) { #if !defined(LLDB_DISABLE_POSIX) + Log *log (GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PROCESS)); + if (log) + log->Printf("GDBRemoteCommunicationServerCommon::%s begin", __FUNCTION__); + // Packet format: "qUserName:%i" where %i is the uid packet.SetFilePos(::strlen ("qUserName:")); uint32_t uid = packet.GetU32 (UINT32_MAX); @@ -409,6 +413,8 @@ GDBRemoteCommunicationServerCommon::Handle_qUserName (StringExtractorGDBRemote & return SendPacketNoLock (response.GetData(), response.GetSize()); } } + if (log) + log->Printf("GDBRemoteCommunicationServerCommon::%s end", __FUNCTION__); #endif return SendErrorResponse (5); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp index 0ab9658..36d6485 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp @@ -117,7 +117,7 @@ GDBRemoteCommunicationServerPlatform::Handle_qLaunchGDBServer (StringExtractorGD if (hostname.empty()) hostname = "127.0.0.1"; if (log) - log->Printf("Launching debugserver with: %s:%u...\n", hostname.c_str(), port); + log->Printf("Launching debugserver with: %s:%u...", hostname.c_str(), port); // Do not run in a new session so that it can not linger after the // platform closes. diff --git a/lldb/source/Utility/PseudoTerminal.cpp b/lldb/source/Utility/PseudoTerminal.cpp index 302c265..bc3cfee 100644 --- a/lldb/source/Utility/PseudoTerminal.cpp +++ b/lldb/source/Utility/PseudoTerminal.cpp @@ -34,6 +34,7 @@ pid_t fork(void) { return 0; } pid_t setsid(void) { return 0; } #elif defined(__ANDROID_NDK__) #include "lldb/Host/android/Android.h" +int posix_openpt(int flags); #endif using namespace lldb_utility;