I have brought LLDB up-to-date with top of tree
LLVM/Clang.  This brings in several fixes, including:

- Improvements in the Just-In-Time compiler's
  allocation of memory: the JIT now allocates
  memory in chunks of sections, improving its
  ability to generate relocations.  I have
  revamped the RecordingMemoryManager to reflect
  these changes, as well as to get the memory
  allocation and data copying out fo the
  ClangExpressionParser code.  Jim Grosbach wrote
  the updates to the JIT on the LLVM side.

- A new ExternalASTSource interface to allow LLDB to
  report accurate structure layout information to
  Clang.  Previously we could only report the sizes
  of fields, not their offsets.  This meant that if
  data structures included field alignment
  directives, we could not communicate the necessary
  alignment to Clang and accesses to the data would
  fail.  Now we can (and I have update the relevant
  test case).  Thanks to Doug Gregor for implementing
  the Clang side of this fix.

- The way Objective-C interfaces are completed by
  Clang has been made consistent with RecordDecls;
  with help from Doug Gregor and Greg Clayton I have
  ensured that this still works.

- I have eliminated all local LLVM and Clang patches,
  committing the ones that are still relevant to LLVM
  and Clang as needed.

I have tested the changes extensively locally, but
please let me know if they cause any trouble for you.


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@149775 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Expression/ClangExpressionParser.cpp b/source/Expression/ClangExpressionParser.cpp
index 625b03e..958d18b 100644
--- a/source/Expression/ClangExpressionParser.cpp
+++ b/source/Expression/ClangExpressionParser.cpp
@@ -172,8 +172,7 @@
     // If there are any AST files to merge, create a frontend action
     // adaptor to perform the merge.
     if (!CI.getFrontendOpts().ASTMergeFiles.empty())
-        Act = new ASTMergeAction(Act, &CI.getFrontendOpts().ASTMergeFiles[0],
-                                 CI.getFrontendOpts().ASTMergeFiles.size());
+        Act = new ASTMergeAction(Act, CI.getFrontendOpts().ASTMergeFiles);
     
     return Act;
 }
@@ -492,12 +491,7 @@
                                   error_stream,
                                   function_name.c_str());
         
-        if (!ir_for_target.runOnModule(*module))
-        {
-            err.SetErrorToGenericError();
-            err.SetErrorString("Couldn't prepare the expression for execution in the target");
-            return err;
-        }
+        ir_for_target.runOnModule(*module);
         
         Error &interpreter_error(ir_for_target.getInterpreterError());
         
@@ -519,6 +513,7 @@
                 err.SetErrorString("Execution needed to run in the target, but the target can't be run");
             else
                 err.SetErrorStringWithFormat("Interpreting the expression locally failed: %s", interpreter_error.AsCString());
+
             return err;
         }
         
@@ -629,58 +624,9 @@
         err.SetErrorString("Couldn't write the JIT compiled code into the target because there is no target");
         return err;
     }
-    
-    // Look over the regions allocated for the function compiled.  The JIT
-    // tries to allocate the functions & stubs close together, so we should try to
-    // write them that way too...
-    // For now I only write functions with no stubs, globals, exception tables,
-    // etc.  So I only need to write the functions.
-    
-    size_t alloc_size = 0;
-    
-    std::map<uint8_t *, uint8_t *>::iterator fun_pos = jit_memory_manager->m_functions.begin();
-    std::map<uint8_t *, uint8_t *>::iterator fun_end = jit_memory_manager->m_functions.end();
-
-    for (; fun_pos != fun_end; ++fun_pos)
-    {
-        size_t mem_size = fun_pos->second - fun_pos->first;
-        if (log)
-            log->Printf ("JIT memory: [%p - %p) size = %zu", fun_pos->first, fun_pos->second, mem_size);
-        alloc_size += mem_size;
-    }
-    
-    Error alloc_error;
-    func_allocation_addr = process->AllocateMemory (alloc_size, 
-                                                                lldb::ePermissionsReadable|lldb::ePermissionsExecutable, 
-                                                                alloc_error);
-    
-    if (func_allocation_addr == LLDB_INVALID_ADDRESS)
-    {
-        err.SetErrorToGenericError();
-        err.SetErrorStringWithFormat("Couldn't allocate memory for the JITted function: %s", alloc_error.AsCString("unknown error"));
-        return err;
-    }
-    
-    lldb::addr_t cursor = func_allocation_addr;
         
-    for (fun_pos = jit_memory_manager->m_functions.begin(); fun_pos != fun_end; fun_pos++)
-    {
-        lldb::addr_t lstart = (lldb::addr_t) (*fun_pos).first;
-        lldb::addr_t lend = (lldb::addr_t) (*fun_pos).second;
-        size_t size = lend - lstart;
-        
-        Error write_error;
-        
-        if (process->WriteMemory(cursor, (void *) lstart, size, write_error) != size)
-        {
-            err.SetErrorToGenericError();
-            err.SetErrorStringWithFormat("Couldn't copy JIT code for function into the target: %s", write_error.AsCString("unknown error"));
-            return err;
-        }
-            
-        jit_memory_manager->AddToLocalToRemoteMap (lstart, size, cursor);
-        cursor += size;
-    }
+    jit_memory_manager->CommitAllocations(*process);
+    jit_memory_manager->WriteData(*process);
     
     std::vector<JittedFunction>::iterator pos, end = m_jitted_functions.end();
     
@@ -690,7 +636,8 @@
     
         if (!(*pos).m_name.compare(function_name.c_str()))
         {
-            func_end = jit_memory_manager->GetRemoteRangeForLocal ((*pos).m_local_addr).second;
+            RecordingMemoryManager::AddrRange func_range = jit_memory_manager->GetRemoteRangeForLocal((*pos).m_local_addr);
+            func_end = func_range.first + func_range.second;
             func_addr = (*pos).m_remote_addr;
         }
     }
@@ -766,7 +713,7 @@
     }
     
     if (log)
-        log->Printf("Function's code range is [0x%llx-0x%llx]", func_range.first, func_range.second);
+        log->Printf("Function's code range is [0x%llx+0x%llx]", func_range.first, func_range.second);
     
     Target *target = exe_ctx.GetTargetPtr();
     if (!target)
@@ -775,7 +722,7 @@
         ret.SetErrorString("Couldn't find the target");
     }
     
-    lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second - func_remote_addr, 0));
+    lldb::DataBufferSP buffer_sp(new DataBufferHeap(func_range.second, 0));
     
     Process *process = exe_ctx.GetProcessPtr();
     Error err;