github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/debug/dwarf/type.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // DWARF type information structures. 6 // The format is heavily biased toward C, but for simplicity 7 // the String methods use a pseudo-Go syntax. 8 9 package dwarf 10 11 // Typeは、通常、特定のType構造体([CharType]、[StructType] など)のいずれかへのポインタを表します。 12 type Type interface { 13 Common() *CommonType 14 String() string 15 Size() int64 16 } 17 18 // CommonTypeは、複数の型で共通のフィールドを保持します。 19 // フィールドが特定の型に対して不明または適用できない場合、 20 // ゼロ値が使用されます。 21 type CommonType struct { 22 ByteSize int64 23 Name string 24 } 25 26 func (c *CommonType) Common() *CommonType 27 28 func (c *CommonType) Size() int64 29 30 // BasicTypeは、すべての基本型に共通するフィールドを保持します。 31 // 32 // BitSize / BitOffset / DataBitOffsetフィールドの解釈に関する詳細については、[StructField] のドキュメントを参照してください。 33 type BasicType struct { 34 CommonType 35 BitSize int64 36 BitOffset int64 37 DataBitOffset int64 38 } 39 40 func (b *BasicType) Basic() *BasicType 41 42 func (t *BasicType) String() string 43 44 // CharTypeは、符号付き文字型を表します。 45 type CharType struct { 46 BasicType 47 } 48 49 // UcharTypeは、符号なし文字型を表します。 50 type UcharType struct { 51 BasicType 52 } 53 54 // IntTypeは、符号付き整数型を表します。 55 type IntType struct { 56 BasicType 57 } 58 59 // UintTypeは、符号なし整数型を表します。 60 type UintType struct { 61 BasicType 62 } 63 64 // FloatTypeは、浮動小数点数型を表します。 65 type FloatType struct { 66 BasicType 67 } 68 69 // ComplexTypeは、複素数の浮動小数点数型を表します。 70 type ComplexType struct { 71 BasicType 72 } 73 74 // BoolTypeは、ブール型を表します。 75 type BoolType struct { 76 BasicType 77 } 78 79 // AddrTypeは、マシンアドレス型を表します。 80 type AddrType struct { 81 BasicType 82 } 83 84 // UnspecifiedTypeは、暗黙的な、不明な、曖昧な、または存在しない型を表します。 85 type UnspecifiedType struct { 86 BasicType 87 } 88 89 // QualTypeは、C/C++の「const」、「restrict」、または「volatile」修飾子を持つ型を表します。 90 type QualType struct { 91 CommonType 92 Qual string 93 Type Type 94 } 95 96 func (t *QualType) String() string 97 98 func (t *QualType) Size() int64 99 100 // ArrayTypeは、固定サイズの配列型を表します。 101 type ArrayType struct { 102 CommonType 103 Type Type 104 StrideBitSize int64 105 Count int64 106 } 107 108 func (t *ArrayType) String() string 109 110 func (t *ArrayType) Size() int64 111 112 // VoidTypeは、Cのvoid型を表します。 113 type VoidType struct { 114 CommonType 115 } 116 117 func (t *VoidType) String() string 118 119 // PtrTypeは、ポインタ型を表します。 120 type PtrType struct { 121 CommonType 122 Type Type 123 } 124 125 func (t *PtrType) String() string 126 127 // StructTypeは、構造体、共用体、またはC++クラス型を表します。 128 type StructType struct { 129 CommonType 130 StructName string 131 Kind string 132 Field []*StructField 133 Incomplete bool 134 } 135 136 // StructFieldは、構造体、共用体、またはC++クラス型のフィールドを表します。 137 // 138 // # ビットフィールド 139 // 140 // BitSize、BitOffset、DataBitOffsetフィールドは、C/C++のstruct/union/class型でビットフィールドとして宣言されたデータメンバーのビットサイズとオフセットを記述します。 141 // 142 // BitSizeは、ビットフィールドのビット数です。 143 // 144 // DataBitOffsetが0以外の場合、それは、 145 // ビットフィールドの開始位置から囲むエンティティ(例:含まれるstruct/class/union)の開始位置までのビット数です。 146 // これは、DWARF 4で導入されたDW_AT_data_bit_offset DWARF属性に対応します。 147 // 148 // BitOffsetが0以外の場合、それは、 149 // ビットフィールドを保持するストレージユニットの最上位ビットからビットフィールドの最上位ビットまでのビット数です。 150 // ここで「ストレージユニット」とは、ビットフィールドの前の型名です(フィールド「unsigned x:17」の場合、ストレージユニットは「unsigned」です)。 151 // BitOffsetの値は、システムのエンディアンによって異なる場合があります。 152 // BitOffsetは、DWARF 4で廃止され、DWARF 5で削除されたDW_AT_bit_offset DWARF属性に対応します。 153 // 154 // DataBitOffsetとBitOffsetのうち、最大1つだけが非ゼロになります。 155 // DataBitOffset/BitOffsetは、BitSizeが非ゼロの場合にのみ非ゼロになります。 156 // Cコンパイラがどちらを使用するかは、コンパイラのバージョンとコマンドラインオプションに依存します。 157 // 158 // 以下は、C/C++のビットフィールドの使用例と、DWARFビットオフセット情報の期待値の例です。 159 // このコードを考えてみましょう。 160 // 161 // struct S { 162 // int q; 163 // int j:5; 164 // int k:6; 165 // int m:5; 166 // int n:8; 167 // } s; 168 // 169 // 上記のコードに対して、GCC 8を使用している場合、DW_AT_bit_offsetの値は次のようになることが期待されます。 170 // 171 // Little | Big 172 // Endian | Endian 173 // | 174 // "j": 27 | 0 175 // "k": 21 | 5 176 // "m": 16 | 11 177 // "n": 8 | 16 178 // 179 // 上記のように、j/k/m/nの含まれるストレージユニットに対するオフセットのみが考慮されます。これらの値は、含まれる構造体の前のデータメンバーのサイズに基づいて変化することはありません。 180 // 181 // コンパイラがDW_AT_data_bit_offsetを出力する場合、期待される値は次のようになります。 182 // 183 // "j": 32 184 // "k": 37 185 // "m": 43 186 // "n": 48 187 // 188 // ここで、"j"の値32は、ビットフィールドが他のデータメンバーに続くことを反映しています(DW_AT_data_bit_offset値は、含まれる構造体の開始位置を基準としています)。 189 // したがって、DW_AT_data_bit_offset値は、多数のフィールドを持つ構造体ではかなり大きくなる可能性があります。 190 // 191 // DWARFは、ビットサイズとビットオフセットがゼロでない基本型の可能性も許容しているため、これらの情報は基本型に対してもキャプチャされます。 192 // ただし、主流の言語を使用してこの動作をトリガーすることはできないことに注意する価値があります。 193 type StructField struct { 194 Name string 195 Type Type 196 ByteOffset int64 197 ByteSize int64 198 BitOffset int64 199 DataBitOffset int64 200 BitSize int64 201 } 202 203 func (t *StructType) String() string 204 205 func (t *StructType) Defn() string 206 207 // EnumTypeは、列挙型を表します。 208 // ネイティブの整数型の唯一の指標は、[CommonType] 内のByteSizeです。 209 type EnumType struct { 210 CommonType 211 EnumName string 212 Val []*EnumValue 213 } 214 215 // EnumValueは、単一の列挙値を表します。 216 type EnumValue struct { 217 Name string 218 Val int64 219 } 220 221 func (t *EnumType) String() string 222 223 // FuncTypeは、関数の型を表します。 224 type FuncType struct { 225 CommonType 226 ReturnType Type 227 ParamType []Type 228 } 229 230 func (t *FuncType) String() string 231 232 // DotDotDotTypeは、可変長の...関数パラメータを表します。 233 type DotDotDotType struct { 234 CommonType 235 } 236 237 func (t *DotDotDotType) String() string 238 239 // TypedefTypeは、名前付き型を表します。 240 type TypedefType struct { 241 CommonType 242 Type Type 243 } 244 245 func (t *TypedefType) String() string 246 247 func (t *TypedefType) Size() int64 248 249 // UnsupportedTypeは、サポートされていない型に遭遇した場合に返されるプレースホルダーです。 250 type UnsupportedType struct { 251 CommonType 252 Tag Tag 253 } 254 255 func (t *UnsupportedType) String() string 256 257 // Typeは、DWARF「info」セクションのoffにある型を読み取ります。 258 func (d *Data) Type(off Offset) (Type, error)