File indexing completed on 2026-05-10 08:42:57
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef LLDB_UTILITY_INSTRUMENTATION_H
0009 #define LLDB_UTILITY_INSTRUMENTATION_H
0010
0011 #include "lldb/Utility/FileSpec.h"
0012 #include "lldb/Utility/Log.h"
0013 #include "llvm/ADT/DenseMap.h"
0014 #include "llvm/ADT/StringRef.h"
0015 #include "llvm/Support/ErrorHandling.h"
0016
0017 #include <map>
0018 #include <thread>
0019 #include <type_traits>
0020
0021 namespace lldb_private {
0022 namespace instrumentation {
0023
0024 template <typename T, std::enable_if_t<std::is_fundamental<T>::value, int> = 0>
0025 inline void stringify_append(llvm::raw_string_ostream &ss, const T &t) {
0026 ss << t;
0027 }
0028
0029 template <typename T, std::enable_if_t<!std::is_fundamental<T>::value, int> = 0>
0030 inline void stringify_append(llvm::raw_string_ostream &ss, const T &t) {
0031 ss << &t;
0032 }
0033
0034 template <typename T>
0035 inline void stringify_append(llvm::raw_string_ostream &ss, T *t) {
0036 ss << reinterpret_cast<void *>(t);
0037 }
0038
0039 template <typename T>
0040 inline void stringify_append(llvm::raw_string_ostream &ss, const T *t) {
0041 ss << reinterpret_cast<const void *>(t);
0042 }
0043
0044 template <>
0045 inline void stringify_append<char>(llvm::raw_string_ostream &ss,
0046 const char *t) {
0047 ss << '\"' << t << '\"';
0048 }
0049
0050 template <>
0051 inline void stringify_append<std::nullptr_t>(llvm::raw_string_ostream &ss,
0052 const std::nullptr_t &t) {
0053 ss << "\"nullptr\"";
0054 }
0055
0056 template <typename Head>
0057 inline void stringify_helper(llvm::raw_string_ostream &ss, const Head &head) {
0058 stringify_append(ss, head);
0059 }
0060
0061 template <typename Head, typename... Tail>
0062 inline void stringify_helper(llvm::raw_string_ostream &ss, const Head &head,
0063 const Tail &...tail) {
0064 stringify_append(ss, head);
0065 ss << ", ";
0066 stringify_helper(ss, tail...);
0067 }
0068
0069 template <typename... Ts> inline std::string stringify_args(const Ts &...ts) {
0070 std::string buffer;
0071 llvm::raw_string_ostream ss(buffer);
0072 stringify_helper(ss, ts...);
0073 return buffer;
0074 }
0075
0076
0077 class Instrumenter {
0078 public:
0079 Instrumenter(llvm::StringRef pretty_func, std::string &&pretty_args = {});
0080 ~Instrumenter();
0081
0082 private:
0083 void UpdateBoundary();
0084
0085 llvm::StringRef m_pretty_func;
0086
0087
0088 bool m_local_boundary = false;
0089 };
0090 }
0091 }
0092
0093 #define LLDB_INSTRUMENT() \
0094 lldb_private::instrumentation::Instrumenter _instr(LLVM_PRETTY_FUNCTION);
0095
0096 #define LLDB_INSTRUMENT_VA(...) \
0097 lldb_private::instrumentation::Instrumenter _instr( \
0098 LLVM_PRETTY_FUNCTION, \
0099 lldb_private::instrumentation::stringify_args(__VA_ARGS__));
0100
0101 #endif