lldb: remove adhoc implementation of array_sizeof
authorSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 27 Jun 2014 05:17:41 +0000 (05:17 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 27 Jun 2014 05:17:41 +0000 (05:17 +0000)
Replace adhoc inline implementation of llvm::array_lengthof in favour of the
implementation in LLVM.  This is simply a cleanup change, no functional change
intended.

llvm-svn: 211868

31 files changed:
lldb/source/Commands/CommandObjectExpression.cpp
lldb/source/Commands/CommandObjectRegister.cpp
lldb/source/Core/ArchSpec.cpp
lldb/source/Core/Language.cpp
lldb/source/DataFormatters/FormatManager.cpp
lldb/source/Host/common/Host.cpp
lldb/source/Host/common/Terminal.cpp
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/source/Interpreter/OptionValueBoolean.cpp
lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp
lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp
lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp
lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp
lldb/source/Plugins/Instruction/ARM/EmulateInstructionARM.cpp
lldb/source/Plugins/Instruction/ARM64/EmulateInstructionARM64.cpp
lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_i386.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_x86_64.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/source/Utility/SharingPtr.cpp
lldb/tools/debugserver/source/DNB.cpp
lldb/tools/debugserver/source/MacOSX/MachThreadList.cpp
lldb/tools/debugserver/source/MacOSX/arm/DNBArchImpl.cpp
lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp
lldb/tools/debugserver/source/MacOSX/i386/DNBArchImplI386.cpp
lldb/tools/debugserver/source/MacOSX/ppc/DNBArchImpl.cpp
lldb/tools/debugserver/source/MacOSX/x86_64/DNBArchImplX86_64.cpp
lldb/tools/debugserver/source/TTYState.h
lldb/tools/lldb-perf/common/clang/lldb_perf_clang.cpp

index 28fd322..bfce324 100644 (file)
@@ -34,6 +34,7 @@
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 
 using namespace lldb;
@@ -71,7 +72,7 @@ CommandObjectExpression::CommandOptions::g_option_table[] =
 uint32_t
 CommandObjectExpression::CommandOptions::GetNumDefinitions ()
 {
-    return sizeof(g_option_table)/sizeof(OptionDefinition);
+    return llvm::array_lengthof(g_option_table);
 }
 
 Error
index 035fcf9..9c7c350 100644 (file)
@@ -31,6 +31,7 @@
 #include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/SectionLoadList.h"
 #include "lldb/Target/Thread.h"
+#include "llvm/ADT/STLExtras.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -360,7 +361,7 @@ CommandObjectRegisterRead::CommandOptions::g_option_table[] =
 uint32_t
 CommandObjectRegisterRead::CommandOptions::GetNumDefinitions ()
 {
-    return sizeof(g_option_table)/sizeof(OptionDefinition);
+    return llvm::array_lengthof(g_option_table);
 }
 
 
index 8276469..f9db53b 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <string>
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/COFF.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/Host.h"
@@ -227,7 +228,7 @@ static const ArchDefinitionEntry g_macho_arch_entries[] =
 };
 static const ArchDefinition g_macho_arch_def = {
     eArchTypeMachO,
-    sizeof(g_macho_arch_entries)/sizeof(g_macho_arch_entries[0]),
+    llvm::array_lengthof(g_macho_arch_entries),
     g_macho_arch_entries,
     "mach-o"
 };
@@ -253,7 +254,7 @@ static const ArchDefinitionEntry g_elf_arch_entries[] =
 
 static const ArchDefinition g_elf_arch_def = {
     eArchTypeELF,
-    sizeof(g_elf_arch_entries)/sizeof(g_elf_arch_entries[0]),
+    llvm::array_lengthof(g_elf_arch_entries),
     g_elf_arch_entries,
     "elf",
 };
@@ -271,7 +272,7 @@ static const ArchDefinitionEntry g_coff_arch_entries[] =
 
 static const ArchDefinition g_coff_arch_def = {
     eArchTypeCOFF,
-    sizeof(g_coff_arch_entries)/sizeof(g_coff_arch_entries[0]),
+    llvm::array_lengthof(g_coff_arch_entries),
     g_coff_arch_entries,
     "pe-coff",
 };
@@ -284,8 +285,7 @@ static const ArchDefinition *g_arch_definitions[] = {
     &g_coff_arch_def
 };
 
-static const size_t k_num_arch_definitions =
-    sizeof(g_arch_definitions) / sizeof(g_arch_definitions[0]);
+static const size_t k_num_arch_definitions = llvm::array_lengthof(g_arch_definitions);
 
 //===----------------------------------------------------------------------===//
 // Static helper functions.
index af62af3..1ffd5aa 100644 (file)
@@ -10,6 +10,7 @@
 #include "lldb/lldb-private.h"
 #include "lldb/Core/Language.h"
 #include "lldb/Core/Stream.h"
+#include "llvm/ADT/STLExtras.h"
 #include <string.h>
 
 using namespace lldb;
