r293416 - [c-index-test] Provide capability for 'c-index-test core' to dump symbol information from a PCH/module file.

Argyrios Kyrtzidis via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 30 08:18:07 PST 2017


Hi Hans,

Could this go into the stable branch, along with the follow-ups:
r293461
r293463
r293466

> On Jan 28, 2017, at 8:50 PM, Argyrios Kyrtzidis via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> 
> Author: akirtzidis
> Date: Sat Jan 28 22:50:35 2017
> New Revision: 293416
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=293416&view=rev
> Log:
> [c-index-test] Provide capability for 'c-index-test core' to dump symbol information from a PCH/module file.
> 
> Added:
>    cfe/trunk/test/Index/Core/index-pch.c
> Modified:
>    cfe/trunk/tools/c-index-test/CMakeLists.txt
>    cfe/trunk/tools/c-index-test/core_main.cpp
> 
> Added: cfe/trunk/test/Index/Core/index-pch.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-pch.c?rev=293416&view=auto
> ==============================================================================
> --- cfe/trunk/test/Index/Core/index-pch.c (added)
> +++ cfe/trunk/test/Index/Core/index-pch.c Sat Jan 28 22:50:35 2017
> @@ -0,0 +1,13 @@
> +// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
> +// RUN: %clang_cc1 -emit-pch %s -o %t.pch
> +// RUN: c-index-test core -print-source-symbols -module-file %t.pch | FileCheck %s
> +
> +// CHECK: [[@LINE+1]]:6 | function/C | test1 | [[TEST1_USR:.*]] | [[TEST1_CG:.*]] | Decl | rel: 0
> +void test1();
> +
> +// CHECK: [[@LINE+1]]:20 | function/C | test2 | [[TEST2_USR:.*]] | {{.*}} | Def | rel: 0
> +static inline void test2() {
> +  // CHECK: [[@LINE+2]]:3 | function/C | test1 | [[TEST1_USR]] | [[TEST1_CG]] | Ref,Call,RelCall,RelCont | rel: 1
> +  // CHECK-NEXT: RelCall,RelCont | test2 | [[TEST2_USR]]
> +  test1();
> +}
> 
> Modified: cfe/trunk/tools/c-index-test/CMakeLists.txt
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/CMakeLists.txt?rev=293416&r1=293415&r2=293416&view=diff
> ==============================================================================
> --- cfe/trunk/tools/c-index-test/CMakeLists.txt (original)
> +++ cfe/trunk/tools/c-index-test/CMakeLists.txt Sat Jan 28 22:50:35 2017
> @@ -24,6 +24,7 @@ else()
>     libclang
>     clangAST
>     clangBasic
> +    clangCodeGen
>     clangFrontend
>     clangIndex
>   )
> 
> Modified: cfe/trunk/tools/c-index-test/core_main.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/core_main.cpp?rev=293416&r1=293415&r2=293416&view=diff
> ==============================================================================
> --- cfe/trunk/tools/c-index-test/core_main.cpp (original)
> +++ cfe/trunk/tools/c-index-test/core_main.cpp Sat Jan 28 22:50:35 2017
> @@ -7,6 +7,7 @@
> //
> //===----------------------------------------------------------------------===//
> 
> +#include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
> #include "clang/Frontend/ASTUnit.h"
> #include "clang/Frontend/CompilerInstance.h"
> #include "clang/Frontend/CompilerInvocation.h"
> @@ -49,6 +50,13 @@ static cl::extrahelp MoreHelp(
>   "invocation\n"
> );
> 
> +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'"));
> +
> }
> } // anonymous namespace
> 
> @@ -160,6 +168,39 @@ static bool printSourceSymbols(ArrayRef<
>   return false;
> }
> 
> +static bool printSourceSymbolsFromModule(StringRef modulePath,
> +                                         StringRef format) {
> +  FileSystemOptions FileSystemOpts;
> +  auto pchContOps = std::make_shared<PCHContainerOperations>();
> +  // Register the support for object-file-wrapped Clang modules.
> +  pchContOps->registerReader(llvm::make_unique<ObjectFilePCHContainerReader>());
> +  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(
> +      modulePath, *pchRdr, Diags,
> +      FileSystemOpts, /*UseDebugInfo=*/false,
> +      /*OnlyLocalDecls=*/true, None,
> +      /*CaptureDiagnostics=*/false,
> +      /*AllowPCHWithCompilerErrors=*/true,
> +      /*UserFilesAreVolatile=*/false);
> +  if (!AU) {
> +    errs() << "failed to create TU for: " << modulePath << '\n';
> +    return true;
> +  }
> +
> +  auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(outs());
> +  IndexingOptions IndexOpts;
> +  indexASTUnit(*AU, DataConsumer, IndexOpts);
> +
> +  return false;
> +}
> +
> //===----------------------------------------------------------------------===//
> // Helper Utils
> //===----------------------------------------------------------------------===//
> @@ -219,6 +260,10 @@ int indextest_core_main(int argc, const
>   }
> 
>   if (options::Action == ActionType::PrintSourceSymbols) {
> +    if (!options::ModuleFilePath.empty()) {
> +      return printSourceSymbolsFromModule(options::ModuleFilePath,
> +                                          options::ModuleFormat);
> +    }
>     if (CompArgs.empty()) {
>       errs() << "error: missing compiler args; pass '-- <compiler arguments>'\n";
>       return 1;
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list