eran.ifrah updated this revision to Diff 51918.
eran.ifrah added a comment.

Fixed: WindowsMiniDump should now also compile and work on MinGW by adding 
`Dbghelp` library 
Fixed: DebuggerThread: don't pass std::atomic<DWORD> to the LOG macros as it 
yields g++ error on MinGW, instead use a temp variable
Fixed: Re-enable LOG macros on MinGW


http://reviews.llvm.org/D18519

Files:
  CMakeLists.txt
  cmake/modules/AddLLDB.cmake
  cmake/modules/LLDBConfig.cmake
  include/lldb/Host/windows/win32.h
  source/API/CMakeLists.txt
  source/API/SystemInitializerFull.cpp
  source/Host/common/OptionParser.cpp
  source/Host/windows/EditLineWin.cpp
  source/Host/windows/FileSystem.cpp
  source/Host/windows/ProcessRunLock.cpp
  source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
  source/Plugins/Process/Windows/Live/DebuggerThread.cpp
  source/Target/ProcessLaunchInfo.cpp
  source/Utility/PseudoTerminal.cpp
  tools/CMakeLists.txt
  tools/argdumper/CMakeLists.txt
  tools/driver/CMakeLists.txt
  tools/driver/Driver.cpp

Index: tools/driver/Driver.cpp
===================================================================
--- tools/driver/Driver.cpp
+++ tools/driver/Driver.cpp
@@ -1299,7 +1299,7 @@
 }
 
 int
-#ifdef WIN32
+#if defined(_MSC_VER)
 wmain(int argc, wchar_t const *wargv[])
 #else
 main(int argc, char const *argv[])
@@ -1311,7 +1311,7 @@
 	setvbuf(stdin , NULL, _IONBF, 0);
 #endif
 
-#ifdef _WIN32
+#if defined(_MSC_VER)
         // Convert wide arguments to UTF-8
         std::vector<std::string> argvStrings(argc);
         std::vector<const char *> argvPointers(argc);
Index: tools/driver/CMakeLists.txt
===================================================================
--- tools/driver/CMakeLists.txt
+++ tools/driver/CMakeLists.txt
@@ -17,7 +17,14 @@
   add_dependencies(lldb debugserver)
 endif()
 
+if(MINGW)
+    # link directly against the dll file
+    add_dependencies(lldb liblldb)
+    target_link_libraries(lldb -L"${CMAKE_BINARY_DIR}/bin" -llldb)
+else()
 target_link_libraries(lldb liblldb)
+endif()
+
 # TODO: why isn't this done by add_lldb_executable?
 #target_link_libraries(lldb ${LLDB_USED_LIBS})
 #llvm_config(lldb ${LLVM_LINK_COMPONENTS})
Index: tools/argdumper/CMakeLists.txt
===================================================================
--- tools/argdumper/CMakeLists.txt
+++ tools/argdumper/CMakeLists.txt
@@ -2,7 +2,13 @@
   argdumper.cpp
   )
 
+if(MINGW)
+    # link directly against the dll file
+    add_dependencies(lldb-argdumper liblldb)
+    target_link_libraries(lldb-argdumper -L"${CMAKE_BINARY_DIR}/bin" -llldb)
+else()
 target_link_libraries(lldb-argdumper liblldb)
+endif()
 
 install(TARGETS lldb-argdumper
   RUNTIME DESTINATION bin)
Index: tools/CMakeLists.txt
===================================================================
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -4,7 +4,8 @@
 endif()
   add_subdirectory(argdumper)
   add_subdirectory(driver)
-if (NOT __ANDROID_NDK__)
+if (NOT __ANDROID_NDK__ AND NOT MINGW)
+  # TODO: we should really make lldb-mi compile under MinGW
   add_subdirectory(lldb-mi)
 endif()
 if (LLDB_CAN_USE_LLDB_SERVER)
Index: source/Utility/PseudoTerminal.cpp
===================================================================
--- source/Utility/PseudoTerminal.cpp
+++ source/Utility/PseudoTerminal.cpp
@@ -20,7 +20,9 @@
 
 #ifdef _WIN32
 #include "lldb/Host/windows/win32.h"
+#if defined(_MSC_VER)
 typedef uint32_t pid_t;
+#endif
 // empty functions
 int posix_openpt(int flag) { return 0; }
 
Index: source/Target/ProcessLaunchInfo.cpp
===================================================================
--- source/Target/ProcessLaunchInfo.cpp
+++ source/Target/ProcessLaunchInfo.cpp
@@ -366,7 +366,7 @@
                                  __FUNCTION__);
 
                 int open_flags = O_RDWR | O_NOCTTY;
