Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===-- FormattersHelpers.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_DATAFORMATTERS_FORMATTERSHELPERS_H
0010 #define LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H
0011 
0012 #include "lldb/lldb-enumerations.h"
0013 #include "lldb/lldb-forward.h"
0014 
0015 #include "lldb/DataFormatters/TypeCategory.h"
0016 #include "lldb/DataFormatters/TypeFormat.h"
0017 #include "lldb/DataFormatters/TypeSummary.h"
0018 #include "lldb/DataFormatters/TypeSynthetic.h"
0019 
0020 namespace lldb_private {
0021 namespace formatters {
0022 void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format,
0023                llvm::StringRef type_name, TypeFormatImpl::Flags flags,
0024                bool regex = false);
0025 
0026 void AddSummary(TypeCategoryImpl::SharedPointer category_sp,
0027                 lldb::TypeSummaryImplSP summary_sp, llvm::StringRef type_name,
0028                 bool regex = false);
0029 
0030 void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
0031                       const char *string, llvm::StringRef type_name,
0032                       TypeSummaryImpl::Flags flags, bool regex = false);
0033 
0034 void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp,
0035                        llvm::StringRef type_name, TypeSummaryImpl::Flags flags,
0036                        bool regex = false);
0037 
0038 /// Add a summary that is implemented by a C++ callback.
0039 void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp,
0040                    CXXFunctionSummaryFormat::Callback funct,
0041                    const char *description, llvm::StringRef type_name,
0042                    TypeSummaryImpl::Flags flags, bool regex = false);
0043 
0044 /// Add a synthetic that is implemented by a C++ callback.
0045 void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp,
0046                      CXXSyntheticChildren::CreateFrontEndCallback generator,
0047                      const char *description, llvm::StringRef type_name,
0048                      ScriptedSyntheticChildren::Flags flags,
0049                      bool regex = false);
0050 
0051 void AddFilter(TypeCategoryImpl::SharedPointer category_sp,
0052                std::vector<std::string> children, const char *description,
0053                llvm::StringRef type_name,
0054                ScriptedSyntheticChildren::Flags flags, bool regex = false);
0055 
0056 size_t ExtractIndexFromString(const char *item_name);
0057 
0058 Address GetArrayAddressOrPointerValue(ValueObject &valobj);
0059 
0060 time_t GetOSXEpoch();
0061 
0062 struct InferiorSizedWord {
0063 
0064   InferiorSizedWord(const InferiorSizedWord &word) : ptr_size(word.ptr_size) {
0065     if (ptr_size == 4)
0066       thirty_two = word.thirty_two;
0067     else
0068       sixty_four = word.sixty_four;
0069   }
0070 
0071   InferiorSizedWord operator=(const InferiorSizedWord &word) {
0072     ptr_size = word.ptr_size;
0073     if (ptr_size == 4)
0074       thirty_two = word.thirty_two;
0075     else
0076       sixty_four = word.sixty_four;
0077     return *this;
0078   }
0079 
0080   InferiorSizedWord(uint64_t val, Process &process)
0081       : ptr_size(process.GetAddressByteSize()) {
0082     if (ptr_size == 4)
0083       thirty_two = (uint32_t)val;
0084     else if (ptr_size == 8)
0085       sixty_four = val;
0086     else
0087       assert(false && "new pointer size is unknown");
0088   }
0089 
0090   bool IsNegative() const {
0091     if (ptr_size == 4)
0092       return ((int32_t)thirty_two) < 0;
0093     else
0094       return ((int64_t)sixty_four) < 0;
0095   }
0096 
0097   bool IsZero() const {
0098     if (ptr_size == 4)
0099       return thirty_two == 0;
0100     else
0101       return sixty_four == 0;
0102   }
0103 
0104   static InferiorSizedWord GetMaximum(Process &process) {
0105     if (process.GetAddressByteSize() == 4)
0106       return InferiorSizedWord(UINT32_MAX, 4);
0107     else
0108       return InferiorSizedWord(UINT64_MAX, 8);
0109   }
0110 
0111   InferiorSizedWord operator>>(int rhs) const {
0112     if (ptr_size == 4)
0113       return InferiorSizedWord(thirty_two >> rhs, 4);
0114     return InferiorSizedWord(sixty_four >> rhs, 8);
0115   }
0116 
0117   InferiorSizedWord operator<<(int rhs) const {
0118     if (ptr_size == 4)
0119       return InferiorSizedWord(thirty_two << rhs, 4);
0120     return InferiorSizedWord(sixty_four << rhs, 8);
0121   }
0122 
0123   InferiorSizedWord operator&(const InferiorSizedWord &word) const {
0124     if (ptr_size != word.ptr_size)
0125       return InferiorSizedWord(0, ptr_size);
0126     if (ptr_size == 4)
0127       return InferiorSizedWord(thirty_two & word.thirty_two, 4);
0128     return InferiorSizedWord(sixty_four & word.sixty_four, 8);
0129   }
0130 
0131   InferiorSizedWord operator&(int x) const {
0132     if (ptr_size == 4)
0133       return InferiorSizedWord(thirty_two & x, 4);
0134     return InferiorSizedWord(sixty_four & x, 8);
0135   }
0136 
0137   size_t GetBitSize() const { return ptr_size << 3; }
0138 
0139   size_t GetByteSize() const { return ptr_size; }
0140 
0141   uint64_t GetValue() const {
0142     if (ptr_size == 4)
0143       return (uint64_t)thirty_two;
0144     return sixty_four;
0145   }
0146 
0147   InferiorSizedWord SignExtend() const {
0148     if (ptr_size == 4)
0149       return InferiorSizedWord((int32_t)thirty_two, 4);
0150     return InferiorSizedWord((int64_t)sixty_four, 8);
0151   }
0152 
0153   uint8_t *CopyToBuffer(uint8_t *buffer) const {
0154     if (ptr_size == 4) {
0155       memcpy(buffer, &thirty_two, 4);
0156       return buffer + 4;
0157     } else {
0158       memcpy(buffer, &sixty_four, 8);
0159       return buffer + 8;
0160     }
0161   }
0162 
0163   DataExtractor
0164   GetAsData(lldb::ByteOrder byte_order = lldb::eByteOrderInvalid) const {
0165     if (ptr_size == 4)
0166       return DataExtractor(&thirty_two, 4, byte_order, 4);
0167     else
0168       return DataExtractor(&sixty_four, 8, byte_order, 8);
0169   }
0170 
0171 private:
0172   InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
0173     if (ptr_size == 4)
0174       thirty_two = (uint32_t)val;
0175     else
0176       sixty_four = val;
0177   }
0178 
0179   size_t ptr_size;
0180   union {
0181     uint32_t thirty_two;
0182     uint64_t sixty_four;
0183   };
0184 };
0185 } // namespace formatters
0186 } // namespace lldb_private
0187 
0188 #endif // LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H