@@ -48,8 +49,7 @@ g_languages[] =
     { { "python"  , NULL          , "Python"              } }
 };
 
-static const size_t
-g_num_languages = sizeof(g_languages)/sizeof(LanguageStrings);
+static const size_t g_num_languages = llvm::array_lengthof(g_languages);
 
 Language::Language(LanguageType language) :
     m_language (language)
index f3146b9..1571837 100644 (file)
@@ -21,6 +21,7 @@
 #include "lldb/Interpreter/ScriptInterpreterPython.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Platform.h"
+#include "llvm/ADT/STLExtras.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -76,8 +77,7 @@ g_format_infos[] =
     { eFormatVoid           , 'v'   , "void"                }
 };
 
-static uint32_t 
-g_num_format_infos = sizeof(g_format_infos)/sizeof(FormatInfo);
+static uint32_t g_num_format_infos = llvm::array_lengthof(g_format_infos);
 
 static bool
 GetFormatFromFormatChar (char format_char, Format &format)
index 77341b1..edd64c6 100644 (file)
@@ -66,6 +66,7 @@
 #include "lldb/Target/TargetList.h"
 #include "lldb/Utility/CleanUp.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/raw_ostream.h"
@@ -2063,7 +2064,7 @@ Host::GetNumberCPUS ()
 #endif
         
         /* get the number of CPUs from the system */
