2016-02-14 14:39:11 +08:00
|
|
|
//===-- core_main.cpp - Core Index Tool testbed ---------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-02-14 14:39:11 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-09-06 04:33:52 +08:00
|
|
|
#include "clang/AST/Mangle.h"
|
2018-07-09 16:44:05 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2017-01-29 12:50:35 +08:00
|
|
|
#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
|
2016-02-14 14:39:11 +08:00
|
|
|
#include "clang/Frontend/ASTUnit.h"
|
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Frontend/CompilerInvocation.h"
|
|
|
|
#include "clang/Frontend/FrontendAction.h"
|
2019-11-26 10:06:56 +08:00
|
|
|
#include "clang/Index/IndexDataConsumer.h"
|
2021-01-22 03:19:34 +08:00
|
|
|
#include "clang/Index/IndexingAction.h"
|
2016-02-14 14:39:11 +08:00
|
|
|
#include "clang/Index/USRGeneration.h"
|
2018-07-09 16:44:05 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2017-01-30 14:05:58 +08:00
|
|
|
#include "clang/Serialization/ASTReader.h"
|
2016-02-14 14:39:11 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2018-08-03 01:29:53 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2021-01-22 03:19:34 +08:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2016-02-14 14:39:11 +08:00
|
|
|
#include "llvm/Support/Signals.h"
|
2021-01-22 03:19:34 +08:00
|
|
|
#include "llvm/Support/StringSaver.h"
|
2016-02-14 14:39:11 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::index;
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
extern "C" int indextest_core_main(int argc, const char **argv);
|
2021-01-22 03:19:34 +08:00
|
|
|
extern "C" int indextest_perform_shell_execution(const char *command_line);
|
2016-02-14 14:39:11 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
enum class ActionType {
|
|
|
|
None,
|
|
|
|
PrintSourceSymbols,
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace options {
|
|
|
|
|
|
|
|
static cl::OptionCategory IndexTestCoreCategory("index-test-core options");
|
|
|
|
|
|
|
|
static cl::opt<ActionType>
|
|
|
|
Action(cl::desc("Action:"), cl::init(ActionType::None),
|
|
|
|
cl::values(
|
|
|
|
clEnumValN(ActionType::PrintSourceSymbols,
|
2016-10-09 03:41:06 +08:00
|
|
|
"print-source-symbols", "Print symbols from source")),
|
2016-02-14 14:39:11 +08:00
|
|
|
cl::cat(IndexTestCoreCategory));
|
|
|
|
|
|
|
|
static cl::extrahelp MoreHelp(
|
|
|
|
"\nAdd \"-- <compiler arguments>\" at the end to setup the compiler "
|
|
|
|
"invocation\n"
|
|
|
|
);
|
|
|
|
|
2017-01-30 14:05:58 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
DumpModuleImports("dump-imported-module-files",
|
|
|
|
cl::desc("Print symbols and input files from imported modules"));
|
|
|
|
|
2017-02-26 13:37:56 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
IncludeLocals("include-locals", cl::desc("Print local symbols"));
|
|
|
|
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-24 06:22:58 +08:00
|
|
|
static cl::opt<bool> IgnoreMacros("ignore-macros",
|
|
|
|
cl::desc("Skip indexing macros"));
|
|
|
|
|
2017-01-29 12:50:35 +08:00
|
|
|
static cl::opt<std::string>
|
|
|
|
ModuleFilePath("module-file",
|
|
|
|
cl::desc("Path to module file to print symbols from"));
|
|
|
|
static cl::opt<std::string>
|
|
|
|
ModuleFormat("fmodule-format", cl::init("raw"),
|
|
|
|
cl::desc("Container format for clang modules and PCH, 'raw' or 'obj'"));
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
static void printSymbolInfo(SymbolInfo SymInfo, raw_ostream &OS);
|
|
|
|
static void printSymbolNameAndUSR(const Decl *D, ASTContext &Ctx,
|
|
|
|
raw_ostream &OS);
|
2018-09-18 23:02:56 +08:00
|
|
|
static void printSymbolNameAndUSR(const clang::Module *Mod, raw_ostream &OS);
|
2016-02-14 14:39:11 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class PrintIndexDataConsumer : public IndexDataConsumer {
|
|
|
|
raw_ostream &OS;
|
2019-09-06 04:33:52 +08:00
|
|
|
std::unique_ptr<ASTNameGenerator> ASTNameGen;
|
2018-07-09 16:44:05 +08:00
|
|
|
std::shared_ptr<Preprocessor> PP;
|
2016-02-14 14:39:11 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
PrintIndexDataConsumer(raw_ostream &OS) : OS(OS) {
|
|
|
|
}
|
|
|
|
|
2016-02-15 06:30:14 +08:00
|
|
|
void initialize(ASTContext &Ctx) override {
|
2019-09-06 04:33:52 +08:00
|
|
|
ASTNameGen.reset(new ASTNameGenerator(Ctx));
|
2016-02-15 06:30:14 +08:00
|
|
|
}
|
|
|
|
|
2018-07-09 16:44:05 +08:00
|
|
|
void setPreprocessor(std::shared_ptr<Preprocessor> PP) override {
|
|
|
|
this->PP = std::move(PP);
|
|
|
|
}
|
|
|
|
|
2019-12-16 17:33:56 +08:00
|
|
|
bool handleDeclOccurrence(const Decl *D, SymbolRoleSet Roles,
|
|
|
|
ArrayRef<SymbolRelation> Relations,
|
|
|
|
SourceLocation Loc, ASTNodeInfo ASTNode) override {
|
2016-02-14 14:39:11 +08:00
|
|
|
ASTContext &Ctx = D->getASTContext();
|
|
|
|
SourceManager &SM = Ctx.getSourceManager();
|
|
|
|
|
2018-04-09 22:12:51 +08:00
|
|
|
Loc = SM.getFileLoc(Loc);
|
|
|
|
FileID FID = SM.getFileID(Loc);
|
|
|
|
unsigned Line = SM.getLineNumber(FID, SM.getFileOffset(Loc));
|
|
|
|
unsigned Col = SM.getColumnNumber(FID, SM.getFileOffset(Loc));
|
2016-02-14 14:39:11 +08:00
|
|
|
OS << Line << ':' << Col << " | ";
|
|
|
|
|
|
|
|
printSymbolInfo(getSymbolInfo(D), OS);
|
|
|
|
OS << " | ";
|
|
|
|
|
|
|
|
printSymbolNameAndUSR(D, Ctx, OS);
|
|
|
|
OS << " | ";
|
|
|
|
|
2019-09-06 04:33:52 +08:00
|
|
|
if (ASTNameGen->writeName(D, OS))
|
2016-02-15 06:30:14 +08:00
|
|
|
OS << "<no-cgname>";
|
|
|
|
OS << " | ";
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
printSymbolRoles(Roles, OS);
|
|
|
|
OS << " | ";
|
|
|
|
|
|
|
|
OS << "rel: " << Relations.size() << '\n';
|
|
|
|
|
|
|
|
for (auto &SymRel : Relations) {
|
|
|
|
OS << '\t';
|
|
|
|
printSymbolRoles(SymRel.Roles, OS);
|
|
|
|
OS << " | ";
|
|
|
|
printSymbolNameAndUSR(SymRel.RelatedSymbol, Ctx, OS);
|
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-29 15:56:07 +08:00
|
|
|
|
2019-12-16 17:33:56 +08:00
|
|
|
bool handleModuleOccurrence(const ImportDecl *ImportD,
|
|
|
|
const clang::Module *Mod, SymbolRoleSet Roles,
|
|
|
|
SourceLocation Loc) override {
|
2016-02-29 15:56:07 +08:00
|
|
|
ASTContext &Ctx = ImportD->getASTContext();
|
|
|
|
SourceManager &SM = Ctx.getSourceManager();
|
|
|
|
|
2018-04-09 22:12:51 +08:00
|
|
|
Loc = SM.getFileLoc(Loc);
|
|
|
|
FileID FID = SM.getFileID(Loc);
|
|
|
|
unsigned Line = SM.getLineNumber(FID, SM.getFileOffset(Loc));
|
|
|
|
unsigned Col = SM.getColumnNumber(FID, SM.getFileOffset(Loc));
|
2016-02-29 15:56:07 +08:00
|
|
|
OS << Line << ':' << Col << " | ";
|
|
|
|
|
|
|
|
printSymbolInfo(getSymbolInfo(ImportD), OS);
|
|
|
|
OS << " | ";
|
|
|
|
|
2018-09-18 23:02:56 +08:00
|
|
|
printSymbolNameAndUSR(Mod, OS);
|
|
|
|
OS << " | ";
|
2016-02-29 15:56:07 +08:00
|
|
|
|
|
|
|
printSymbolRoles(Roles, OS);
|
|
|
|
OS << " |\n";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-09 16:44:05 +08:00
|
|
|
|
2019-12-16 17:33:56 +08:00
|
|
|
bool handleMacroOccurrence(const IdentifierInfo *Name, const MacroInfo *MI,
|
|
|
|
SymbolRoleSet Roles, SourceLocation Loc) override {
|
2018-07-09 16:44:05 +08:00
|
|
|
assert(PP);
|
|
|
|
SourceManager &SM = PP->getSourceManager();
|
|
|
|
|
|
|
|
Loc = SM.getFileLoc(Loc);
|
|
|
|
FileID FID = SM.getFileID(Loc);
|
|
|
|
unsigned Line = SM.getLineNumber(FID, SM.getFileOffset(Loc));
|
|
|
|
unsigned Col = SM.getColumnNumber(FID, SM.getFileOffset(Loc));
|
|
|
|
OS << Line << ':' << Col << " | ";
|
|
|
|
|
|
|
|
printSymbolInfo(getSymbolInfoForMacro(*MI), OS);
|
|
|
|
OS << " | ";
|
|
|
|
|
|
|
|
OS << Name->getName();
|
|
|
|
OS << " | ";
|
|
|
|
|
|
|
|
SmallString<256> USRBuf;
|
|
|
|
if (generateUSRForMacro(Name->getName(), MI->getDefinitionLoc(), SM,
|
|
|
|
USRBuf)) {
|
|
|
|
OS << "<no-usr>";
|
|
|
|
} else {
|
|
|
|
OS << USRBuf;
|
|
|
|
}
|
|
|
|
OS << " | ";
|
|
|
|
|
|
|
|
printSymbolRoles(Roles, OS);
|
|
|
|
OS << " |\n";
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-14 14:39:11 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Print Source Symbols
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-01-30 14:05:58 +08:00
|
|
|
static void dumpModuleFileInputs(serialization::ModuleFile &Mod,
|
|
|
|
ASTReader &Reader,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
OS << "---- Module Inputs ----\n";
|
|
|
|
Reader.visitInputFiles(Mod, /*IncludeSystem=*/true, /*Complain=*/false,
|
|
|
|
[&](const serialization::InputFile &IF, bool isSystem) {
|
|
|
|
OS << (isSystem ? "system" : "user") << " | ";
|
|
|
|
OS << IF.getFile()->getName() << '\n';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-03 01:29:53 +08:00
|
|
|
static bool printSourceSymbols(const char *Executable,
|
|
|
|
ArrayRef<const char *> Args,
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-24 06:22:58 +08:00
|
|
|
bool dumpModuleImports, bool indexLocals,
|
|
|
|
bool ignoreMacros) {
|
2016-02-14 14:39:11 +08:00
|
|
|
SmallVector<const char *, 4> ArgsWithProgName;
|
2018-08-03 01:29:53 +08:00
|
|
|
ArgsWithProgName.push_back(Executable);
|
2016-02-14 14:39:11 +08:00
|
|
|
ArgsWithProgName.append(Args.begin(), Args.end());
|
|
|
|
IntrusiveRefCntPtr<DiagnosticsEngine>
|
|
|
|
Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
|
2017-01-07 03:49:01 +08:00
|
|
|
auto CInvok = createInvocationFromCommandLine(ArgsWithProgName, Diags);
|
2016-02-14 14:39:11 +08:00
|
|
|
if (!CInvok)
|
|
|
|
return true;
|
|
|
|
|
2017-01-30 14:05:58 +08:00
|
|
|
raw_ostream &OS = outs();
|
|
|
|
auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(OS);
|
2016-02-14 14:39:11 +08:00
|
|
|
IndexingOptions IndexOpts;
|
2017-02-26 13:37:56 +08:00
|
|
|
IndexOpts.IndexFunctionLocals = indexLocals;
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-24 06:22:58 +08:00
|
|
|
IndexOpts.IndexMacros = !ignoreMacros;
|
|
|
|
IndexOpts.IndexMacrosInPreprocessor = !ignoreMacros;
|
2019-08-29 19:43:05 +08:00
|
|
|
std::unique_ptr<FrontendAction> IndexAction =
|
|
|
|
createIndexingAction(DataConsumer, IndexOpts);
|
2016-02-14 14:39:11 +08:00
|
|
|
|
|
|
|
auto PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
2017-01-07 01:47:10 +08:00
|
|
|
std::unique_ptr<ASTUnit> Unit(ASTUnit::LoadFromCompilerInvocationAction(
|
2017-01-07 03:49:01 +08:00
|
|
|
std::move(CInvok), PCHContainerOps, Diags, IndexAction.get()));
|
2016-02-14 14:39:11 +08:00
|
|
|
|
|
|
|
if (!Unit)
|
|
|
|
return true;
|
|
|
|
|
2017-01-30 14:05:58 +08:00
|
|
|
if (dumpModuleImports) {
|
|
|
|
if (auto Reader = Unit->getASTReader()) {
|
|
|
|
Reader->getModuleManager().visit([&](serialization::ModuleFile &Mod) -> bool {
|
|
|
|
OS << "==== Module " << Mod.ModuleName << " ====\n";
|
2018-04-23 22:30:21 +08:00
|
|
|
indexModuleFile(Mod, *Reader, *DataConsumer, IndexOpts);
|
2017-01-30 14:05:58 +08:00
|
|
|
dumpModuleFileInputs(Mod, *Reader, OS);
|
|
|
|
return true; // skip module dependencies.
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-29 12:50:35 +08:00
|
|
|
static bool printSourceSymbolsFromModule(StringRef modulePath,
|
|
|
|
StringRef format) {
|
|
|
|
FileSystemOptions FileSystemOpts;
|
|
|
|
auto pchContOps = std::make_shared<PCHContainerOperations>();
|
|
|
|
// Register the support for object-file-wrapped Clang modules.
|
2019-08-15 07:04:18 +08:00
|
|
|
pchContOps->registerReader(std::make_unique<ObjectFilePCHContainerReader>());
|
2017-01-29 12:50:35 +08:00
|
|
|
auto pchRdr = pchContOps->getReaderOrNull(format);
|
|
|
|
if (!pchRdr) {
|
|
|
|
errs() << "unknown module format: " << format << '\n';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
|
|
|
|
CompilerInstance::createDiagnostics(new DiagnosticOptions());
|
|
|
|
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
|
2020-01-29 03:23:46 +08:00
|
|
|
std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags,
|
2017-01-29 12:50:35 +08:00
|
|
|
FileSystemOpts, /*UseDebugInfo=*/false,
|
2020-11-06 01:37:41 +08:00
|
|
|
/*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
|
2020-11-18 09:25:50 +08:00
|
|
|
/*AllowASTWithCompilerErrors=*/true,
|
2017-01-29 12:50:35 +08:00
|
|
|
/*UserFilesAreVolatile=*/false);
|
|
|
|
if (!AU) {
|
|
|
|
errs() << "failed to create TU for: " << modulePath << '\n';
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-23 22:30:21 +08:00
|
|
|
PrintIndexDataConsumer DataConsumer(outs());
|
2017-01-29 12:50:35 +08:00
|
|
|
IndexingOptions IndexOpts;
|
|
|
|
indexASTUnit(*AU, DataConsumer, IndexOpts);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Helper Utils
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static void printSymbolInfo(SymbolInfo SymInfo, raw_ostream &OS) {
|
|
|
|
OS << getSymbolKindString(SymInfo.Kind);
|
2017-01-09 07:21:35 +08:00
|
|
|
if (SymInfo.SubKind != SymbolSubKind::None)
|
|
|
|
OS << '/' << getSymbolSubKindString(SymInfo.SubKind);
|
2016-11-12 07:49:55 +08:00
|
|
|
if (SymInfo.Properties) {
|
2016-04-22 15:21:10 +08:00
|
|
|
OS << '(';
|
2016-11-12 07:49:55 +08:00
|
|
|
printSymbolProperties(SymInfo.Properties, OS);
|
2016-04-22 15:21:10 +08:00
|
|
|
OS << ')';
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
|
|
|
OS << '/' << getSymbolLanguageString(SymInfo.Lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printSymbolNameAndUSR(const Decl *D, ASTContext &Ctx,
|
|
|
|
raw_ostream &OS) {
|
2016-02-15 09:32:36 +08:00
|
|
|
if (printSymbolName(D, Ctx.getLangOpts(), OS)) {
|
2016-02-14 14:39:11 +08:00
|
|
|
OS << "<no-name>";
|
|
|
|
}
|
|
|
|
OS << " | ";
|
|
|
|
|
|
|
|
SmallString<256> USRBuf;
|
|
|
|
if (generateUSRForDecl(D, USRBuf)) {
|
|
|
|
OS << "<no-usr>";
|
|
|
|
} else {
|
|
|
|
OS << USRBuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 23:02:56 +08:00
|
|
|
static void printSymbolNameAndUSR(const clang::Module *Mod, raw_ostream &OS) {
|
|
|
|
assert(Mod);
|
|
|
|
OS << Mod->getFullModuleName() << " | ";
|
|
|
|
generateFullUSRForModule(Mod, OS);
|
|
|
|
}
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Command line processing.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
int indextest_core_main(int argc, const char **argv) {
|
2019-11-26 10:06:56 +08:00
|
|
|
sys::PrintStackTraceOnErrorSignal(argv[0]);
|
|
|
|
PrettyStackTraceProgram X(argc, argv);
|
2018-08-03 01:29:53 +08:00
|
|
|
void *MainAddr = (void*) (intptr_t) indextest_core_main;
|
|
|
|
std::string Executable = llvm::sys::fs::getMainExecutable(argv[0], MainAddr);
|
2016-02-14 14:39:11 +08:00
|
|
|
|
2016-06-09 08:53:41 +08:00
|
|
|
assert(argv[1] == StringRef("core"));
|
|
|
|
++argv;
|
|
|
|
--argc;
|
|
|
|
|
2016-02-14 14:39:11 +08:00
|
|
|
std::vector<const char *> CompArgs;
|
2016-02-14 15:08:31 +08:00
|
|
|
const char **DoubleDash = std::find(argv, argv + argc, StringRef("--"));
|
2016-02-14 14:39:11 +08:00
|
|
|
if (DoubleDash != argv + argc) {
|
|
|
|
CompArgs = std::vector<const char *>(DoubleDash + 1, argv + argc);
|
|
|
|
argc = DoubleDash - argv;
|
|
|
|
}
|
|
|
|
|
|
|
|
cl::HideUnrelatedOptions(options::IndexTestCoreCategory);
|
|
|
|
cl::ParseCommandLineOptions(argc, argv, "index-test-core");
|
|
|
|
|
|
|
|
if (options::Action == ActionType::None) {
|
|
|
|
errs() << "error: action required; pass '-help' for options\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options::Action == ActionType::PrintSourceSymbols) {
|
2017-01-29 12:50:35 +08:00
|
|
|
if (!options::ModuleFilePath.empty()) {
|
|
|
|
return printSourceSymbolsFromModule(options::ModuleFilePath,
|
|
|
|
options::ModuleFormat);
|
|
|
|
}
|
2016-02-14 14:39:11 +08:00
|
|
|
if (CompArgs.empty()) {
|
|
|
|
errs() << "error: missing compiler args; pass '-- <compiler arguments>'\n";
|
|
|
|
return 1;
|
|
|
|
}
|
2018-08-03 01:29:53 +08:00
|
|
|
return printSourceSymbols(Executable.c_str(), CompArgs,
|
|
|
|
options::DumpModuleImports,
|
[index] Improve macro indexing support
The major change here is to index macro occurrences in more places than
before, specifically
* In non-expansion references such as `#if`, `#ifdef`, etc.
* When the macro is a reference to a builtin macro such as __LINE__.
* When using the preprocessor state instead of callbacks, we now include
all definition locations and undefinitions instead of just the latest
one (which may also have had the wrong location previously).
* When indexing an existing module file (.pcm), we now include module
macros, and we no longer report unrelated preprocessor macros during
indexing the module, which could have caused duplication.
Additionally, we now correctly obey the system symbol filter for macros,
so by default in system headers only definition/undefinition occurrences
are reported, but it can be configured to report references as well if
desired.
Extends FileIndexRecord to support occurrences of macros. Since the
design of this type is to keep a single list of entities organized by
source location, we incorporate macros into the existing DeclOccurrence
struct.
Differential Revision: https://reviews.llvm.org/D99758
2021-03-24 06:22:58 +08:00
|
|
|
options::IncludeLocals, options::IgnoreMacros);
|
2016-02-14 14:39:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-22 03:19:34 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Utility functions
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
int indextest_perform_shell_execution(const char *command_line) {
|
|
|
|
BumpPtrAllocator Alloc;
|
|
|
|
llvm::StringSaver Saver(Alloc);
|
|
|
|
SmallVector<const char *, 4> Args;
|
|
|
|
llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args);
|
|
|
|
auto Program = llvm::sys::findProgramByName(Args[0]);
|
|
|
|
if (std::error_code ec = Program.getError()) {
|
|
|
|
llvm::errs() << "command not found: " << Args[0] << "\n";
|
|
|
|
return ec.value();
|
|
|
|
}
|
|
|
|
SmallVector<StringRef, 8> execArgs(Args.begin(), Args.end());
|
|
|
|
return llvm::sys::ExecuteAndWait(*Program, execArgs);
|
|
|
|
}
|