[lldb/MachO] "Fix" intentional out-of-bounds error (NFC)
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 18 Dec 2019 20:49:46 +0000 (12:49 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 18 Dec 2019 20:54:04 +0000 (12:54 -0800)
Remove the hack that populates the cpsr register in the gpr struct by
writing past the end of the array. This was tripping up ASan.

Patch by: Reva Cuthbertson

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp

index 57c43de..ef6ad16 100644 (file)
@@ -479,12 +479,13 @@ public:
       switch (flavor) {
       case GPRAltRegSet:
       case GPRRegSet:
-        for (uint32_t i = 0; i < count; ++i) {
+        // On ARM, the CPSR register is also included in the count but it is
+        // not included in gpr.r so loop until (count-1).
+        for (uint32_t i = 0; i < (count - 1); ++i) {
           gpr.r[i] = data.GetU32(&offset);
         }
-
-        // Note that gpr.cpsr is also copied by the above loop; this loop
-        // technically extends one element past the end of the gpr.r[] array.
+        // Save cpsr explicitly.
+        gpr.cpsr = data.GetU32(&offset);
 
         SetError(GPRRegSet, Read, 0);
         offset = next_thread_state;
index 94eebab..173e669 100644 (file)
@@ -1140,10 +1140,11 @@ bool RegisterContextDarwin_arm::ReadRegister(const RegisterInfo *reg_info,
   case gpr_sp:
   case gpr_lr:
   case gpr_pc:
-  case gpr_cpsr:
     value.SetUInt32(gpr.r[reg - gpr_r0]);
     break;
-
+  case gpr_cpsr:
+    value.SetUInt32(gpr.cpsr);
+    break;
   case fpu_s0:
   case fpu_s1:
   case fpu_s2: