Skip to content

Commit 49660c3

Browse files
committed
[lldb] Implement a formatter bytecode interpreter in C++
Compared to the python version, this also does type checking and error handling, so it's slightly longer, however, it's still comfortably under 500 lines.
1 parent c9a4d24 commit 49660c3

File tree

15 files changed

+1014
-46
lines changed

15 files changed

+1014
-46
lines changed

lldb/include/lldb/DataFormatters/TypeSummary.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include "lldb/Utility/Status.h"
2323
#include "lldb/Utility/StructuredData.h"
2424

25+
namespace llvm {
26+
class MemoryBuffer;
27+
}
28+
2529
namespace lldb_private {
2630
class TypeSummaryOptions {
2731
public:
@@ -44,7 +48,7 @@ class TypeSummaryOptions {
4448

4549
class TypeSummaryImpl {
4650
public:
47-
enum class Kind { eSummaryString, eScript, eCallback, eInternal };
51+
enum class Kind { eSummaryString, eScript, eBytecode, eCallback, eInternal };
4852

4953
virtual ~TypeSummaryImpl() = default;
5054

@@ -409,6 +413,22 @@ struct ScriptSummaryFormat : public TypeSummaryImpl {
409413
ScriptSummaryFormat(const ScriptSummaryFormat &) = delete;
410414
const ScriptSummaryFormat &operator=(const ScriptSummaryFormat &) = delete;
411415
};
416+
417+
/// A summary formatter that is defined in LLDB formmater bytecode.
418+
class BytecodeSummaryFormat : public TypeSummaryImpl {
419+
std::unique_ptr<llvm::MemoryBuffer> m_bytecode;
420+
public:
421+
BytecodeSummaryFormat(const TypeSummaryImpl::Flags &flags,
422+
std::unique_ptr<llvm::MemoryBuffer> bytecode);
423+
bool FormatObject(ValueObject *valobj, std::string &dest,
424+
const TypeSummaryOptions &options) override;
425+
std::string GetDescription() override;
426+
std::string GetName() override;
427+
static bool classof(const TypeSummaryImpl *S) {
428+
return S->GetKind() == Kind::eBytecode;
429+
}
430+
};
431+
412432
} // namespace lldb_private
413433

414434
#endif // LLDB_DATAFORMATTERS_TYPESUMMARY_H

lldb/include/lldb/lldb-enumerations.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,7 @@ enum SectionType {
762762
eSectionTypeDWARFDebugTuIndex,
763763
eSectionTypeCTF,
764764
eSectionTypeLLDBTypeSummaries,
765+
eSectionTypeLLDBFormatters,
765766
eSectionTypeSwiftModules,
766767
};
767768

lldb/source/Core/Section.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ bool Section::ContainsOnlyDebugInfo() const {
460460
case eSectionTypeDWARFGNUDebugAltLink:
461461
case eSectionTypeCTF:
462462
case eSectionTypeLLDBTypeSummaries:
463+
case eSectionTypeLLDBFormatters:
463464
case eSectionTypeSwiftModules:
464465
return true;
465466
}

lldb/source/DataFormatters/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_lldb_library(lldbDataFormatters NO_PLUGIN_DEPENDENCIES
55
FormatCache.cpp
66
FormatClasses.cpp
77
FormatManager.cpp
8+
FormatterBytecode.cpp
89
FormattersHelpers.cpp
910
LanguageCategory.cpp
1011
StringPrinter.cpp

0 commit comments

Comments
 (0)