| 1 | //===- tools/dsymutil/Reproducer.h ------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef LLVM_TOOLS_DSYMUTIL_REPRODUCER_H |
| 10 | #define LLVM_TOOLS_DSYMUTIL_REPRODUCER_H |
| 11 | |
| 12 | #include "llvm/Support/FileCollector.h" |
| 13 | #include "llvm/Support/VirtualFileSystem.h" |
| 14 | |
| 15 | namespace llvm { |
| 16 | namespace dsymutil { |
| 17 | |
| 18 | /// The reproducer mode. |
| 19 | enum class ReproducerMode { |
| 20 | GenerateOnExit, |
| 21 | GenerateOnCrash, |
| 22 | Use, |
| 23 | Off, |
| 24 | }; |
| 25 | |
| 26 | /// The reproducer class manages the sate related to reproducers in dsymutil. |
| 27 | /// Instances should be created with Reproducer::createReproducer. An instance |
| 28 | /// of this class is returned when reproducers are off. The VFS returned by |
| 29 | /// this instance is the real file system. |
| 30 | class Reproducer { |
| 31 | public: |
| 32 | Reproducer(); |
| 33 | virtual ~Reproducer(); |
| 34 | |
| 35 | IntrusiveRefCntPtr<vfs::FileSystem> getVFS() const { return VFS; } |
| 36 | |
| 37 | virtual void generate(){}; |
| 38 | |
| 39 | /// Create a Reproducer instance based on the given mode. |
| 40 | static llvm::Expected<std::unique_ptr<Reproducer>> |
| 41 | createReproducer(ReproducerMode Mode, StringRef Root, int Argc, char **Argv); |
| 42 | |
| 43 | protected: |
| 44 | IntrusiveRefCntPtr<vfs::FileSystem> VFS; |
| 45 | }; |
| 46 | |
| 47 | /// Reproducer instance used to generate a new reproducer. The VFS returned by |
| 48 | /// this instance is a FileCollectorFileSystem that tracks every file used by |
| 49 | /// dsymutil. |
| 50 | class ReproducerGenerate : public Reproducer { |
| 51 | public: |
| 52 | ReproducerGenerate(std::error_code &EC, int Argc, char **Argv, |
| 53 | bool GenerateOnExit); |
| 54 | ~ReproducerGenerate() override; |
| 55 | |
| 56 | void generate() override; |
| 57 | |
| 58 | private: |
| 59 | /// The path to the reproducer. |
| 60 | std::string Root; |
| 61 | |
| 62 | /// The FileCollector used by the FileCollectorFileSystem. |
| 63 | std::shared_ptr<FileCollector> FC; |
| 64 | |
| 65 | /// The input arguments to build the reproducer invocation. |
| 66 | llvm::SmallVector<llvm::StringRef, 0> Args; |
| 67 | |
| 68 | /// Whether to generate the reproducer on destruction. |
| 69 | bool GenerateOnExit = false; |
| 70 | |
| 71 | /// Whether we already generated the reproducer. |
| 72 | bool Generated = false; |
| 73 | }; |
| 74 | |
| 75 | /// Reproducer instance used to use an existing reproducer. The VFS returned by |
| 76 | /// this instance is a RedirectingFileSystem that remaps paths to their |
| 77 | /// counterpart in the reproducer. |
| 78 | class ReproducerUse : public Reproducer { |
| 79 | public: |
| 80 | ReproducerUse(StringRef Root, std::error_code &EC); |
| 81 | ~ReproducerUse() override; |
| 82 | |
| 83 | private: |
| 84 | /// The path to the reproducer. |
| 85 | std::string Root; |
| 86 | }; |
| 87 | |
| 88 | } // end namespace dsymutil |
| 89 | } // end namespace llvm |
| 90 | |
| 91 | #endif // LLVM_TOOLS_DSYMUTIL_REPRODUCER_H |
| 92 | |