summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core
diff options
context:
space:
mode:
authorVirgile Bello <virgile.bello@gmail.com>2013-08-23 12:44:05 +0000
committerVirgile Bello <virgile.bello@gmail.com>2013-08-23 12:44:05 +0000
commitb2f1fb2943c5e6833dcd2e1166b83ae4aca06d7a (patch)
tree2cf9567a828318ccccd4df22f7af31b4e796e5ec /lldb/source/Core
parentfcfa0afd7a09133d00bdc047cf894fce005a287a (diff)
downloadbcm5719-llvm-b2f1fb2943c5e6833dcd2e1166b83ae4aca06d7a.tar.gz
bcm5719-llvm-b2f1fb2943c5e6833dcd2e1166b83ae4aca06d7a.zip
MingW compilation (windows). Includes various refactoring to improve portability.
llvm-svn: 189107
Diffstat (limited to 'lldb/source/Core')
-rw-r--r--lldb/source/Core/CMakeLists.txt1
-rw-r--r--lldb/source/Core/Communication.cpp4
-rw-r--r--lldb/source/Core/ConnectionFileDescriptor.cpp62
-rw-r--r--lldb/source/Core/ConnectionSharedMemory.cpp21
-rw-r--r--lldb/source/Core/DataBufferMemoryMap.cpp45
-rw-r--r--lldb/source/Core/Log.cpp1
-rw-r--r--lldb/source/Core/Timer.cpp12
7 files changed, 123 insertions, 23 deletions
diff --git a/lldb/source/Core/CMakeLists.txt b/lldb/source/Core/CMakeLists.txt
index 3b8f8641b00..f2946ce1be1 100644
--- a/lldb/source/Core/CMakeLists.txt
+++ b/lldb/source/Core/CMakeLists.txt
@@ -71,6 +71,5 @@ add_lldb_library(lldbCore
ValueObjectSyntheticFilter.cpp
ValueObjectVariable.cpp
VMRange.cpp
- #Windows.cpp
)
diff --git a/lldb/source/Core/Communication.cpp b/lldb/source/Core/Communication.cpp
index 7f40e652020..6ea7a11426b 100644
--- a/lldb/source/Core/Communication.cpp
+++ b/lldb/source/Core/Communication.cpp
@@ -333,8 +333,8 @@ Communication::ReadThreadIsRunning ()
return m_read_thread_enabled;
}
-void *
-Communication::ReadThread (void *p)
+lldb::thread_result_t
+Communication::ReadThread (lldb::thread_arg_t p)
{
Communication *comm = (Communication *)p;
diff --git a/lldb/source/Core/ConnectionFileDescriptor.cpp b/lldb/source/Core/ConnectionFileDescriptor.cpp
index e320bda2fcd..77645d2194c 100644
--- a/lldb/source/Core/ConnectionFileDescriptor.cpp
+++ b/lldb/source/Core/ConnectionFileDescriptor.cpp
@@ -15,10 +15,15 @@
#endif
#include "lldb/Core/ConnectionFileDescriptor.h"
+#include "lldb/Host/Config.h"
// C Includes
#include <errno.h>
#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#ifndef LLDB_DISABLE_POSIX
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
@@ -26,10 +31,8 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <termios.h>
-#include <sys/types.h>
-#include <string.h>
-#include <stdlib.h>
#include <unistd.h>
+#endif
// C++ Includes
// Other libraries and framework includes
@@ -135,7 +138,11 @@ ConnectionFileDescriptor::OpenCommandPipe ()
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION));
// Make the command file descriptor here:
int filedes[2];
+#ifndef LLDB_DISABLE_POSIX
int result = pipe (filedes);
+#else
+ int result = -1;
+#endif
if (result != 0)
{
if (log)
@@ -223,7 +230,11 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
// get the flags from the file descriptor and making sure it
// isn't a bad fd.
errno = 0;
+#ifndef LLDB_DISABLE_POSIX
int flags = ::fcntl (m_fd_send, F_GETFL, 0);
+#else
+ int flags = -1;
+#endif
if (flags == -1 || errno == EBADF)
{
if (error_ptr)
@@ -262,6 +273,7 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
{
// file:///PATH
const char *path = s + strlen("file://");
+#ifndef LLDB_DISABLE_POSIX
do
{
m_fd_send = m_fd_recv = ::open (path, O_RDWR);
@@ -304,6 +316,9 @@ ConnectionFileDescriptor::Connect (const char *s, Error *error_ptr)
}
m_should_close_fd = true;
return eConnectionStatusSuccess;
+#else
+ return eConnectionStatusError;
+#endif
}
if (error_ptr)
error_ptr->SetErrorStringWithFormat ("unsupported connection URL: '%s'", s);
@@ -420,7 +435,21 @@ ConnectionFileDescriptor::Read (void *dst,
{
do
{
+#ifndef LLDB_DISABLE_POSIX
bytes_read = ::read (m_fd_recv, dst, dst_len);
+#else
+ switch (m_fd_send_type) {
+ case eFDTypeSocket:
+ case eFDTypeSocketUDP:
+ bytes_read = ::recv (m_fd_recv, (char*)dst, dst_len, 0);
+ break;
+ default:
+ bytes_read = -1;
+ break;
+
+ }
+
+#endif
} while (bytes_read < 0 && errno == EINTR);
}
@@ -523,17 +552,18 @@ ConnectionFileDescriptor::Write (const void *src, size_t src_len, ConnectionStat
switch (m_fd_send_type)
{
+#ifndef LLDB_DISABLE_POSIX
case eFDTypeFile: // Other FD requireing read/write
do
{
bytes_sent = ::write (m_fd_send, src, src_len);
} while (bytes_sent < 0 && errno == EINTR);
break;
-
+#endif
case eFDTypeSocket: // Socket requiring send/recv
do
{
- bytes_sent = ::send (m_fd_send, src, src_len, 0);
+ bytes_sent = ::send (m_fd_send, (char*)src, src_len, 0);
} while (bytes_sent < 0 && errno == EINTR);
break;
@@ -542,7 +572,7 @@ ConnectionFileDescriptor::Write (const void *src, size_t src_len, ConnectionStat
do
{
bytes_sent = ::sendto (m_fd_send,
- src,
+ (char*)src,
src_len,
0,
m_udp_send_sockaddr,
@@ -1115,6 +1145,7 @@ ConnectionFileDescriptor::Close (int& fd, Error *error_ptr)
ConnectionStatus
ConnectionFileDescriptor::NamedSocketAccept (const char *socket_name, Error *error_ptr)
{
+#ifndef LLDB_DISABLE_POSIX
ConnectionStatus result = eConnectionStatusError;
struct sockaddr_un saddr_un;
@@ -1159,11 +1190,15 @@ ConnectionFileDescriptor::NamedSocketAccept (const char *socket_name, Error *err
// We are done with the listen port
Close (listen_socket, NULL);
return result;
+#else
+ return eConnectionStatusError;
+#endif
}
ConnectionStatus
ConnectionFileDescriptor::NamedSocketConnect (const char *socket_name, Error *error_ptr)
{
+#ifndef LLDB_DISABLE_POSIX
Disconnect (NULL);
m_fd_send_type = m_fd_recv_type = eFDTypeSocket;
@@ -1194,6 +1229,9 @@ ConnectionFileDescriptor::NamedSocketConnect (const char *socket_name, Error *er
if (error_ptr)
error_ptr->Clear();
return eConnectionStatusSuccess;
+#else
+ return eConnectionStatusError;
+#endif
}
ConnectionStatus
@@ -1430,18 +1468,18 @@ ConnectionFileDescriptor::ConnectUDP (const char *host_and_port, Error *error_pt
return eConnectionStatusSuccess;
}
-#if defined(__MINGW32__) || defined(__MINGW64__)
+#if defined(_WIN32)
typedef const char * set_socket_option_arg_type;
typedef char * get_socket_option_arg_type;
-#else // #if defined(__MINGW32__) || defined(__MINGW64__)
+#else // #if defined(_WIN32)
typedef const void * set_socket_option_arg_type;
typedef void * get_socket_option_arg_type;
-#endif // #if defined(__MINGW32__) || defined(__MINGW64__)
+#endif // #if defined(_WIN32)
int
ConnectionFileDescriptor::GetSocketOption(int fd, int level, int option_name, int &option_value)
{
- get_socket_option_arg_type option_value_p = static_cast<get_socket_option_arg_type>(&option_value);
+ get_socket_option_arg_type option_value_p = reinterpret_cast<get_socket_option_arg_type>(&option_value);
socklen_t option_value_size = sizeof(int);
return ::getsockopt(fd, level, option_name, option_value_p, &option_value_size);
}
@@ -1449,7 +1487,7 @@ ConnectionFileDescriptor::GetSocketOption(int fd, int level, int option_name, in
int
ConnectionFileDescriptor::SetSocketOption(int fd, int level, int option_name, int option_value)
{
- set_socket_option_arg_type option_value_p = static_cast<get_socket_option_arg_type>(&option_value);
+ set_socket_option_arg_type option_value_p = reinterpret_cast<get_socket_option_arg_type>(&option_value);
return ::setsockopt(fd, level, option_name, option_value_p, sizeof(option_value));
}
@@ -1487,7 +1525,7 @@ ConnectionFileDescriptor::SetSocketReceiveTimeout (uint32_t timeout_usec)
timeout.tv_sec = timeout_usec / TimeValue::MicroSecPerSec;
timeout.tv_usec = timeout_usec % TimeValue::MicroSecPerSec;
}
- if (::setsockopt (m_fd_recv, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == 0)
+ if (::setsockopt (m_fd_recv, SOL_SOCKET, SO_RCVTIMEO, reinterpret_cast<get_socket_option_arg_type>(&timeout), sizeof(timeout)) == 0)
{
m_socket_timeout_usec = timeout_usec;
return true;
diff --git a/lldb/source/Core/ConnectionSharedMemory.cpp b/lldb/source/Core/ConnectionSharedMemory.cpp
index 625f17a0985..cd708c4868c 100644
--- a/lldb/source/Core/ConnectionSharedMemory.cpp
+++ b/lldb/source/Core/ConnectionSharedMemory.cpp
@@ -11,12 +11,15 @@
// C Includes
#include <errno.h>
-#include <pthread.h>
#include <stdlib.h>
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#else
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
+#endif
// C++ Includes
// Other libraries and framework includes
@@ -73,7 +76,12 @@ ConnectionSharedMemory::Disconnect (Error *error_ptr)
m_mmap.Clear();
if (!m_name.empty())
{
+#ifdef _WIN32
+ close(m_fd);
+ m_fd = -1;
+#else
shm_unlink (m_name.c_str());
+#endif
m_name.clear();
}
return eConnectionStatusSuccess;
@@ -114,6 +122,16 @@ ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error
}
m_name.assign (name);
+
+#ifdef _WIN32
+ HANDLE handle;
+ if (create)
+ handle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, (DWORD)(size >> 32), (DWORD)(size), name);
+ else
+ handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
+
+ m_fd = _open_osfhandle((intptr_t)handle, 0);
+#else
int oflag = O_RDWR;
if (create)
oflag |= O_CREAT;
@@ -121,6 +139,7 @@ ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error
if (create)
::ftruncate (m_fd, size);
+#endif
if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
return eConnectionStatusSuccess;
diff --git a/lldb/source/Core/DataBufferMemoryMap.cpp b/lldb/source/Core/DataBufferMemoryMap.cpp
index a4382a0c67e..374834a00e0 100644
--- a/lldb/source/Core/DataBufferMemoryMap.cpp
+++ b/lldb/source/Core/DataBufferMemoryMap.cpp
@@ -12,7 +12,11 @@
#include <fcntl.h>
#include <limits.h>
#include <sys/stat.h>
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#else
#include <sys/mman.h>
+#endif
#include "lldb/Core/DataBufferMemoryMap.h"
#include "lldb/Core/Error.h"
@@ -86,7 +90,11 @@ DataBufferMemoryMap::Clear()
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MMAP));
if (log)
log->Printf("DataBufferMemoryMap::Clear() m_mmap_addr = %p, m_mmap_size = %zu", m_mmap_addr, m_mmap_size);
+#ifdef _WIN32
+ UnmapViewOfFile(m_mmap_addr);
+#else
::munmap((void *)m_mmap_addr, m_mmap_size);
+#endif
m_mmap_addr = NULL;
m_mmap_size = 0;
m_data = NULL;
@@ -166,13 +174,49 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MMAP|LIBLLDB_LOG_VERBOSE));
if (log)
{
+#ifdef _WIN32
+ log->Printf("DataBufferMemoryMap::MemoryMapFromFileSpec(fd=%p, offset=0x%" PRIx64 ", length=0x%" PRIx64 ", writeable=%i, fd_is_file=%i)",
+#else
log->Printf("DataBufferMemoryMap::MemoryMapFromFileSpec(fd=%i, offset=0x%" PRIx64 ", length=0x%" PRIx64 ", writeable=%i, fd_is_file=%i)",
+#endif
fd,
offset,
length,
writeable,
fd_is_file);
}
+#ifdef _WIN32
+ HANDLE handle = (HANDLE)_get_osfhandle(fd);
+ DWORD file_size_low, file_size_high;
+ file_size_low = GetFileSize(handle, &file_size_high);
+ const size_t file_size = (file_size_high << 32) | file_size_low;
+ const size_t max_bytes_available = file_size - offset;
+ if (length == SIZE_MAX)
+ {
+ length = max_bytes_available;
+ }
+ else if (length > max_bytes_available)
+ {
+ // Cap the length if too much data was requested
+ length = max_bytes_available;
+ }
+
+ if (length > 0)
+ {
+ HANDLE fileMapping = CreateFileMapping(handle, NULL, writeable ? PAGE_READWRITE : PAGE_READONLY, file_size_high, file_size_low, NULL);
+ if (fileMapping != NULL)
+ {
+ m_mmap_addr = (uint8_t*)MapViewOfFile(fileMapping, writeable ? FILE_MAP_ALL_ACCESS : FILE_MAP_READ, (DWORD)(offset >> 32), (DWORD)(offset), length);
+ if (m_mmap_addr != NULL)
+ {
+ m_mmap_size = length;
+ m_data = m_mmap_addr;
+ m_size = length;
+ }
+ CloseHandle(fileMapping);
+ }
+ }
+#else
struct stat stat;
if (::fstat(fd, &stat) == 0)
{
@@ -253,6 +297,7 @@ DataBufferMemoryMap::MemoryMapFromFileDescriptor (int fd,
}
}
}
+#endif
}
return GetByteSize ();
}
diff --git a/lldb/source/Core/Log.cpp b/lldb/source/Core/Log.cpp
index d73ab15f697..9200fe13892 100644
--- a/lldb/source/Core/Log.cpp
+++ b/lldb/source/Core/Log.cpp
@@ -10,7 +10,6 @@
#include "lldb/lldb-python.h"
// C Includes
-#include <pthread.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
diff --git a/lldb/source/Core/Timer.cpp b/lldb/source/Core/Timer.cpp
index b1416bdaf62..bbd990056ba 100644
--- a/lldb/source/Core/Timer.cpp
+++ b/lldb/source/Core/Timer.cpp
@@ -14,6 +14,7 @@
#include "lldb/Core/Stream.h"
#include "lldb/Host/Mutex.h"
+#include "lldb/Host/Host.h"
#include <stdio.h>
@@ -26,7 +27,7 @@ uint32_t Timer::g_display_depth = 0;
FILE * Timer::g_file = NULL;
typedef std::vector<Timer *> TimerStack;
typedef std::map<const char *, uint64_t> TimerCategoryMap;
-static pthread_key_t g_key;
+static lldb::thread_key_t g_key;
static Mutex &
GetCategoryMutex()
@@ -46,11 +47,11 @@ GetCategoryMap()
static TimerStack *
GetTimerStackForCurrentThread ()
{
- void *timer_stack = ::pthread_getspecific (g_key);
+ void *timer_stack = Host::ThreadLocalStorageGet(g_key);
if (timer_stack == NULL)
{
- ::pthread_setspecific (g_key, new TimerStack);
- timer_stack = ::pthread_getspecific (g_key);
+ Host::ThreadLocalStorageSet(g_key, new TimerStack);
+ timer_stack = Host::ThreadLocalStorageGet(g_key);
}
return (TimerStack *)timer_stack;
}
@@ -71,8 +72,7 @@ void
Timer::Initialize ()
{
Timer::g_file = stdout;
- ::pthread_key_create (&g_key, ThreadSpecificCleanup);
-
+ g_key = Host::ThreadLocalStorageCreate(ThreadSpecificCleanup);
}
Timer::Timer (const char *category, const char *format, ...) :
OpenPOWER on IntegriCloud