-        if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
+        if (sysctl(mib, llvm::array_lengthof(mib), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
         {
             g_num_cores = num_cores;
         }
@@ -2071,7 +2072,7 @@ Host::GetNumberCPUS ()
         {
             mib[1] = HW_NCPU;
             num_cores_len = sizeof(num_cores);
-            if (sysctl(mib, sizeof(mib)/sizeof(int), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
+            if (sysctl(mib, llvm::array_lengthof(mib), &num_cores, &num_cores_len, NULL, 0) == 0 && (num_cores > 0))
             {
                 if (num_cores > 0)
                     g_num_cores = num_cores;
index 811d712..ca46eb0 100644 (file)
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "lldb/Host/Terminal.h"
+#include "llvm/ADT/STLExtras.h"
 
 #include <fcntl.h>
 #include <signal.h>
@@ -274,7 +275,7 @@ TerminalStateSwitcher::~TerminalStateSwitcher ()
 uint32_t
 TerminalStateSwitcher::GetNumberOfStates() const
 {
-    return sizeof(m_ttystates)/sizeof(TerminalState);
+    return llvm::array_lengthof(m_ttystates);
 }
 
 //------------------------------------------------------------------
index 0fca4f2..959b90f 100644 (file)
@@ -67,6 +67,8 @@
 
 #include "lldb/Utility/CleanUp.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -417,7 +419,7 @@ CommandInterpreter::LoadCommandDictionary ()
                                       {"^\\&(.*[^[:space:]])[[:space:]]*$", "breakpoint set --name '%1' --skip-prologue=0"},
                                       {"^(.*[^[:space:]])[[:space:]]*$", "breakpoint set --name '%1'"}};
     
-    size_t num_regexes = sizeof break_regexes/sizeof(char *[2]);
+    size_t num_regexes = llvm::array_lengthof(break_regexes);
         
     std::unique_ptr<CommandObjectRegexCommand>
     break_regex_cmd_ap(new CommandObjectRegexCommand (*this,
index de8af04..bf153a1 100644 (file)
@@ -16,6 +16,7 @@
 #include "lldb/Core/Stream.h"
 #include "lldb/Core/StringList.h"
 #include "lldb/Interpreter/Args.h"
+#include "llvm/ADT/STLExtras.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -110,7 +111,7 @@ OptionValueBoolean::AutoComplete (CommandInterpreter &interpreter,
         { "1"    , 1 },
         { "0"    , 1 },
     };
-    const size_t k_num_autocomplete_entries = sizeof(g_autocomplete_entries)/sizeof(StringEntry);
+    const size_t k_num_autocomplete_entries = llvm::array_lengthof(g_autocomplete_entries);
     
     if (s && s[0])
     {
index c884b84..a9f8f3b 100644 (file)
@@ -24,6 +24,7 @@
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Triple.h"
 
 #include "Utility/ARM_DWARF_Registers.h"
@@ -144,7 +145,7 @@ static RegisterInfo g_register_infos[] =
     {   "r13_svc", "sp_svc",  4, 0, eEncodingUint    , eFormatHex,   { LLDB_INVALID_REGNUM,  dwarf_r13_svc,      LLDB_INVALID_REGNUM,        LLDB_INVALID_REGNUM,    LLDB_INVALID_REGNUM },      NULL,              NULL},
     {   "r14_svc", "lr_svc",  4, 0, eEncodingUint    , eFormatHex,   { LLDB_INVALID_REGNUM,  dwarf_r14_svc,      LLDB_INVALID_REGNUM,        LLDB_INVALID_REGNUM,    LLDB_INVALID_REGNUM },      NULL,              NULL}
 };
-static const uint32_t k_num_register_infos = sizeof(g_register_infos)/sizeof(RegisterInfo);
+static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 static bool g_register_info_names_constified = false;
 
 const lldb_private::RegisterInfo *
@@ -214,7 +215,7 @@ ABIMacOSX_arm::PrepareTrivialCall (Thread &thread,
     
     llvm::ArrayRef<addr_t>::iterator ai = args.begin(), ae = args.end();
     
-    for (size_t i = 0; i < (sizeof(reg_names) / sizeof(reg_names[0])); ++i)
+    for (size_t i = 0; i < llvm::array_lengthof(reg_names); ++i)
     {
         if (ai == ae)
             break;
index a964ebd..05b16e2 100644 (file)
@@ -26,7 +26,7 @@
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
 
-
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Triple.h"
 
 #include "Utility/ARM64_DWARF_Registers.h"
@@ -182,7 +182,7 @@ static RegisterInfo g_register_infos[] =
     {   "d31",     NULL,     8, 0, eEncodingIEEE754 , eFormatFloat         , { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,    LLDB_INVALID_REGNUM,        LLDB_INVALID_REGNUM,    LLDB_INVALID_REGNUM }, NULL, NULL }
 };
 
-static const uint32_t k_num_register_infos = sizeof(g_register_infos)/sizeof(RegisterInfo);
+static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 static bool g_register_info_names_constified = false;
 
 const lldb_private::RegisterInfo *
index 1783489..9a1ea11 100644 (file)
@@ -199,7 +199,7 @@ static RegisterInfo g_register_infos[] =
     { "ymm7"  , NULL,   32,  0, eEncodingVector, eFormatVectorOfUInt8, { LLDB_INVALID_REGNUM , dwarf_ymm7          , LLDB_INVALID_REGNUM       , gdb_ymm7           , LLDB_INVALID_REGNUM },      NULL,              NULL}
 };
 
-static const uint32_t k_num_register_infos = sizeof(g_register_infos)/sizeof(RegisterInfo);
+static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 static bool g_register_info_names_constified = false;
 
 const lldb_private::RegisterInfo *
index 1316da4..b537415 100644 (file)
@@ -28,6 +28,7 @@
 #include "lldb/Target/StackFrame.h"
 #include "lldb/Target/Thread.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Triple.h"
 
 using namespace lldb;
@@ -251,7 +252,7 @@ static RegisterInfo g_register_infos[] =
     { "ymm15" , NULL,   32,  0, eEncodingVector, eFormatVectorOfUInt8, { gcc_dwarf_ymm15     , gcc_dwarf_ymm15     , LLDB_INVALID_REGNUM       , gdb_ymm15          , LLDB_INVALID_REGNUM },      NULL,              NULL}
 };
 
-static const uint32_t k_num_register_infos = sizeof(g_register_infos)/sizeof(RegisterInfo);
+static const uint32_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 static bool g_register_info_names_constified = false;
 
 const lldb_private::RegisterInfo *
index bbd534e..618f3f3 100644 (file)
@@ -24,6 +24,7 @@
 #include "Plugins/Process/Utility/ARMUtils.h"
 #include "Utility/ARM_DWARF_Registers.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MathExtras.h" // for SignExtend32 template function
                                      // and countTrailingZeros function
 
@@ -12506,7 +12507,7 @@ EmulateInstructionARM::GetARMOpcodeForInstruction (const uint32_t opcode, uint32
         { 0xfe500000, 0xf8100000, ARMV6_ABOVE,  eEncodingA1, No_VFP, eSize32, &EmulateInstructionARM::EmulateRFE, "rfe{<amode>} <Rn>{!}" }
                   
     };
-    static const size_t k_num_arm_opcodes = sizeof(g_arm_opcodes)/sizeof(ARMOpcode);
+    static const size_t k_num_arm_opcodes = llvm::array_lengthof(g_arm_opcodes);
                   
     for (size_t i=0; i<k_num_arm_opcodes; ++i)
     {
@@ -12832,7 +12833,7 @@ EmulateInstructionARM::GetThumbOpcodeForInstruction (const uint32_t opcode, uint
         { 0xfffff080, 0xfa1ff080, ARMV6T2_ABOVE, eEncodingT2, No_VFP, eSize32, &EmulateInstructionARM::EmulateUXTH, "uxth<c>.w <Rd>,<Rm>{,<rotation>}" },
     };
 
-    const size_t k_num_thumb_opcodes = sizeof(g_thumb_opcodes)/sizeof(ARMOpcode);
+    const size_t k_num_thumb_opcodes = llvm::array_lengthof(g_thumb_opcodes);
     for (size_t i=0; i<k_num_thumb_opcodes; ++i)
     {
         if ((g_thumb_opcodes[i].mask & opcode) == g_thumb_opcodes[i].value &&
index a432069..a987e96 100644 (file)
@@ -22,6 +22,7 @@
 #include "Plugins/Process/Utility/ARMUtils.h"
 #include "Utility/ARM64_DWARF_Registers.h"
 
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/MathExtras.h" // for SignExtend32 template function
                                      // and CountTrailingZeros_32 function
 
@@ -254,7 +255,7 @@ EmulateInstructionARM64::GetOpcodeForInstruction (const uint32_t opcode)
         { 0xffc00000, 0xa9800000, No_VFP, &EmulateInstructionARM64::Emulate_ldstpair_pre, "STP  <Xt>, <Xt2>, [<Xn|SP>, #<imm>]!" },
 
     };
-    static const size_t k_num_arm_opcodes = sizeof(g_opcodes)/sizeof(EmulateInstructionARM64::Opcode);
+    static const size_t k_num_arm_opcodes = llvm::array_lengthof(g_opcodes);
                   
     for (size_t i=0; i<k_num_arm_opcodes; ++i)
     {
index 29d8bc8..64bc2ae 100644 (file)
@@ -28,6 +28,7 @@
 #include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/SymbolVendor.h"
 #include "lldb/Target/Target.h"
+#include "llvm/ADT/STLExtras.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -1327,7 +1328,7 @@ PlatformDarwin::SetThreadCreationBreakpoint (Target &target)
     };
 
     FileSpecList bp_modules;
-    for (size_t i = 0; i < sizeof(g_bp_modules)/sizeof(const char *); i++)
+    for (size_t i = 0; i < llvm::array_lengthof(g_bp_modules); i++)
     {
         const char *bp_module = g_bp_modules[i];
         bp_modules.Append(FileSpec(bp_module, false));
@@ -1339,7 +1340,7 @@ PlatformDarwin::SetThreadCreationBreakpoint (Target &target)
     bp_sp = target.CreateBreakpoint (&bp_modules,
                                      NULL,
                                      g_bp_names,
-                                     sizeof(g_bp_names)/sizeof(const char *),
+                                     llvm::array_lengthof(g_bp_names),
                                      eFunctionNameTypeFull,
                                      skip_prologue,
                                      internal,
index 4d77b6f..4f90817 100644 (file)
@@ -37,6 +37,8 @@
 #include "ARM_GCC_Registers.h"
 #include "ARM_DWARF_Registers.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -399,7 +401,7 @@ g_exc_regnums[] =
     exc_far,
 };
 
-static size_t k_num_register_infos = (sizeof(g_register_infos)/sizeof(RegisterInfo));
+static size_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 
 void
 RegisterContextDarwin_arm::InvalidateAllRegisters ()
@@ -438,9 +440,9 @@ RegisterContextDarwin_arm::GetRegisterInfos ()
 
 
 // Number of registers in each register set
-const size_t k_num_gpr_registers = sizeof(g_gpr_regnums) / sizeof(uint32_t);
-const size_t k_num_fpu_registers = sizeof(g_fpu_regnums) / sizeof(uint32_t);
-const size_t k_num_exc_registers = sizeof(g_exc_regnums) / sizeof(uint32_t);
+const size_t k_num_gpr_registers = llvm::array_lengthof(g_gpr_regnums);
+const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
+const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
 
 //----------------------------------------------------------------------
 // Register set definitions. The first definitions at register set index
@@ -454,7 +456,7 @@ static const RegisterSet g_reg_sets[] =
     { "Exception State Registers",  "exc",  k_num_exc_registers,    g_exc_regnums       }
 };
 
-const size_t k_num_regsets = sizeof(g_reg_sets) / sizeof(RegisterSet);
+const size_t k_num_regsets = llvm::array_lengthof(g_reg_sets);
 
 
 size_t
index b42f35b..2cb1b28 100644 (file)
@@ -24,6 +24,7 @@
 #include "lldb/Core/RegisterValue.h"
 #include "lldb/Core/Scalar.h"
 #include "lldb/Host/Endian.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 
 #include "Plugins/Process/Utility/InstructionUtils.h"
@@ -462,7 +463,7 @@ g_exc_regnums[] =
     exc_exception
 };
 
-static size_t k_num_register_infos = (sizeof(g_register_infos)/sizeof(RegisterInfo));
+static size_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 
 void
 RegisterContextDarwin_arm64::InvalidateAllRegisters ()
@@ -501,9 +502,9 @@ RegisterContextDarwin_arm64::GetRegisterInfos ()
 
 
 // Number of registers in each register set
-const size_t k_num_gpr_registers = sizeof(g_gpr_regnums) / sizeof(uint32_t);
-const size_t k_num_fpu_registers = sizeof(g_fpu_regnums) / sizeof(uint32_t);
-const size_t k_num_exc_registers = sizeof(g_exc_regnums) / sizeof(uint32_t);
+const size_t k_num_gpr_registers = llvm::array_lengthof(g_gpr_regnums);
+const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
+const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
 
 //----------------------------------------------------------------------
 // Register set definitions. The first definitions at register set index
@@ -517,7 +518,7 @@ static const RegisterSet g_reg_sets[] =
     { "Exception State Registers",  "exc",  k_num_exc_registers,    g_exc_regnums       }
 };
 
-const size_t k_num_regsets = sizeof(g_reg_sets) / sizeof(RegisterSet);
+const size_t k_num_regsets = llvm::array_lengthof(g_reg_sets);
 
 
 size_t
index a94d1f5..6535d31 100644 (file)
@@ -19,6 +19,7 @@
 #include "lldb/Core/RegisterValue.h"
 #include "lldb/Core/Scalar.h"
 #include "lldb/Host/Endian.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 
 // Support building against older versions of LLVM, this macro was added
@@ -281,7 +282,7 @@ static RegisterInfo g_register_infos[] =
     { DEFINE_EXC(faultvaddr)        , { LLDB_INVALID_REGNUM , LLDB_INVALID_REGNUM   , LLDB_INVALID_REGNUM     , LLDB_INVALID_REGNUM, exc_faultvaddr },   NULL,              NULL}
 };
 
-static size_t k_num_register_infos = (sizeof(g_register_infos)/sizeof(RegisterInfo));
+static size_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 
 void
 RegisterContextDarwin_i386::InvalidateAllRegisters ()
@@ -384,9 +385,9 @@ g_exc_regnums[] =
 };
 
 // Number of registers in each register set
-const size_t k_num_gpr_registers = sizeof(g_gpr_regnums) / sizeof(uint32_t);
-const size_t k_num_fpu_registers = sizeof(g_fpu_regnums) / sizeof(uint32_t);
-const size_t k_num_exc_registers = sizeof(g_exc_regnums) / sizeof(uint32_t);
+const size_t k_num_gpr_registers = llvm::array_lengthof(g_gpr_regnums);
+const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
+const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
 
 //----------------------------------------------------------------------
 // Register set definitions. The first definitions at register set index
@@ -400,7 +401,7 @@ static const RegisterSet g_reg_sets[] =
     { "Exception State Registers",  "exc",  k_num_exc_registers,    g_exc_regnums       }
 };
 
-const size_t k_num_regsets = sizeof(g_reg_sets) / sizeof(RegisterSet);
+const size_t k_num_regsets = llvm::array_lengthof(g_reg_sets);
 
 
 size_t
index bc6aeee..0161a02 100644 (file)
@@ -21,6 +21,7 @@
 #include "lldb/Core/RegisterValue.h"
 #include "lldb/Core/Scalar.h"
 #include "lldb/Host/Endian.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Compiler.h"
 
 // Support building against older versions of LLVM, this macro was added
@@ -318,7 +319,7 @@ static RegisterInfo g_register_infos[] =
     { DEFINE_EXC(faultvaddr)        , { LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM      , LLDB_INVALID_REGNUM, exc_faultvaddr },      NULL,              NULL}
 };
 
-static size_t k_num_register_infos = (sizeof(g_register_infos)/sizeof(RegisterInfo));
+static size_t k_num_register_infos = llvm::array_lengthof(g_register_infos);
 
 
 void
@@ -432,9 +433,9 @@ g_exc_regnums[] =
 };
 
 // Number of registers in each register set
