OLD | NEW |
1 // Copyright 2014 The Go Authors. All rights reserved. | 1 // Copyright 2014 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 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "debug/goobj" | 9 "debug/goobj" |
10 "fmt" | 10 "fmt" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 checkPCData(t, r, name, off, pc, 2, pcdata2) | 134 checkPCData(t, r, name, off, pc, 2, pcdata2) |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 // findFunc finds the function information in the pclntab of p | 139 // findFunc finds the function information in the pclntab of p |
140 // for the function with the given name. | 140 // for the function with the given name. |
141 // It returns a symbol reader for pclntab, the offset of the function informatio
n | 141 // It returns a symbol reader for pclntab, the offset of the function informatio
n |
142 // within that symbol, and the args and frame values read out of the information
. | 142 // within that symbol, and the args and frame values read out of the information
. |
143 func findFunc(t *testing.T, p *Prog, name string) (r *SymReader, off, args, fram
e int, ok bool) { | 143 func findFunc(t *testing.T, p *Prog, name string) (r *SymReader, off, args, fram
e int, ok bool) { |
144 » tabsym := p.Syms[goobj.SymID{Name: "pclntab"}] | 144 » tabsym := p.Syms[goobj.SymID{Name: "runtime.pclntab"}] |
145 if tabsym == nil { | 145 if tabsym == nil { |
146 t.Errorf("pclntab is missing in binary") | 146 t.Errorf("pclntab is missing in binary") |
147 return | 147 return |
148 } | 148 } |
149 | 149 |
150 r = new(SymReader) | 150 r = new(SymReader) |
151 r.Init(p, tabsym) | 151 r.Init(p, tabsym) |
152 | 152 |
153 // pclntab must with 8-byte header | 153 // pclntab must with 8-byte header |
154 if r.Uint32(0) != 0xfffffffb || r.Uint8(4) != 0 || r.Uint8(5) != 0 || r.
Uint8(6) != uint8(p.pcquantum) || r.Uint8(7) != uint8(p.ptrsize) { | 154 if r.Uint32(0) != 0xfffffffb || r.Uint8(4) != 0 || r.Uint8(5) != 0 || r.
Uint8(6) != uint8(p.pcquantum) || r.Uint8(7) != uint8(p.ptrsize) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 return | 269 return |
270 } | 270 } |
271 if pcval != val { | 271 if pcval != val { |
272 t.Errorf("pclntab(%s): at pc=+%#x, pcdata#%d=%d, want %d", name,
pc, pnum, pcval, val) | 272 t.Errorf("pclntab(%s): at pc=+%#x, pcdata#%d=%d, want %d", name,
pc, pnum, pcval, val) |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 // readPCData reads the PCData table offset off | 276 // readPCData reads the PCData table offset off |
277 // to obtain and return the value associated with pc. | 277 // to obtain and return the value associated with pc. |
278 func readPCData(t *testing.T, r *SymReader, name, pcdataname string, pcoff uint3
2, pc int) (int, bool) { | 278 func readPCData(t *testing.T, r *SymReader, name, pcdataname string, pcoff uint3
2, pc int) (int, bool) { |
| 279 // "If pcsp, pcfile, pcln, or any of the pcdata offsets is zero, |
| 280 // that table is considered missing, and all PCs take value -1." |
| 281 if pcoff == 0 { |
| 282 return -1, true |
| 283 } |
| 284 |
279 var it PCIter | 285 var it PCIter |
280 for it.Init(r.p, r.data[pcoff:]); !it.Done; it.Next() { | 286 for it.Init(r.p, r.data[pcoff:]); !it.Done; it.Next() { |
281 if it.PC <= uint32(pc) && uint32(pc) < it.NextPC { | 287 if it.PC <= uint32(pc) && uint32(pc) < it.NextPC { |
282 return int(it.Value), true | 288 return int(it.Value), true |
283 } | 289 } |
284 } | 290 } |
285 if it.Corrupt { | 291 if it.Corrupt { |
286 t.Errorf("pclntab(%s): %s: corrupt pcdata table", name, pcdatana
me) | 292 t.Errorf("pclntab(%s): %s: corrupt pcdata table", name, pcdatana
me) |
287 } | 293 } |
288 return 0, false | 294 return 0, false |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 return Addr(r.Uint64(off)) | 331 return Addr(r.Uint64(off)) |
326 } | 332 } |
327 | 333 |
328 func (r *SymReader) String(off int) string { | 334 func (r *SymReader) String(off int) string { |
329 end := off | 335 end := off |
330 for r.data[end] != '\x00' { | 336 for r.data[end] != '\x00' { |
331 end++ | 337 end++ |
332 } | 338 } |
333 return string(r.data[off:end]) | 339 return string(r.data[off:end]) |
334 } | 340 } |
OLD | NEW |