2012-10-16 23:46:21 +00:00
|
|
|
//===-- llvm-dwarfdump.cpp - Debug info dumping utility for llvm ----------===//
|
2011-09-13 19:42:23 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This program is a utility that works like "dwarfdump".
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-09-30 00:22:25 +00:00
|
|
|
#include "llvm/ADT/StringSet.h"
|
2012-12-04 10:44:52 +00:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2015-04-23 17:37:47 +00:00
|
|
|
#include "llvm/DebugInfo/DIContext.h"
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
|
2017-09-14 17:01:53 +00:00
|
|
|
#include "llvm/Object/Archive.h"
|
2015-08-03 00:10:31 +00:00
|
|
|
#include "llvm/Object/MachOUniversal.h"
|
2011-09-13 19:42:23 +00:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/Format.h"
|
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2015-12-23 21:51:13 +00:00
|
|
|
#include "llvm/Support/Path.h"
|
2011-09-13 19:42:23 +00:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2017-10-03 22:08:22 +00:00
|
|
|
#include "llvm/Support/Regex.h"
|
2011-09-13 19:42:23 +00:00
|
|
|
#include "llvm/Support/Signals.h"
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-29 21:41:21 +00:00
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2017-09-22 09:20:57 +00:00
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
2011-09-13 19:42:23 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-11-07 23:22:07 +00:00
|
|
|
|
2011-09-13 19:42:23 +00:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace object;
|
|
|
|
|
2017-09-15 23:04:04 +00:00
|
|
|
/// Parser for options that take an optional offest argument.
|
|
|
|
/// @{
|
|
|
|
struct OffsetOption {
|
|
|
|
uint64_t Val = 0;
|
|
|
|
bool HasValue = false;
|
|
|
|
bool IsRequested = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace cl {
|
|
|
|
template <>
|
|
|
|
class parser<OffsetOption> final : public basic_parser<OffsetOption> {
|
|
|
|
public:
|
|
|
|
parser(Option &O) : basic_parser(O) {}
|
|
|
|
|
|
|
|
/// Return true on error.
|
|
|
|
bool parse(Option &O, StringRef ArgName, StringRef Arg, OffsetOption &Val) {
|
|
|
|
if (Arg == "") {
|
|
|
|
Val.Val = 0;
|
|
|
|
Val.HasValue = false;
|
|
|
|
Val.IsRequested = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Arg.getAsInteger(0, Val.Val))
|
|
|
|
return O.error("'" + Arg + "' value invalid for integer argument!");
|
|
|
|
Val.HasValue = true;
|
|
|
|
Val.IsRequested = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ValueExpected getValueExpectedFlagDefault() const {
|
|
|
|
return ValueOptional;
|
|
|
|
}
|
|
|
|
|
|
|
|
void printOptionInfo(const Option &O, size_t GlobalWidth) const {
|
|
|
|
outs() << " -" << O.ArgStr;
|
|
|
|
Option::printHelpStr(O.HelpStr, GlobalWidth, getOptionWidth(O));
|
|
|
|
}
|
|
|
|
|
|
|
|
void printOptionDiff(const Option &O, OffsetOption V, OptVal Default,
|
|
|
|
size_t GlobalWidth) const {
|
|
|
|
printOptionName(O, GlobalWidth);
|
|
|
|
outs() << "[=offset]";
|
|
|
|
}
|
|
|
|
|
|
|
|
// An out-of-line virtual method to provide a 'home' for this class.
|
|
|
|
void anchor() override {};
|
|
|
|
};
|
|
|
|
} // cl
|
|
|
|
} // llvm
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
/// Command line options.
|
|
|
|
/// @{
|
|
|
|
|
2017-09-12 22:32:53 +00:00
|
|
|
namespace {
|
2017-09-15 23:04:04 +00:00
|
|
|
using namespace cl;
|
2017-09-12 22:32:53 +00:00
|
|
|
|
|
|
|
OptionCategory DwarfDumpCategory("Specific Options");
|
|
|
|
static opt<bool> Help("h", desc("Alias for -help"), Hidden,
|
|
|
|
cat(DwarfDumpCategory));
|
|
|
|
static list<std::string>
|
|
|
|
InputFilenames(Positional, desc("<input object files or .dSYM bundles>"),
|
|
|
|
ZeroOrMore, cat(DwarfDumpCategory));
|
|
|
|
|
2017-09-15 23:04:04 +00:00
|
|
|
cl::OptionCategory SectionCategory("Section-specific Dump Options",
|
|
|
|
"These control which sections are dumped. "
|
|
|
|
"Where applicable these parameters take an "
|
|
|
|
"optional =<offset> argument to dump only "
|
|
|
|
"the entry at the specified offset.");
|
|
|
|
|
2017-09-12 22:32:53 +00:00
|
|
|
static opt<bool> DumpAll("all", desc("Dump all debug info sections"),
|
|
|
|
cat(SectionCategory));
|
|
|
|
static alias DumpAllAlias("a", desc("Alias for -all"), aliasopt(DumpAll));
|
2017-09-11 22:59:45 +00:00
|
|
|
|
2017-09-15 23:04:04 +00:00
|
|
|
// Options for dumping specific sections.
|
2017-09-13 22:09:01 +00:00
|
|
|
static unsigned DumpType = DIDT_Null;
|
2017-09-19 20:58:57 +00:00
|
|
|
static std::array<llvm::Optional<uint64_t>, (unsigned)DIDT_ID_Count>
|
|
|
|
DumpOffsets;
|
2017-09-11 22:59:45 +00:00
|
|
|
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
|
2017-09-15 23:04:04 +00:00
|
|
|
static opt<OffsetOption> Dump##ENUM_NAME( \
|
|
|
|
CMDLINE_NAME, desc("Dump the " ELF_NAME " section"), \
|
|
|
|
cat(SectionCategory));
|
2017-09-11 22:59:45 +00:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.def"
|
|
|
|
#undef HANDLE_DWARF_SECTION
|
2017-09-15 23:04:04 +00:00
|
|
|
|
2017-09-18 14:15:57 +00:00
|
|
|
static alias DumpDebugFrameAlias("eh-frame", desc("Alias for -debug-frame"),
|
2017-09-20 23:29:31 +00:00
|
|
|
NotHidden, cat(SectionCategory),
|
2017-09-18 14:15:57 +00:00
|
|
|
aliasopt(DumpDebugFrame));
|
2017-09-21 16:26:18 +00:00
|
|
|
static list<std::string>
|
|
|
|
ArchFilters("arch",
|
|
|
|
desc("Dump debug information for the specified CPU "
|
|
|
|
"architecture only. Architectures may be specified by "
|
|
|
|
"name or by number. This option can be specified "
|
|
|
|
"multiple times, once for each desired architecture."),
|
|
|
|
cat(DwarfDumpCategory));
|
2017-12-08 23:32:47 +00:00
|
|
|
static opt<bool>
|
|
|
|
Diff("diff",
|
|
|
|
desc("Emit diff-friendly output by omitting offsets and addresses."),
|
|
|
|
cat(DwarfDumpCategory));
|
2017-09-28 18:10:52 +00:00
|
|
|
static list<std::string>
|
|
|
|
Find("find",
|
|
|
|
desc("Search for the exact match for <name> in the accelerator tables "
|
2017-09-30 00:31:15 +00:00
|
|
|
"and print the matching debug information entries. When no "
|
|
|
|
"accelerator tables are available, the slower but more complete "
|
|
|
|
"-name option can be used instead."),
|
2017-09-28 18:10:52 +00:00
|
|
|
value_desc("name"), cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias FindAlias("f", desc("Alias for -find."), aliasopt(Find));
|
2017-10-02 21:21:09 +00:00
|
|
|
static opt<bool>
|
|
|
|
IgnoreCase("ignore-case",
|
|
|
|
desc("Ignore case distinctions in when searching by name."),
|
|
|
|
value_desc("i"), cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias IgnoreCaseAlias("i", desc("Alias for -ignore-case."),
|
2017-10-02 21:21:09 +00:00
|
|
|
aliasopt(IgnoreCase));
|
2017-10-03 22:08:22 +00:00
|
|
|
static list<std::string> Name(
|
|
|
|
"name",
|
|
|
|
desc("Find and print all debug info entries whose name (DW_AT_name "
|
|
|
|
"attribute) matches the exact text in <pattern>. When used with the "
|
|
|
|
"the -regex option <pattern> is interpreted as a regular expression."),
|
|
|
|
value_desc("pattern"), cat(DwarfDumpCategory));
|
2017-09-30 00:22:25 +00:00
|
|
|
static alias NameAlias("n", desc("Alias for -name"), aliasopt(Name));
|
2017-12-19 09:45:26 +00:00
|
|
|
static opt<unsigned long long> Lookup("lookup",
|
2017-10-25 21:56:41 +00:00
|
|
|
desc("Lookup <address> in the debug information and print out any"
|
|
|
|
"available file, function, block and line table details."),
|
|
|
|
value_desc("address"), cat(DwarfDumpCategory));
|
2017-09-22 09:20:57 +00:00
|
|
|
static opt<std::string>
|
|
|
|
OutputFilename("out-file", cl::init(""),
|
2017-10-06 20:24:35 +00:00
|
|
|
cl::desc("Redirect output to the specified file."),
|
2017-10-03 18:39:13 +00:00
|
|
|
cl::value_desc("filename"));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias OutputFilenameAlias("o", desc("Alias for -out-file."),
|
2017-10-03 18:39:13 +00:00
|
|
|
aliasopt(OutputFilename),
|
|
|
|
cat(DwarfDumpCategory));
|
2017-10-03 22:08:22 +00:00
|
|
|
static opt<bool>
|
|
|
|
UseRegex("regex",
|
|
|
|
desc("Treat any <pattern> strings as regular expressions when "
|
|
|
|
"searching instead of just as an exact string match."),
|
|
|
|
cat(DwarfDumpCategory));
|
|
|
|
static alias RegexAlias("x", desc("Alias for -regex"), aliasopt(UseRegex));
|
2017-09-16 17:28:00 +00:00
|
|
|
static opt<bool>
|
|
|
|
ShowChildren("show-children",
|
|
|
|
desc("Show a debug info entry's children when selectively "
|
2017-10-06 20:24:35 +00:00
|
|
|
"printing with the =<offset> option."),
|
2017-09-19 20:58:57 +00:00
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias ShowChildrenAlias("c", desc("Alias for -show-children."),
|
2017-09-16 17:28:00 +00:00
|
|
|
aliasopt(ShowChildren));
|
2017-09-18 21:27:44 +00:00
|
|
|
static opt<bool>
|
|
|
|
ShowParents("show-parents",
|
|
|
|
desc("Show a debug info entry's parents when selectively "
|
2017-10-06 20:24:35 +00:00
|
|
|
"printing with the =<offset> option."),
|
2017-09-19 20:58:57 +00:00
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias ShowParentsAlias("p", desc("Alias for -show-parents."),
|
2017-09-18 21:27:44 +00:00
|
|
|
aliasopt(ShowParents));
|
2017-10-02 16:02:04 +00:00
|
|
|
static opt<bool>
|
|
|
|
ShowForm("show-form",
|
|
|
|
desc("Show DWARF form types after the DWARF attribute types."),
|
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias ShowFormAlias("F", desc("Alias for -show-form."),
|
2017-10-02 16:02:04 +00:00
|
|
|
aliasopt(ShowForm), cat(DwarfDumpCategory));
|
2017-09-20 17:44:00 +00:00
|
|
|
static opt<unsigned> RecurseDepth(
|
|
|
|
"recurse-depth",
|
|
|
|
desc("Only recurse to a depth of N when displaying debug info entries."),
|
|
|
|
cat(DwarfDumpCategory), init(-1U), value_desc("N"));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias RecurseDepthAlias("r", desc("Alias for -recurse-depth."),
|
2017-09-20 17:44:00 +00:00
|
|
|
aliasopt(RecurseDepth));
|
2017-10-02 16:02:04 +00:00
|
|
|
|
2017-09-12 22:32:53 +00:00
|
|
|
static opt<bool>
|
2016-10-18 21:09:48 +00:00
|
|
|
SummarizeTypes("summarize-types",
|
2017-10-06 20:24:35 +00:00
|
|
|
desc("Abbreviate the description of type unit entries."),
|
2017-09-19 20:58:57 +00:00
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:34 +00:00
|
|
|
static cl::opt<bool>
|
|
|
|
Statistics("statistics",
|
|
|
|
cl::desc("Emit JSON-formatted debug info quality metrics."),
|
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static opt<bool> Verify("verify", desc("Verify the DWARF debug info."),
|
2017-09-12 22:32:53 +00:00
|
|
|
cat(DwarfDumpCategory));
|
|
|
|
static opt<bool> Quiet("quiet", desc("Use with -verify to not emit to STDOUT."),
|
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static opt<bool> DumpUUID("uuid", desc("Show the UUID for each architecture."),
|
2017-09-30 00:22:25 +00:00
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias DumpUUIDAlias("u", desc("Alias for -uuid."), aliasopt(DumpUUID));
|
2017-09-12 22:32:53 +00:00
|
|
|
static opt<bool> Verbose("verbose",
|
2017-10-06 20:24:35 +00:00
|
|
|
desc("Print more low-level encoding details."),
|
2017-09-12 22:32:53 +00:00
|
|
|
cat(DwarfDumpCategory));
|
2017-10-06 20:24:35 +00:00
|
|
|
static alias VerboseAlias("v", desc("Alias for -verbose."), aliasopt(Verbose),
|
2017-09-12 22:32:53 +00:00
|
|
|
cat(DwarfDumpCategory));
|
|
|
|
} // namespace
|
2017-09-15 23:04:04 +00:00
|
|
|
/// @}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-09-22 09:20:57 +00:00
|
|
|
static void error(StringRef Prefix, std::error_code EC) {
|
2015-06-25 23:40:15 +00:00
|
|
|
if (!EC)
|
2015-07-26 05:35:59 +00:00
|
|
|
return;
|
2017-09-22 09:20:57 +00:00
|
|
|
errs() << Prefix << ": " << EC.message() << "\n";
|
2015-07-26 05:35:59 +00:00
|
|
|
exit(1);
|
2015-06-25 23:40:15 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 23:07:24 +00:00
|
|
|
static DIDumpOptions getDumpOpts() {
|
2017-09-13 09:43:05 +00:00
|
|
|
DIDumpOptions DumpOpts;
|
|
|
|
DumpOpts.DumpType = DumpType;
|
2017-09-20 17:44:00 +00:00
|
|
|
DumpOpts.RecurseDepth = RecurseDepth;
|
2017-12-08 23:32:47 +00:00
|
|
|
DumpOpts.ShowAddresses = !Diff;
|
2017-09-16 17:28:00 +00:00
|
|
|
DumpOpts.ShowChildren = ShowChildren;
|
2017-09-18 21:27:44 +00:00
|
|
|
DumpOpts.ShowParents = ShowParents;
|
2017-10-02 16:02:04 +00:00
|
|
|
DumpOpts.ShowForm = ShowForm;
|
2017-09-13 09:43:05 +00:00
|
|
|
DumpOpts.SummarizeTypes = SummarizeTypes;
|
|
|
|
DumpOpts.Verbose = Verbose;
|
2017-09-20 17:44:00 +00:00
|
|
|
// In -verify mode, print DIEs without children in error messages.
|
|
|
|
if (Verify)
|
|
|
|
return DumpOpts.noImplicitRecursion();
|
2017-09-13 09:43:05 +00:00
|
|
|
return DumpOpts;
|
|
|
|
}
|
|
|
|
|
2017-09-21 16:26:18 +00:00
|
|
|
static uint32_t getCPUType(MachOObjectFile &MachO) {
|
|
|
|
if (MachO.is64Bit())
|
|
|
|
return MachO.getHeader64().cputype;
|
|
|
|
else
|
|
|
|
return MachO.getHeader().cputype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if the object file has not been filtered by an --arch option.
|
|
|
|
static bool filterArch(ObjectFile &Obj) {
|
|
|
|
if (ArchFilters.empty())
|
|
|
|
return true;
|
2017-09-30 00:22:21 +00:00
|
|
|
|
2017-09-21 16:26:18 +00:00
|
|
|
if (auto *MachO = dyn_cast<MachOObjectFile>(&Obj)) {
|
|
|
|
std::string ObjArch =
|
|
|
|
Triple::getArchTypeName(MachO->getArchTriple().getArch());
|
2017-09-30 00:22:21 +00:00
|
|
|
|
2017-09-21 16:26:18 +00:00
|
|
|
for (auto Arch : ArchFilters) {
|
2017-09-30 00:22:21 +00:00
|
|
|
// Match name.
|
2017-09-21 16:26:18 +00:00
|
|
|
if (Arch == ObjArch)
|
|
|
|
return true;
|
2017-09-30 00:22:21 +00:00
|
|
|
|
|
|
|
// Match architecture number.
|
2017-09-21 16:26:18 +00:00
|
|
|
unsigned Value;
|
|
|
|
if (!StringRef(Arch).getAsInteger(0, Value))
|
|
|
|
if (Value == getCPUType(*MachO))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:20:57 +00:00
|
|
|
using HandlerFn = std::function<bool(ObjectFile &, DWARFContext &DICtx, Twine,
|
|
|
|
raw_ostream &)>;
|
2017-09-21 16:26:18 +00:00
|
|
|
|
2017-09-30 00:22:25 +00:00
|
|
|
/// Print only DIEs that have a certain name.
|
|
|
|
static void filterByName(const StringSet<> &Names,
|
|
|
|
DWARFContext::cu_iterator_range CUs, raw_ostream &OS) {
|
|
|
|
for (const auto &CU : CUs)
|
|
|
|
for (const auto &Entry : CU->dies()) {
|
|
|
|
DWARFDie Die = {CU.get(), &Entry};
|
2017-10-02 21:21:09 +00:00
|
|
|
if (const char *NamePtr = Die.getName(DINameKind::ShortName)) {
|
2017-10-03 22:08:22 +00:00
|
|
|
std::string Name =
|
|
|
|
(IgnoreCase && !UseRegex) ? StringRef(NamePtr).lower() : NamePtr;
|
|
|
|
// Match regular expression.
|
|
|
|
if (UseRegex)
|
|
|
|
for (auto Pattern : Names.keys()) {
|
|
|
|
Regex RE(Pattern, IgnoreCase ? Regex::IgnoreCase : Regex::NoFlags);
|
|
|
|
std::string Error;
|
|
|
|
if (!RE.isValid(Error)) {
|
|
|
|
errs() << "error in regular expression: " << Error << "\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (RE.match(Name))
|
|
|
|
Die.dump(OS, 0, getDumpOpts());
|
|
|
|
}
|
|
|
|
// Match full text.
|
|
|
|
else if (Names.count(Name))
|
2017-10-02 21:21:09 +00:00
|
|
|
Die.dump(OS, 0, getDumpOpts());
|
|
|
|
}
|
2017-09-30 00:22:25 +00:00
|
|
|
}
|
2017-10-25 21:56:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Handle the --lookup option and dump the DIEs and line info for the given
|
|
|
|
/// address.
|
|
|
|
static bool lookup(DWARFContext &DICtx, uint64_t Address, raw_ostream &OS) {
|
|
|
|
auto DIEsForAddr = DICtx.getDIEsForAddress(Lookup);
|
|
|
|
|
|
|
|
if (!DIEsForAddr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DIDumpOptions DumpOpts = getDumpOpts();
|
|
|
|
DumpOpts.RecurseDepth = 0;
|
|
|
|
DIEsForAddr.CompileUnit->dump(OS, DumpOpts);
|
|
|
|
if (DIEsForAddr.FunctionDIE) {
|
|
|
|
DIEsForAddr.FunctionDIE.dump(OS, 2, DumpOpts);
|
|
|
|
if (DIEsForAddr.BlockDIE)
|
|
|
|
DIEsForAddr.BlockDIE.dump(OS, 4, DumpOpts);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DILineInfo LineInfo = DICtx.getLineInfoForAddress(Lookup))
|
|
|
|
LineInfo.dump(OS);
|
|
|
|
|
|
|
|
return true;
|
2017-09-30 00:22:25 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 20:24:34 +00:00
|
|
|
bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
|
|
|
|
Twine Filename, raw_ostream &OS);
|
|
|
|
|
2017-09-22 09:20:57 +00:00
|
|
|
static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
|
|
|
|
raw_ostream &OS) {
|
2017-09-21 16:26:18 +00:00
|
|
|
logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-29 21:41:21 +00:00
|
|
|
Filename.str() + ": ");
|
2017-09-30 00:22:25 +00:00
|
|
|
// The UUID dump already contains all the same information.
|
|
|
|
if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
|
|
|
|
OS << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n';
|
|
|
|
|
2017-10-25 21:56:41 +00:00
|
|
|
// Handle the --lookup option.
|
|
|
|
if (Lookup)
|
|
|
|
return lookup(DICtx, Lookup, OS);
|
|
|
|
|
2017-09-30 00:22:25 +00:00
|
|
|
// Handle the --name option.
|
|
|
|
if (!Name.empty()) {
|
|
|
|
StringSet<> Names;
|
|
|
|
for (auto name : Name)
|
2017-10-03 22:08:22 +00:00
|
|
|
Names.insert((IgnoreCase && !UseRegex) ? StringRef(name).lower() : name);
|
2017-10-02 16:02:04 +00:00
|
|
|
|
2017-09-30 00:22:25 +00:00
|
|
|
filterByName(Names, DICtx.compile_units(), OS);
|
|
|
|
filterByName(Names, DICtx.dwo_compile_units(), OS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-09-28 18:10:52 +00:00
|
|
|
// Handle the --find option and lower it to --debug-info=<offset>.
|
|
|
|
if (!Find.empty()) {
|
2017-09-28 18:27:00 +00:00
|
|
|
DumpOffsets[DIDT_ID_DebugInfo] = [&]() -> llvm::Optional<uint64_t> {
|
2017-09-29 00:33:22 +00:00
|
|
|
for (auto Name : Find) {
|
2018-01-22 13:17:23 +00:00
|
|
|
auto find = [&](const AppleAcceleratorTable &Accel)
|
2017-09-29 00:33:22 +00:00
|
|
|
-> llvm::Optional<uint64_t> {
|
|
|
|
for (auto Entry : Accel.equal_range(Name))
|
|
|
|
for (auto Atom : Entry)
|
|
|
|
if (auto Offset = Atom.getAsSectionOffset())
|
|
|
|
return Offset;
|
|
|
|
return None;
|
|
|
|
};
|
|
|
|
if (auto Offset = find(DICtx.getAppleNames()))
|
|
|
|
return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
|
|
|
|
if (auto Offset = find(DICtx.getAppleTypes()))
|
|
|
|
return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
|
2017-09-29 00:52:33 +00:00
|
|
|
if (auto Offset = find(DICtx.getAppleNamespaces()))
|
|
|
|
return DumpOffsets[DIDT_ID_DebugInfo] = *Offset;
|
[DebugInfo] Basic .debug_names dumping support
Summary:
This commit renames DWARFAcceleratorTable to AppleAcceleratorTable to free up
the first name as an interface for the different accelerator tables.
Then I add a DWARFDebugNames class for the dwarf5 table.
Presently, the only common functionality of the two classes is the dump()
method, because this is the only method that was necessary to implement
dwarfdump -debug-names; and because the rest of the
AppleAcceleratorTable interface does not directly transfer to the dwarf5
tables (the main reason for that is that the present interface assumes
the tables are homogeneous, but the dwarf5 tables can have different
keys associated with each entry).
I expect to make the common interface richer as I add more functionality
to the new class (and invent a way to represent it in generic way).
In terms of sharing the implementation, I found the format of the two
tables sufficiently different to frustrate any attempts to have common
parsing or dumping code, so presently the implementations share just low
level code for formatting dwarf constants.
Reviewers: vleschuk, JDevlieghere, clayborg, aprantl, probinson, echristo, dblaikie
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D42297
llvm-svn: 323638
2018-01-29 11:08:32 +00:00
|
|
|
// TODO: Add .debug_names support
|
2017-09-29 00:33:22 +00:00
|
|
|
}
|
2017-09-28 18:10:52 +00:00
|
|
|
return None;
|
|
|
|
}();
|
|
|
|
// Early exit if --find was specified but the current file doesn't have it.
|
|
|
|
if (!DumpOffsets[DIDT_ID_DebugInfo])
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-02 16:02:04 +00:00
|
|
|
|
2015-08-03 00:10:25 +00:00
|
|
|
// Dump the complete DWARF structure.
|
2017-09-22 09:20:57 +00:00
|
|
|
DICtx.dump(OS, getDumpOpts(), DumpOffsets);
|
2017-09-13 23:07:24 +00:00
|
|
|
return true;
|
2015-08-03 00:10:25 +00:00
|
|
|
}
|
|
|
|
|
2017-09-21 16:26:18 +00:00
|
|
|
static bool verifyObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
|
2017-09-22 09:20:57 +00:00
|
|
|
Twine Filename, raw_ostream &OS) {
|
2017-05-01 22:07:02 +00:00
|
|
|
// Verify the DWARF and exit with non-zero exit status if verification
|
|
|
|
// fails.
|
2017-09-22 09:20:57 +00:00
|
|
|
raw_ostream &stream = Quiet ? nulls() : OS;
|
2017-05-01 22:07:02 +00:00
|
|
|
stream << "Verifying " << Filename.str() << ":\tfile format "
|
|
|
|
<< Obj.getFileFormatName() << "\n";
|
2017-09-21 16:26:18 +00:00
|
|
|
bool Result = DICtx.verify(stream, getDumpOpts());
|
2017-05-01 22:07:02 +00:00
|
|
|
if (Result)
|
|
|
|
stream << "No errors.\n";
|
|
|
|
else
|
|
|
|
stream << "Errors detected.\n";
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-09-14 17:01:53 +00:00
|
|
|
static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
|
2017-09-22 09:20:57 +00:00
|
|
|
HandlerFn HandleObj, raw_ostream &OS);
|
2017-09-14 17:01:53 +00:00
|
|
|
|
|
|
|
static bool handleArchive(StringRef Filename, Archive &Arch,
|
2017-09-22 09:20:57 +00:00
|
|
|
HandlerFn HandleObj, raw_ostream &OS) {
|
2017-09-14 17:01:53 +00:00
|
|
|
bool Result = true;
|
|
|
|
Error Err = Error::success();
|
|
|
|
for (auto Child : Arch.children(Err)) {
|
|
|
|
auto BuffOrErr = Child.getMemoryBufferRef();
|
|
|
|
error(Filename, errorToErrorCode(BuffOrErr.takeError()));
|
|
|
|
auto NameOrErr = Child.getName();
|
|
|
|
error(Filename, errorToErrorCode(NameOrErr.takeError()));
|
|
|
|
std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();
|
2017-09-22 09:20:57 +00:00
|
|
|
Result &= handleBuffer(Name, BuffOrErr.get(), HandleObj, OS);
|
2017-09-14 17:01:53 +00:00
|
|
|
}
|
|
|
|
error(Filename, errorToErrorCode(std::move(Err)));
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-09-13 23:16:13 +00:00
|
|
|
static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
|
2017-09-22 09:20:57 +00:00
|
|
|
HandlerFn HandleObj, raw_ostream &OS) {
|
2017-09-13 23:16:13 +00:00
|
|
|
Expected<std::unique_ptr<Binary>> BinOrErr = object::createBinary(Buffer);
|
2017-09-14 17:01:53 +00:00
|
|
|
error(Filename, errorToErrorCode(BinOrErr.takeError()));
|
2017-08-31 16:44:47 +00:00
|
|
|
|
2017-05-01 22:07:02 +00:00
|
|
|
bool Result = true;
|
2017-09-21 16:26:18 +00:00
|
|
|
if (auto *Obj = dyn_cast<ObjectFile>(BinOrErr->get())) {
|
|
|
|
if (filterArch(*Obj)) {
|
|
|
|
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(*Obj);
|
2017-09-22 09:20:57 +00:00
|
|
|
Result = HandleObj(*Obj, *DICtx, Filename, OS);
|
2017-09-21 16:26:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-01 22:07:02 +00:00
|
|
|
else if (auto *Fat = dyn_cast<MachOUniversalBinary>(BinOrErr->get()))
|
|
|
|
for (auto &ObjForArch : Fat->objects()) {
|
2017-09-14 17:01:53 +00:00
|
|
|
std::string ObjName =
|
|
|
|
(Filename + "(" + ObjForArch.getArchFlagName() + ")").str();
|
|
|
|
if (auto MachOOrErr = ObjForArch.getAsObjectFile()) {
|
2017-09-21 16:26:18 +00:00
|
|
|
auto &Obj = **MachOOrErr;
|
|
|
|
if (filterArch(Obj)) {
|
|
|
|
std::unique_ptr<DWARFContext> DICtx = DWARFContext::create(Obj);
|
2017-09-22 09:20:57 +00:00
|
|
|
Result &= HandleObj(Obj, *DICtx, ObjName, OS);
|
2017-09-21 16:26:18 +00:00
|
|
|
}
|
2017-09-14 17:01:53 +00:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
consumeError(MachOOrErr.takeError());
|
|
|
|
if (auto ArchiveOrErr = ObjForArch.getAsArchive()) {
|
|
|
|
error(ObjName, errorToErrorCode(ArchiveOrErr.takeError()));
|
2017-09-22 09:20:57 +00:00
|
|
|
Result &= handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj, OS);
|
2017-09-14 17:01:53 +00:00
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
consumeError(ArchiveOrErr.takeError());
|
2017-05-01 22:07:02 +00:00
|
|
|
}
|
2017-09-14 17:01:53 +00:00
|
|
|
else if (auto *Arch = dyn_cast<Archive>(BinOrErr->get()))
|
2017-09-22 09:20:57 +00:00
|
|
|
Result = handleArchive(Filename, *Arch, HandleObj, OS);
|
2017-05-01 22:07:02 +00:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2017-09-22 09:20:57 +00:00
|
|
|
static bool handleFile(StringRef Filename, HandlerFn HandleObj,
|
|
|
|
raw_ostream &OS) {
|
2017-09-13 23:07:24 +00:00
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> BuffOrErr =
|
|
|
|
MemoryBuffer::getFileOrSTDIN(Filename);
|
|
|
|
error(Filename, BuffOrErr.getError());
|
|
|
|
std::unique_ptr<MemoryBuffer> Buffer = std::move(BuffOrErr.get());
|
2017-09-22 09:20:57 +00:00
|
|
|
return handleBuffer(Filename, *Buffer, HandleObj, OS);
|
2017-09-13 23:07:24 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 21:51:13 +00:00
|
|
|
/// If the input path is a .dSYM bundle (as created by the dsymutil tool),
|
|
|
|
/// replace it with individual entries for each of the object files inside the
|
|
|
|
/// bundle otherwise return the input path.
|
2016-06-08 19:09:22 +00:00
|
|
|
static std::vector<std::string> expandBundle(const std::string &InputPath) {
|
2015-12-23 21:51:13 +00:00
|
|
|
std::vector<std::string> BundlePaths;
|
|
|
|
SmallString<256> BundlePath(InputPath);
|
|
|
|
// Manually open up the bundle to avoid introducing additional dependencies.
|
|
|
|
if (sys::fs::is_directory(BundlePath) &&
|
|
|
|
sys::path::extension(BundlePath) == ".dSYM") {
|
|
|
|
std::error_code EC;
|
|
|
|
sys::path::append(BundlePath, "Contents", "Resources", "DWARF");
|
|
|
|
for (sys::fs::directory_iterator Dir(BundlePath, EC), DirEnd;
|
|
|
|
Dir != DirEnd && !EC; Dir.increment(EC)) {
|
|
|
|
const std::string &Path = Dir->path();
|
|
|
|
sys::fs::file_status Status;
|
|
|
|
EC = sys::fs::status(Path, Status);
|
|
|
|
error(Path, EC);
|
|
|
|
switch (Status.type()) {
|
|
|
|
case sys::fs::file_type::regular_file:
|
|
|
|
case sys::fs::file_type::symlink_file:
|
|
|
|
case sys::fs::file_type::type_unknown:
|
|
|
|
BundlePaths.push_back(Path);
|
|
|
|
break;
|
|
|
|
default: /*ignore*/;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error(BundlePath, EC);
|
|
|
|
}
|
|
|
|
if (!BundlePaths.size())
|
|
|
|
BundlePaths.push_back(InputPath);
|
|
|
|
return BundlePaths;
|
|
|
|
}
|
|
|
|
|
2011-09-13 19:42:23 +00:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
// Print a stack trace if we signal out.
|
2016-06-09 00:53:21 +00:00
|
|
|
sys::PrintStackTraceOnErrorSignal(argv[0]);
|
2011-09-13 19:42:23 +00:00
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
|
|
|
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
|
|
|
|
|
[dwarfdump] Pretty print location expressions and location lists
Summary:
Based on Fred's patch here: https://reviews.llvm.org/D6771
I can't seem to commandeer the old review, so I'm creating a new one.
With that change the locations exrpessions are pretty printed inline in the
DIE tree. The output looks like this for debug_loc entries:
DW_AT_location [DW_FORM_data4] (0x00000000
0x0000000000000001 - 0x000000000000000b: DW_OP_consts +3
0x000000000000000b - 0x0000000000000012: DW_OP_consts +7
0x0000000000000012 - 0x000000000000001b: DW_OP_reg0 RAX, DW_OP_piece 0x4
0x000000000000001b - 0x0000000000000024: DW_OP_breg5 RDI+0)
And like this for debug_loc.dwo entries:
DW_AT_location [DW_FORM_sec_offset] (0x00000000
Addr idx 2 (w/ length 190): DW_OP_consts +0, DW_OP_stack_value
Addr idx 3 (w/ length 23): DW_OP_reg0 RAX, DW_OP_piece 0x4)
Simple locations without ranges are printed inline:
DW_AT_location [DW_FORM_block1] (DW_OP_reg4 RSI, DW_OP_piece 0x4, DW_OP_bit_piece 0x20 0x0)
The debug_loc(.dwo) dumping in changed accordingly to factor the code.
Reviewers: dblaikie, aprantl, friss
Subscribers: mgorny, javed.absar, hiraditya, llvm-commits, JDevlieghere
Differential Revision: https://reviews.llvm.org/D37123
llvm-svn: 312042
2017-08-29 21:41:21 +00:00
|
|
|
llvm::InitializeAllTargetInfos();
|
|
|
|
llvm::InitializeAllTargetMCs();
|
|
|
|
|
2017-09-12 22:32:53 +00:00
|
|
|
HideUnrelatedOptions({&DwarfDumpCategory, &SectionCategory});
|
|
|
|
cl::ParseCommandLineOptions(
|
|
|
|
argc, argv,
|
|
|
|
"pretty-print DWARF debug information in object files"
|
|
|
|
" and debug info archives.\n");
|
|
|
|
|
|
|
|
if (Help) {
|
|
|
|
PrintHelpMessage(/*Hidden =*/false, /*Categorized =*/true);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-09-13 19:42:23 +00:00
|
|
|
|
2017-09-23 01:04:42 +00:00
|
|
|
std::unique_ptr<ToolOutputFile> OutputFile;
|
2017-09-22 09:20:57 +00:00
|
|
|
if (!OutputFilename.empty()) {
|
|
|
|
std::error_code EC;
|
2017-09-23 01:04:42 +00:00
|
|
|
OutputFile = llvm::make_unique<ToolOutputFile>(OutputFilename, EC,
|
2017-09-22 09:38:52 +00:00
|
|
|
sys::fs::F_None);
|
2017-09-22 09:20:57 +00:00
|
|
|
error("Unable to open output file" + OutputFilename, EC);
|
|
|
|
// Don't remove output file if we exit with an error.
|
|
|
|
OutputFile->keep();
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_ostream &OS = OutputFile ? OutputFile->os() : outs();
|
2017-11-29 01:12:22 +00:00
|
|
|
bool OffsetRequested = false;
|
2017-09-22 09:20:57 +00:00
|
|
|
|
2017-08-31 16:44:47 +00:00
|
|
|
// Defaults to dumping all sections, unless brief mode is specified in which
|
|
|
|
// case only the .debug_info section in dumped.
|
2017-09-11 22:59:45 +00:00
|
|
|
#define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \
|
2017-09-15 23:04:04 +00:00
|
|
|
if (Dump##ENUM_NAME.IsRequested) { \
|
|
|
|
DumpType |= DIDT_##ENUM_NAME; \
|
2017-11-29 01:12:22 +00:00
|
|
|
if (Dump##ENUM_NAME.HasValue) { \
|
2017-09-15 23:04:04 +00:00
|
|
|
DumpOffsets[DIDT_ID_##ENUM_NAME] = Dump##ENUM_NAME.Val; \
|
2017-11-29 01:12:22 +00:00
|
|
|
OffsetRequested = true; \
|
|
|
|
} \
|
2017-09-15 23:04:04 +00:00
|
|
|
}
|
2017-09-11 22:59:45 +00:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.def"
|
|
|
|
#undef HANDLE_DWARF_SECTION
|
2017-09-13 18:22:59 +00:00
|
|
|
if (DumpUUID)
|
|
|
|
DumpType |= DIDT_UUID;
|
2017-09-11 22:59:45 +00:00
|
|
|
if (DumpAll)
|
|
|
|
DumpType = DIDT_All;
|
2017-08-31 16:44:47 +00:00
|
|
|
if (DumpType == DIDT_Null) {
|
2017-09-11 23:05:20 +00:00
|
|
|
if (Verbose)
|
2017-08-31 16:44:47 +00:00
|
|
|
DumpType = DIDT_All;
|
2017-09-11 23:05:20 +00:00
|
|
|
else
|
|
|
|
DumpType = DIDT_DebugInfo;
|
2017-08-31 16:44:47 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 01:12:22 +00:00
|
|
|
// Unless dumping a specific DIE, default to --show-children.
|
|
|
|
if (!ShowChildren && !Verify && !OffsetRequested && Name.empty() && Find.empty())
|
|
|
|
ShowChildren = true;
|
|
|
|
|
2011-09-13 19:42:23 +00:00
|
|
|
// Defaults to a.out if no filenames specified.
|
|
|
|
if (InputFilenames.size() == 0)
|
|
|
|
InputFilenames.push_back("a.out");
|
|
|
|
|
2015-12-23 21:51:13 +00:00
|
|
|
// Expand any .dSYM bundles to the individual object files contained therein.
|
|
|
|
std::vector<std::string> Objects;
|
2016-05-27 12:30:51 +00:00
|
|
|
for (const auto &F : InputFilenames) {
|
2015-12-23 21:51:13 +00:00
|
|
|
auto Objs = expandBundle(F);
|
|
|
|
Objects.insert(Objects.end(), Objs.begin(), Objs.end());
|
|
|
|
}
|
|
|
|
|
2017-05-01 22:07:02 +00:00
|
|
|
if (Verify) {
|
|
|
|
// If we encountered errors during verify, exit with a non-zero exit status.
|
2017-09-22 09:20:57 +00:00
|
|
|
if (!std::all_of(Objects.begin(), Objects.end(), [&](std::string Object) {
|
|
|
|
return handleFile(Object, verifyObjectFile, OS);
|
2017-09-13 23:07:24 +00:00
|
|
|
}))
|
2017-05-01 22:07:02 +00:00
|
|
|
exit(1);
|
2017-10-06 20:24:34 +00:00
|
|
|
} else if (Statistics)
|
|
|
|
for (auto Object : Objects)
|
|
|
|
handleFile(Object, collectStatsForObjectFile, OS);
|
|
|
|
else
|
2017-09-18 22:11:33 +00:00
|
|
|
for (auto Object : Objects)
|
2017-09-22 09:20:57 +00:00
|
|
|
handleFile(Object, dumpObjectFile, OS);
|
2011-09-13 19:42:23 +00:00
|
|
|
|
2015-07-26 05:35:59 +00:00
|
|
|
return EXIT_SUCCESS;
|
2011-09-13 19:42:23 +00:00
|
|
|
}
|