diff options
author | Greg Clayton <gclayton@apple.com> | 2010-06-11 03:25:34 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2010-06-11 03:25:34 +0000 |
commit | 41f923275eb15ac0b2fc9442f272fd6e4ed8f12a (patch) | |
tree | 51ee99af424e6a63af024889f2550151c3d5957e | |
parent | 9af2d4a6141c4bad8a9e53912469b5ff13079464 (diff) | |
download | bcm5719-llvm-41f923275eb15ac0b2fc9442f272fd6e4ed8f12a.tar.gz bcm5719-llvm-41f923275eb15ac0b2fc9442f272fd6e4ed8f12a.zip |
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.
llvm-svn: 105806
20 files changed, 487 insertions, 370 deletions
diff --git a/lldb/include/lldb/Core/ArchSpec.h b/lldb/include/lldb/Core/ArchSpec.h index 71b63f6b5b7..a4093d56211 100644 --- a/lldb/include/lldb/Core/ArchSpec.h +++ b/lldb/include/lldb/Core/ArchSpec.h @@ -28,6 +28,19 @@ namespace lldb_private { class ArchSpec { public: + // Generic CPU types that each m_type needs to know how to convert + // their m_cpu and m_sub to. + typedef enum CPU + { + eCPU_Unknown, + eCPU_arm, + eCPU_i386, + eCPU_x86_64, + eCPU_ppc, + eCPU_ppc64, + eCPU_sparc + }; + //------------------------------------------------------------------ /// Default constructor. /// @@ -42,7 +55,7 @@ public: /// Constructor that initializes the object with supplied cpu and /// subtypes. //------------------------------------------------------------------ - ArchSpec (uint32_t cpu, uint32_t sub); + ArchSpec (lldb::ArchitectureType arch_type, uint32_t cpu, uint32_t sub); //------------------------------------------------------------------ /// Construct with architecture name. @@ -108,7 +121,7 @@ public: /// freed. //------------------------------------------------------------------ static const char * - AsCString (uint32_t cpu, uint32_t subtype); + AsCString (lldb::ArchitectureType arch_type, uint32_t cpu, uint32_t subtype); //------------------------------------------------------------------ /// Clears the object state. @@ -127,6 +140,10 @@ public: uint32_t GetAddressByteSize () const; + + CPU + GetGenericCPUType () const; + //------------------------------------------------------------------ /// CPU subtype get accessor. /// @@ -194,7 +211,7 @@ public: /// String values that are returned do not need to be freed. //------------------------------------------------------------------ static const char * - GetRegisterName (uint32_t cpu, uint32_t subtype, uint32_t reg_num, uint32_t flavor); + GetRegisterName (lldb::ArchitectureType arch_type, uint32_t cpu, uint32_t subtype, uint32_t reg_num, uint32_t flavor); //------------------------------------------------------------------ /// Test if the contained architecture is valid. @@ -271,12 +288,22 @@ public: //------------------------------------------------------------------ lldb::ByteOrder GetDefaultEndian () const; + + + lldb::ArchitectureType + GetType() const + { + return m_type; + } + protected: //------------------------------------------------------------------ // Member variables //------------------------------------------------------------------ - uint32_t m_cpu; ///< The cpu type of the architecture - uint32_t m_sub; ///< The cpu subtype of the architecture + lldb::ArchitectureType m_type; + // m_type => eArchTypeMachO eArchTypeELF + uint32_t m_cpu; // cpu type ELF header e_machine + uint32_t m_sub; // cpu subtype nothing }; diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h index f9e5c2da111..8fcd98fde7e 100644 --- a/lldb/include/lldb/Symbol/ObjectFile.h +++ b/lldb/include/lldb/Symbol/ObjectFile.h @@ -33,15 +33,6 @@ namespace lldb_private { /// the same file, or archive files that contain multiple objects /// (ranlib archives) (possibly for multiple architectures as well). /// -/// It is possible to determine how many architectures an object file -/// contains by using the ObjectFile::GetNumArchitectures() const -/// accessor function. The individual architectures can be extracted -/// using the -/// ObjectFile::GetArchitectureAtIndex (uint32_t, ArchSpec&) const -/// function. The object file can also be asked to select one of these -/// architectures using the -/// ObjectFile::SetArchitecture (const ArchSpec&) function. -/// /// Object archive files (e.g. ranlib archives) can contain /// multiple .o (object) files that must be selected by index or by name. /// The number of objects that an ObjectFile contains can be determined diff --git a/lldb/include/lldb/lldb-enumerations.h b/lldb/include/lldb/lldb-enumerations.h index e63b1484483..e5f28b1a689 100644 --- a/lldb/include/lldb/lldb-enumerations.h +++ b/lldb/include/lldb/lldb-enumerations.h @@ -354,6 +354,15 @@ typedef enum InputReaderAction eInputReaderDone // reader was just popped off the stack and is done } InputReaderAction; + +typedef enum ArchitectureType +{ + eArchTypeInvalid, + eArchTypeMachO, + eArchTypeELF, + kNumArchTypes +} ArchitectureType; + } // namespace lldb diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index 9591635ed51..6c86a8dcfcc 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -527,7 +527,7 @@ 2676A093119C93C8008A98EF /* StringExtractorGDBRemote.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringExtractorGDBRemote.cpp; path = source/Utility/StringExtractorGDBRemote.cpp; sourceTree = "<group>"; }; 2676A094119C93C8008A98EF /* StringExtractorGDBRemote.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StringExtractorGDBRemote.h; path = source/Utility/StringExtractorGDBRemote.h; sourceTree = "<group>"; }; 2682F16A115EDA0D00CCFF99 /* PseudoTerminal.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PseudoTerminal.cpp; path = source/Utility/PseudoTerminal.cpp; sourceTree = "<group>"; }; - 2682F16B115EDA0D00CCFF99 /* PseudoTerminal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PseudoTerminal.h; path = source/Utility/PseudoTerminal.h; sourceTree = "<group>"; }; + 2682F16B115EDA0D00CCFF99 /* PseudoTerminal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PseudoTerminal.h; path = include/lldb/Utility/PseudoTerminal.h; sourceTree = "<group>"; }; 2682F284115EF3A700CCFF99 /* SBError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SBError.cpp; path = source/API/SBError.cpp; sourceTree = "<group>"; }; 2682F286115EF3BD00CCFF99 /* SBError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SBError.h; path = include/lldb/API/SBError.h; sourceTree = "<group>"; }; 2689B0A4113EE3CD00A4AEDB /* Symbols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Symbols.h; path = include/lldb/Host/Symbols.h; sourceTree = "<group>"; }; diff --git a/lldb/source/Core/ArchSpec.cpp b/lldb/source/Core/ArchSpec.cpp index 3cc8232ac97..132c5c1488a 100644 --- a/lldb/source/Core/ArchSpec.cpp +++ b/lldb/source/Core/ArchSpec.cpp @@ -9,43 +9,19 @@ #include "lldb/Core/ArchSpec.h" -#include <mach/mach.h> -#include <mach-o/nlist.h> +//#include <mach/mach.h> +//#include <mach-o/nlist.h> #include <string> +#include "llvm/Support/ELF.h" +#include "llvm/Support/MachO.h" + using namespace lldb; using namespace lldb_private; #define ARCH_SPEC_SEPARATOR_CHAR '-' -#ifndef CPU_TYPE_ARM -#define CPU_TYPE_ARM ((cpu_type_t) 12) -#endif - -#ifndef CPU_SUBTYPE_ARM_ALL -#define CPU_SUBTYPE_ARM_ALL ((cpu_subtype_t) 0) -#endif - -#ifndef CPU_SUBTYPE_ARM_V4T -#define CPU_SUBTYPE_ARM_V4T ((cpu_subtype_t) 5) -#endif - -#ifndef CPU_SUBTYPE_ARM_V6 -#define CPU_SUBTYPE_ARM_V6 ((cpu_subtype_t) 6) -#endif - -#ifndef CPU_SUBTYPE_ARM_V5TEJ -#define CPU_SUBTYPE_ARM_V5TEJ ((cpu_subtype_t) 7) -#endif - -#ifndef CPU_SUBTYPE_ARM_XSCALE -#define CPU_SUBTYPE_ARM_XSCALE ((cpu_subtype_t) 8) -#endif - -#ifndef CPU_SUBTYPE_ARM_V7 -#define CPU_SUBTYPE_ARM_V7 ((cpu_subtype_t) 9) -#endif //---------------------------------------------------------------------- // A structure that describes all of the information we want to know @@ -58,6 +34,16 @@ struct ArchDefinition const char *name; }; + +static const char *g_arch_type_strings[] = +{ + "invalid", + "mach-o", + "elf" +}; + +#define CPU_ANY (UINT32_MAX) + //---------------------------------------------------------------------- // A table that gets searched linearly for matches. This table is used // to convert cpu type and subtypes to architecture names, and to @@ -65,38 +51,38 @@ struct ArchDefinition // is important and allows the precedence to be set when the table is // built. //---------------------------------------------------------------------- -static ArchDefinition g_arch_defs[] = +static ArchDefinition g_mach_arch_defs[] = { - { CPU_TYPE_ANY, CPU_TYPE_ANY , "all" }, - { CPU_TYPE_ARM, CPU_TYPE_ANY , "arm" }, - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_ALL , "arm" }, - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V4T , "armv4" }, - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V5TEJ , "armv5" }, - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6 , "armv6" }, - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V7 , "armv7" }, - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_XSCALE , "xscale" }, - { CPU_TYPE_POWERPC, CPU_TYPE_ANY , "ppc" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_ALL , "ppc" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_601 , "ppc601" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_602 , "ppc602" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_603 , "ppc603" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_603e , "ppc603e" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_603ev , "ppc603ev" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_604 , "ppc604" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_604e , "ppc604e" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_620 , "ppc620" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_750 , "ppc750" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7400 , "ppc7400" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7450 , "ppc7450" }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_970 , "ppc970" }, - { CPU_TYPE_POWERPC64, CPU_SUBTYPE_POWERPC_ALL , "ppc64" }, - { CPU_TYPE_POWERPC64, CPU_SUBTYPE_POWERPC_970 , "ppc970-64" }, - { CPU_TYPE_I386, CPU_SUBTYPE_I386_ALL , "i386" }, - { CPU_TYPE_I386, CPU_SUBTYPE_486 , "i486" }, - { CPU_TYPE_I386, CPU_SUBTYPE_486SX , "i486sx" }, - { CPU_TYPE_I386, CPU_TYPE_ANY , "i386" }, - { CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL , "x86_64" }, - { CPU_TYPE_X86_64, CPU_TYPE_ANY , "x86_64" }, + { CPU_ANY, CPU_ANY , "all" }, + { llvm::MachO::CPUTypeARM, CPU_ANY , "arm" }, + { llvm::MachO::CPUTypeARM, 0 , "arm" }, + { llvm::MachO::CPUTypeARM, 5 , "armv4" }, + { llvm::MachO::CPUTypeARM, 6 , "armv6" }, + { llvm::MachO::CPUTypeARM, 7 , "armv5" }, + { llvm::MachO::CPUTypeARM, 8 , "xscale" }, + { llvm::MachO::CPUTypeARM, 9 , "armv7" }, + { llvm::MachO::CPUTypePowerPC, CPU_ANY , "ppc" }, + { llvm::MachO::CPUTypePowerPC, 0 , "ppc" }, + { llvm::MachO::CPUTypePowerPC, 1 , "ppc601" }, + { llvm::MachO::CPUTypePowerPC, 2 , "ppc602" }, + { llvm::MachO::CPUTypePowerPC, 3 , "ppc603" }, + { llvm::MachO::CPUTypePowerPC, 4 , "ppc603e" }, + { llvm::MachO::CPUTypePowerPC, 5 , "ppc603ev" }, + { llvm::MachO::CPUTypePowerPC, 6 , "ppc604" }, + { llvm::MachO::CPUTypePowerPC, 7 , "ppc604e" }, + { llvm::MachO::CPUTypePowerPC, 8 , "ppc620" }, + { llvm::MachO::CPUTypePowerPC, 9 , "ppc750" }, + { llvm::MachO::CPUTypePowerPC, 10 , "ppc7400" }, + { llvm::MachO::CPUTypePowerPC, 11 , "ppc7450" }, + { llvm::MachO::CPUTypePowerPC, 100 , "ppc970" }, + { llvm::MachO::CPUTypePowerPC64, 0 , "ppc64" }, + { llvm::MachO::CPUTypePowerPC64, 100 , "ppc970-64" }, + { llvm::MachO::CPUTypeI386, 3 , "i386" }, + { llvm::MachO::CPUTypeI386, 4 , "i486" }, + { llvm::MachO::CPUTypeI386, 0x84 , "i486sx" }, + { llvm::MachO::CPUTypeI386, CPU_ANY , "i386" }, + { llvm::MachO::CPUTypeX86_64, 3 , "x86_64" }, + { llvm::MachO::CPUTypeX86_64, CPU_ANY , "x86_64" }, // TODO: when we get a platform that knows more about the host OS we should // let it call some accessor funcitons to set the default system arch for @@ -104,29 +90,74 @@ static ArchDefinition g_arch_defs[] = // table. #if defined (__i386__) || defined(__x86_64__) - { CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL , LLDB_ARCH_DEFAULT }, - { CPU_TYPE_I386, CPU_SUBTYPE_I386_ALL , LLDB_ARCH_DEFAULT_32BIT }, - { CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL , LLDB_ARCH_DEFAULT_64BIT }, + { llvm::MachO::CPUTypeX86_64, 3 , LLDB_ARCH_DEFAULT }, + { llvm::MachO::CPUTypeI386, 3 , LLDB_ARCH_DEFAULT_32BIT }, + { llvm::MachO::CPUTypeX86_64, 3 , LLDB_ARCH_DEFAULT_64BIT }, #elif defined (__arm__) - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6 , LLDB_ARCH_DEFAULT }, - { CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6 , LLDB_ARCH_DEFAULT_32BIT }, + { llvm::MachO::CPUTypeARM, 6 , LLDB_ARCH_DEFAULT }, + { llvm::MachO::CPUTypeARM, 6 , LLDB_ARCH_DEFAULT_32BIT }, #elif defined (__powerpc__) || defined (__ppc__) || defined (__ppc64__) - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7400 , LLDB_ARCH_DEFAULT }, - { CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7400 , LLDB_ARCH_DEFAULT_32BIT }, - { CPU_TYPE_POWERPC64, CPU_SUBTYPE_POWERPC_970 , LLDB_ARCH_DEFAULT_64BIT }, + { llvm::MachO::CPUTypePowerPC, 10 , LLDB_ARCH_DEFAULT }, + { llvm::MachO::CPUTypePowerPC, 10 , LLDB_ARCH_DEFAULT_32BIT }, + { llvm::MachO::CPUTypePowerPC64, 100 , LLDB_ARCH_DEFAULT_64BIT }, #endif }; //---------------------------------------------------------------------- // Figure out how many architecture definitions we have //---------------------------------------------------------------------- -const size_t k_num_arch_defs = sizeof(g_arch_defs)/sizeof(ArchDefinition); +const size_t k_num_mach_arch_defs = sizeof(g_mach_arch_defs)/sizeof(ArchDefinition); + +//---------------------------------------------------------------------- +// A table that gets searched linearly for matches. This table is used +// to convert cpu type and subtypes to architecture names, and to +// convert architecture names to cpu types and subtypes. The ordering +// is important and allows the precedence to be set when the table is +// built. +//---------------------------------------------------------------------- +static ArchDefinition g_elf_arch_defs[] = +{ + { llvm::ELF::EM_M32 , 0, "m32" }, // AT&T WE 32100 + { llvm::ELF::EM_SPARC , 0, "sparc" }, // AT&T WE 32100 + { llvm::ELF::EM_386 , 0, "i386" }, // Intel 80386 + { llvm::ELF::EM_68K , 0, "68k" }, // Motorola 68000 + { llvm::ELF::EM_88K , 0, "88k" }, // Motorola 88000 + { llvm::ELF::EM_486 , 0, "i486" }, // Intel 486 (deprecated) + { llvm::ELF::EM_860 , 0, "860" }, // Intel 80860 + { llvm::ELF::EM_MIPS , 0, "rs3000" }, // MIPS RS3000 + { llvm::ELF::EM_PPC , 0, "ppc" }, // PowerPC + { 21 , 0, "ppc64" }, // PowerPC64 + { llvm::ELF::EM_ARM , 0, "arm" }, // ARM + { llvm::ELF::EM_ALPHA , 0, "alpha" }, // DEC Alpha + { llvm::ELF::EM_SPARCV9, 0, "sparc9" }, // SPARC V9 + { llvm::ELF::EM_X86_64 , 0, "x86_64" }, // AMD64 + +#if defined (__i386__) || defined(__x86_64__) + { llvm::ELF::EM_X86_64 , 0, LLDB_ARCH_DEFAULT }, + { llvm::ELF::EM_386 , 0, LLDB_ARCH_DEFAULT_32BIT }, + { llvm::ELF::EM_X86_64 , 0, LLDB_ARCH_DEFAULT_64BIT }, +#elif defined (__arm__) + { llvm::ELF::EM_ARM , 0, LLDB_ARCH_DEFAULT }, + { llvm::ELF::EM_ARM , 0, LLDB_ARCH_DEFAULT_32BIT }, +#elif defined (__powerpc__) || defined (__ppc__) || defined (__ppc64__) + { llvm::ELF::EM_PPC , 0, LLDB_ARCH_DEFAULT }, + { llvm::ELF::EM_PPC , 0, LLDB_ARCH_DEFAULT_32BIT }, + { llvm::ELF::EM_PPC64 , 0, LLDB_ARCH_DEFAULT_64BIT }, +#endif +}; + +//---------------------------------------------------------------------- +// Figure out how many architecture definitions we have +//---------------------------------------------------------------------- +const size_t k_num_elf_arch_defs = sizeof(g_elf_arch_defs)/sizeof(ArchDefinition); + //---------------------------------------------------------------------- // Default constructor //---------------------------------------------------------------------- ArchSpec::ArchSpec() : + m_type (eArchTypeMachO), // Use the most complete arch definition which will always be translatable to any other ArchitectureType values m_cpu (LLDB_INVALID_CPUTYPE), m_sub (0) { @@ -136,7 +167,8 @@ ArchSpec::ArchSpec() : // Constructor that initializes the object with supplied cpu and // subtypes. //---------------------------------------------------------------------- -ArchSpec::ArchSpec(uint32_t cpu, uint32_t sub) : +ArchSpec::ArchSpec (lldb::ArchitectureType arch_type, uint32_t cpu, uint32_t sub) : + m_type (arch_type), m_cpu (cpu), m_sub (sub) { @@ -156,12 +188,13 @@ ArchSpec::ArchSpec(uint32_t cpu, uint32_t sub) : // liblldb_ARCH_DEFAULT_32BIT // The 64 bit arch the current system defaults to (if any) //---------------------------------------------------------------------- -ArchSpec::ArchSpec(const char *arch_name) : +ArchSpec::ArchSpec (const char *arch_name) : + m_type (eArchTypeMachO), // Use the most complete arch definition which will always be translatable to any other ArchitectureType values m_cpu (LLDB_INVALID_CPUTYPE), m_sub (0) { if (arch_name) - SetArch(arch_name); + SetArch (arch_name); } //---------------------------------------------------------------------- @@ -179,6 +212,7 @@ ArchSpec::operator= (const ArchSpec& rhs) { if (this != &rhs) { + m_type = rhs.m_type; m_cpu = rhs.m_cpu; m_sub = rhs.m_sub; } @@ -191,7 +225,7 @@ ArchSpec::operator= (const ArchSpec& rhs) const char * ArchSpec::AsCString() const { - return ArchSpec::AsCString(m_cpu, m_sub); + return ArchSpec::AsCString(m_type, m_cpu, m_sub); } //---------------------------------------------------------------------- @@ -199,23 +233,55 @@ ArchSpec::AsCString() const // and subtype. //---------------------------------------------------------------------- const char * -ArchSpec::AsCString(uint32_t cpu, uint32_t sub) +ArchSpec::AsCString (lldb::ArchitectureType arch_type, uint32_t cpu, uint32_t sub) { - for (uint32_t i=0; i<k_num_arch_defs; i++) + if (arch_type >= kNumArchTypes) + return NULL; + + switch (arch_type) { - if (cpu == g_arch_defs[i].cpu) + case eArchTypeInvalid: + break; + + case eArchTypeMachO: + for (uint32_t i=0; i<k_num_mach_arch_defs; i++) + { + if (cpu == g_mach_arch_defs[i].cpu) + { + if (sub == g_mach_arch_defs[i].sub) + return g_mach_arch_defs[i].name; + else if (sub != CPU_ANY && sub != LLDB_INVALID_CPUTYPE) + { + if ((sub & 0x00ffffff) == g_mach_arch_defs[i].sub) + return g_mach_arch_defs[i].name; + } + } + } + break; + + case eArchTypeELF: + for (uint32_t i=0; i<k_num_elf_arch_defs; i++) { - if (sub == g_arch_defs[i].sub) - return g_arch_defs[i].name; - else if (sub != CPU_TYPE_ANY && sub != LLDB_INVALID_CPUTYPE) + if (cpu == g_elf_arch_defs[i].cpu) { - if ((sub & ~CPU_SUBTYPE_MASK) == g_arch_defs[i].sub) - return g_arch_defs[i].name; + if (sub == g_elf_arch_defs[i].sub) + return g_elf_arch_defs[i].name; } } + break; } - static char s_cpu_hex_str[64]; - ::snprintf(s_cpu_hex_str, sizeof(s_cpu_hex_str), "%u%c%u", cpu, ARCH_SPEC_SEPARATOR_CHAR, sub); + + const char *arch_type_cstr = g_arch_type_strings[arch_type]; + + static char s_cpu_hex_str[128]; + ::snprintf(s_cpu_hex_str, + sizeof(s_cpu_hex_str), + "%s%c%u%c%u", + arch_type_cstr, + ARCH_SPEC_SEPARATOR_CHAR, + cpu, + ARCH_SPEC_SEPARATOR_CHAR, + sub); return s_cpu_hex_str; } @@ -225,20 +291,27 @@ ArchSpec::AsCString(uint32_t cpu, uint32_t sub) void ArchSpec::Clear() { + m_type = eArchTypeInvalid; m_cpu = LLDB_INVALID_CPUTYPE; m_sub = 0; } + + //---------------------------------------------------------------------- // CPU subtype get accessor. //---------------------------------------------------------------------- uint32_t ArchSpec::GetCPUSubtype() const { - if (m_sub == CPU_TYPE_ANY || m_sub == LLDB_INVALID_CPUTYPE) - return m_sub; - return m_sub & ~CPU_SUBTYPE_MASK; + if (m_type == eArchTypeMachO) + { + if (m_sub == CPU_ANY || m_sub == LLDB_INVALID_CPUTYPE) + return m_sub; + return m_sub & 0xffffff; + } + return 0; } @@ -251,6 +324,50 @@ ArchSpec::GetCPUType() const return m_cpu; } +//---------------------------------------------------------------------- +// This function is designed to abstract us from having to know any +// details about the current m_type, m_cpu, and m_sub values and +// translate the result into a generic CPU type so LLDB core code can +// detect any CPUs that it supports. +//---------------------------------------------------------------------- +ArchSpec::CPU +ArchSpec::GetGenericCPUType () const +{ + switch (m_type) + { + case eArchTypeInvalid: + break; + + case eArchTypeMachO: + switch (m_cpu) + { + case llvm::MachO::CPUTypeARM: return eCPU_arm; + case llvm::MachO::CPUTypeI386: return eCPU_i386; + case llvm::MachO::CPUTypeX86_64: return eCPU_x86_64; + case llvm::MachO::CPUTypePowerPC: return eCPU_ppc; + case llvm::MachO::CPUTypePowerPC64: return eCPU_ppc64; + case llvm::MachO::CPUTypeSPARC: return eCPU_sparc; + } + break; + + case eArchTypeELF: + switch (m_cpu) + { + case llvm::ELF::EM_ARM: return eCPU_arm; + case llvm::ELF::EM_386: return eCPU_i386; + case llvm::ELF::EM_X86_64: return eCPU_x86_64; + case llvm::ELF::EM_PPC: return eCPU_ppc; + case 21: return eCPU_ppc64; + case llvm::ELF::EM_SPARC: return eCPU_sparc; + } + break; + } + + return eCPU_Unknown; +} + + + //---------------------------------------------------------------------- // Feature flags get accessor. @@ -258,9 +375,13 @@ ArchSpec::GetCPUType() const uint32_t ArchSpec::GetFeatureFlags() const { - if (m_sub == CPU_TYPE_ANY || m_sub == LLDB_INVALID_CPUTYPE) - return 0; - return m_sub & CPU_SUBTYPE_MASK; + if (m_type == eArchTypeMachO) + { + if (m_sub == CPU_ANY || m_sub == LLDB_INVALID_CPUTYPE) + return 0; + return m_sub & 0xff000000; + } + return 0; } @@ -897,7 +1018,7 @@ static const char * g_arm_gcc_reg_names[] = { const char * ArchSpec::GetRegisterName(uint32_t reg_num, uint32_t reg_kind) const { - return ArchSpec::GetRegisterName(m_cpu, m_sub, reg_num, reg_kind); + return ArchSpec::GetRegisterName(m_type, m_cpu, m_sub, reg_num, reg_kind); } @@ -906,9 +1027,10 @@ ArchSpec::GetRegisterName(uint32_t reg_num, uint32_t reg_kind) const // a register number, and a reg_kind for that register number. //---------------------------------------------------------------------- const char * -ArchSpec::GetRegisterName(uint32_t cpu, uint32_t subtype, uint32_t reg_num, uint32_t reg_kind) +ArchSpec::GetRegisterName (ArchitectureType arch_type, uint32_t cpu, uint32_t subtype, uint32_t reg_num, uint32_t reg_kind) { - if (cpu == CPU_TYPE_I386) + if ((arch_type == eArchTypeMachO && cpu == llvm::MachO::CPUTypeI386) || + (arch_type == eArchTypeELF && cpu == llvm::ELF::EM_386)) { switch (reg_kind) { @@ -924,7 +1046,8 @@ ArchSpec::GetRegisterName(uint32_t cpu, uint32_t subtype, uint32_t reg_num, uint break; } } - else if (cpu == CPU_TYPE_X86_64) + else if ((arch_type == eArchTypeMachO && cpu == llvm::MachO::CPUTypeX86_64) || + (arch_type == eArchTypeELF && cpu == llvm::ELF::EM_X86_64)) { switch (reg_kind) { @@ -937,7 +1060,8 @@ ArchSpec::GetRegisterName(uint32_t cpu, uint32_t subtype, uint32_t reg_num, uint break; } } - else if (cpu == CPU_TYPE_ARM) + else if ((arch_type == eArchTypeMachO && cpu == llvm::MachO::CPUTypeARM) || + (arch_type == eArchTypeELF && cpu == llvm::ELF::EM_ARM)) { switch (reg_kind) { @@ -1103,7 +1227,8 @@ ArchSpec::GetRegisterName(uint32_t cpu, uint32_t subtype, uint32_t reg_num, uint break; } } - else if (cpu == CPU_TYPE_POWERPC || cpu == CPU_TYPE_POWERPC64) + else if ((arch_type == eArchTypeMachO && (cpu == llvm::MachO::CPUTypePowerPC || cpu == llvm::MachO::CPUTypePowerPC64)) || + (arch_type == eArchTypeELF && cpu == llvm::ELF::EM_PPC)) { switch (reg_kind) { @@ -1479,9 +1604,41 @@ ArchSpec::IsValid() const uint32_t ArchSpec::GetAddressByteSize() const { - if (GetCPUType() & CPU_ARCH_ABI64) - return 8; - return 4; + switch (m_type) + { + case eArchTypeInvalid: + break; + + case eArchTypeMachO: + if (GetCPUType() & CPU_ARCH_ABI64) + return 8; + else + return 4; + break; + + case eArchTypeELF: + switch (m_cpu) + { + case llvm::ELF::EM_M32: + case llvm::ELF::EM_SPARC: + case llvm::ELF::EM_386: + case llvm::ELF::EM_68K: + case llvm::ELF::EM_88K: + case llvm::ELF::EM_486: + case llvm::ELF::EM_860: + case llvm::ELF::EM_MIPS: + case llvm::ELF::EM_PPC: + case llvm::ELF::EM_ARM: + case llvm::ELF::EM_ALPHA: + case llvm::ELF::EM_SPARCV9: + return 4; + case llvm::ELF::EM_X86_64: + return 8; + } + break; + } + + return 0; } //---------------------------------------------------------------------- @@ -1513,73 +1670,104 @@ ArchSpec::SetArchFromTargetTriple (const char *target_triple) // Change the CPU type and subtype given an architecture name. //---------------------------------------------------------------------- bool -ArchSpec::SetArch(const char *arch_name) +ArchSpec::SetArch (const char *arch_name) { if (arch_name && arch_name[0] != '\0') { size_t i; - // Search for ARCH_NAME in our architecture definitions structure - for (i=0; i<k_num_arch_defs; ++i) + + switch (m_type) { - if (strcasecmp(arch_name, g_arch_defs[i].name) == 0) + case eArchTypeInvalid: + case eArchTypeMachO: + for (i=0; i<k_num_mach_arch_defs; i++) { - // we found a match - m_cpu = g_arch_defs[i].cpu; - m_sub = g_arch_defs[i].sub; - return true; + if (strcasecmp(arch_name, g_mach_arch_defs[i].name) == 0) + { + m_type = eArchTypeMachO; + m_cpu = g_mach_arch_defs[i].cpu; + m_sub = g_mach_arch_defs[i].sub; + return true; + } + } + break; + + case eArchTypeELF: + for (i=0; i<k_num_elf_arch_defs; i++) + { + if (strcasecmp(arch_name, g_elf_arch_defs[i].name) == 0) + { + m_cpu = g_elf_arch_defs[i].cpu; + m_sub = g_elf_arch_defs[i].sub; + return true; + } } + break; } - const char *str = arch_name; - char *end = NULL; - // Check for a numeric cpu followed by an optional '.' and numeric subtype. + // Check for a numeric cpu followed by an optional separator char and numeric subtype. // This allows for support of new cpu type/subtypes without having to have // a recompiled debug core. // Examples: // "12.6" is armv6 - // "0x0000000c.0x00000006" is also armv6 - m_cpu = strtoul(str, &end, 0); - if (str != end) + // "0x0000000c-0x00000006" is also armv6 + + m_type = eArchTypeInvalid; + for (i=1; i<kNumArchTypes; ++i) + { + const char *arch_type_cstr = g_arch_type_strings[i]; + if (strstr(str, arch_type_cstr)) + { + m_type = (ArchitectureType)i; + str += strlen(arch_type_cstr) + 1; // Also skip separator char + } + } + + if (m_type != eArchTypeInvalid) { - if (*end == '.') + char *end = NULL; + m_cpu = ::strtoul (str, &end, 0); + if (str != end) { - // We have a cputype.cpusubtype format - str = end + 1; - if (*str != '\0') + if (*end == ARCH_SPEC_SEPARATOR_CHAR) { - m_sub = strtoul(str, &end, 0); - if (*end == '\0') + // We have a cputype.cpusubtype format + str = end + 1; + if (*str != '\0') { - // We consumed the entire string and got a cpu type and subtype - return true; + m_sub = strtoul(str, &end, 0); + if (*end == '\0') + { + // We consumed the entire string and got a cpu type and subtype + return true; + } } } - } - // If we reach this point we have a valid cpu type, but no cpu subtype. - // Search for the first matching cpu type and use the corresponding cpu - // subtype. This setting should typically be the _ALL variant and should - // appear first in the list for each cpu type in the g_arch_defs - // structure. - for (i=0; i<k_num_arch_defs; ++i) - { - if (m_cpu == g_arch_defs[i].cpu) + // If we reach this point we have a valid cpu type, but no cpu subtype. + // Search for the first matching cpu type and use the corresponding cpu + // subtype. This setting should typically be the _ALL variant and should + // appear first in the list for each cpu type in the g_mach_arch_defs + // structure. + for (i=0; i<k_num_mach_arch_defs; ++i) { - m_sub = g_arch_defs[i].sub; - return true; + if (m_cpu == g_mach_arch_defs[i].cpu) + { + m_sub = g_mach_arch_defs[i].sub; + return true; + } } - } - // Default the cpu subtype to zero when we don't have a matching - // cpu type in our architecture defs structure (g_arch_defs). - m_sub = 0; - return true; + // Default the cpu subtype to zero when we don't have a matching + // cpu type in our architecture defs structure (g_mach_arch_defs). + m_sub = 0; + return true; + } } } - m_cpu = LLDB_INVALID_CPUTYPE; - m_sub = 0; + Clear(); return false; } @@ -1616,13 +1804,13 @@ ArchSpec::GetDefaultEndian () const { switch (m_cpu) { - case CPU_TYPE_POWERPC: - case CPU_TYPE_POWERPC64: + case llvm::MachO::CPUTypePowerPC: + case llvm::MachO::CPUTypePowerPC64: return eByteOrderBig; - case CPU_TYPE_ARM: - case CPU_TYPE_I386: - case CPU_TYPE_X86_64: + case llvm::MachO::CPUTypeARM: + case llvm::MachO::CPUTypeI386: + case llvm::MachO::CPUTypeX86_64: return eByteOrderLittle; default: @@ -1640,14 +1828,14 @@ lldb_private::operator== (const ArchSpec& lhs, const ArchSpec& rhs) uint32_t lhs_cpu = lhs.GetCPUType(); uint32_t rhs_cpu = rhs.GetCPUType(); - if (lhs_cpu == CPU_TYPE_ANY || rhs_cpu == CPU_TYPE_ANY) + if (lhs_cpu == CPU_ANY || rhs_cpu == CPU_ANY) return true; else if (lhs_cpu == rhs_cpu) { uint32_t lhs_subtype = lhs.GetCPUSubtype(); uint32_t rhs_subtype = rhs.GetCPUSubtype(); - if (lhs_subtype == CPU_TYPE_ANY || rhs_subtype == CPU_TYPE_ANY) + if (lhs_subtype == CPU_ANY || rhs_subtype == CPU_ANY) return true; return lhs_subtype == rhs_subtype; } diff --git a/lldb/source/Host/macosx/Symbols.cpp b/lldb/source/Host/macosx/Symbols.cpp index ff28157258b..2b8026f7985 100644 --- a/lldb/source/Host/macosx/Symbols.cpp +++ b/lldb/source/Host/macosx/Symbols.cpp @@ -65,7 +65,7 @@ SkinnyMachOFileContainsArchAndUUID // Check the architecture if we have a valid arch pointer if (arch) { - ArchSpec file_arch(cputype, cpusubtype); + ArchSpec file_arch(eArchTypeMachO, cputype, cpusubtype); if (file_arch != *arch) return false; @@ -150,7 +150,7 @@ UniversalMachOFileContainsArchAndUUID // Only process this slice if the cpu type/subtype matches if (arch) { - ArchSpec fat_arch(arch_cputype, arch_cpusubtype); + ArchSpec fat_arch(eArchTypeMachO, arch_cputype, arch_cpusubtype); if (fat_arch != *arch) continue; } diff --git a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp index db2d561b24a..510f55baca6 100644 --- a/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp +++ b/lldb/source/Plugins/Disassembler/llvm/DisassemblerLLVM.cpp @@ -313,54 +313,50 @@ DisassemblerLLVM::Instruction::Extract(const DataExtractor &data, uint32_t data_ } static inline const char * -TripleForCPU(cpu_type_t cpuType) +TripleForArchSpec (const ArchSpec &arch, char *triple, size_t triple_len) { - switch (cpuType) + const char *arch_name = arch.AsCString(); + + if (arch_name) { - default: - return NULL; - case CPU_TYPE_X86: - return "i386-unknown-unknown"; - case CPU_TYPE_X86_64: - return "x86_64-unknown-unknown"; + snprintf(triple, triple_len, "%s-unknown-unknown", arch_name); + return triple; } + return NULL; } static inline EDAssemblySyntax_t -SyntaxForCPU(cpu_type_t cpuType) +SyntaxForArchSpec (const ArchSpec &arch) { - switch (cpuType) - { - default: - return (EDAssemblySyntax_t)0; // default - case CPU_TYPE_X86: - case CPU_TYPE_X86_64: + const char *arch_name = arch.AsCString(); + + if (arch_name != NULL && + ((strcasestr (arch_name, "i386") == arch_name) || + (strcasestr (arch_name, "x86_64") == arch_name))) return kEDAssemblySyntaxX86ATT; - } + + return (EDAssemblySyntax_t)0; // default } Disassembler * DisassemblerLLVM::CreateInstance(const ArchSpec &arch) { - cpu_type_t cpuType = arch.GetCPUType(); + char triple[256]; - if (TripleForCPU(cpuType)) - return new DisassemblerLLVM(arch); - else - return NULL; + if (TripleForArchSpec (arch, triple, sizeof(triple))) + return new DisassemblerLLVM(triple); + return NULL; } DisassemblerLLVM::DisassemblerLLVM(const ArchSpec &arch) : Disassembler(arch) { - cpu_type_t cpuType = arch.GetCPUType(); - - const char *triple = TripleForCPU(cpuType); - assert(triple && "Unhandled CPU type!"); - - EDAssemblySyntax_t syntax = SyntaxForCPU(cpuType); - - assert(!EDGetDisassembler(&m_disassembler, triple, syntax) && "No disassembler created!"); + char triple[256]; + if (TripleForArchSpec (arch, triple, sizeof(triple))) + { + EDAssemblySyntax_t syntax = SyntaxForArchSpec (arch); + assert(!EDGetDisassembler(&m_disassembler, triple, syntax) && "No disassembler created!"); + } } DisassemblerLLVM::~DisassemblerLLVM() diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp index b55aeb9877b..3166887aaf2 100644 --- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp @@ -199,7 +199,7 @@ DynamicLoaderMacOSXDYLD::ReadDYLDInfoFromMemoryAndSetNotificationCallback(lldb:: { if (m_dyld.file_spec) { - ArchSpec dyld_arch(m_dyld.header.cputype, m_dyld.header.cpusubtype); + ArchSpec dyld_arch(eArchTypeMachO, m_dyld.header.cputype, m_dyld.header.cpusubtype); dyld_module_sp = m_process->GetTarget().GetImages().FindFirstModuleForFileSpec (m_dyld.file_spec); if (dyld_module_sp.get() == NULL || dyld_module_sp->GetArchitecture() != dyld_arch) @@ -591,7 +591,7 @@ DynamicLoaderMacOSXDYLD::UpdateAllImageInfos() ModuleList loaded_module_list; for (uint32_t idx = 0; idx<num_dylibs; ++idx) { - ArchSpec arch_spec(m_dyld_image_infos[idx].header.cputype, m_dyld_image_infos[idx].header.cpusubtype); + ArchSpec arch_spec(eArchTypeMachO, m_dyld_image_infos[idx].header.cputype, m_dyld_image_infos[idx].header.cpusubtype); ModuleSP image_module_sp(m_process->GetTarget().GetImages().FindFirstModuleForFileSpec (m_dyld_image_infos[idx].file_spec)); if (image_module_sp.get() == NULL || image_module_sp->GetArchitecture() != arch_spec) { @@ -829,7 +829,7 @@ DynamicLoaderMacOSXDYLD::UpdateAllImageInfosHeaderAndLoadCommands() if (exe_idx < m_dyld_image_infos.size()) { bool set_executable = false; - ArchSpec dyld_exe_arch_spec(m_dyld_image_infos[exe_idx].header.cputype, m_dyld_image_infos[exe_idx].header.cpusubtype); + ArchSpec dyld_exe_arch_spec(eArchTypeMachO, m_dyld_image_infos[exe_idx].header.cputype, m_dyld_image_infos[exe_idx].header.cpusubtype); ModuleSP exe_module_sp(m_process->GetTarget().GetExecutableModule()); if (exe_module_sp.get()) { diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp index b34dd3db289..6a5b5f32eb6 100644 --- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -25,8 +25,6 @@ #define CASE_AND_STREAM(s, def, width) case def: s->Printf("%-*s", width, #def); break; -static uint32_t ELFMachineToMachCPU(Elf32_Half machine); - using namespace lldb; using namespace lldb_private; using namespace std; @@ -824,24 +822,6 @@ ObjectFileELF::DumpELFSectionHeaders(Stream *s) } } -static uint32_t -ELFMachineToMachCPU(Elf32_Half machine) -{ - switch (machine) - { - case EM_SPARC: return CPU_TYPE_SPARC; - case EM_386: return CPU_TYPE_I386; - case EM_68K: return CPU_TYPE_MC680x0; - case EM_88K: return CPU_TYPE_MC88000; - case EM_860: return CPU_TYPE_I860; - case EM_MIPS: return 8; // commented out in mach/machine.h - case EM_PPC: return CPU_TYPE_POWERPC; - case EM_PPC64: return CPU_TYPE_POWERPC64; - case EM_ARM: return 12; // commented out in mach/machine.h - } - return 0; -} - bool ObjectFileELF::GetTargetTriple (ConstString &target_triple) { @@ -866,10 +846,10 @@ ObjectFileELF::GetTargetTriple (ConstString &target_triple) case EM_PPC64: triple.assign("powerpc64-"); break; case EM_ARM: triple.assign("arm-"); break; } - // TODO: determine if there is a vendor in the ELF? Default to "apple" for now - triple += "apple-"; - // TODO: determine if there is an OS in the ELF? Default to "darwin" for now - triple += "darwin10"; + // TODO: determine if there is a vendor in the ELF? Default to "linux" for now + triple += "linux-"; + // TODO: determine if there is an OS in the ELF? Default to "gnu" for now + triple += "gnu"; g_target_triple.SetCString(triple.c_str()); target_triple = g_target_triple; } @@ -877,14 +857,6 @@ ObjectFileELF::GetTargetTriple (ConstString &target_triple) } -//bool -//ELF32RuntimeFileParser::GetArch(ArchSpec &arch) const -//{ -// arch.SetCPUType(ELFMachineToMachCPU(m_header.e_machine)); -// arch.SetCPUSubtype(ArchSpec::eAny); -// return true; -//} - //------------------------------------------------------------------ // PluginInterface protocol //------------------------------------------------------------------ diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 682a116d213..21860e1e4fb 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -171,7 +171,7 @@ ObjectFileMachO::ParseHeader () { m_data.GetU32(&offset, &m_header.cputype, 6); - ArchSpec mach_arch(m_header.cputype, m_header.cpusubtype); + ArchSpec mach_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype); if (mach_arch == m_module->GetArchitecture()) { // Read in all only the load command data @@ -1168,7 +1168,7 @@ ObjectFileMachO::Dump (Stream *s) else s->PutCString("ObjectFileMachO32"); - ArchSpec header_arch(m_header.cputype, m_header.cpusubtype); + ArchSpec header_arch(eArchTypeMachO, m_header.cputype, m_header.cpusubtype); *s << ", file = '" << m_file << "', arch = " << header_arch.AsCString() << "\n"; diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp index 4f6b17c81a2..28a28c71b0d 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.cpp @@ -94,13 +94,6 @@ MachThreadContext_arm::InitializeInstance() } - -uint32_t -MachThreadContext_arm::GetCPUType() -{ - return CPU_TYPE_ARM; -} - void MachThreadContext_arm::ThreadWillResume() { @@ -1879,6 +1872,6 @@ MachThreadContext_arm::Create (const ArchSpec &arch_spec, ThreadMacOSX &thread) 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/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h index 4ec72dfd0d4..333efee00ab 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_arm.h @@ -46,9 +46,6 @@ public: virtual void RefreshStateAfterStop (); - static uint32_t - GetCPUType (); - protected: kern_return_t EnableHardwareSingleStep (bool enable); diff --git a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp index ea148a69f41..03b5c2a4fb2 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.cpp @@ -55,13 +55,6 @@ MachThreadContext_i386::InitializeInstance() 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/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h index 4bee2e7be8f..7da2259af7f 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_i386.h @@ -40,7 +40,6 @@ public: 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/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp index 3ee9eb419de..7eaa8f46aa2 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.cpp @@ -54,12 +54,6 @@ MachThreadContext_x86_64::InitializeInstance() 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/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h index 45d5a375052..f4fc130000c 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h +++ b/lldb/source/Plugins/Process/MacOSX-User/source/MacOSX/MachThreadContext_x86_64.h @@ -54,9 +54,6 @@ public: 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/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp index 0116f006ffd..d887b09dd3a 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/ProcessMacOSX.cpp @@ -532,31 +532,32 @@ ProcessMacOSX::GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) 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 @@ ProcessMacOSX::PosixSpawnChildForPTraceDebugging // 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/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp b/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp index 37472547f55..5909bc42211 100644 --- a/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp +++ b/lldb/source/Plugins/Process/MacOSX-User/source/RegisterContextMach_arm.cpp @@ -1153,38 +1153,14 @@ RegisterContextMach_arm::NumSupportedHardwareBreakpoints () // 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 @@ RegisterContextMach_arm::NumSupportedHardwareWatchpoints () { // 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/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp b/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp index 58a7ac043c5..e6c7b354abc 100644 --- a/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp +++ b/lldb/source/Plugins/Process/Utility/MacOSXLibunwindCallbacks.cpp @@ -250,15 +250,16 @@ instruction_length (lldb_private::unw_addr_space_t as, lldb_private::unw_word_t 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/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index e8b194e26de..8bf90c2c22b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -875,31 +875,32 @@ ProcessGDBRemote::GetSoftwareBreakpointTrapOpcode (BreakpointSite* bp_site) 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 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; + 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; + + default: + assert(!"Unhandled architecture in ProcessMacOSX::GetSoftwareBreakpointTrapOpcode()"); + break; } if (trap_opcode && trap_opcode_size) @@ -1719,16 +1720,19 @@ ProcessGDBRemote::StartDebugserverProcess // 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 @@ lldb_private::unw_addr_space_t 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) |