Made lldb_private::ArchSpec more generic so that it can take a mach-o cpu
type and sub-type, or an ELF e_machine value. Also added a generic CPU type
to the arch spec class so we can have a single arch definition that the LLDB
core code can use. Previously a lot of places in the code were using the
mach-o definitions from a macosx header file. 

Switches over to using "llvm/Support/MachO.h" for the llvm::MachO::XXX for the
CPU types and sub types for mach-o ArchSpecs. Added "llvm/Support/ELF.h" so 
we can use the "llvm::ELF::XXX" defines for the ELF ArchSpecs.

Got rid of all CPU_TYPE_ and CPU_SUBTYPE_ defines that were previously being
used in LLDB.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@105806 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp
index 4f6b17c..28a28c7 100644
--- a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp
+++ b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp
@@ -94,13 +94,6 @@
 }
 
 
-
-uint32_t
-MachThreadContext_arm::GetCPUType()
-{
-    return CPU_TYPE_ARM;
-}
-
 void
 MachThreadContext_arm::ThreadWillResume()
 {
@@ -1879,6 +1872,6 @@
 void
 MachThreadContext_arm::Initialize()
 {
-    ArchSpec arch_spec(CPU_TYPE_ARM, CPU_TYPE_ANY);
+    ArchSpec arch_spec(eArchTypeMachO, 12, UINT32_MAX);
     ProcessMacOSX::AddArchCreateCallback(arch_spec, MachThreadContext_arm::Create);
 }
diff --git a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h
index 4ec72df..333efee 100644
--- a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h
+++ b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h
@@ -46,9 +46,6 @@
     virtual void
     RefreshStateAfterStop ();
 
-    static uint32_t
-    GetCPUType ();
-
 protected:
     kern_return_t
     EnableHardwareSingleStep (bool enable);
diff --git a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp
index ea148a6..03b5c2a 100644
--- a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp
+++ b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp
@@ -55,13 +55,6 @@
     m_flags_reg = reg_ctx->ConvertRegisterKindToRegisterNumber (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
 }
 
-
-uint32_t
-MachThreadContext_i386::GetCPUType()
-{
-    return CPU_TYPE_I386;
-}
-
 void
 MachThreadContext_i386::ThreadWillResume()
 {
diff --git a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h
index 4bee2e7..7da2259 100644
--- a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h
+++ b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h
@@ -40,7 +40,6 @@
 
     virtual bool            NotifyException(MachException::Data& exc);
     virtual size_t          GetStackFrameData(lldb_private::StackFrame *first_frame, std::vector<std::pair<lldb::addr_t, lldb::addr_t> >& fp_pc_pairs);
-    static uint32_t         GetCPUType();
 
 protected:
 //    kern_return_t EnableHardwareSingleStep (bool enable);
diff --git a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp
index 3ee9eb4..7eaa8f4 100644
--- a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp
+++ b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp
@@ -54,12 +54,6 @@
     m_flags_reg = reg_ctx->ConvertRegisterKindToRegisterNumber (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_FLAGS);
 }
 
-uint32_t
-MachThreadContext_x86_64::GetCPUType()
-{
-    return CPU_TYPE_X86_64;
-}
-
 void
 MachThreadContext_x86_64::ThreadWillResume()
 {
diff --git a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h
index 45d5a37..f4fc130 100644
--- a/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h
+++ b/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h
@@ -54,9 +54,6 @@
     virtual size_t
     GetStackFrameData (lldb_private::StackFrame *first_frame, std::vector<std::pair<lldb::addr_t, lldb::addr_t> >& fp_pc_pairs);
 
-    static uint32_t
-    GetCPUType();
-
 protected:
 //    kern_return_t EnableHardwareSingleStep (bool enable);
     uint32_t m_flags_reg;
diff --git a/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp b/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
index 0116f00..d887b09 100644
--- a/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
+++ b/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp
@@ -532,31 +532,32 @@
     static const uint8_t g_ppc_breakpoint_opcode[] = { 0x7F, 0xC0, 0x00, 0x08 };
     static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC };
 
-    switch (m_arch_spec.GetCPUType())
+    ArchSpec::CPU arch_cpu = m_arch_spec.GetGenericCPUType();
+    switch (arch_cpu)
     {
-    case CPU_TYPE_ARM:
+    case ArchSpec::eCPU_i386:
+    case ArchSpec::eCPU_x86_64:
+        trap_opcode = g_i386_breakpoint_opcode;
+        trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
+        break;
+    
+    case ArchSpec::eCPU_arm:
         // TODO: fill this in for ARM. We need to dig up the symbol for
         // the address in the breakpoint locaiton and figure out if it is
         // an ARM or Thumb breakpoint.
         trap_opcode = g_arm_breakpoint_opcode;
         trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
         break;
-
-    case CPU_TYPE_POWERPC:
-    case CPU_TYPE_POWERPC64:
+    
+    case ArchSpec::eCPU_ppc:
+    case ArchSpec::eCPU_ppc64:
         trap_opcode = g_ppc_breakpoint_opcode;
         trap_opcode_size = sizeof(g_ppc_breakpoint_opcode);
         break;
 
-    case CPU_TYPE_I386:
-    case CPU_TYPE_X86_64:
-        trap_opcode = g_i386_breakpoint_opcode;
-        trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
-        break;
-
     default:
         assert(!"Unhandled architecture in ProcessMacOSX::GetSoftwareBreakpointTrapOpcode()");
-        return 0;
+        break;
     }
 
     if (trap_opcode && trap_opcode_size)
@@ -1721,16 +1722,19 @@
     // We don't need to do this for ARM, and we really shouldn't now that we
     // have multiple CPU subtypes and no posix_spawnattr call that allows us
     // to set which CPU subtype to launch...
-    cpu_type_t cpu = arch_spec.GetCPUType();
-    if (cpu != 0 && cpu != CPU_TYPE_ANY && cpu != LLDB_INVALID_CPUTYPE)
+    if (arch_spec.GetType() == eArchTypeMachO)
     {
-        size_t ocount = 0;
-        err.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
-        if (err.Fail() || log)
-            err.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount);
+        cpu_type_t cpu = arch_spec.GetCPUType();
+        if (cpu != 0 && cpu != UINT32_MAX && cpu != LLDB_INVALID_CPUTYPE)
+        {
+            size_t ocount = 0;
+            err.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
+            if (err.Fail() || log)
+                err.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount);
 
-        if (err.Fail() != 0 || ocount != 1)
-            return LLDB_INVALID_PROCESS_ID;
+            if (err.Fail() != 0 || ocount != 1)
+                return LLDB_INVALID_PROCESS_ID;
+        }
     }
 
 #endif