-#if !defined(_MSC_VER)
+#if !defined(LLVM_ON_WIN32)
                 // We really shouldn't be specifying platform specific flags
                 // that are intended for a system call in generic code.  But
                 // this will have to do for now.
Index: source/Plugins/Process/Windows/Live/DebuggerThread.cpp
===================================================================
--- source/Plugins/Process/Windows/Live/DebuggerThread.cpp
+++ source/Plugins/Process/Windows/Live/DebuggerThread.cpp
@@ -377,9 +377,10 @@
         // we use simply to wake up the DebuggerThread so that we can close out the debug loop.
         if (m_pid_to_detach != 0 && info.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT)
         {
+            DWORD dwPidToDetach = m_pid_to_detach;
             WINLOG_IFANY(WINDOWS_LOG_EVENT | WINDOWS_LOG_EXCEPTION | WINDOWS_LOG_PROCESS,
                             "Breakpoint exception is cue to detach from process 0x%x",
-                            m_pid_to_detach);
+                            dwPidToDetach);
             ::DebugActiveProcessStop(m_pid_to_detach);
             m_detached = true;
         }
Index: source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
===================================================================
--- source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
+++ source/Plugins/ObjectFile/PECOFF/WindowsMiniDump.cpp
@@ -27,7 +27,7 @@
              lldb_private::Error &error)
 {
     if (!process_sp) return false;
-#ifdef _WIN32
+#if defined(LLVM_ON_WIN32)
     HANDLE process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process_sp->GetID());
     const std::string file_name = outfile.GetCString();
     std::wstring wide_name;
Index: source/Host/windows/ProcessRunLock.cpp
===================================================================
--- source/Host/windows/ProcessRunLock.cpp
+++ source/Host/windows/ProcessRunLock.cpp
@@ -1,20 +1,9 @@
 #include "lldb/Host/ProcessRunLock.h"
 #include "lldb/Host/windows/windows.h"
-
-namespace
-{
-#if defined(__MINGW32__)
-// Taken from WinNT.h
-typedef struct _RTL_SRWLOCK {
-    PVOID Ptr;
-} RTL_SRWLOCK, *PRTL_SRWLOCK;
-
-// Taken from WinBase.h
-typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK;
+#ifdef __MINGW32__
+#include <synchapi.h>
 #endif
-}
 
