Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:57

0001 //===-- Diagnostics.h -------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_DIAGNOSTICS_H
0010 #define LLDB_UTILITY_DIAGNOSTICS_H
0011 
0012 #include "lldb/Utility/FileSpec.h"
0013 #include "lldb/Utility/Log.h"
0014 #include "llvm/ADT/SmallVector.h"
0015 #include "llvm/ADT/StringSet.h"
0016 #include "llvm/Support/Error.h"
0017 
0018 #include <functional>
0019 #include <mutex>
0020 #include <optional>
0021 #include <vector>
0022 
0023 namespace lldb_private {
0024 
0025 /// Diagnostics are a collection of files to help investigate bugs and
0026 /// troubleshoot issues. Any part of the debugger can register itself with the
0027 /// help of a callback to emit one or more files into the diagnostic directory.
0028 class Diagnostics {
0029 public:
0030   Diagnostics();
0031   ~Diagnostics();
0032 
0033   /// Gather diagnostics in the given directory.
0034   llvm::Error Create(const FileSpec &dir);
0035 
0036   /// Gather diagnostics and print a message to the given output stream.
0037   /// @{
0038   bool Dump(llvm::raw_ostream &stream);
0039   bool Dump(llvm::raw_ostream &stream, const FileSpec &dir);
0040   /// @}
0041 
0042   void Report(llvm::StringRef message);
0043 
0044   using Callback = std::function<llvm::Error(const FileSpec &)>;
0045   using CallbackID = uint64_t;
0046 
0047   CallbackID AddCallback(Callback callback);
0048   void RemoveCallback(CallbackID id);
0049 
0050   static Diagnostics &Instance();
0051 
0052   static bool Enabled();
0053   static void Initialize();
0054   static void Terminate();
0055 
0056   /// Create a unique diagnostic directory.
0057   static llvm::Expected<FileSpec> CreateUniqueDirectory();
0058 
0059 private:
0060   static std::optional<Diagnostics> &InstanceImpl();
0061 
0062   llvm::Error DumpDiangosticsLog(const FileSpec &dir) const;
0063 
0064   RotatingLogHandler m_log_handler;
0065 
0066   struct CallbackEntry {
0067     CallbackEntry(CallbackID id, Callback callback)
0068         : id(id), callback(std::move(callback)) {}
0069     CallbackID id;
0070     Callback callback;
0071   };
0072 
0073   /// Monotonically increasing callback identifier. Unique per Diagnostic
0074   /// instance.
0075   CallbackID m_callback_id;
0076 
0077   /// List of callback entries.
0078   llvm::SmallVector<CallbackEntry, 4> m_callbacks;
0079 
0080   /// Mutex to protect callback list and callback identifier.
0081   std::mutex m_callbacks_mutex;
0082 };
0083 
0084 } // namespace lldb_private
0085 
0086 #endif