diff options
Diffstat (limited to 'src/cc/bcc_debug.cc')
-rw-r--r-- | src/cc/bcc_debug.cc | 95 |
1 files changed, 50 insertions, 45 deletions
diff --git a/src/cc/bcc_debug.cc b/src/cc/bcc_debug.cc index 52b6571e..d7ed49fa 100644 --- a/src/cc/bcc_debug.cc +++ b/src/cc/bcc_debug.cc @@ -19,6 +19,9 @@ #include <tuple> #include <vector> +#if LLVM_MAJOR_VERSION >= 15 +#include <llvm/DebugInfo/DWARF/DWARFCompileUnit.h> +#endif #include <llvm/DebugInfo/DWARF/DWARFContext.h> #include <llvm/DebugInfo/DWARF/DWARFDebugLine.h> #include <llvm/IR/Module.h> @@ -29,6 +32,9 @@ #include <llvm/MC/MCInstrInfo.h> #include <llvm/MC/MCObjectFileInfo.h> #include <llvm/MC/MCRegisterInfo.h> +#if LLVM_MAJOR_VERSION >= 15 +#include <llvm/MC/MCSubtargetInfo.h> +#endif #if LLVM_MAJOR_VERSION >= 14 #include <llvm/MC/TargetRegistry.h> #else @@ -190,68 +196,67 @@ void SourceDebugger::dump() { vector<string> LineCache = buildLineCache(); // Start to disassemble with source code annotation section by section - for (auto section : sections_) - if (!strncmp(fn_prefix_.c_str(), section.first.c_str(), - fn_prefix_.size())) { - MCDisassembler::DecodeStatus S; - MCInst Inst; - uint64_t Size; - uint8_t *FuncStart = get<0>(section.second); - uint64_t FuncSize = get<1>(section.second); + prog_func_info_.for_each_func([&](std::string func_name, FuncInfo &info) { + MCDisassembler::DecodeStatus S; + MCInst Inst; + uint64_t Size; + uint8_t *FuncStart = info.start_; + uint64_t FuncSize = info.size_; #if LLVM_MAJOR_VERSION >= 9 - unsigned SectionID = get<2>(section.second); + auto section = sections_.find(info.section_); + if (section == sections_.end()) { + errs() << "Debug Error: no section entry for section " << info.section_ + << '\n'; + return; + } + unsigned SectionID = get<2>(section->second); #endif - ArrayRef<uint8_t> Data(FuncStart, FuncSize); - uint32_t CurrentSrcLine = 0; - string func_name = section.first.substr(fn_prefix_.size()); + ArrayRef<uint8_t> Data(FuncStart, FuncSize); + uint32_t CurrentSrcLine = 0; - errs() << "Disassembly of section " << section.first << ":\n" - << func_name << ":\n"; + errs() << "Disassembly of function " << func_name << "\n"; - string src_dbg_str; - llvm::raw_string_ostream os(src_dbg_str); - for (uint64_t Index = 0; Index < FuncSize; Index += Size) { + string src_dbg_str; + llvm::raw_string_ostream os(src_dbg_str); + for (uint64_t Index = 0; Index < FuncSize; Index += Size) { #if LLVM_MAJOR_VERSION >= 10 - S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, - nulls()); + S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls()); #else - S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, - nulls(), nulls()); + S = DisAsm->getInstruction(Inst, Size, Data.slice(Index), Index, nulls(), + nulls()); #endif - if (S != MCDisassembler::Success) { - os << "Debug Error: disassembler failed: " << std::to_string(S) - << '\n'; - break; - } else { - DILineInfo LineInfo; + if (S != MCDisassembler::Success) { + os << "Debug Error: disassembler failed: " << std::to_string(S) << '\n'; + break; + } else { + DILineInfo LineInfo; - LineTable->getFileLineInfoForAddress( + LineTable->getFileLineInfoForAddress( #if LLVM_MAJOR_VERSION >= 9 - {(uint64_t)FuncStart + Index, SectionID}, + {(uint64_t)FuncStart + Index, SectionID}, #else - (uint64_t)FuncStart + Index, + (uint64_t)FuncStart + Index, #endif - CU->getCompilationDir(), - DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, - LineInfo); + CU->getCompilationDir(), + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, LineInfo); - adjustInstSize(Size, Data[Index], Data[Index + 1]); - dumpSrcLine(LineCache, LineInfo.FileName, LineInfo.Line, - CurrentSrcLine, os); - os << format("%4" PRIu64 ":", Index >> 3) << '\t'; - dumpBytes(Data.slice(Index, Size), os); + adjustInstSize(Size, Data[Index], Data[Index + 1]); + dumpSrcLine(LineCache, LineInfo.FileName, LineInfo.Line, CurrentSrcLine, + os); + os << format("%4" PRIu64 ":", Index >> 3) << '\t'; + dumpBytes(Data.slice(Index, Size), os); #if LLVM_MAJOR_VERSION >= 10 - IP->printInst(&Inst, 0, "", *STI, os); + IP->printInst(&Inst, 0, "", *STI, os); #else - IP->printInst(&Inst, os, "", *STI); + IP->printInst(&Inst, os, "", *STI); #endif - os << '\n'; - } + os << '\n'; } - os.flush(); - errs() << src_dbg_str << '\n'; - src_dbg_fmap_[func_name] = src_dbg_str; } + os.flush(); + errs() << src_dbg_str << '\n'; + src_dbg_fmap_[func_name] = src_dbg_str; + }); } } // namespace ebpf |