Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/CTF/SymbolFileCTF.h
39642 views
//===-- SymbolFileCTF.h -----------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H9#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H1011#include <map>12#include <optional>13#include <vector>1415#include "CTFTypes.h"16#include "lldb/Symbol/CompileUnit.h"17#include "lldb/Symbol/SymbolFile.h"1819namespace lldb_private {2021class SymbolFileCTF : public lldb_private::SymbolFileCommon {22/// LLVM RTTI support.23static char ID;2425public:26/// LLVM RTTI support.27/// \{28bool isA(const void *ClassID) const override {29return ClassID == &ID || SymbolFileCommon::isA(ClassID);30}31static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }32/// \}3334SymbolFileCTF(lldb::ObjectFileSP objfile_sp);3536static void Initialize();3738static void Terminate();3940static llvm::StringRef GetPluginNameStatic() { return "CTF"; }4142static llvm::StringRef GetPluginDescriptionStatic();4344static lldb_private::SymbolFile *45CreateInstance(lldb::ObjectFileSP objfile_sp);4647llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }4849uint32_t CalculateAbilities() override;5051void InitializeObject() override;5253lldb::LanguageType ParseLanguage(CompileUnit &comp_unit) override {54return lldb::eLanguageTypeUnknown;55}5657bool ParseHeader();5859size_t ParseFunctions(CompileUnit &comp_unit) override;6061size_t ParseObjects(CompileUnit &comp_unit);6263bool ParseLineTable(CompileUnit &comp_unit) override { return false; }6465bool ParseDebugMacros(CompileUnit &comp_unit) override { return false; }6667bool ParseSupportFiles(CompileUnit &comp_unit,68SupportFileList &support_files) override {69return false;70}7172size_t ParseTypes(CompileUnit &cu) override;7374bool ParseImportedModules(75const SymbolContext &sc,76std::vector<lldb_private::SourceModule> &imported_modules) override {77return false;78}7980size_t ParseBlocksRecursive(Function &func) override { return 0; }8182size_t ParseVariablesForContext(const SymbolContext &sc) override;8384uint32_t CalculateNumCompileUnits() override { return 0; }8586lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index) override;8788Type *ResolveTypeUID(lldb::user_id_t type_uid) override;89std::optional<ArrayInfo> GetDynamicArrayInfoForUID(90lldb::user_id_t type_uid,91const lldb_private::ExecutionContext *exe_ctx) override {92return std::nullopt;93}9495bool CompleteType(CompilerType &compiler_type) override;9697uint32_t ResolveSymbolContext(const lldb_private::Address &so_addr,98lldb::SymbolContextItem resolve_scope,99lldb_private::SymbolContext &sc) override;100101void AddSymbols(Symtab &symtab) override;102103void GetTypes(lldb_private::SymbolContextScope *sc_scope,104lldb::TypeClass type_mask,105lldb_private::TypeList &type_list) override {}106107void FindTypes(const lldb_private::TypeQuery &match,108lldb_private::TypeResults &results) override;109110void FindTypesByRegex(const lldb_private::RegularExpression ®ex,111uint32_t max_matches, lldb_private::TypeMap &types);112113void FindFunctions(const lldb_private::Module::LookupInfo &lookup_info,114const lldb_private::CompilerDeclContext &parent_decl_ctx,115bool include_inlines,116lldb_private::SymbolContextList &sc_list) override;117118void FindFunctions(const lldb_private::RegularExpression ®ex,119bool include_inlines,120lldb_private::SymbolContextList &sc_list) override;121122void123FindGlobalVariables(lldb_private::ConstString name,124const lldb_private::CompilerDeclContext &parent_decl_ctx,125uint32_t max_matches,126lldb_private::VariableList &variables) override;127128void FindGlobalVariables(const lldb_private::RegularExpression ®ex,129uint32_t max_matches,130lldb_private::VariableList &variables) override;131132enum TypeKind : uint32_t {133eUnknown = 0,134eInteger = 1,135eFloat = 2,136ePointer = 3,137eArray = 4,138eFunction = 5,139eStruct = 6,140eUnion = 7,141eEnum = 8,142eForward = 9,143eTypedef = 10,144eVolatile = 11,145eConst = 12,146eRestrict = 13,147eSlice = 14,148};149150private:151enum Flags : uint32_t {152eFlagCompress = (1u << 0),153eFlagNewFuncInfo = (1u << 1),154eFlagIdxSorted = (1u << 2),155eFlagDynStr = (1u << 3),156};157158enum IntEncoding : uint32_t {159eSigned = 0x1,160eChar = 0x2,161eBool = 0x4,162eVarArgs = 0x8,163};164165struct ctf_preamble_t {166uint16_t magic;167uint8_t version;168uint8_t flags;169};170171struct ctf_header_t {172ctf_preamble_t preamble;173uint32_t parlabel;174uint32_t parname;175uint32_t lbloff;176uint32_t objtoff;177uint32_t funcoff;178uint32_t typeoff;179uint32_t stroff;180uint32_t strlen;181};182183struct ctf_type_t {184uint32_t name;185uint32_t info;186union {187uint32_t size;188uint32_t type;189};190uint32_t lsizehi;191uint32_t lsizelo;192};193194struct ctf_stype_t {195uint32_t name;196uint32_t info;197union {198uint32_t size;199uint32_t type;200};201202bool IsLargeType() const { return size == 0xffff; }203uint32_t GetStructSize() const {204if (IsLargeType())205return sizeof(ctf_type_t);206return sizeof(ctf_stype_t);207}208uint32_t GetType() const { return type; }209uint32_t GetSize() const { return size; }210};211212llvm::Expected<std::unique_ptr<CTFType>> ParseType(lldb::offset_t &offset,213lldb::user_id_t uid);214215llvm::Expected<lldb::TypeSP> CreateType(CTFType *ctf_type);216llvm::Expected<lldb::TypeSP> CreateInteger(const CTFInteger &ctf_integer);217llvm::Expected<lldb::TypeSP> CreateModifier(const CTFModifier &ctf_modifier);218llvm::Expected<lldb::TypeSP> CreateTypedef(const CTFTypedef &ctf_typedef);219llvm::Expected<lldb::TypeSP> CreateArray(const CTFArray &ctf_array);220llvm::Expected<lldb::TypeSP> CreateEnum(const CTFEnum &ctf_enum);221llvm::Expected<lldb::TypeSP> CreateFunction(const CTFFunction &ctf_function);222llvm::Expected<lldb::TypeSP> CreateRecord(const CTFRecord &ctf_record);223llvm::Expected<lldb::TypeSP> CreateForward(const CTFForward &ctf_forward);224225llvm::StringRef ReadString(lldb::offset_t offset) const;226227std::vector<uint16_t> GetFieldSizes(lldb::offset_t field_offset,228uint32_t fields, uint32_t struct_size);229230DataExtractor m_data;231232/// The start offset of the CTF body into m_data. If the body is uncompressed,233/// m_data contains the header and the body and the body starts after the234/// header. If the body is compressed, m_data only contains the body and the235/// offset is zero.236lldb::offset_t m_body_offset = 0;237238TypeSystemClang *m_ast;239lldb::CompUnitSP m_comp_unit_sp;240241std::optional<ctf_header_t> m_header;242243/// Parsed CTF types.244llvm::DenseMap<lldb::user_id_t, std::unique_ptr<CTFType>> m_ctf_types;245246/// Parsed LLDB types.247llvm::DenseMap<lldb::user_id_t, lldb::TypeSP> m_types;248249/// To complete types, we need a way to map (imcomplete) compiler types back250/// to parsed CTF types.251llvm::DenseMap<lldb::opaque_compiler_type_t, const CTFType *>252m_compiler_types;253254std::vector<lldb::FunctionSP> m_functions;255std::vector<lldb::VariableSP> m_variables;256257static constexpr uint16_t g_ctf_magic = 0xcff1;258static constexpr uint8_t g_ctf_version = 4;259static constexpr uint16_t g_ctf_field_threshold = 0x2000;260};261} // namespace lldb_private262263#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_CTF_SYMBOLFILECTF_H264265266