Skip to content

[lldb] Implement a formatter bytecode interpreter in C++ #114333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lldb/include/lldb/DataFormatters/FormatterSection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===-- FormattersSection.h -------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_DATAFORMATTERS_FORMATTERSECTION_H
#define LLDB_DATAFORMATTERS_FORMATTERSECTION_H

#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-forward.h"

namespace lldb_private {
/// Load type summaries embedded in the binary. These are type summaries
/// provided by the authors of the code.
void LoadTypeSummariesForModule(lldb::ModuleSP module_sp);

/// Load data formatters embedded in the binary. These are formatters provided
/// by the authors of the code using LLDB formatter bytecode.
void LoadFormattersForModule(lldb::ModuleSP module_sp);

} // namespace lldb_private

#endif // LLDB_DATAFORMATTERS_FORMATTERSECTION_H
3 changes: 1 addition & 2 deletions lldb/include/lldb/DataFormatters/FormattersHelpers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//===-- FormattersHelpers.h --------------------------------------*- C++
//-*-===//
//===-- FormattersHelpers.h -------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down
23 changes: 22 additions & 1 deletion lldb/include/lldb/DataFormatters/TypeSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StructuredData.h"

namespace llvm {
class MemoryBuffer;
}

namespace lldb_private {
class TypeSummaryOptions {
public:
Expand All @@ -44,7 +48,7 @@ class TypeSummaryOptions {

class TypeSummaryImpl {
public:
enum class Kind { eSummaryString, eScript, eCallback, eInternal };
enum class Kind { eSummaryString, eScript, eBytecode, eCallback, eInternal };

virtual ~TypeSummaryImpl() = default;

Expand Down Expand Up @@ -409,6 +413,23 @@ struct ScriptSummaryFormat : public TypeSummaryImpl {
ScriptSummaryFormat(const ScriptSummaryFormat &) = delete;
const ScriptSummaryFormat &operator=(const ScriptSummaryFormat &) = delete;
};

/// A summary formatter that is defined in LLDB formmater bytecode.
class BytecodeSummaryFormat : public TypeSummaryImpl {
std::unique_ptr<llvm::MemoryBuffer> m_bytecode;

public:
BytecodeSummaryFormat(const TypeSummaryImpl::Flags &flags,
std::unique_ptr<llvm::MemoryBuffer> bytecode);
bool FormatObject(ValueObject *valobj, std::string &dest,
const TypeSummaryOptions &options) override;
std::string GetDescription() override;
std::string GetName() override;
static bool classof(const TypeSummaryImpl *S) {
return S->GetKind() == Kind::eBytecode;
}
};

} // namespace lldb_private

#endif // LLDB_DATAFORMATTERS_TYPESUMMARY_H
2 changes: 2 additions & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ enum SectionType {
eSectionTypeDWARFDebugLocListsDwo,
eSectionTypeDWARFDebugTuIndex,
eSectionTypeCTF,
eSectionTypeLLDBTypeSummaries,
eSectionTypeLLDBFormatters,
eSectionTypeSwiftModules,
};

Expand Down
1 change: 1 addition & 0 deletions lldb/source/API/SBTypeSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ bool SBTypeSummary::IsEqualTo(lldb::SBTypeSummary &rhs) {
case TypeSummaryImpl::Kind::eCallback:
return llvm::dyn_cast<CXXFunctionSummaryFormat>(m_opaque_sp.get()) ==
llvm::dyn_cast<CXXFunctionSummaryFormat>(rhs.m_opaque_sp.get());
case TypeSummaryImpl::Kind::eBytecode:
case TypeSummaryImpl::Kind::eScript:
if (IsFunctionCode() != rhs.IsFunctionCode())
return false;
Expand Down
10 changes: 8 additions & 2 deletions lldb/source/Core/Section.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,14 @@ const char *Section::GetTypeAsCString() const {
return "dwarf-gnu-debugaltlink";
case eSectionTypeCTF:
return "ctf";
case eSectionTypeOther:
return "regular";
case eSectionTypeLLDBTypeSummaries:
return "lldb-type-summaries";
case eSectionTypeLLDBFormatters:
return "lldb-formatters";
case eSectionTypeSwiftModules:
return "swift-modules";
case eSectionTypeOther:
return "regular";
}
return "unknown";
}
Expand Down Expand Up @@ -457,6 +461,8 @@ bool Section::ContainsOnlyDebugInfo() const {
case eSectionTypeDWARFAppleObjC:
case eSectionTypeDWARFGNUDebugAltLink:
case eSectionTypeCTF:
case eSectionTypeLLDBTypeSummaries:
case eSectionTypeLLDBFormatters:
case eSectionTypeSwiftModules:
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions lldb/source/DataFormatters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ add_lldb_library(lldbDataFormatters NO_PLUGIN_DEPENDENCIES
FormatCache.cpp
FormatClasses.cpp
FormatManager.cpp
FormatterBytecode.cpp
FormattersHelpers.cpp
FormatterSection.cpp
LanguageCategory.cpp
StringPrinter.cpp
TypeCategory.cpp
Expand Down
Loading
Loading