[lldb-dev] remote debugging from another platform

Carlo Kok ck at remobjects.com
Tue Sep 4 12:35:33 PDT 2012


Op 4-9-2012 16:46, Greg Clayton schreef:
>
> On Sep 3, 2012, at 12:32 PM, Carlo Kok <ck at remobjects.com> wrote:
>
>> Op 27-8-2012 19:16, Greg Clayton schreef:
>>> Yes it can, but work is definitely needed. Linux to OSX will work
>>> because we have the lldb modified "debugserver" binary which can
>>> debug macosx apps. There is no linux equivalent because the current
>>> "debugserver" binary was initially made for the Mac only and it isn't
>>> well orgnanized to be used as a starting point for porting to other
>>> systems.
>>>
>>> What I would like see happen, is in our Host layer (in
>>> "lldb/source/Host" and "lldb/include/lldb/Host"), we should have a
>>> native debug API that is very closely based on
>>> "lldb/tools/debugserver/source/DNB.h" and name it something like
>>> "lldb_private::NativeDebug". Once we do this, we can then support
>>> native debugging on every platform by making a new Process plugin in
>>> "lldb/source/Plugins/Process" called "Host" which would link against
>>> the new API in the lldb_private::NativeDebug. We then also have
>>> classes which implement remote GDB debugging inside lldb:
>>>
>>> lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
>>> lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
>>>
>>>
>>
>>
>> Are there any technical limitations that keep these from working on windows (the client side of things, not the host)? (I tried to import it but there are a lot of missing include files which i presume is just because nobody ever did this and it's just missing defines).
>
> We have a host layer in our code that is designed to abstract you from the OS your are running on, though I am sure it is far from perfect. One of the big challenges in making a windows port will be correctly implementing an abstraction layer that makes sense.
>
> Does anyone else have any experience and comments for Windows? I seem to remember a few folks working on windows over that past year.
>
> Greg Clayton
>

There are quite a few places that presume unix (like spawn.h, 
pthread.h); the patch attached has some small tweaks for this but is far 
from complete. Atm I'm stuck with regex.h (completely missing on vc++) 
and a read/write lock primitive (readwritelock.h wants it). Win32 
doesn't seem to have an equivalent.

--
Carlo Kok
-------------- next part --------------
Index: include/lldb/Core/Debugger.h
===================================================================
--- include/lldb/Core/Debugger.h	(revision 163122)
+++ include/lldb/Core/Debugger.h	(working copy)
@@ -13,7 +13,9 @@
 
 
 #include <stdint.h>
+#if !defined(WIN32)
 #include <unistd.h>
+#endif
 
 #include <stack>
 
Index: include/lldb/Core/Error.h
===================================================================
--- include/lldb/Core/Error.h	(revision 163122)
+++ include/lldb/Core/Error.h	(working copy)
@@ -175,7 +175,11 @@
     ///     format string \a format.
     //------------------------------------------------------------------
     void
-    PutToLog (Log *log, const char *format, ...)  __attribute__ ((format (printf, 3, 4)));
+    PutToLog (Log *log, const char *format, ...)  
+#if !defined(WIN32)
+	__attribute__ ((format (printf, 3, 4)))
+#endif
+	;
 
     //------------------------------------------------------------------
     /// Log an error to Log() if the error value is an error.
@@ -196,7 +200,11 @@
     ///     format string \a format.
     //------------------------------------------------------------------
     void
-    LogIfError (Log *log, const char *format, ...)  __attribute__ ((format (printf, 3, 4)));
+    LogIfError (Log *log, const char *format, ...)  
+#if !defined(WIN32)
+	__attribute__ ((format (printf, 3, 4)))
+#endif
+	;
 
     //------------------------------------------------------------------
     /// Set accessor from a kern_return_t.
@@ -266,7 +274,11 @@
     ///     A printf style format string
     //------------------------------------------------------------------
     int
-    SetErrorStringWithFormat (const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+    SetErrorStringWithFormat (const char *format, ...) 
+#if !defined(WIN32)	
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     int
     SetErrorStringWithVarArg (const char *format, va_list args);
Index: include/lldb/Core/Flags.h
===================================================================
--- include/lldb/Core/Flags.h	(revision 163122)
+++ include/lldb/Core/Flags.h	(working copy)
@@ -13,7 +13,9 @@
 
 
 #include <stdint.h>
+#if !defined(WIN32)
 #include <unistd.h>
+#endif
 
 namespace lldb_private {
 
Index: include/lldb/Core/Log.h
===================================================================
--- include/lldb/Core/Log.h	(revision 163122)
+++ include/lldb/Core/Log.h	(working copy)
@@ -11,11 +11,15 @@
 #define liblldb_Log_h_
 
 // C Includes
+#if !(WIN32)
 #include <stdbool.h>
+#endif
 #include <stdint.h>
 #include <signal.h>
 #include <stdio.h>
+#if !(WIN32)
 #include <unistd.h>
+#endif
 
 // C++ Includes
 // Other libraries and framework includes
@@ -126,37 +130,77 @@
     PutCString (const char *cstr);
 
     void
-    Printf (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
+    Printf (const char *format, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     void
     VAPrintf (const char *format, va_list args);
 
     void
-    PrintfWithFlags( uint32_t flags, const char *format, ...)  __attribute__ ((format (printf, 3, 4)));
+    PrintfWithFlags( uint32_t flags, const char *format, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 3, 4)))
+#endif
+	;
 
     void
-    LogIf (uint32_t mask, const char *fmt, ...)  __attribute__ ((format (printf, 3, 4)));
+    LogIf (uint32_t mask, const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 3, 4)))
+#endif
+	;
 
     void
-    Debug (const char *fmt, ...)  __attribute__ ((format (printf, 2, 3)));
+    Debug (const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     void
-    DebugVerbose (const char *fmt, ...)  __attribute__ ((format (printf, 2, 3)));
+    DebugVerbose (const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     void
-    Error (const char *fmt, ...)  __attribute__ ((format (printf, 2, 3)));
+    Error (const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     void
-    FatalError (int err, const char *fmt, ...)  __attribute__ ((format (printf, 3, 4)));
+    FatalError (int err, const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 3, 4)))
+#endif
+	;
 
     void
-    Verbose (const char *fmt, ...)  __attribute__ ((format (printf, 2, 3)));
+    Verbose (const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     void
-    Warning (const char *fmt, ...)  __attribute__ ((format (printf, 2, 3)));
+    Warning (const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     void
-    WarningVerbose (const char *fmt, ...)  __attribute__ ((format (printf, 2, 3)));
+    WarningVerbose (const char *fmt, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     Flags &
     GetOptions();
Index: include/lldb/Core/Stream.h
===================================================================
--- include/lldb/Core/Stream.h	(revision 163122)
+++ include/lldb/Core/Stream.h	(working copy)
@@ -126,7 +126,11 @@
     ///     The number of bytes that were appended to the stream.
     //------------------------------------------------------------------
     int
-    PrintfAsRawHex8 (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
+    PrintfAsRawHex8 (const char *format, ...)  
+#if !(WIN32)	
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     //------------------------------------------------------------------
     /// Format a C string from a printf style format and variable
@@ -518,7 +522,11 @@
     ///     format string \a format.
     //------------------------------------------------------------------
     int
-    Printf (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
+    Printf (const char *format, ...)  
+#if !(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     int
     PrintfVarArg(const char *format, va_list args);
Index: include/lldb/Host/Condition.h
===================================================================
--- include/lldb/Host/Condition.h	(revision 163122)
+++ include/lldb/Host/Condition.h	(working copy)
@@ -12,8 +12,13 @@
 #if defined(__cplusplus)
 
 
+#if defined(WIN32)
+#include <Windows.h>
+#else
 #include <pthread.h>
+#endif
 #include "lldb/Host/Mutex.h"
+#include "lldb/lldb-types.h"
 
 namespace lldb_private {
 
@@ -105,7 +110,7 @@
     //------------------------------------------------------------------
     // Member variables
     //------------------------------------------------------------------
-    pthread_cond_t m_condition; ///< The condition variable.
+    lldb::condition_t m_condition; ///< The condition variable.
     
     //------------------------------------------------------------------
     /// Get accessor to the pthread condition object.
@@ -113,7 +118,7 @@
     /// @return
     ///     A pointer to the condition variable owned by this object.
     //------------------------------------------------------------------
-    pthread_cond_t *
+    lldb::condition_t *
     GetCondition ();
 };
 
Index: include/lldb/Host/File.h
===================================================================
--- include/lldb/Host/File.h	(revision 163122)
+++ include/lldb/Host/File.h	(working copy)
@@ -472,7 +472,11 @@
     ///     format string \a format.
     //------------------------------------------------------------------
     int
-    Printf (const char *format, ...)  __attribute__ ((format (printf, 2, 3)));
+    Printf (const char *format, ...)  
+#if !defined(WIN32)
+	__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
     
     int
     PrintfVarArg(const char *format, va_list args);
Index: include/lldb/Host/Host.h
===================================================================
--- include/lldb/Host/Host.h	(revision 163122)
+++ include/lldb/Host/Host.h	(working copy)
@@ -18,6 +18,9 @@
 #include "lldb/lldb-private.h"
 #include "lldb/Core/StringList.h"
 #include "lldb/Host/File.h"
+#if defined(WIN32)
+#define mode_t int
+#endif
 
 namespace lldb_private {
 
@@ -141,7 +144,11 @@
     };
 
     static void
-    SystemLog (SystemLogType type, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+    SystemLog (SystemLogType type, const char *format, ...) 
+#if !defined(WIN32)
+		__attribute__ ((format (printf, 2, 3)))
+#endif
+	;
 
     static void
     SystemLog (SystemLogType type, const char *format, va_list args);
@@ -399,7 +406,11 @@
     ///     description string.
     //------------------------------------------------------------------
     static void
-    SetCrashDescriptionWithFormat (const char *format, ...)  __attribute__ ((format (printf, 1, 2)));
+    SetCrashDescriptionWithFormat (const char *format, ...)  
+#if !defined(WIN32)
+	__attribute__ ((format (printf, 1, 2)))
+#endif
+	;
 
     static void
     SetCrashDescription (const char *description);
Index: include/lldb/Host/Mutex.h
===================================================================
--- include/lldb/Host/Mutex.h	(revision 163122)
+++ include/lldb/Host/Mutex.h	(working copy)
@@ -11,9 +11,13 @@
 #define liblldb_Mutex_h_
 #if defined(__cplusplus)
 
+#if defined(WIN32)
+#include <Windows.h>
+#else
 #include <pthread.h>
+#endif
 #include <assert.h>
-
+#include "lldb/lldb-types.h"
 #ifdef LLDB_CONFIGURATION_DEBUG
 #include <string>
 #endif
@@ -235,7 +239,7 @@
     //------------------------------------------------------------------
     // TODO: Hide the mutex in the implementation file in case we ever need to port to an
     // architecture that doesn't have pthread mutexes.
-    pthread_mutex_t m_mutex; ///< The pthread mutex object.
+    lldb::mutex_t m_mutex; ///< The pthread mutex object.
 
 private:
     //------------------------------------------------------------------
@@ -244,7 +248,7 @@
     /// @return
     ///     A pointer to the pthread mutex object owned by this object.
     //------------------------------------------------------------------
-    pthread_mutex_t *
+    lldb::mutex_t *
     GetMutex();
 
     Mutex(const Mutex&);
Index: include/lldb/Host/ReadWriteLock.h
===================================================================
--- include/lldb/Host/ReadWriteLock.h	(revision 163122)
+++ include/lldb/Host/ReadWriteLock.h	(working copy)
@@ -13,7 +13,9 @@
 
 #include "lldb/Host/Mutex.h"
 #include "lldb/Host/Condition.h"
+#if !defined(WIN32)
 #include <pthread.h>
+#endif
 #include <stdint.h>
 #include <time.h>
 
Index: include/lldb/Host/TimeValue.h
===================================================================
--- include/lldb/Host/TimeValue.h	(revision 163122)
+++ include/lldb/Host/TimeValue.h	(working copy)
@@ -12,12 +12,20 @@
 
 // C Includes
 #include <stdint.h>
+#if WIN32
+#include <time.h>
+#else
 #include <sys/time.h>
+#endif
 
 // BEGIN: MinGW work around
 #if !defined(_STRUCT_TIMESPEC) && !defined(HAVE_STRUCT_TIMESPEC)
+#if defined(WIN32)
+#include <Windows.h>
+#else
 #include <pthread.h>
 #endif
+#endif
 // END: MinGW work around
 
 // C++ Includes
Index: include/lldb/Interpreter/Args.h
===================================================================
--- include/lldb/Interpreter/Args.h	(revision 163122)
+++ include/lldb/Interpreter/Args.h	(working copy)
@@ -11,7 +11,7 @@
 #define liblldb_Command_h_
 
 // C Includes
-#include <getopt.h>
+//#include <getopt.h>
 
 // C++ Includes
 #include <list>
Index: include/lldb/Interpreter/Options.h
===================================================================
--- include/lldb/Interpreter/Options.h	(revision 163122)
+++ include/lldb/Interpreter/Options.h	(working copy)
@@ -11,7 +11,7 @@
 #define liblldb_Options_h_
 
 // C Includes
-#include <getopt.h>
+//#include <getopt.h>
 
 // C++ Includes
 #include <set>
Index: include/lldb/lldb-types.h
===================================================================
--- include/lldb/lldb-types.h	(revision 163122)
+++ include/lldb/lldb-types.h	(working copy)
@@ -14,11 +14,15 @@
 #include "lldb/lldb-forward.h"
 
 #include <assert.h>
+#if defined(WIN32)
+#include <Windows.h>
+#else
 #include <pthread.h>
+#endif
 #include <signal.h>
 #include <stdint.h>
-#include <stdbool.h>
-#include <unistd.h>
+//#include <stdbool.h>
+//#include <unistd.h>
 
 //----------------------------------------------------------------------
 // All host systems must define:
@@ -39,13 +43,20 @@
 // things should be defined. Currently MacOSX is being assumed by default
 // since that is what lldb was first developed for.
 
+
 namespace lldb {
         //----------------------------------------------------------------------
         // MacOSX Types
         //----------------------------------------------------------------------
+#if defined(WIN32)
+        typedef CRITICAL_SECTION    mutex_t;
+        typedef HANDLE              condition_t;
+        typedef HANDLE              thread_t;                   // Host thread type
+#else
         typedef ::pthread_mutex_t   mutex_t;
         typedef pthread_cond_t      condition_t;
         typedef pthread_t           thread_t;                   // Host thread type
+#endif
         typedef void *              thread_arg_t;               // Host thread argument type
         typedef void *              thread_result_t;            // Host thread result type
         typedef void *              (*thread_func_t)(void *);   // Host thread function type
Index: include/lldb/Target/Process.h
===================================================================
--- include/lldb/Target/Process.h	(revision 163122)
+++ include/lldb/Target/Process.h	(working copy)
@@ -12,7 +12,14 @@
 
 // C Includes
 #include <limits.h>
+#if defined(WIN32)
+#include <Windows.h>
+#define STDIN_FILENO stdin
+#define STDOUT_FILENO stdout
+#define STDERR_FILENO stderr
+#else
 #include <spawn.h>
+#endif
 
 // C++ Includes
 #include <list>
@@ -190,7 +197,11 @@
             m_executable = exe_file;
             if (add_exe_file_as_first_arg)
             {
+#if defined(WIN32)
+				char filename[MAX_PATH];
+#else
                 char filename[PATH_MAX];
+#endif
                 if (exe_file.GetPath(filename, sizeof(filename)))
                     m_arguments.InsertArgumentAtIndex (0, filename);
             }
@@ -479,12 +490,14 @@
 
         bool
         Open (int fd, const char *path, bool read, bool write);
-        
+
+#if !defined(WIN32)
         static bool
         AddPosixSpawnFileAction (posix_spawn_file_actions_t *file_actions,
                                  const FileAction *info,
                                  Log *log, 
                                  Error& error);
+#endif
 
         int
         GetFD () const
Index: include/lldb/Utility/RefCounter.h
===================================================================
--- include/lldb/Utility/RefCounter.h	(revision 163122)
+++ include/lldb/Utility/RefCounter.h	(working copy)
@@ -39,14 +39,22 @@
     inline T
     increment(T* t)
     {
+#if defined(WIN32)
+	return InterlockedIncrement(t) -1;
+#else
         return __sync_fetch_and_add(t, 1);
-    }
+#endif
+	}
     
     template <class T>
     inline T
     decrement(T* t)
     {
+#if defined(WIN32)
+	return InterlockedDecrement(t) +1;
+#else
         return __sync_fetch_and_add(t, -1);
+#endif
     }
     
 };
Index: include/lldb/Utility/SharingPtr.h
===================================================================
--- include/lldb/Utility/SharingPtr.h	(revision 163122)
+++ include/lldb/Utility/SharingPtr.h	(working copy)
@@ -12,11 +12,14 @@
 
 #include <algorithm>
 #include <memory>
+#if defined(WIN32)
+#include <Windows.h>
+#endif
 
 //#define ENABLE_SP_LOGGING 1 // DON'T CHECK THIS LINE IN UNLESS COMMENTED OUT
 #if defined (ENABLE_SP_LOGGING)
 
-extern "C" void track_sp (void *sp_this, void *ptr, long count);
+extern "C" void track_sp (void *sp_this, void *ptr, losng count);
 
 #endif
 
@@ -28,14 +31,22 @@
 inline T
 increment(T& t)
 {
-    return __sync_add_and_fetch(&t, 1);
+#if defined(WIN32)
+	return InterlockedIncrement(&t);
+#else
+	return __sync_add_and_fetch(&t, 1);
+#endif
 }
 
 template <class T>
 inline T
 decrement(T& t)
 {
+#if defined(WIN32)
+	return InterlockedDecrement(&t);
+#else
     return __sync_add_and_fetch(&t, -1);
+#endif
 }
 
 class shared_count
Index: source/Core/ConnectionSharedMemory.cpp
===================================================================
--- source/Core/ConnectionSharedMemory.cpp	(revision 163122)
+++ source/Core/ConnectionSharedMemory.cpp	(working copy)
@@ -11,7 +11,11 @@
 
 // C Includes
 #include <errno.h>
+#if defined(WIN32)
+#include <Windows.h>
+#else
 #include <pthread.h>
+#endif
 #include <stdlib.h>
 #include <sys/file.h>
 #include <sys/mman.h>
Index: source/Core/Log.cpp
===================================================================
--- source/Core/Log.cpp	(revision 163122)
+++ source/Core/Log.cpp	(working copy)
@@ -8,7 +8,11 @@
 //===----------------------------------------------------------------------===//
 
 // C Includes
+#if defined(WIN32)
+#include <Windows.h>
+#else
 #include <pthread.h>
+#endif
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
Index: source/Host/freebsd/Host.cpp
===================================================================
--- source/Host/freebsd/Host.cpp	(revision 163122)
+++ source/Host/freebsd/Host.cpp	(working copy)
@@ -21,7 +21,9 @@
 #include <sys/exec.h>
 #include <machine/elf.h>
 
+#if !defined(WIN32)
 #include <spawn.h>
+#endif
 
 // C++ Includes
 // Other libraries and framework includes
Index: source/lldb-log.cpp
===================================================================
--- source/lldb-log.cpp	(revision 163122)
+++ source/lldb-log.cpp	(working copy)
@@ -21,6 +21,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
+#define strncasecmp(a,b,c) _strnicmp(a, b, c)
+#define strcasecmp(a,b) _stricmp(a,b)
 
 // We want to avoid global constructors where code needs to be run so here we
 // control access to our static g_log_sp by hiding it in a singleton function


More information about the lldb-dev mailing list