diff --git a/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp b/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp
index 3747254..5909bc4 100644
--- a/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp
+++ b/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp
@@ -1153,38 +1153,14 @@
         // Set this to zero in case we can't tell if there are any HW breakpoints
         g_num_supported_hw_breakpoints = 0;
 
-        // Read the DBGDIDR to get the number of available hardware breakpoints
-        // However, in some of our current armv7 processors, hardware
-        // breakpoints/watchpoints were not properly connected. So detect those
-        // cases using a field in a sysctl. For now we are using "hw.cpusubtype"
-        // field to distinguish CPU architectures. This is a hack until we can
-        // get <rdar://problem/6372672> fixed, at which point we will switch to
-        // using a different sysctl string that will tell us how many BRPs
-        // are available to us directly without having to read DBGDIDR.
         uint32_t register_DBGDIDR;
 
         asm("mrc p14, 0, %0, c0, c0, 0" : "=r" (register_DBGDIDR));
-        uint32_t numBRPs = bits(register_DBGDIDR, 27, 24);
+        g_num_supported_hw_breakpoints = bits(register_DBGDIDR, 27, 24);
         // Zero is reserved for the BRP count, so don't increment it if it is zero
-        if (numBRPs > 0)
-            numBRPs++;
-        ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "DBGDIDR=0x%8.8x (number BRP pairs = %u)", register_DBGDIDR, numBRPs);
-
-        if (numBRPs > 0)
-        {
-            uint32_t cpu_subtype;
-            size_t len;
-            len = sizeof(cpusubtype);
-            // TODO: remove this hack and change to using hw.optional.xx when implmented
-            if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) == 0)
-            {
-                ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "hw.cpusubtype=0x%d", cpusubtype);
-                if (cpusubtype == CPU_SUBTYPE_ARM_V7)
-                    ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "Hardware breakpoints disabled for armv7 (rdar://problem/6372672)");
-                else
-                    g_num_supported_hw_breakpoints = numBRPs;
-            }
-        }
+        if (g_num_supported_hw_breakpoints > 0)
+            g_num_supported_hw_breakpoints++;
+        ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "DBGDIDR=0x%8.8x (number BRP pairs = %u)", register_DBGDIDR, g_num_supported_hw_breakpoints);
 
     }
     return g_num_supported_hw_breakpoints;