-const size_t k_num_gpr_registers = sizeof(g_gpr_regnums) / sizeof(uint32_t);
-const size_t k_num_fpu_registers = sizeof(g_fpu_regnums) / sizeof(uint32_t);
-const size_t k_num_exc_registers = sizeof(g_exc_regnums) / sizeof(uint32_t);
+const size_t k_num_gpr_registers = llvm::array_lengthof(g_gpr_regnums);
+const size_t k_num_fpu_registers = llvm::array_lengthof(g_fpu_regnums);
+const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_regnums);
 
 //----------------------------------------------------------------------
 // Register set definitions. The first definitions at register set index
@@ -448,7 +449,7 @@ static const RegisterSet g_reg_sets[] =
     { "Exception State Registers",  "exc",  k_num_exc_registers,    g_exc_regnums       }
 };
 
-const size_t k_num_regsets = sizeof(g_reg_sets) / sizeof(RegisterSet);
+const size_t k_num_regsets = llvm::array_lengthof(g_reg_sets);
 
 
 size_t
index c3c2c67..f871f25 100644 (file)
@@ -17,6 +17,7 @@
 #include <sstream>
 
 // Other libraries and framework includes
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Triple.h"
 #include "lldb/Interpreter/Args.h"
 #include "lldb/Core/ConnectionFileDescriptor.h"
