Get lldb-server building on android-9
authorVince Harron <vince@nethacker.com>
Tue, 12 May 2015 01:10:56 +0000 (01:10 +0000)
committerVince Harron <vince@nethacker.com>
Tue, 12 May 2015 01:10:56 +0000 (01:10 +0000)
Build lldb-server with an android-9 sysroot.

llvm-svn: 237078

18 files changed:
lldb/cmake/platforms/Android.cmake
lldb/include/lldb/Host/Time.h [new file with mode: 0644]
lldb/include/lldb/Host/android/Android.h
lldb/include/lldb/Host/linux/Personality.h [new file with mode: 0644]
lldb/include/lldb/Host/linux/Ptrace.h [new file with mode: 0644]
lldb/include/lldb/Host/linux/Signalfd.h [new file with mode: 0644]
lldb/include/lldb/Host/posix/Fcntl.h [new file with mode: 0644]
lldb/source/DataFormatters/CXXFormatterFunctions.cpp
lldb/source/Host/CMakeLists.txt
lldb/source/Host/android/LibcGlue.cpp [new file with mode: 0644]
lldb/source/Host/posix/HostInfoPosix.cpp
lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp
lldb/source/Plugins/Process/POSIX/ProcessPOSIX.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
lldb/source/Utility/PseudoTerminal.cpp

index 725895a..2af8de7 100644 (file)
@@ -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 (file)
index 0000000..1da1449
--- /dev/null
@@ -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 <android/api-level.h>
+#endif
+
+#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
+#include <time64.h>
+static time_t timegm(struct tm* t);
+#else
+#include <time.h>
+#endif
+
+#endif // liblldb_Host_Time_h_
index df2f735..8efc1a5 100644 (file)
@@ -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 (file)
index 0000000..48fc2e2
--- /dev/null
@@ -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 <android/api-level.h>
+#endif
+
+#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
+#include <linux/personality.h>
+#else
+#include <sys/personality.h>
+#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 (file)
index 0000000..b28bb37
--- /dev/null
@@ -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 <sys/ptrace.h>
+
+#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 (file)
index 0000000..cf50e87
--- /dev/null
@@ -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 <android/api-level.h>
+#endif
+
+#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
+
+#include <linux/types.h>
+#include <linux/fcntl.h>
+
+#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 <sys/signalfd.h>
+#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 (file)
index 0000000..3e3a472
--- /dev/null
@@ -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 <android/api-level.h>
+#endif
+
+#include <fcntl.h>
+
+#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
+#define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6)
+#endif
+
+#endif // liblldb_Host_posix_Fcntl_h_
index 9c45e27..de62139 100644 (file)
 #include "lldb/Utility/ProcessStructReader.h"
 
 #include <algorithm>
+
 #if __ANDROID_NDK__
 #include <sys/types.h>
 #endif
 
+#include "lldb/Host/Time.h"
+
 using namespace lldb;
 using namespace lldb_private;
 using namespace lldb_private::formatters;
index 5f55477..a13defa 100644 (file)
@@ -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 (file)
index 0000000..d443a92
--- /dev/null
@@ -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 <android/api-level.h>
+
+#if __ANDROID_API__ < 21
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/syscall.h>
+#include <signal.h>
+
+#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
index debff52..160bd23 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <grp.h>
 #include <limits.h>
+#include <mutex>
 #include <netdb.h>
 #include <pwd.h>
 #include <sys/types.h>
@@ -47,9 +48,31 @@ HostInfoPosix::GetHostname(std::string &s)
     return false;
 }
 
+#ifdef __ANDROID_NDK__
+#include <android/api-level.h>
+#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<std::mutex> 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 *
index 4e4bbd8..5491efe 100644 (file)
 // System includes - They have to be included after framework includes because they define some
 // macros which collide with variable names in other modules
 #include <linux/unistd.h>
-#include <sys/personality.h>
-#include <sys/ptrace.h>
 #include <sys/socket.h>
-#include <sys/signalfd.h>
+
 #include <sys/types.h>
 #include <sys/uio.h>
 #include <sys/user.h>
 #include <elf.h>
 #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
 
index 4b29a09..b8f2a3f 100644 (file)
 
 // System includes - They have to be included after framework includes because they define some
 // macros which collide with variable names in other modules
-#include <sys/personality.h>
-#include <sys/ptrace.h>
+
+#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 <sys/socket.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
 #include <sys/user.h>
 #include <sys/wait.h>
 
-#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
index 798818b..09f72cb 100644 (file)
@@ -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;
 
index 064b60a..89d9876 100644 (file)
@@ -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;
 }
 
index e8b39ea..0cc528f 100644 (file)
@@ -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);
 
index 0ab9658..36d6485 100644 (file)
@@ -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.
index 302c265..bc3cfee 100644 (file)
@@ -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;