OLD | NEW |
1 # Copyright 2010 The Go Authors. All rights reserved. | 1 # Copyright 2010 The Go Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style | 2 # Use of this source code is governed by a BSD-style |
3 # license that can be found in the LICENSE file. | 3 # license that can be found in the LICENSE file. |
4 | 4 |
5 """GDB Pretty printers and convenience functions for Go's runtime structures. | 5 """GDB Pretty printers and convenience functions for Go's runtime structures. |
6 | 6 |
7 This script is loaded by GDB when it finds a .debug_gdb_scripts | 7 This script is loaded by GDB when it finds a .debug_gdb_scripts |
8 section in the compiled binary. The [68]l linkers emit this with a | 8 section in the compiled binary. The [68]l linkers emit this with a |
9 path to this file based on the path to the runtime package. | 9 path to this file based on the path to the runtime package. |
10 """ | 10 """ |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if klass.pattern.match(str(val.type)): | 142 if klass.pattern.match(str(val.type)): |
143 return klass(val) | 143 return klass(val) |
144 except: | 144 except: |
145 pass | 145 pass |
146 return matcher | 146 return matcher |
147 | 147 |
148 goobjfile.pretty_printers.extend([makematcher(k) for k in vars().values() if has
attr(k, 'pattern')]) | 148 goobjfile.pretty_printers.extend([makematcher(k) for k in vars().values() if has
attr(k, 'pattern')]) |
149 | 149 |
150 # | 150 # |
151 # For reference, this is what we're trying to do: | 151 # For reference, this is what we're trying to do: |
152 # eface: p *(*(struct 'runtime.commonType'*)'main.e'->type_->data)->string | 152 # eface: p *(*(struct 'runtime.rtype'*)'main.e'->type_->data)->string |
153 # iface: p *(*(struct 'runtime.commonType'*)'main.s'->tab->Type->data)->string | 153 # iface: p *(*(struct 'runtime.rtype'*)'main.s'->tab->Type->data)->string |
154 # | 154 # |
155 # interface types can't be recognized by their name, instead we check | 155 # interface types can't be recognized by their name, instead we check |
156 # if they have the expected fields. Unfortunately the mapping of | 156 # if they have the expected fields. Unfortunately the mapping of |
157 # fields to python attributes in gdb.py isn't complete: you can't test | 157 # fields to python attributes in gdb.py isn't complete: you can't test |
158 # for presence other than by trapping. | 158 # for presence other than by trapping. |
159 | 159 |
160 | 160 |
161 def is_iface(val): | 161 def is_iface(val): |
162 try: | 162 try: |
163 return str(val['tab'].type) == "struct runtime.itab *" \ | 163 return str(val['tab'].type) == "struct runtime.itab *" \ |
(...skipping 15 matching lines...) Expand all Loading... |
179 pass | 179 pass |
180 try: | 180 try: |
181 return gdb.lookup_type('struct ' + name) | 181 return gdb.lookup_type('struct ' + name) |
182 except: | 182 except: |
183 pass | 183 pass |
184 try: | 184 try: |
185 return gdb.lookup_type('struct ' + name[1:]).pointer() | 185 return gdb.lookup_type('struct ' + name[1:]).pointer() |
186 except: | 186 except: |
187 pass | 187 pass |
188 | 188 |
189 _rctp_type = gdb.lookup_type("struct runtime.commonType").pointer() | 189 _rctp_type = gdb.lookup_type("struct runtime.rtype").pointer() |
190 _rtp_type = gdb.lookup_type("struct runtime._type").pointer() | |
191 | 190 |
192 def iface_commontype(obj): | 191 def iface_commontype(obj): |
193 if is_iface(obj): | 192 if is_iface(obj): |
194 go_type_ptr = obj['tab']['_type'] | 193 go_type_ptr = obj['tab']['_type'] |
195 elif is_eface(obj): | 194 elif is_eface(obj): |
196 go_type_ptr = obj['_type'] | 195 go_type_ptr = obj['_type'] |
197 else: | 196 else: |
198 return | 197 return |
199 | |
200 # sanity check: reflection type description ends in a loop. | |
201 tt = go_type_ptr['_type'].cast(_rtp_type).dereference()['_type'] | |
202 if tt != tt.cast(_rtp_type).dereference()['_type']: | |
203 return | |
204 ········ | 198 ········ |
205 » return go_type_ptr['ptr'].cast(_rctp_type).dereference() | 199 » return go_type_ptr.cast(_rctp_type).dereference() |
206 ········ | 200 ········ |
207 | 201 |
208 def iface_dtype(obj): | 202 def iface_dtype(obj): |
209 "Decode type of the data field of an eface or iface struct." | 203 "Decode type of the data field of an eface or iface struct." |
210 » # known issue: dtype_name decoded from runtime.commonType is "nested.Foo
" | 204 » # known issue: dtype_name decoded from runtime.rtype is "nested.Foo" |
211 # but the dwarf table lists it as "full/path/to/nested.Foo" | 205 # but the dwarf table lists it as "full/path/to/nested.Foo" |
212 | 206 |
213 dynamic_go_type = iface_commontype(obj) | 207 dynamic_go_type = iface_commontype(obj) |
214 if dynamic_go_type is None: | 208 if dynamic_go_type is None: |
215 return | 209 return |
216 dtype_name = dynamic_go_type['string'].dereference()['str'].string() | 210 dtype_name = dynamic_go_type['string'].dereference()['str'].string() |
217 | 211 |
218 dynamic_gdb_type = lookup_type(dtype_name) | 212 dynamic_gdb_type = lookup_type(dtype_name) |
219 if dynamic_gdb_type is None: | 213 if dynamic_gdb_type is None: |
220 return | 214 return |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 #rsc: "to find the number of entries in the itab's Fn field look at itab.inter->
numMethods | 422 #rsc: "to find the number of entries in the itab's Fn field look at itab.inter->
numMethods |
429 #i am sure i have the names wrong but look at the interface type and its method
count" | 423 #i am sure i have the names wrong but look at the interface type and its method
count" |
430 # so Itype will start with a commontype which has kind = interface | 424 # so Itype will start with a commontype which has kind = interface |
431 | 425 |
432 # | 426 # |
433 # Register all convenience functions and CLI commands | 427 # Register all convenience functions and CLI commands |
434 # | 428 # |
435 for k in vars().values(): | 429 for k in vars().values(): |
436 if hasattr(k, 'invoke'): | 430 if hasattr(k, 'invoke'): |
437 k() | 431 k() |
OLD | NEW |