From 0c5c7b52f0f395a6beb7956ba210b8ca727c0471 Mon Sep 17 00:00:00 2001 From: Daniel Paoliello Date: Thu, 31 Aug 2023 12:06:50 -0700 Subject: Emit the CodeView `S_ARMSWITCHTABLE` debug symbol for jump tables The CodeView `S_ARMSWITCHTABLE` debug symbol is used to describe the layout of a jump table, it contains the following information: * The address of the branch instruction that uses the jump table. * The address of the jump table. * The "base" address that the values in the jump table are relative to. * The type of each entry (absolute pointer, a relative integer, a relative integer that is shifted). Together this information can be used by debuggers and binary analysis tools to understand what an jump table indirect branch is doing and where it might jump to. Documentation for the symbol can be found in the Microsoft PDB library dumper: https://github.com/microsoft/microsoft-pdb/blob/0fe89a942f9a0f8e061213313e438884f4c9b876/cvdump/dumpsym7.cpp#L5518 This change adds support to LLVM to emit the `S_ARMSWITCHTABLE` debug symbol as well as to dump it out (for testing purposes). Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D149367 --- llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'llvm/lib/ObjectYAML') diff --git a/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp b/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp index 8d2028abfe9b..64e1a58aa71a 100644 --- a/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp +++ b/llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp @@ -61,6 +61,7 @@ LLVM_YAML_DECLARE_ENUM_TRAITS(CPUType) LLVM_YAML_DECLARE_ENUM_TRAITS(RegisterId) LLVM_YAML_DECLARE_ENUM_TRAITS(TrampolineType) LLVM_YAML_DECLARE_ENUM_TRAITS(ThunkOrdinal) +LLVM_YAML_DECLARE_ENUM_TRAITS(JumpTableEntrySize) LLVM_YAML_STRONG_TYPEDEF(StringRef, TypeName) @@ -207,6 +208,15 @@ void ScalarEnumerationTraits::enumeration( } } +void ScalarEnumerationTraits::enumeration( + IO &io, JumpTableEntrySize &FC) { + auto ThunkNames = getJumpTableEntrySizeNames(); + for (const auto &E : ThunkNames) { + io.enumCase(FC, E.Name.str().c_str(), + static_cast(E.Value)); + } +} + namespace llvm { namespace yaml { template <> struct MappingTraits { @@ -586,6 +596,17 @@ template <> void SymbolRecordImpl::map(IO &IO) { IO.mapRequired("Strings", Symbol.Strings); } +template <> void SymbolRecordImpl::map(IO &IO) { + IO.mapRequired("BaseOffset", Symbol.BaseOffset); + IO.mapRequired("BaseSegment", Symbol.BaseSegment); + IO.mapRequired("SwitchType", Symbol.SwitchType); + IO.mapRequired("BranchOffset", Symbol.BranchOffset); + IO.mapRequired("TableOffset", Symbol.TableOffset); + IO.mapRequired("BranchSegment", Symbol.BranchSegment); + IO.mapRequired("TableSegment", Symbol.TableSegment); + IO.mapRequired("EntriesCount", Symbol.EntriesCount); +} + } // end namespace detail } // end namespace CodeViewYAML } // end namespace llvm -- cgit v1.2.3