#include "FormatUtil.h"
#include "SystemInitializerTest.h"
#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/Section.h"
#include "lldb/Expression/IRMemoryMap.h"
#include "lldb/Initialization/SystemLifetimeManager.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolFile.h"
#include "lldb/Symbol/Symtab.h"
#include "lldb/Symbol/TypeList.h"
#include "lldb/Symbol/TypeMap.h"
#include "lldb/Symbol/VariableList.h"
#include "lldb/Target/Language.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/State.h"
#include "lldb/Utility/StreamString.h"
#include "llvm/ADT/IntervalMap.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/WithColor.h"
#include <cstdio>
#include <optional>
#include <thread>
usingnamespacelldb;
usingnamespacelldb_private;
usingnamespacellvm;
namespace opts {
static cl::SubCommand BreakpointSubcommand("breakpoints",
"Test breakpoint resolution");
cl::SubCommand ObjectFileSubcommand("object-file",
"Display LLDB object file information");
cl::SubCommand SymbolsSubcommand("symbols", "Dump symbols for an object file");
cl::SubCommand SymTabSubcommand("symtab",
"Test symbol table functionality");
cl::SubCommand IRMemoryMapSubcommand("ir-memory-map", "Test IRMemoryMap");
cl::SubCommand AssertSubcommand("assert", "Test assert handling");
cl::opt<std::string> Log("log", cl::desc("Path to a log file"), cl::init(""),
cl::sub(BreakpointSubcommand),
cl::sub(ObjectFileSubcommand),
cl::sub(SymbolsSubcommand),
cl::sub(SymTabSubcommand),
cl::sub(IRMemoryMapSubcommand));
TargetSP createTarget(Debugger &Dbg, const std::string &Filename);
std::unique_ptr<MemoryBuffer> openFile(const std::string &Filename);
namespace breakpoint {
static cl::opt<std::string> Target(cl::Positional, cl::desc("<target>"),
cl::Required, cl::sub(BreakpointSubcommand));
static cl::opt<std::string> CommandFile(cl::Positional,
cl::desc("<command-file>"),
cl::init("-"),
cl::sub(BreakpointSubcommand));
static cl::opt<bool> Persistent(
"persistent",
cl::desc("Don't automatically remove all breakpoints before each command"),
cl::sub(BreakpointSubcommand));
static llvm::StringRef plural(uintmax_t value) { … }
static void dumpState(const BreakpointList &List, LinePrinter &P);
static std::string substitute(StringRef Cmd);
static int evaluateBreakpoints(Debugger &Dbg);
}
namespace object {
cl::opt<bool> SectionContents("contents",
cl::desc("Dump each section's contents"),
cl::sub(ObjectFileSubcommand));
cl::opt<bool> SectionDependentModules("dep-modules",
cl::desc("Dump each dependent module"),
cl::sub(ObjectFileSubcommand));
cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input files>"),
cl::OneOrMore,
cl::sub(ObjectFileSubcommand));
}
namespace symtab {
enum class ManglingPreference { … };
static cl::opt<std::string> FindSymbolsByRegex(
"find-symbols-by-regex",
cl::desc(
"Dump symbols found in the symbol table matching the specified regex."),
cl::sub(SymTabSubcommand));
static cl::opt<ManglingPreference> ManglingPreference(
"mangling-preference",
cl::desc("Preference on mangling scheme the regex should match against and "
"dumped."),
cl::values(
clEnumValN(ManglingPreference::Mangled, "mangled", "Prefer mangled"),
clEnumValN(ManglingPreference::Demangled, "demangled",
"Prefer demangled"),
clEnumValN(ManglingPreference::MangledWithoutArguments,
"demangled-without-args", "Prefer mangled without args")),
cl::sub(SymTabSubcommand));
static cl::opt<std::string> InputFile(cl::Positional, cl::desc("<input file>"),
cl::Required, cl::sub(SymTabSubcommand));
static std::optional<llvm::Error> validate();
static Mangled::NamePreference getNamePreference();
static int handleSymtabCommand(Debugger &Dbg);
}
namespace symbols {
static cl::opt<std::string> InputFile(cl::Positional, cl::desc("<input file>"),
cl::Required, cl::sub(SymbolsSubcommand));
static cl::opt<std::string>
SymbolPath("symbol-file",
cl::desc("The file from which to fetch symbol information."),
cl::value_desc("file"), cl::sub(SymbolsSubcommand));
enum class FindType { … };
static cl::opt<FindType> Find(
"find", cl::desc("Choose search type:"),
cl::values(
clEnumValN(FindType::None, "none", "No search, just dump the module."),
clEnumValN(FindType::Function, "function", "Find functions."),
clEnumValN(FindType::Block, "block", "Find blocks."),
clEnumValN(FindType::Namespace, "namespace", "Find namespaces."),
clEnumValN(FindType::Type, "type", "Find types."),
clEnumValN(FindType::Variable, "variable", "Find global variables.")),
cl::sub(SymbolsSubcommand));
static cl::opt<std::string> Name("name", cl::desc("Name to find."),
cl::sub(SymbolsSubcommand));
static cl::opt<bool>
Regex("regex",
cl::desc("Search using regular expressions (available for variables "
"and functions only)."),
cl::sub(SymbolsSubcommand));
static cl::opt<std::string>
Context("context",
cl::desc("Restrict search to the context of the given variable."),
cl::value_desc("variable"), cl::sub(SymbolsSubcommand));
static cl::opt<std::string> CompilerContext(
"compiler-context",
cl::desc("Specify a compiler context as \"kind:name,...\"."),
cl::value_desc("context"), cl::sub(SymbolsSubcommand));
static cl::opt<bool> FindInAnyModule(
"find-in-any-module",
cl::desc("If true, the type will be searched for in all modules. Otherwise "
"the modules must be provided in -compiler-context"),
cl::sub(SymbolsSubcommand));
static cl::opt<std::string>
Language("language", cl::desc("Specify a language type, like C99."),
cl::value_desc("language"), cl::sub(SymbolsSubcommand));
static cl::list<FunctionNameType> FunctionNameFlags(
"function-flags", cl::desc("Function search flags:"),
cl::values(clEnumValN(eFunctionNameTypeAuto, "auto",
"Automatically deduce flags based on name."),
clEnumValN(eFunctionNameTypeFull, "full", "Full function name."),
clEnumValN(eFunctionNameTypeBase, "base", "Base name."),
clEnumValN(eFunctionNameTypeMethod, "method", "Method name."),
clEnumValN(eFunctionNameTypeSelector, "selector",
"Selector name.")),
cl::sub(SymbolsSubcommand));
static FunctionNameType getFunctionNameFlags() { … }
static cl::opt<bool> DumpAST("dump-ast",
cl::desc("Dump AST restored from symbols."),
cl::sub(SymbolsSubcommand));
static cl::opt<bool> DumpClangAST(
"dump-clang-ast",
cl::desc("Dump clang AST restored from symbols. When used on its own this "
"will dump the entire AST of all loaded symbols. When combined "
"with -find, it changes the presentation of the search results "
"from pretty-printing the types to an AST dump."),
cl::sub(SymbolsSubcommand));
static cl::opt<bool> Verify("verify", cl::desc("Verify symbol information."),
cl::sub(SymbolsSubcommand));
static cl::opt<std::string> File("file",
cl::desc("File (compile unit) to search."),
cl::sub(SymbolsSubcommand));
static cl::opt<int> Line("line", cl::desc("Line to search."),
cl::sub(SymbolsSubcommand));
static Expected<CompilerDeclContext> getDeclContext(SymbolFile &Symfile);
static Error findFunctions(lldb_private::Module &Module);
static Error findBlocks(lldb_private::Module &Module);
static Error findNamespaces(lldb_private::Module &Module);
static Error findTypes(lldb_private::Module &Module);
static Error findVariables(lldb_private::Module &Module);
static Error dumpModule(lldb_private::Module &Module);
static Error dumpAST(lldb_private::Module &Module);
static Error dumpEntireClangAST(lldb_private::Module &Module);
static Error verify(lldb_private::Module &Module);
static Expected<Error (*)(lldb_private::Module &)> getAction();
static int dumpSymbols(Debugger &Dbg);
}
namespace irmemorymap {
static cl::opt<std::string> Target(cl::Positional, cl::desc("<target>"),
cl::Required,
cl::sub(IRMemoryMapSubcommand));
static cl::opt<std::string> CommandFile(cl::Positional,
cl::desc("<command-file>"),
cl::init("-"),
cl::sub(IRMemoryMapSubcommand));
static cl::opt<bool> UseHostOnlyAllocationPolicy(
"host-only", cl::desc("Use the host-only allocation policy"),
cl::init(false), cl::sub(IRMemoryMapSubcommand));
AllocationT;
AddrIntervalMap;
struct IRMemoryMapTestState { … };
bool evalMalloc(StringRef Line, IRMemoryMapTestState &State);
bool evalFree(StringRef Line, IRMemoryMapTestState &State);
int evaluateMemoryMapCommands(Debugger &Dbg);
}
namespace assert {
int lldb_assert(Debugger &Dbg);
}
}
llvm::SmallVector<CompilerContext, 4> parseCompilerContext() { … }
template <typename... Args>
static Error make_string_error(const char *Format, Args &&... args) { … }
TargetSP opts::createTarget(Debugger &Dbg, const std::string &Filename) { … }
std::unique_ptr<MemoryBuffer> opts::openFile(const std::string &Filename) { … }
void opts::breakpoint::dumpState(const BreakpointList &List, LinePrinter &P) { … }
std::string opts::breakpoint::substitute(StringRef Cmd) { … }
int opts::breakpoint::evaluateBreakpoints(Debugger &Dbg) { … }
Expected<CompilerDeclContext>
opts::symbols::getDeclContext(SymbolFile &Symfile) { … }
static lldb::DescriptionLevel GetDescriptionLevel() { … }
Error opts::symbols::findFunctions(lldb_private::Module &Module) { … }
Error opts::symbols::findBlocks(lldb_private::Module &Module) { … }
Error opts::symbols::findNamespaces(lldb_private::Module &Module) { … }
Error opts::symbols::findTypes(lldb_private::Module &Module) { … }
Error opts::symbols::findVariables(lldb_private::Module &Module) { … }
Error opts::symbols::dumpModule(lldb_private::Module &Module) { … }
Error opts::symbols::dumpAST(lldb_private::Module &Module) { … }
Error opts::symbols::dumpEntireClangAST(lldb_private::Module &Module) { … }
Error opts::symbols::verify(lldb_private::Module &Module) { … }
Expected<Error (*)(lldb_private::Module &)> opts::symbols::getAction() { … }
std::optional<llvm::Error> opts::symtab::validate() { … }
static Mangled::NamePreference opts::symtab::getNamePreference() { … }
int opts::symtab::handleSymtabCommand(Debugger &Dbg) { … }
int opts::symbols::dumpSymbols(Debugger &Dbg) { … }
static void dumpSectionList(LinePrinter &Printer, const SectionList &List, bool is_subsection) { … }
static int dumpObjectFiles(Debugger &Dbg) { … }
bool opts::irmemorymap::evalMalloc(StringRef Line,
IRMemoryMapTestState &State) { … }
bool opts::irmemorymap::evalFree(StringRef Line, IRMemoryMapTestState &State) { … }
int opts::irmemorymap::evaluateMemoryMapCommands(Debugger &Dbg) { … }
int opts::assert::lldb_assert(Debugger &Dbg) { … }
int main(int argc, const char *argv[]) { … }