Added new lldb_private::Process memory read/write functions to stop a bunch
of duplicated code from appearing all over LLDB:

lldb::addr_t
Process::ReadPointerFromMemory (lldb::addr_t vm_addr, Error &error);

bool
Process::WritePointerToMemory (lldb::addr_t vm_addr, lldb::addr_t ptr_value, Error &error);

size_t
Process::ReadScalarIntegerFromMemory (lldb::addr_t addr, uint32_t byte_size, bool is_signed, Scalar &scalar, Error &error);

size_t
Process::WriteScalarToMemory (lldb::addr_t vm_addr, const Scalar &scalar, uint32_t size, Error &error);

in lldb_private::Process the following functions were renamed:

From:
uint64_t
Process::ReadUnsignedInteger (lldb::addr_t load_addr, 
                              size_t byte_size,
                              Error &error);

To:
uint64_t
Process::ReadUnsignedIntegerFromMemory (lldb::addr_t load_addr, 
                                        size_t byte_size,
                                        uint64_t fail_value, 
                                        Error &error);

Cleaned up a lot of code that was manually doing what the above functions do
to use the functions listed above.

Added the ability to get a scalar value as a buffer that can be written down
to a process (byte swapping the Scalar value if needed):

uint32_t 
Scalar::GetAsMemoryData (void *dst,
                        uint32_t dst_len, 
                        lldb::ByteOrder dst_byte_order,
                        Error &error) const;

The "dst_len" can be smaller that the size of the scalar and the least 
significant bytes will be written. "dst_len" can also be larger and the
most significant bytes will be padded with zeroes. 

Centralized the code that adds or removes address bits for callable and opcode
addresses into lldb_private::Target:

lldb::addr_t
Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;

lldb::addr_t
Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const;

All necessary lldb_private::Address functions now use the target versions so
changes should only need to happen in one place if anything needs updating.

Fixed up a lot of places that were calling :

addr_t
Address::GetLoadAddress(Target*);

to call the Address::GetCallableLoadAddress() or Address::GetOpcodeLoadAddress()
as needed. There were many places in the breakpoint code where things could
go wrong for ARM if these weren't used.




git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@131878 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Target/Target.cpp b/source/Target/Target.cpp
index 387a336..56b798b 100644
--- a/source/Target/Target.cpp
+++ b/source/Target/Target.cpp
@@ -1014,6 +1014,81 @@
     return execution_results;
 }
 
+lldb::addr_t
+Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
+{
+    addr_t code_addr = load_addr;
+    switch (m_arch.GetMachine())
+    {
+    case llvm::Triple::arm:
+    case llvm::Triple::thumb:
+        switch (addr_class)
+        {
+        case eAddressClassData:
+        case eAddressClassDebug:
+            return LLDB_INVALID_ADDRESS;
+            
+        case eAddressClassUnknown:
+        case eAddressClassInvalid:
+        case eAddressClassCode:
+        case eAddressClassCodeAlternateISA:
+        case eAddressClassRuntime:
+            // Check if bit zero it no set?
+            if ((code_addr & 1ull) == 0)
+            {
+                // Bit zero isn't set, check if the address is a multiple of 2?
+                if (code_addr & 2ull)
+                {
+                    // The address is a multiple of 2 so it must be thumb, set bit zero
+                    code_addr |= 1ull;
+                }
+                else if (addr_class == eAddressClassCodeAlternateISA)
+                {
+                    // We checked the address and the address claims to be the alternate ISA
+                    // which means thumb, so set bit zero.
+                    code_addr |= 1ull;
+                }
+            }
+            break;
+        }
+        break;
+            
+    default:
+        break;
+    }
+    return code_addr;
+}
+
+lldb::addr_t
+Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
+{
+    addr_t opcode_addr = load_addr;
+    switch (m_arch.GetMachine())
+    {
+    case llvm::Triple::arm:
+    case llvm::Triple::thumb:
+        switch (addr_class)
+        {
+        case eAddressClassData:
+        case eAddressClassDebug:
+            return LLDB_INVALID_ADDRESS;
+            
+        case eAddressClassInvalid:
+        case eAddressClassUnknown:
+        case eAddressClassCode:
+        case eAddressClassCodeAlternateISA:
+        case eAddressClassRuntime:
+            opcode_addr &= ~(1ull);
+            break;
+        }
+        break;
+            
+    default:
+        break;
+    }
+    return opcode_addr;
+}
+
 lldb::user_id_t
 Target::AddStopHook (Target::StopHookSP &new_hook_sp)
 {