本文整理汇总了C++中DILineInfo类的典型用法代码示例。如果您正苦于以下问题:C++ DILineInfo类的具体用法?C++ DILineInfo怎么用?C++ DILineInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DILineInfo类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DumpInput
static void DumpInput(const StringRef &Filename) {
OwningPtr<MemoryBuffer> Buff;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
errs() << Filename << ": " << ec.message() << "\n";
return;
}
OwningPtr<ObjectFile> Obj(ObjectFile::createObjectFile(Buff.take()));
StringRef DebugInfoSection;
StringRef DebugAbbrevSection;
StringRef DebugLineSection;
StringRef DebugArangesSection;
StringRef DebugStringSection;
error_code ec;
for (ObjectFile::section_iterator i = Obj->begin_sections(),
e = Obj->end_sections();
i != e; i.increment(ec)) {
StringRef name;
i->getName(name);
StringRef data;
i->getContents(data);
if (name.startswith("__DWARF,"))
name = name.substr(8); // Skip "__DWARF," prefix.
name = name.substr(name.find_first_not_of("._")); // Skip . and _ prefixes.
if (name == "debug_info")
DebugInfoSection = data;
else if (name == "debug_abbrev")
DebugAbbrevSection = data;
else if (name == "debug_line")
DebugLineSection = data;
else if (name == "debug_aranges")
DebugArangesSection = data;
else if (name == "debug_str")
DebugStringSection = data;
}
OwningPtr<DIContext> dictx(DIContext::getDWARFContext(/*FIXME*/true,
DebugInfoSection,
DebugAbbrevSection,
DebugArangesSection,
DebugLineSection,
DebugStringSection));
if (Address == -1ULL) {
outs() << Filename
<< ":\tfile format " << Obj->getFileFormatName() << "\n\n";
// Dump the complete DWARF structure.
dictx->dump(outs());
} else {
// Print line info for the specified address.
DILineInfo dli = dictx->getLineInfoForAddress(Address);
outs() << (dli.getFileName() ? dli.getFileName() : "<unknown>") << ':'
<< dli.getLine() << ':' << dli.getColumn() << '\n';
}
}
示例2: DemangleName
std::string LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo) const {
// By default, DILineInfo contains "<invalid>" for function/filename it
// cannot fetch. We replace it to "??" to make our output closer to addr2line.
static const std::string kDILineInfoBadString = "<invalid>";
std::stringstream Result;
if (Opts.PrintFunctions) {
std::string FunctionName = LineInfo.getFunctionName();
if (FunctionName == kDILineInfoBadString)
FunctionName = kBadString;
DemangleName(FunctionName);
Result << FunctionName << "\n";
}
std::string Filename = LineInfo.getFileName();
if (Filename == kDILineInfoBadString)
Filename = kBadString;
Result << Filename << ":" << LineInfo.getLine()
<< ":" << LineInfo.getColumn() << "\n";
return Result.str();
}
示例3: PrintDILineInfo
static void PrintDILineInfo(DILineInfo dli) {
if (PrintFunctions)
outs() << (dli.getFunctionName() ? dli.getFunctionName() : "<unknown>")
<< "\n";
outs() << (dli.getFileName() ? dli.getFileName() : "<unknown>") << ':'
<< dli.getLine() << ':' << dli.getColumn() << '\n';
}
示例4: lookup_pointer
void lookup_pointer(DIContext *context, const char **name, size_t *line, const char **filename, size_t pointer, int demangle, int *fromC)
{
DILineInfo info;
if (demangle && *name != NULL)
*name = jl_demangle(*name);
#ifdef LLVM35
DILineInfoSpecifier infoSpec(DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
DILineInfoSpecifier::FunctionNameKind::ShortName);
#else
int infoSpec = DILineInfoSpecifier::FileLineInfo |
DILineInfoSpecifier::AbsoluteFilePath |
DILineInfoSpecifier::FunctionName;
#endif
if (context == NULL) goto done;
info = context->getLineInfoForAddress(pointer, infoSpec);
#ifndef LLVM35 // LLVM <= 3.4
if (strcmp(info.getFunctionName(), "<invalid>") == 0) goto done;
if (demangle)
*name = jl_demangle(info.getFunctionName());
else
*name = strdup(info.getFunctionName());
*line = info.getLine();
*filename = strdup(info.getFileName());
#else
if (strcmp(info.FunctionName.c_str(), "<invalid>") == 0) goto done;
*name = strdup(info.FunctionName.c_str());
*line = info.Line;
*filename = strdup(info.FileName.c_str());
#endif
done:
// If this is a jlcall wrapper, set fromC to match JIT behavior
if (*name == NULL || memcmp(*name,"jlcall_",7) == 0)
*fromC = true;
}
示例5: lookup_pointer
void lookup_pointer(DIContext *context, const char **name, int *line, const char **filename, size_t pointer, int demangle)
{
if (context == NULL) return;
#ifdef LLVM35
DILineInfoSpecifier infoSpec(DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath,
DILineInfoSpecifier::FunctionNameKind::ShortName);
#else
int infoSpec = DILineInfoSpecifier::FileLineInfo |
DILineInfoSpecifier::AbsoluteFilePath |
DILineInfoSpecifier::FunctionName;
#endif
DILineInfo info = context->getLineInfoForAddress(pointer, infoSpec);
#ifndef LLVM35 // LLVM <= 3.4
if (strcmp(info.getFunctionName(), "<invalid>") == 0) return;
if (demangle)
*name = jl_demangle(info.getFunctionName());
else
*name = strdup(info.getFunctionName());
*line = info.getLine();
*filename = strdup(info.getFileName());
#else
if (strcmp(info.FunctionName.c_str(), "<invalid>") == 0) return;
*name = strdup(info.FunctionName.c_str());
*line = info.Line;
*filename = strdup(info.FileName.c_str());
#endif
}
示例6: patchFunctionNameInDILineInfo
static void patchFunctionNameInDILineInfo(const std::string &NewFunctionName,
DILineInfo &LineInfo) {
std::string FileName = LineInfo.getFileName();
LineInfo = DILineInfo(StringRef(FileName), StringRef(NewFunctionName),
LineInfo.getLine(), LineInfo.getColumn());
}
示例7: errs
//.........这里部分代码省略.........
Start -= SectionAddress;
// Stop disassembling either at the beginning of the next symbol or at
// the end of the section.
bool containsNextSym = false;
uint64_t NextSym = 0;
uint64_t NextSymIdx = SymIdx+1;
while (Symbols.size() > NextSymIdx) {
SymbolRef::Type NextSymType;
Symbols[NextSymIdx].getType(NextSymType);
if (NextSymType == SymbolRef::ST_Function) {
Sections[SectIdx].containsSymbol(Symbols[NextSymIdx],
containsNextSym);
Symbols[NextSymIdx].getAddress(NextSym);
NextSym -= SectionAddress;
break;
}
++NextSymIdx;
}
uint64_t SectSize;
Sections[SectIdx].getSize(SectSize);
uint64_t End = containsNextSym ? NextSym : SectSize;
uint64_t Size;
symbolTableWorked = true;
if (!CFG) {
// Normal disassembly, print addresses, bytes and mnemonic form.
StringRef SymName;
Symbols[SymIdx].getName(SymName);
outs() << SymName << ":\n";
DILineInfo lastLine;
for (uint64_t Index = Start; Index < End; Index += Size) {
MCInst Inst;
if (DisAsm->getInstruction(Inst, Size, memoryObject, Index,
DebugOut, nulls())) {
uint64_t SectAddress = 0;
Sections[SectIdx].getAddress(SectAddress);
outs() << format("%8" PRIx64 ":\t", SectAddress + Index);
DumpBytes(StringRef(Bytes.data() + Index, Size));
IP->printInst(&Inst, outs(), "");
// Print debug info.
if (diContext) {
DILineInfo dli =
diContext->getLineInfoForAddress(SectAddress + Index);
// Print valid line info if it changed.
if (dli != lastLine && dli.getLine() != 0)
outs() << "\t## " << dli.getFileName() << ':'
<< dli.getLine() << ':' << dli.getColumn();
lastLine = dli;
}
outs() << "\n";
} else {
errs() << "llvm-objdump: warning: invalid instruction encoding\n";
if (Size == 0)
Size = 1; // skip illegible bytes
}
}
} else {
// Create CFG and use it for disassembly.
StringRef SymName;
示例8: DisassembleInputMachO2
//.........这里部分代码省略.........
SymbolRef::Type ST;
Symbols[SymIdx].getType(ST);
if (ST != SymbolRef::ST_Function)
continue;
// Make sure the symbol is defined in this section.
bool containsSym = false;
Sections[SectIdx].containsSymbol(Symbols[SymIdx], containsSym);
if (!containsSym)
continue;
// Start at the address of the symbol relative to the section's address.
uint64_t SectionAddress = 0;
uint64_t Start = 0;
Sections[SectIdx].getAddress(SectionAddress);
Symbols[SymIdx].getAddress(Start);
Start -= SectionAddress;
// Stop disassembling either at the beginning of the next symbol or at
// the end of the section.
bool containsNextSym = false;
uint64_t NextSym = 0;
uint64_t NextSymIdx = SymIdx+1;
while (Symbols.size() > NextSymIdx) {
SymbolRef::Type NextSymType;
Symbols[NextSymIdx].getType(NextSymType);
if (NextSymType == SymbolRef::ST_Function) {
Sections[SectIdx].containsSymbol(Symbols[NextSymIdx],
containsNextSym);
Symbols[NextSymIdx].getAddress(NextSym);
NextSym -= SectionAddress;
break;
}
++NextSymIdx;
}
uint64_t SectSize;
Sections[SectIdx].getSize(SectSize);
uint64_t End = containsNextSym ? NextSym : SectSize;
uint64_t Size;
symbolTableWorked = true;
outs() << SymName << ":\n";
DILineInfo lastLine;
for (uint64_t Index = Start; Index < End; Index += Size) {
MCInst Inst;
if (DisAsm->getInstruction(Inst, Size, memoryObject, Index,
DebugOut, nulls())) {
uint64_t SectAddress = 0;
Sections[SectIdx].getAddress(SectAddress);
outs() << format("%8" PRIx64 ":\t", SectAddress + Index);
DumpBytes(StringRef(Bytes.data() + Index, Size));
IP->printInst(&Inst, outs(), "");
// Print debug info.
if (diContext) {
DILineInfo dli =
diContext->getLineInfoForAddress(SectAddress + Index);
// Print valid line info if it changed.
if (dli != lastLine && dli.getLine() != 0)
outs() << "\t## " << dli.getFileName() << ':'
<< dli.getLine() << ':' << dli.getColumn();
lastLine = dli;
}
outs() << "\n";
} else {
errs() << "llvm-objdump: warning: invalid instruction encoding\n";
if (Size == 0)
Size = 1; // skip illegible bytes
}
}
}
if (!symbolTableWorked) {
// Reading the symbol table didn't work, disassemble the whole section.
uint64_t SectAddress;
Sections[SectIdx].getAddress(SectAddress);
uint64_t SectSize;
Sections[SectIdx].getSize(SectSize);
uint64_t InstSize;
for (uint64_t Index = 0; Index < SectSize; Index += InstSize) {
MCInst Inst;
if (DisAsm->getInstruction(Inst, InstSize, memoryObject, Index,
DebugOut, nulls())) {
outs() << format("%8" PRIx64 ":\t", SectAddress + Index);
DumpBytes(StringRef(Bytes.data() + Index, InstSize));
IP->printInst(&Inst, outs(), "");
outs() << "\n";
} else {
errs() << "llvm-objdump: warning: invalid instruction encoding\n";
if (InstSize == 0)
InstSize = 1; // skip illegible bytes
}
}
}
}
}