Trying to parse header files for macros, but stuck on loading files

Hi all,

I’m rusty with C++ and am new entirely to clang/LLVM development. I’m trying to develop a custom clang-based tool that, among other things, parses all a project’s header files for macros and enums to have on hand for my own nefarious purposes.

I’m looking for two things here:

  1. Am I fundamentally on a wrong-headed approach?, and more specifically,
  2. What is going wrong with my code?

Here’s where I’m at: I have a vector of std::strings representing valid relative paths to files to parse, so I pass them to this function:

std::map<StringRef, int> getMacros(std::vector<std::string> files) {
    std::map<StringRef, int> result;

    CompilerInstance ci;
    Preprocessor &pp = ci.getPreprocessor();
    SourceManager &sm = ci.getSourceManager();
    FileManager &fm = ci.getFileManager();

    for (auto file : files) {
        ErrorOr<const FileEntry *> FileOrErr = fm.getFile(file);

And the rest doesn’t matter, because that’s the line where it falls apart. I have error handling logic after this to retrieve either the error code or the file entry, but it’s never reached. I’ve added printouts before and after the getFile() call to make sure.

From here, the code throws an exception that I haven’t been able to identify; only that it isn’t a std::exception type. So beyond that, I have no useful debugging info.

Any thoughts? Am I going about this all wrong, or is there an obvious detail wrong?