forked from OSchip/llvm-project
Added and improved logging. This is helping us as we
diagnose a problem where we're not correctly emitting PIC code. llvm-svn: 109568
This commit is contained in:
parent
8aeb0fb5ca
commit
cc54bd3cef
|
@ -21,6 +21,7 @@
|
|||
#include "lldb/lldb-forward.h"
|
||||
#include "lldb/lldb-private.h"
|
||||
#include "lldb/Core/ClangForward.h"
|
||||
#include "lldb/Core/Log.h"
|
||||
#include "llvm/ExecutionEngine/JITMemoryManager.h"
|
||||
#include "lldb/Expression/ClangExpression.h"
|
||||
|
||||
|
@ -128,6 +129,8 @@ private:
|
|||
std::map<uint8_t *, unsigned> m_stubs;
|
||||
std::map<uint8_t *, uintptr_t> m_globals;
|
||||
std::map<uint8_t *, uint8_t *> m_exception_tables;
|
||||
|
||||
lldb_private::Log *m_log;
|
||||
|
||||
struct LocalToRemoteAddressRange
|
||||
{
|
||||
|
|
|
@ -527,6 +527,7 @@ ClangExpression::PrepareIRForTarget (ClangExpressionVariableList &expr_local_var
|
|||
bool
|
||||
ClangExpression::JITFunction (const ExecutionContext &exc_context, const char *name)
|
||||
{
|
||||
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
||||
|
||||
llvm::Module *module = m_code_generator_ptr->GetModule();
|
||||
|
||||
|
@ -538,11 +539,41 @@ ClangExpression::JITFunction (const ExecutionContext &exc_context, const char *n
|
|||
m_jit_mm_ptr = new RecordingMemoryManager();
|
||||
|
||||
//llvm::InitializeNativeTarget();
|
||||
|
||||
if (m_execution_engine.get() == 0)
|
||||
m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module, &error, m_jit_mm_ptr));
|
||||
m_execution_engine.reset(llvm::ExecutionEngine::createJIT (module,
|
||||
&error,
|
||||
m_jit_mm_ptr,
|
||||
CodeGenOpt::Default,
|
||||
true,
|
||||
CodeModel::Default));
|
||||
|
||||
m_execution_engine->DisableLazyCompilation();
|
||||
llvm::Function *function = module->getFunction (llvm::StringRef (name));
|
||||
|
||||
|
||||
if (log)
|
||||
{
|
||||
const char *relocation_model_string;
|
||||
|
||||
switch (llvm::TargetMachine::getRelocationModel())
|
||||
{
|
||||
case llvm::Reloc::Default:
|
||||
relocation_model_string = "Default";
|
||||
break;
|
||||
case llvm::Reloc::Static:
|
||||
relocation_model_string = "Static";
|
||||
break;
|
||||
case llvm::Reloc::PIC_:
|
||||
relocation_model_string = "PIC_++";
|
||||
break;
|
||||
case llvm::Reloc::DynamicNoPIC:
|
||||
relocation_model_string = "DynamicNoPIC";
|
||||
break;
|
||||
}
|
||||
|
||||
log->Printf("Target machine's relocation model: %s", relocation_model_string);
|
||||
}
|
||||
|
||||
// We don't actually need the function pointer here, this just forces it to get resolved.
|
||||
void *fun_ptr = m_execution_engine->getPointerToFunction(function);
|
||||
// Note, you probably won't get here on error, since the LLVM JIT tends to just
|
||||
|
@ -558,6 +589,8 @@ ClangExpression::JITFunction (const ExecutionContext &exc_context, const char *n
|
|||
bool
|
||||
ClangExpression::WriteJITCode (const ExecutionContext &exc_context)
|
||||
{
|
||||
Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
||||
|
||||
if (m_jit_mm_ptr == NULL)
|
||||
return false;
|
||||
|
||||
|
@ -586,6 +619,9 @@ ClangExpression::WriteJITCode (const ExecutionContext &exc_context)
|
|||
lldb::addr_t cursor = target_addr;
|
||||
for (fun_pos = m_jit_mm_ptr->m_functions.begin(); fun_pos != fun_end; fun_pos++)
|
||||
{
|
||||
if (log)
|
||||
log->Printf("Reading [%p-%p] from m_functions", fun_pos->first, fun_pos->second);
|
||||
|
||||
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;
|
||||
|
|
|
@ -511,20 +511,22 @@ IRForTarget::runOnModule(Module &M)
|
|||
return false;
|
||||
}
|
||||
|
||||
// TEMPORARY FOR DEBUGGING
|
||||
M.dump();
|
||||
|
||||
if (!replaceVariables(M, function))
|
||||
return false;
|
||||
|
||||
if (log)
|
||||
{
|
||||
for (bbi = function->begin();
|
||||
bbi != function->end();
|
||||
++bbi)
|
||||
{
|
||||
log->Printf("Rewrote basic block %s for running: \n%s",
|
||||
bbi->hasName() ? bbi->getNameStr().c_str() : "[anonymous]",
|
||||
PrintValue(bbi).c_str());
|
||||
}
|
||||
std::string s;
|
||||
raw_string_ostream oss(s);
|
||||
|
||||
M.print(oss, NULL);
|
||||
|
||||
oss.flush();
|
||||
|
||||
log->Printf("Module after preparing for execution: \n%s", s.c_str());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -119,9 +119,7 @@ private:
|
|||
|
||||
bool
|
||||
IRToDWARF::runOnBasicBlock(BasicBlock &BB, Relocator &R)
|
||||
{
|
||||
lldb_private::Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
||||
|
||||
{
|
||||
///////////////////////////////////////
|
||||
// Mark the current block as visited
|
||||
//
|
||||
|
@ -139,29 +137,6 @@ IRToDWARF::runOnBasicBlock(BasicBlock &BB, Relocator &R)
|
|||
// Translate the current basic block to DWARF
|
||||
//
|
||||
|
||||
if (log)
|
||||
{
|
||||
log->Printf("Translating basic block %s:",
|
||||
BB.hasName() ? BB.getNameStr().c_str() : "[anonymous]");
|
||||
|
||||
llvm::BasicBlock::iterator ii;
|
||||
|
||||
for (ii = BB.begin();
|
||||
ii != BB.end();
|
||||
++ii)
|
||||
{
|
||||
llvm::Instruction &inst = *ii;
|
||||
|
||||
std::string s;
|
||||
raw_string_ostream os(s);
|
||||
|
||||
inst.print(os);
|
||||
|
||||
if (log)
|
||||
log->Printf(" %s", s.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// Visit all successors we haven't visited yet
|
||||
//
|
||||
|
@ -210,6 +185,18 @@ IRToDWARF::runOnModule(Module &M)
|
|||
if (!runOnBasicBlock(function->getEntryBlock(), relocator))
|
||||
return false;
|
||||
|
||||
if (log)
|
||||
{
|
||||
std::string s;
|
||||
raw_string_ostream oss(s);
|
||||
|
||||
M.print(oss, NULL);
|
||||
|
||||
oss.flush();
|
||||
|
||||
log->Printf("Module being translated to DWARF: \n%s", s.c_str());
|
||||
}
|
||||
|
||||
// TEMPORARY: Fail in order to force execution in the target.
|
||||
return false;
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ RecordingMemoryManager::RecordingMemoryManager () :
|
|||
llvm::JITMemoryManager(),
|
||||
m_default_mm_ap (llvm::JITMemoryManager::CreateDefaultMemManager())
|
||||
{
|
||||
m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS);
|
||||
}
|
||||
|
||||
RecordingMemoryManager::~RecordingMemoryManager ()
|
||||
|
@ -60,6 +61,9 @@ RecordingMemoryManager::endFunctionBody(const llvm::Function *F, uint8_t *Functi
|
|||
uint8_t *FunctionEnd)
|
||||
{
|
||||
m_default_mm_ap->endFunctionBody(F, FunctionStart, FunctionEnd);
|
||||
if (m_log)
|
||||
m_log->Printf("Adding [%p-%p] to m_functions",
|
||||
FunctionStart, FunctionEnd);
|
||||
m_functions.insert(std::pair<uint8_t *, uint8_t *>(FunctionStart, FunctionEnd));
|
||||
}
|
||||
|
||||
|
@ -67,6 +71,9 @@ uint8_t *
|
|||
RecordingMemoryManager::allocateSpace(intptr_t Size, unsigned Alignment)
|
||||
{
|
||||
uint8_t *return_value = m_default_mm_ap->allocateSpace(Size, Alignment);
|
||||
if (m_log)
|
||||
m_log->Printf("RecordingMemoryManager::allocateSpace(Size=0x%llx, Alignment=%u) = %p",
|
||||
(uint64_t)Size, Alignment, return_value);
|
||||
m_spaceBlocks.insert (std::pair<uint8_t *, intptr_t>(return_value, Size));
|
||||
return return_value;
|
||||
}
|
||||
|
@ -75,6 +82,9 @@ uint8_t *
|
|||
RecordingMemoryManager::allocateGlobal(uintptr_t Size, unsigned Alignment)
|
||||
{
|
||||
uint8_t *return_value = m_default_mm_ap->allocateGlobal(Size, Alignment);
|
||||
if (m_log)
|
||||
m_log->Printf("RecordingMemoryManager::allocateGlobal(Size=0x%llx, Alignment=%u) = %p",
|
||||
(uint64_t)Size, Alignment, return_value);
|
||||
m_globals.insert (std::pair<uint8_t *, uintptr_t>(return_value, Size));
|
||||
return return_value;
|
||||
}
|
||||
|
@ -144,6 +154,9 @@ RecordingMemoryManager::GetRemoteRangeForLocal (lldb::addr_t local_address)
|
|||
void
|
||||
RecordingMemoryManager::AddToLocalToRemoteMap (lldb::addr_t lstart, size_t size, lldb::addr_t rstart)
|
||||
{
|
||||
if (m_log)
|
||||
m_log->Printf("Adding local [0x%llx-0x%llx], remote [0x%llx-0x%llx] to local->remote map", lstart, lstart + size, rstart, rstart + size);
|
||||
|
||||
m_address_map.push_back (LocalToRemoteAddressRange(lstart, size, rstart));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue