Reproducer.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #ifndef LLVM_TOOLS_DSYMUTIL_REPRODUCER_H
  9. #define LLVM_TOOLS_DSYMUTIL_REPRODUCER_H
  10. #include "llvm/Support/FileCollector.h"
  11. #include "llvm/Support/VirtualFileSystem.h"
  12. namespace llvm {
  13. namespace dsymutil {
  14. /// The reproducer mode.
  15. enum class ReproducerMode {
  16. GenerateOnExit,
  17. GenerateOnCrash,
  18. Use,
  19. Off,
  20. };
  21. /// The reproducer class manages the sate related to reproducers in dsymutil.
  22. /// Instances should be created with Reproducer::createReproducer. An instance
  23. /// of this class is returned when reproducers are off. The VFS returned by
  24. /// this instance is the real file system.
  25. class Reproducer {
  26. public:
  27. Reproducer();
  28. virtual ~Reproducer();
  29. IntrusiveRefCntPtr<vfs::FileSystem> getVFS() const { return VFS; }
  30. virtual void generate(){};
  31. /// Create a Reproducer instance based on the given mode.
  32. static llvm::Expected<std::unique_ptr<Reproducer>>
  33. createReproducer(ReproducerMode Mode, StringRef Root, int Argc, char **Argv);
  34. protected:
  35. IntrusiveRefCntPtr<vfs::FileSystem> VFS;
  36. };
  37. /// Reproducer instance used to generate a new reproducer. The VFS returned by
  38. /// this instance is a FileCollectorFileSystem that tracks every file used by
  39. /// dsymutil.
  40. class ReproducerGenerate : public Reproducer {
  41. public:
  42. ReproducerGenerate(std::error_code &EC, int Argc, char **Argv,
  43. bool GenerateOnExit);
  44. ~ReproducerGenerate() override;
  45. void generate() override;
  46. private:
  47. /// The path to the reproducer.
  48. std::string Root;
  49. /// The FileCollector used by the FileCollectorFileSystem.
  50. std::shared_ptr<FileCollector> FC;
  51. /// The input arguments to build the reproducer invocation.
  52. llvm::SmallVector<llvm::StringRef, 0> Args;
  53. /// Whether to generate the reproducer on destruction.
  54. bool GenerateOnExit = false;
  55. /// Whether we already generated the reproducer.
  56. bool Generated = false;
  57. };
  58. /// Reproducer instance used to use an existing reproducer. The VFS returned by
  59. /// this instance is a RedirectingFileSystem that remaps paths to their
  60. /// counterpart in the reproducer.
  61. class ReproducerUse : public Reproducer {
  62. public:
  63. ReproducerUse(StringRef Root, std::error_code &EC);
  64. ~ReproducerUse() override;
  65. private:
  66. /// The path to the reproducer.
  67. std::string Root;
  68. };
  69. } // end namespace dsymutil
  70. } // end namespace llvm
  71. #endif // LLVM_TOOLS_DSYMUTIL_REPRODUCER_H