@@ -1306,37 +1282,11 @@
     {
         // Set this to zero in case we can't tell if there are any HW breakpoints
         g_num_supported_hw_watchpoints = 0;
-        // Read the DBGDIDR to get the number of available hardware breakpoints
-        // However, in some of our current armv7 processors, hardware
-        // breakpoints/watchpoints were not properly connected. So detect those
-        // cases using a field in a sysctl. For now we are using "hw.cpusubtype"
-        // field to distinguish CPU architectures. This is a hack until we can
-        // get <rdar://problem/6372672> fixed, at which point we will switch to
-        // using a different sysctl string that will tell us how many WRPs
-        // are available to us directly without having to read DBGDIDR.
 
         uint32_t register_DBGDIDR;
         asm("mrc p14, 0, %0, c0, c0, 0" : "=r" (register_DBGDIDR));
-        uint32_t numWRPs = bits(register_DBGDIDR, 31, 28) + 1;
-        ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "DBGDIDR=0x%8.8x (number WRP pairs = %u)", register_DBGDIDR, numWRPs);
-
-        if (numWRPs > 0)
-        {
-            uint32_t cpusubtype;
-            size_t len;
-            len = sizeof(cpusubtype);
-            // TODO: remove this hack and change to using hw.optional.xx when implmented
-            if (::sysctlbyname("hw.cpusubtype", &cpusubtype, &len, NULL, 0) == 0)
-            {
-                ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "hw.cpusubtype=0x%d", cpusubtype);
-
-                if (cpusubtype == CPU_SUBTYPE_ARM_V7)
-                    ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "Hardware watchpoints disabled for armv7 (rdar://problem/6372672)");
-                else
-                    g_num_supported_hw_watchpoints = numWRPs;
-            }
-        }
-
+        g_num_supported_hw_watchpoints = bits(register_DBGDIDR, 31, 28) + 1;
+        ProcessMacOSXLog::LogIf(PD_LOG_THREAD, "DBGDIDR=0x%8.8x (number WRP pairs = %u)", register_DBGDIDR, g_num_supported_hw_watchpoints);
     }
     return g_num_supported_hw_watchpoints;
 #else
diff --git a/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp b/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp
index 58a7ac0..e6c7b35 100644
--- a/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp
+++ b/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp
@@ -250,15 +250,16 @@
     
     if (arg == 0)
         return -1;
-    Thread *th = (Thread *) arg;
-    const ArchSpec target_arch (th->GetProcess().GetTarget().GetArchitecture ());
+    Thread *thread = (Thread *) arg;
     
-    if (target_arch.GetCPUType() == CPU_TYPE_I386)
+    const ArchSpec::CPU arch_cpu = thread->GetProcess().GetTarget().GetArchitecture ().GetGenericCPUType();
+
+    if (arch_cpu == ArchSpec::eCPU_i386)
     {
         if (EDGetDisassembler (&disasm, "i386-apple-darwin", kEDAssemblySyntaxX86ATT) != 0)
             return -1;
     }