@@ -2660,8 +2661,8 @@ GDBRemoteCommunicationClient::TestPacketSpeed (const uint32_t num_packets)
     {
         static uint32_t g_send_sizes[] = { 0, 64, 128, 512, 1024 };
         static uint32_t g_recv_sizes[] = { 0, 64, 128, 512, 1024 }; //, 4*1024, 8*1024, 16*1024, 32*1024, 48*1024, 64*1024, 96*1024, 128*1024 };
-        const size_t k_num_send_sizes = sizeof(g_send_sizes)/sizeof(uint32_t);
-        const size_t k_num_recv_sizes = sizeof(g_recv_sizes)/sizeof(uint32_t);
+        const size_t k_num_send_sizes = llvm::array_lengthof(g_send_sizes);
+        const size_t k_num_recv_sizes = llvm::array_lengthof(g_recv_sizes);
         const uint64_t k_recv_amount = 4*1024*1024; // Receive 4MB
         for (uint32_t send_idx = 0; send_idx < k_num_send_sizes; ++send_idx)
         {
index be237ce..4083975 100644 (file)
@@ -18,6 +18,8 @@
 #include <assert.h>
 #include "lldb/Host/Mutex.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 #include <vector>
 
 class Backtrace
@@ -51,7 +53,7 @@ void
 Backtrace::GetFrames ()
 {
     void *frames[1024];
-    const int count = ::backtrace (frames, sizeof(frames)/sizeof(void*));
+    const int count = ::backtrace (frames, llvm::array_lengthof(frames));
     if (count > 2)
         m_frames.assign (frames + 2, frames + (count - 2));
 }
index 8380752..cbbf82f 100644 (file)
@@ -47,6 +47,7 @@
 #include "DNBTimer.h"
 #include "CFBundle.h"
 
+#include "llvm/ADT/STLExtras.h"
 
 typedef std::shared_ptr<MachProcess> MachProcessSP;
 typedef std::map<nub_process_t, MachProcessSP> ProcessMap;
@@ -542,7 +543,7 @@ GetAllInfos (std::vector<struct kinfo_proc>& proc_infos)
 {
     size_t size = 0;
     int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
-    u_int namelen = sizeof(name)/sizeof(int);
+    u_int namelen = llvm::array_lengthof(name);
     int err;
 
     // Try to find out how many processes are around so we can
index 68b272a..a012515 100644 (file)
@@ -20,6 +20,8 @@
 #include "DNBThreadResumeActions.h"
 #include "MachProcess.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 MachThreadList::MachThreadList() :
     m_threads(),
     m_threads_mutex(PTHREAD_MUTEX_RECURSIVE),
@@ -313,7 +315,7 @@ MachThreadList::UpdateThreadList(MachProcess *process, bool update, MachThreadLi
         int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process->ProcessID() };
         struct kinfo_proc processInfo;
         size_t bufsize = sizeof(processInfo);
-        if (sysctl(mib, (unsigned)(sizeof(mib)/sizeof(int)), &processInfo, &bufsize, NULL, 0) == 0 && bufsize > 0)
+        if (sysctl(mib, llvm::array_lengthof(mib), &processInfo, &bufsize, NULL, 0) == 0 && bufsize > 0)
         {
             if (processInfo.kp_proc.p_flag & P_LP64)
                 m_is_64_bit = true;
index 3282d70..08cbbfb 100644 (file)
@@ -23,6 +23,8 @@
 #include "ARM_GCC_Registers.h"
 #include "ARM_DWARF_Registers.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 #include <inttypes.h>
 #include <sys/sysctl.h>
 
@@ -1555,9 +1557,9 @@ DNBArchMachARM::g_exc_registers[] =
 };
 
 // Number of registers in each register set
-const size_t DNBArchMachARM::k_num_gpr_registers = sizeof(g_gpr_registers)/sizeof(DNBRegisterInfo);
-const size_t DNBArchMachARM::k_num_vfp_registers = sizeof(g_vfp_registers)/sizeof(DNBRegisterInfo);
-const size_t DNBArchMachARM::k_num_exc_registers = sizeof(g_exc_registers)/sizeof(DNBRegisterInfo);
+const size_t DNBArchMachARM::k_num_gpr_registers = llvm::array_lengthof(g_gpr_registers);
+const size_t DNBArchMachARM::k_num_vfp_registers = llvm::array_lengthof(g_vfp_registers);
+const size_t DNBArchMachARM::k_num_exc_registers = llvm::array_lengthof(g_exc_registers);
 const size_t DNBArchMachARM::k_num_all_registers = k_num_gpr_registers + k_num_vfp_registers + k_num_exc_registers;
 
 //----------------------------------------------------------------------
@@ -1574,7 +1576,7 @@ DNBArchMachARM::g_reg_sets[] =
     { "Exception State Registers",  g_exc_registers,    k_num_exc_registers     }
 };
 // Total number of register sets for this architecture
-const size_t DNBArchMachARM::k_num_register_sets = sizeof(g_reg_sets)/sizeof(DNBRegisterSetInfo);
+const size_t DNBArchMachARM::k_num_register_sets = llvm::array_lengthof(g_reg_sets);
 
 
 const DNBRegisterSetInfo *
index 909fac6..42e0d4c 100644 (file)
@@ -24,6 +24,8 @@
 #include "DNBRegisterInfo.h"
 #include "DNB.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 #include <inttypes.h>
 #include <sys/sysctl.h>
 
@@ -1644,9 +1646,9 @@ DNBArchMachARM64::g_exc_registers[] =
 };
 
 // Number of registers in each register set
-const size_t DNBArchMachARM64::k_num_gpr_registers = sizeof(g_gpr_registers)/sizeof(DNBRegisterInfo);
-const size_t DNBArchMachARM64::k_num_vfp_registers = sizeof(g_vfp_registers)/sizeof(DNBRegisterInfo);
-const size_t DNBArchMachARM64::k_num_exc_registers = sizeof(g_exc_registers)/sizeof(DNBRegisterInfo);
+const size_t DNBArchMachARM64::k_num_gpr_registers = llvm::array_lengthof(g_gpr_registers);
+const size_t DNBArchMachARM64::k_num_vfp_registers = llvm::array_lengthof(g_vfp_registers);
+const size_t DNBArchMachARM64::k_num_exc_registers = llvm::array_lengthof(g_exc_registers);
 const size_t DNBArchMachARM64::k_num_all_registers = k_num_gpr_registers + k_num_vfp_registers + k_num_exc_registers;
 
 //----------------------------------------------------------------------
@@ -1663,7 +1665,7 @@ DNBArchMachARM64::g_reg_sets[] =
     { "Exception State Registers",  g_exc_registers,    k_num_exc_registers     }
 };
 // Total number of register sets for this architecture
