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/Expression/ClangFunction.cpp b/source/Expression/ClangFunction.cpp
index 935ff95..0d8fbf4 100644
--- a/source/Expression/ClangFunction.cpp
+++ b/source/Expression/ClangFunction.cpp
@@ -314,12 +314,10 @@
         }
     }
 
-    // FIXME: This is fake, and just assumes that it matches that architecture.
-    // Make a data extractor and put the address into the right byte order & size.
-
-    uint64_t fun_addr = function_address.GetLoadAddress(exe_ctx.target);
+    // TODO: verify fun_addr needs to be a callable address
+    Scalar fun_addr (function_address.GetCallableLoadAddress(exe_ctx.target));
     int first_offset = m_member_offsets[0];
-    process->WriteMemory(args_addr_ref + first_offset, &fun_addr, 8, error);
+    process->WriteScalarToMemory(args_addr_ref + first_offset, fun_addr, process->GetAddressByteSize(), error);
 
     // FIXME: We will need to extend this for Variadic functions.
 
@@ -350,13 +348,8 @@
         
         const Scalar &arg_scalar = arg_value->ResolveValue(&exe_ctx, m_clang_ast_context->getASTContext());
 
-        int byte_size = arg_scalar.GetByteSize();
-        std::vector<uint8_t> buffer;
-        buffer.resize(byte_size);
-        DataExtractor value_data;
-        arg_scalar.GetData (value_data);
-        value_data.ExtractBytes(0, byte_size, process->GetByteOrder(), &buffer.front());
-        process->WriteMemory(args_addr_ref + offset, &buffer.front(), byte_size, error);
+        if (!process->WriteScalarToMemory(args_addr_ref + offset, arg_scalar, arg_scalar.GetByteSize(), error))
+            return false;
     }
 
     return true;
@@ -420,8 +413,6 @@
     // Read the return value - it is the last field in the struct:
     // FIXME: How does clang tell us there's no return value?  We need to handle that case.
     
-    std::vector<uint8_t> data_buffer;
-    data_buffer.resize(m_return_size);
     Process *process = exe_ctx.process;
     
     if (process == NULL)
@@ -430,25 +421,13 @@
         return false;
                 
     Error error;
-    size_t bytes_read = process->ReadMemory(args_addr + m_return_offset, &data_buffer.front(), m_return_size, error);
+    ret_value.GetScalar() = process->ReadUnsignedIntegerFromMemory (args_addr + m_return_offset, m_return_size, 0, error);
 
-    if (bytes_read == 0)
-    {
-        return false;
-    }
-
-    if (bytes_read < m_return_size)
+    if (error.Fail())
         return false;
 
-    DataExtractor data(&data_buffer.front(), m_return_size, process->GetByteOrder(), process->GetAddressByteSize());
-    // FIXME: Assuming an integer scalar for now:
-    
-    uint32_t offset = 0;
-    uint64_t return_integer = data.GetMaxU64(&offset, m_return_size);
-    
     ret_value.SetContext (Value::eContextTypeClangType, m_function_return_qual_type);
     ret_value.SetValueType(Value::eValueTypeScalar);
-    ret_value.GetScalar() = return_integer;
     return true;
 }