
values or persistent expression variables. Now if an expression consists of a value that is a child of a variable, or of a persistent variable only, we will create a value object for it and make a ValueObjectConstResult from it to freeze the value (for program variables only, not persistent variables) and avoid running JITed code. For everything else we still parse up and JIT code and run it in the inferior. There was also a lot of clean up in the expression code. I made the ClangExpressionVariables be stored in collections of shared pointers instead of in collections of objects. This will help stop a lot of copy constructors on these large objects and also cleans up the code considerably. The persistent clang expression variables were moved over to the Target to ensure they persist across process executions. Added the ability for lldb_private::Target objects to evaluate expressions. We want to evaluate expressions at the target level in case we aren't running yet, or we have just completed running. We still want to be able to access the persistent expression variables between runs, and also evaluate constant expressions. Added extra logging to the dynamic loader plug-in for MacOSX. ModuleList objects can now dump their contents with the UUID, arch and full paths being logged with appropriate prefix values. Thread hardened the Communication class a bit by making the connection auto_ptr member into a shared pointer member and then making a local copy of the shared pointer in each method that uses it to make sure another thread can't nuke the connection object while it is being used by another thread. Added a new file to the lldb/test/load_unload test that causes the test a.out file to link to the libd.dylib file all the time. This will allow us to test using the DYLD_LIBRARY_PATH environment variable after moving libd.dylib somewhere else. llvm-svn: 121745
220 lines
5.5 KiB
C++
220 lines
5.5 KiB
C++
//===-- IRToDWARF.cpp -------------------------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Expression/IRToDWARF.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
#include "llvm/InstrTypes.h"
|
|
#include "llvm/Module.h"
|
|
|
|
#include "lldb/Core/dwarf.h"
|
|
#include "lldb/Core/Log.h"
|
|
#include "lldb/Core/Scalar.h"
|
|
#include "lldb/Core/StreamString.h"
|
|
#include "lldb/Expression/ClangExpressionDeclMap.h"
|
|
#include "lldb/Expression/ClangExpressionVariable.h"
|
|
|
|
#include <map>
|
|
|
|
using namespace llvm;
|
|
|
|
static char ID;
|
|
|
|
IRToDWARF::IRToDWARF(lldb_private::ClangExpressionVariableList &local_vars,
|
|
lldb_private::ClangExpressionDeclMap *decl_map,
|
|
lldb_private::StreamString &strm,
|
|
const char *func_name) :
|
|
ModulePass(ID),
|
|
m_local_vars(local_vars),
|
|
m_decl_map(decl_map),
|
|
m_strm(strm),
|
|
m_func_name(func_name)
|
|
{
|
|
}
|
|
|
|
IRToDWARF::~IRToDWARF()
|
|
{
|
|
}
|
|
|
|
class Relocator
|
|
{
|
|
public:
|
|
Relocator()
|
|
{
|
|
}
|
|
|
|
~Relocator()
|
|
{
|
|
}
|
|
|
|
void MarkBasicBlock(BasicBlock *bb, uint16_t offset)
|
|
{
|
|
m_basic_blocks[bb] = offset;
|
|
}
|
|
|
|
bool BasicBlockIsMarked(BasicBlock *bb)
|
|
{
|
|
return m_basic_blocks.find(bb) != m_basic_blocks.end();
|
|
}
|
|
|
|
void MarkRelocation(BasicBlock *bb, uint16_t offset)
|
|
{
|
|
m_relocations[offset] = bb;
|
|
}
|
|
|
|
bool ResolveRelocations(lldb_private::StreamString &strm)
|
|
{
|
|
std::map<uint16_t, BasicBlock*>::const_iterator iter;
|
|
|
|
lldb_private::StreamString swapper(0, 32, strm.GetByteOrder());
|
|
|
|
// This array must be delete [] d at every exit
|
|
size_t temporary_bufsize = strm.GetSize();
|
|
uint8_t *temporary_buffer(new uint8_t[temporary_bufsize]);
|
|
|
|
memcpy(temporary_buffer, strm.GetData(), temporary_bufsize);
|
|
|
|
for (iter = m_relocations.begin();
|
|
iter != m_relocations.end();
|
|
++iter)
|
|
{
|
|
const std::pair<uint16_t, BasicBlock*> &pair = *iter;
|
|
|
|
uint16_t off = pair.first;
|
|
BasicBlock *bb = pair.second;
|
|
|
|
if (m_basic_blocks.find(bb) == m_basic_blocks.end())
|
|
{
|
|
delete [] temporary_buffer;
|
|
return false;
|
|
}
|
|
|
|
uint16_t target_off = m_basic_blocks[bb];
|
|
|
|
int16_t relative = (int16_t)target_off - (int16_t)off;
|
|
|
|
swapper.Clear();
|
|
swapper << relative;
|
|
|
|
// off is intended to be the offset of the branch opcode (which is
|
|
// what the relative location is added to) so
|
|
// (temporary_buffer + off + 1) skips the opcode and writes to the
|
|
// relative location
|
|
memcpy(temporary_buffer + off + 1, swapper.GetData(), sizeof(uint16_t));
|
|
}
|
|
|
|
strm.Clear();
|
|
strm.Write(temporary_buffer, temporary_bufsize);
|
|
|
|
delete [] temporary_buffer;
|
|
return true;
|
|
}
|
|
private:
|
|
std::map<BasicBlock*, uint16_t> m_basic_blocks;
|
|
std::map<uint16_t, BasicBlock*> m_relocations;
|
|
};
|
|
|
|
bool
|
|
IRToDWARF::runOnBasicBlock(BasicBlock &BB, Relocator &R)
|
|
{
|
|
///////////////////////////////////////
|
|
// Mark the current block as visited
|
|
//
|
|
|
|
size_t stream_size = m_strm.GetSize();
|
|
|
|
if (stream_size > 0xffff)
|
|
return false;
|
|
|
|
uint16_t offset = stream_size & 0xffff;
|
|
|
|
R.MarkBasicBlock(&BB, offset);
|
|
|
|
////////////////////////////////////////////////
|
|
// Translate the current basic block to DWARF
|
|
//
|
|
|
|
/////////////////////////////////////////////////
|
|
// Visit all successors we haven't visited yet
|
|
//
|
|
|
|
TerminatorInst *arnold = BB.getTerminator();
|
|
|
|
if (!arnold)
|
|
return false;
|
|
|
|
unsigned successor_index;
|
|
unsigned num_successors = arnold->getNumSuccessors();
|
|
|
|
for (successor_index = 0;
|
|
successor_index < num_successors;
|
|
++successor_index)
|
|
{
|
|
BasicBlock *successor = arnold->getSuccessor(successor_index);
|
|
|
|
if (!R.BasicBlockIsMarked(successor))
|
|
{
|
|
if (!runOnBasicBlock(*successor, R))
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
IRToDWARF::runOnModule(Module &M)
|
|
{
|
|
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
|
|
|
|
llvm::Function* function = M.getFunction(StringRef(m_func_name.c_str()));
|
|
|
|
if (!function)
|
|
{
|
|
if (log)
|
|
log->Printf("Couldn't find %s() in the module", m_func_name.c_str());
|
|
|
|
return false;
|
|
}
|
|
|
|
Relocator relocator;
|
|
|
|
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;
|
|
|
|
return relocator.ResolveRelocations(m_strm);
|
|
}
|
|
|
|
void
|
|
IRToDWARF::assignPassManager(PMStack &PMS,
|
|
PassManagerType T)
|
|
{
|
|
}
|
|
|
|
PassManagerType
|
|
IRToDWARF::getPotentialPassManagerType() const
|
|
{
|
|
return PMT_ModulePassManager;
|
|
}
|