-const size_t DNBArchMachARM64::k_num_register_sets = sizeof(g_reg_sets)/sizeof(DNBRegisterSetInfo);
+const size_t DNBArchMachARM64::k_num_register_sets = llvm::array_lengthof(g_reg_sets);
 
 
 const DNBRegisterSetInfo *
index faa534e..fef0d47 100644 (file)
@@ -20,6 +20,8 @@
 #include "MachThread.h"
 #include "MachProcess.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 extern "C" bool CPUHasAVX(); // Defined over in DNBArchImplX86_64.cpp
 
 #if defined (LLDB_DEBUGSERVER_RELEASE) || defined (LLDB_DEBUGSERVER_DEBUG)
@@ -1201,10 +1203,10 @@ DNBArchImplI386::g_exc_registers[] =
 };
 
 // Number of registers in each register set
-const size_t DNBArchImplI386::k_num_gpr_registers = sizeof(g_gpr_registers)/sizeof(DNBRegisterInfo);
-const size_t DNBArchImplI386::k_num_fpu_registers_no_avx = sizeof(g_fpu_registers_no_avx)/sizeof(DNBRegisterInfo);
-const size_t DNBArchImplI386::k_num_fpu_registers_avx = sizeof(g_fpu_registers_avx)/sizeof(DNBRegisterInfo);
-const size_t DNBArchImplI386::k_num_exc_registers = sizeof(g_exc_registers)/sizeof(DNBRegisterInfo);
+const size_t DNBArchImplI386::k_num_gpr_registers = llvm::array_lengthof(g_gpr_registers);
+const size_t DNBArchImplI386::k_num_fpu_registers_no_avx = llvm::array_lengthof(g_fpu_registers_no_avx);
+const size_t DNBArchImplI386::k_num_fpu_registers_avx = llvm::array_lengthof(g_fpu_registers_avx);
+const size_t DNBArchImplI386::k_num_exc_registers = llvm::array_lengthof(g_exc_registers);
 const size_t DNBArchImplI386::k_num_all_registers_no_avx = k_num_gpr_registers + k_num_fpu_registers_no_avx + k_num_exc_registers;
 const size_t DNBArchImplI386::k_num_all_registers_avx = k_num_gpr_registers + k_num_fpu_registers_avx + k_num_exc_registers;
 