-
 static PSRWLOCK GetLock(lldb::rwlock_t lock)
 {
     return static_cast<PSRWLOCK>(lock);
Index: source/Host/windows/FileSystem.cpp
===================================================================
--- source/Host/windows/FileSystem.cpp
+++ source/Host/windows/FileSystem.cpp
@@ -255,14 +255,20 @@
 FILE *
 FileSystem::Fopen(const char *path, const char *mode)
 {
+#ifndef __MINGW32__
     std::wstring wpath, wmode;
     if (!llvm::ConvertUTF8toWide(path, wpath))
         return nullptr;
     if (!llvm::ConvertUTF8toWide(mode, wmode))
         return nullptr;
     FILE *file;
+
     if (_wfopen_s(&file, wpath.c_str(), wmode.c_str()) != 0)
         return nullptr;
+#else
+    FILE *file;
+    file = fopen(path, mode);
+#endif
     return file;
 }
 
Index: source/Host/windows/EditLineWin.cpp
===================================================================
--- source/Host/windows/EditLineWin.cpp
+++ source/Host/windows/EditLineWin.cpp
@@ -42,7 +42,7 @@
 // default to what we expect to receive anyway
 static const char *_prompt = "(lldb) ";
 
-#if !defined( _WIP_INPUT_METHOD )
+#if !defined( _WIP_INPUT_METHOD ) && !defined(__MINGW32__)
 
 static char *
 el_get_s (char *buffer, int chars)
Index: source/Host/common/OptionParser.cpp
===================================================================
--- source/Host/common/OptionParser.cpp
+++ source/Host/common/OptionParser.cpp
@@ -6,7 +6,6 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-
 #include "lldb/Host/OptionParser.h"
 #include "lldb/Host/HostGetOpt.h"
 #include "lldb/lldb-private-types.h"
Index: source/API/SystemInitializerFull.cpp
===================================================================
--- source/API/SystemInitializerFull.cpp
+++ source/API/SystemInitializerFull.cpp
@@ -87,7 +87,7 @@
 #include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
 #endif
 
-#if defined(_MSC_VER)
+#if defined(LLVM_ON_WIN32)
 #include "lldb/Host/windows/windows.h"
 #include "Plugins/Process/Windows/Live/ProcessWindowsLive.h"
 #include "Plugins/Process/Windows/MiniDump/ProcessWinMiniDump.h"
@@ -331,7 +331,7 @@
     ObjCLanguage::Initialize();
     ObjCPlusPlusLanguage::Initialize();
 
-#if defined(_MSC_VER)
+#if defined(LLVM_ON_WIN32)
     ProcessWindowsLive::Initialize();
 #endif
 #if defined(__FreeBSD__)
Index: source/API/CMakeLists.txt
===================================================================
--- source/API/CMakeLists.txt
+++ source/API/CMakeLists.txt
@@ -71,10 +71,18 @@
 
 # This should not be part of LLDBDependencies.cmake, because we don't
 # want every single library taking a dependency on the script interpreters.
+if(MINGW)
 target_link_libraries(liblldb PRIVATE
   lldbPluginScriptInterpreterNone
   lldbPluginScriptInterpreterPython
+    Dbghelp # Needed for MiniDumpWriteDump
   )
+else()
+  target_link_libraries(liblldb PRIVATE
+    lldbPluginScriptInterpreterNone
+    lldbPluginScriptInterpreterPython
+    )
+endif()
 
 set_target_properties(liblldb
   PROPERTIES
Index: include/lldb/Host/windows/win32.h
===================================================================
--- include/lldb/Host/windows/win32.h
+++ include/lldb/Host/windows/win32.h
@@ -10,9 +10,17 @@
 #ifndef LLDB_lldb_win32_h_
 #define LLDB_lldb_win32_h_
 
+#ifdef __MINGW32__
+// MinGW lacks this definition
+#ifndef _SH_DENYNO
+#define _SH_DENYNO 0x40
+#endif
+#endif
+
 #include <stdarg.h>
 #include <time.h>
 
+
 // posix utilities
 int vasprintf(char **ret, const char *fmt, va_list ap);
 char * strcasestr(const char *s, const char* find);
@@ -93,15 +101,14 @@
 
 // timespec
 // MSVC 2015 and higher have timespec.  Otherwise we need to define it ourselves.
-#if defined(_MSC_VER) && _MSC_VER >= 1900
-#include <time.h>
-#else
+#if defined(_MSC_VER) && (_MSC_VER < 1900)
 struct timespec
 {
     time_t tv_sec;
     long   tv_nsec;
 };
+#else
+#include <time.h>
 #endif
 
-
 #endif  // LLDB_lldb_win32_h_
Index: cmake/modules/LLDBConfig.cmake
===================================================================
--- cmake/modules/LLDBConfig.cmake
+++ cmake/modules/LLDBConfig.cmake
@@ -221,6 +221,7 @@
 endif ()
 
 # Disable Clang warnings
+if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 check_cxx_compiler_flag("-Wno-deprecated-register"
                         CXX_SUPPORTS_NO_DEPRECATED_REGISTER)
 if (CXX_SUPPORTS_NO_DEPRECATED_REGISTER)
@@ -232,6 +233,7 @@
 if (CXX_SUPPORTS_NO_VLA_EXTENSION)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-vla-extension")
 endif ()
+endif()
 
 # Disable MSVC warnings
 if( MSVC )
@@ -247,8 +249,12 @@
 
 # Use the Unicode (UTF-16) APIs by default on Win32
 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
+  if(MINGW)
+    add_definitions( -D_UNICODE -DUNICODE -D_WIN32_WINNT=0x0600 -D_BSD_SOURCE)
+  else()
 	add_definitions( /D _UNICODE /D UNICODE )
 endif()
+endif()
 
 set(LLDB_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(LLDB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
Index: cmake/modules/AddLLDB.cmake
===================================================================
--- cmake/modules/AddLLDB.cmake
+++ cmake/modules/AddLLDB.cmake
@@ -49,7 +49,7 @@
   endif()
 
   #PIC not needed on Win
-  if (NOT MSVC)
+  if (NOT MSVC AND NOT MINGW)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
   endif()
 
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1,5 +1,11 @@
 cmake_minimum_required(VERSION 2.8)
 
+if(MINGW_DEBUG)
+    # force debugging info into lldb sources
+    message("-- Building LLDB in Debug mode")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0")
+endif()
+
 include(cmake/modules/LLDBStandalone.cmake)
 include(cmake/modules/LLDBConfig.cmake)
 include(cmake/modules/AddLLDB.cmake)
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to