[Lldb-commits] [lldb] r146135 - in /lldb/trunk/tools/debugserver/source/MacOSX: i386/DNBArchImplI386.cpp i386/DNBArchImplI386.h x86_64/DNBArchImplX86_64.cpp x86_64/DNBArchImplX86_64.h
Greg Clayton
gclayton at apple.com
Wed Dec 7 19:19:36 PST 2011
Author: gclayton
Date: Wed Dec 7 21:19:36 2011
New Revision: 146135
URL: http://llvm.org/viewvc/llvm-project?rev=146135&view=rev
Log:
<rdar://problem/10544202>
Fixed detection of AVX on darwin now that our kernel supports it.
Modified:
lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h
lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h
Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp?rev=146135&r1=146134&r2=146135&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp Wed Dec 7 21:19:36 2011
@@ -27,6 +27,8 @@
debugStateOn
};
+extern "C" bool CPUHasAVX(); // Defined over in DNBArchImplX86_64.cpp
+
static debugState sFPUDebugState = debugStateUnknown;
static debugState sAVXForceState = debugStateUnknown;
@@ -252,9 +254,6 @@
gdb_ymm7 = gdb_xmm7
};
-// AVX support isn't working at all from user space, so disable it for now.
-enum DNBArchImplI386::AVXPresence DNBArchImplI386::s_has_avx = DNBArchImplI386::kAVXNotPresent;
-
uint64_t
DNBArchImplI386::GetPC(uint64_t failValue)
{
Modified: lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h?rev=146135&r1=146134&r2=146135&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.h Wed Dec 7 21:19:36 2011
@@ -223,15 +223,6 @@
static const DNBRegisterSetInfo *
GetRegisterSetInfo(nub_size_t *num_reg_sets);
- static bool
- CPUHasAVX()
- {
- if (s_has_avx == kAVXUnknown)
- s_has_avx = (::HasAVX() ? kAVXPresent : kAVXNotPresent);
-
- return (s_has_avx == kAVXPresent);
- }
-
// Helper functions for watchpoint manipulations.
static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write);
static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index);
@@ -242,12 +233,6 @@
MachThread *m_thread;
State m_state;
-
- static enum AVXPresence {
- kAVXPresent,
- kAVXNotPresent,
- kAVXUnknown
- } s_has_avx;
};
#endif // #if defined (__i386__) || defined (__x86_64__)
Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp?rev=146135&r1=146134&r2=146135&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp Wed Dec 7 21:19:36 2011
@@ -14,6 +14,8 @@
#if defined (__i386__) || defined (__x86_64__)
#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
#include "MacOSX/x86_64/DNBArchImplX86_64.h"
#include "DNBLog.h"
@@ -65,7 +67,54 @@
#define FORCE_AVX_REGS (0)
#endif
-enum DNBArchImplX86_64::AVXPresence DNBArchImplX86_64::s_has_avx = DNBArchImplX86_64::kAVXNotPresent;
+
+extern "C" bool
+CPUHasAVX()
+{
+ enum AVXPresence
+ {
+ eAVXUnknown = -1,
+ eAVXNotPresent = 0,
+ eAVXPresent = 1
+ };
+
+ static AVXPresence g_has_avx = eAVXUnknown;
+ if (g_has_avx == eAVXUnknown)
+ {
+ g_has_avx = eAVXNotPresent;
+
+ // Only xnu-2020 or later has AVX support, any versions before
+ // this have a busted thread_get_state RPC where it would truncate
+ // the thread state buffer (<rdar://problem/10122874>). So we need to
+ // verify the kernel version number manually or disable AVX support.
+ int mib[2];
+ char buffer[1024];
+ size_t length = sizeof(buffer);
+ uint64_t xnu_version = 0;
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_VERSION;
+ int err = ::sysctl(mib, 2, &buffer, &length, NULL, 0);
+ if (err == 0)
+ {
+ const char *xnu = strstr (buffer, "xnu-");
+ if (xnu)
+ {
+ const char *xnu_version_cstr = xnu + 4;
+ xnu_version = strtoull (xnu_version_cstr, NULL, 0);
+ if (xnu_version >= 2020 && xnu_version != ULLONG_MAX)
+ {
+ if (::HasAVX())
+ {
+ g_has_avx = eAVXPresent;
+ }
+ }
+ }
+ }
+ DNBLogThreadedIf (LOG_THREAD, "CPUHasAVX(): g_has_avx = %i (err = %i, errno = %i, xnu_version = %llu)\n", g_has_avx, err, errno, xnu_version);
+ }
+
+ return (g_has_avx == eAVXPresent);
+}
uint64_t
DNBArchImplX86_64::GetPC(uint64_t failValue)
Modified: lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h?rev=146135&r1=146134&r2=146135&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.h Wed Dec 7 21:19:36 2011
@@ -230,15 +230,6 @@
static const DNBRegisterSetInfo *
GetRegisterSetInfo(nub_size_t *num_reg_sets);
- static bool
- CPUHasAVX()
- {
- if (s_has_avx == kAVXUnknown)
- s_has_avx = (::HasAVX() ? kAVXPresent : kAVXNotPresent);
-
- return (s_has_avx == kAVXPresent);
- }
-
// Helper functions for watchpoint manipulations.
static void SetWatchpoint(DBG &debug_state, uint32_t hw_index, nub_addr_t addr, nub_size_t size, bool read, bool write);
static void ClearWatchpoint(DBG &debug_state, uint32_t hw_index);
@@ -248,13 +239,7 @@
static nub_addr_t GetWatchAddress(const DBG &debug_state, uint32_t hw_index);
MachThread *m_thread;
- State m_state;
-
- static enum AVXPresence {
- kAVXPresent,
- kAVXNotPresent,
- kAVXUnknown
- } s_has_avx;
+ State m_state;
};
#endif // #if defined (__i386__) || defined (__x86_64__)
More information about the lldb-commits
mailing list