@@ -1232,7 +1234,7 @@ DNBArchImplI386::g_reg_sets_avx[] =
 };
 
 // Total number of register sets for this architecture
-const size_t DNBArchImplI386::k_num_register_sets = sizeof(g_reg_sets_no_avx)/sizeof(DNBRegisterSetInfo);
+const size_t DNBArchImplI386::k_num_register_sets = llvm::array_lengthof(g_reg_sets_no_avx);
 
 DNBArchProtocol *
 DNBArchImplI386::Create (MachThread *thread)
index 2feb1f4..0f555d7 100644 (file)
@@ -25,6 +25,8 @@
 #include "DNBLog.h"
 #include "DNBRegisterInfo.h"
 
+#include "llvm/ADT/STLExtras.h"
+
 static const uint8_t g_breakpoint_opcode[] = { 0x7F, 0xC0, 0x00, 0x08 };
 
 const uint8_t * const
@@ -386,10 +388,10 @@ static DNBRegisterInfo g_vec_registers[] =
 };
 
 // Number of registers in each register set
-const size_t k_num_gpr_registers = sizeof(g_gpr_registers)/sizeof(DNBRegisterInfo);
-const size_t k_num_fpr_registers = sizeof(g_fpr_registers)/sizeof(DNBRegisterInfo);
-const size_t k_num_exc_registers = sizeof(g_exc_registers)/sizeof(DNBRegisterInfo);
-const size_t k_num_vec_registers = sizeof(g_vec_registers)/sizeof(DNBRegisterInfo);
+const size_t k_num_gpr_registers = llvm::array_lengthof(g_gpr_registers);
+const size_t k_num_fpr_registers = llvm::array_lengthof(g_fpr_registers);
+const size_t k_num_exc_registers = llvm::array_lengthof(g_exc_registers);
+const size_t k_num_vec_registers = llvm::array_lengthof(g_vec_registers);
 // Total number of registers for this architecture
 const size_t k_num_ppc_registers = k_num_gpr_registers + k_num_fpr_registers + k_num_exc_registers + k_num_vec_registers;
 