-    else if (target_arch.GetCPUType() == CPU_TYPE_X86_64)
+    else if (arch_cpu == ArchSpec::eCPU_x86_64)
     {
         if (EDGetDisassembler (&disasm, "x86_64-apple-darwin", kEDAssemblySyntaxX86ATT) != 0)
             return -1;
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index e8b194e..8bf90c2 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -875,31 +875,32 @@
     static const uint8_t g_ppc_breakpoint_opcode[] = { 0x7F, 0xC0, 0x00, 0x08 };
     static const uint8_t g_i386_breakpoint_opcode[] = { 0xCC };
 
-    switch (m_arch_spec.GetCPUType())
+    ArchSpec::CPU arch_cpu = m_arch_spec.GetGenericCPUType();
+    switch (arch_cpu)
     {
-        case CPU_TYPE_ARM:
-            // TODO: fill this in for ARM. We need to dig up the symbol for
-            // the address in the breakpoint locaiton and figure out if it is
-            // an ARM or Thumb breakpoint.
-            trap_opcode = g_arm_breakpoint_opcode;
-            trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
-            break;
+    case ArchSpec::eCPU_i386:
+    case ArchSpec::eCPU_x86_64:
+        trap_opcode = g_i386_breakpoint_opcode;
+        trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
+        break;
+    
+    case ArchSpec::eCPU_arm:
+        // TODO: fill this in for ARM. We need to dig up the symbol for
+        // the address in the breakpoint locaiton and figure out if it is
+        // an ARM or Thumb breakpoint.
+        trap_opcode = g_arm_breakpoint_opcode;
+        trap_opcode_size = sizeof(g_arm_breakpoint_opcode);
+        break;
+    
+    case ArchSpec::eCPU_ppc:
+    case ArchSpec::eCPU_ppc64:
+        trap_opcode = g_ppc_breakpoint_opcode;
+        trap_opcode_size = sizeof(g_ppc_breakpoint_opcode);
+        break;
 
-        case CPU_TYPE_POWERPC:
-        case CPU_TYPE_POWERPC64:
-            trap_opcode = g_ppc_breakpoint_opcode;
-            trap_opcode_size = sizeof(g_ppc_breakpoint_opcode);
-            break;
-
-        case CPU_TYPE_I386:
-        case CPU_TYPE_X86_64:
-            trap_opcode = g_i386_breakpoint_opcode;
-            trap_opcode_size = sizeof(g_i386_breakpoint_opcode);
-            break;
-
-        default:
-            assert(!"Unhandled architecture in ProcessGDBRemote::GetSoftwareBreakpointTrapOpcode()");
-            return 0;
+    default:
+        assert(!"Unhandled architecture in ProcessMacOSX::GetSoftwareBreakpointTrapOpcode()");
+        break;
     }
 
     if (trap_opcode && trap_opcode_size)
@@ -1719,16 +1720,19 @@
             // We don't need to do this for ARM, and we really shouldn't now that we
             // have multiple CPU subtypes and no posix_spawnattr call that allows us
             // to set which CPU subtype to launch...
-            cpu_type_t cpu = inferior_arch.GetCPUType();
-            if (cpu != 0 && cpu != CPU_TYPE_ANY && cpu != LLDB_INVALID_CPUTYPE)
+            if (inferior_arch.GetType() == eArchTypeMachO)
             {
-                size_t ocount = 0;
-                error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
-                if (error.Fail() || log)
-                    error.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount);
+                cpu_type_t cpu = inferior_arch.GetCPUType();
+                if (cpu != 0 && cpu != UINT32_MAX && cpu != LLDB_INVALID_CPUTYPE)
+                {
+                    size_t ocount = 0;
+                    error.SetError( ::posix_spawnattr_setbinpref_np (&attr, 1, &cpu, &ocount), eErrorTypePOSIX);
+                    if (error.Fail() || log)
+                        error.PutToLog(log, "::posix_spawnattr_setbinpref_np ( &attr, 1, cpu_type = 0x%8.8x, count => %zu )", cpu, ocount);
 
-                if (error.Fail() != 0 || ocount != 1)
-                    return error;
+                    if (error.Fail() != 0 || ocount != 1)
+                        return error;
+                }
             }
 
 #endif
@@ -2175,9 +2179,11 @@
 ProcessGDBRemote::GetLibUnwindAddressSpace ()
 {
     unw_targettype_t target_type = UNW_TARGET_UNSPECIFIED;
-    if (m_target.GetArchitecture().GetCPUType() == CPU_TYPE_I386)
+
+    ArchSpec::CPU arch_cpu = m_target.GetArchitecture().GetGenericCPUType();
+    if (arch_cpu == ArchSpec::eCPU_i386)
         target_type = UNW_TARGET_I386;
-    if (m_target.GetArchitecture().GetCPUType() == CPU_TYPE_X86_64)
+    else if (arch_cpu == ArchSpec::eCPU_x86_64)
         target_type = UNW_TARGET_X86_64;
 
     if (m_libunwind_addr_space)