@@ -407,7 +409,7 @@ static const DNBRegisterSetInfo g_reg_sets[] =
     { "Altivec Registers",            g_vec_registers, k_num_vec_registers }
 };
 // Total number of register sets for this architecture
-const size_t k_num_register_sets = sizeof(g_reg_sets)/sizeof(DNBRegisterSetInfo);
+const size_t k_num_register_sets = llvm::array_lengthof(g_reg_sets);
 
 
 const DNBRegisterSetInfo *
index f683635..7d859e4 100644 (file)
@@ -13,6 +13,8 @@
 
 #if defined (__i386__) || defined (__x86_64__)
 
+#include "llvm/ADT/STLExtras.h"
+
 #include <sys/cdefs.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
@@ -1525,10 +1527,10 @@ DNBArchImplX86_64::g_exc_registers[] =
 };
 
 // Number of registers in each register set
-const size_t DNBArchImplX86_64::k_num_gpr_registers = sizeof(g_gpr_registers)/sizeof(DNBRegisterInfo);
-const size_t DNBArchImplX86_64::k_num_fpu_registers_no_avx = sizeof(g_fpu_registers_no_avx)/sizeof(DNBRegisterInfo);
-const size_t DNBArchImplX86_64::k_num_fpu_registers_avx = sizeof(g_fpu_registers_avx)/sizeof(DNBRegisterInfo);
-const size_t DNBArchImplX86_64::k_num_exc_registers = sizeof(g_exc_registers)/sizeof(DNBRegisterInfo);
+const size_t DNBArchImplX86_64::k_num_gpr_registers = llvm::array_lengthof(g_gpr_registers);
+const size_t DNBArchImplX86_64::k_num_fpu_registers_no_avx = llvm::array_lengthof(g_fpu_registers_no_avx);
+const size_t DNBArchImplX86_64::k_num_fpu_registers_avx = llvm::array_lengthof(g_fpu_registers_avx);
+const size_t DNBArchImplX86_64::k_num_exc_registers = llvm::array_lengthof(g_exc_registers);
 const size_t DNBArchImplX86_64::k_num_all_registers_no_avx = k_num_gpr_registers + k_num_fpu_registers_no_avx + k_num_exc_registers;
 const size_t DNBArchImplX86_64::k_num_all_registers_avx = k_num_gpr_registers + k_num_fpu_registers_avx + k_num_exc_registers;
 
@@ -1556,7 +1558,7 @@ DNBArchImplX86_64::g_reg_sets_avx[] =
 };
 
 // Total number of register sets for this architecture
-const size_t DNBArchImplX86_64::k_num_register_sets = sizeof(g_reg_sets_avx)/sizeof(DNBRegisterSetInfo);
+const size_t DNBArchImplX86_64::k_num_register_sets = llvm::array_lengthof(g_reg_sets_avx);
 
 
 DNBArchProtocol *
index c01d512..7d26f5e 100644 (file)
@@ -17,6 +17,8 @@
 #include <termios.h>
 #include <stdint.h>
 
+#include "llvm/ADT/STLExtras.h"
+
 class TTYState
 {
 public:
@@ -50,7 +52,7 @@ public:
 
     bool GetState(uint32_t idx, int fd, bool saveProcessGroup);
     bool SetState(uint32_t idx) const;
-    uint32_t NumStates() const { return sizeof(m_ttystates)/sizeof(TTYState); }
+    uint32_t NumStates() const { return llvm::array_lengthof(m_ttystates); }
     bool ValidStateIndex(uint32_t idx) const { return idx < NumStates(); }
 
 protected:
@@ -58,4 +60,4 @@ protected:
     TTYState            m_ttystates[2];
 };
 
-#endif
\ No newline at end of file
+#endif
index 3e7d043..ac9481c 100644 (file)
@@ -13,6 +13,7 @@
 #include "lldb-perf/lib/Results.h"
 #include "lldb-perf/lib/TestCase.h"
 #include "lldb-perf/lib/Xcode.h"
+#include "llvm/ADT/STLExtras.h"
 #include <iostream>
 #include <unistd.h>
 #include <fstream>
@@ -179,7 +180,7 @@ int main (int argc, char const *argv[], char const *envp[])
                         "-x", "c++",
                         NULL,
                         NULL };
-                    clang_argv[sizeof(clang_argv)/sizeof(const char *)-2] = temp_source_path;
+                    clang_argv[llvm::array_lengthof(clang_argv)-2] = temp_source_path;
                     SBLaunchInfo launch_info(clang_argv);
                     Launch (launch_info);
                     next_action.None(); // Don't continue or do anything, just wait for next event...