You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

101 lines
2.3 KiB

  1. // Copyright 2018 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package dwarf
  15. import "strconv"
  16. // DWARF debug info is split into a sequence of compilation units.
  17. // Each unit has its own abbreviation table and address size.
  18. type unit struct {
  19. base Offset // byte offset of header within the aggregate info
  20. off Offset // byte offset of data within the aggregate info
  21. data []byte
  22. atable abbrevTable
  23. asize int
  24. vers int
  25. is64 bool // True for 64-bit DWARF format
  26. }
  27. // Implement the dataFormat interface.
  28. func (u *unit) version() int {
  29. return u.vers
  30. }
  31. func (u *unit) dwarf64() (bool, bool) {
  32. return u.is64, true
  33. }
  34. func (u *unit) addrsize() int {
  35. return u.asize
  36. }
  37. func (d *Data) parseUnits() ([]unit, error) {
  38. // Count units.
  39. nunit := 0
  40. b := makeBuf(d, unknownFormat{}, "info", 0, d.info)
  41. for len(b.data) > 0 {
  42. len := b.uint32()
  43. if len == 0xffffffff {
  44. len64 := b.uint64()
  45. if len64 != uint64(uint32(len64)) {
  46. b.error("unit length overflow")
  47. break
  48. }
  49. len = uint32(len64)
  50. }
  51. b.skip(int(len))
  52. nunit++
  53. }
  54. if b.err != nil {
  55. return nil, b.err
  56. }
  57. // Again, this time writing them down.
  58. b = makeBuf(d, unknownFormat{}, "info", 0, d.info)
  59. units := make([]unit, nunit)
  60. for i := range units {
  61. u := &units[i]
  62. u.base = b.off
  63. n := b.uint32()
  64. if n == 0xffffffff {
  65. u.is64 = true
  66. n = uint32(b.uint64())
  67. }
  68. vers := b.uint16()
  69. if vers != 2 && vers != 3 && vers != 4 {
  70. b.error("unsupported DWARF version " + strconv.Itoa(int(vers)))
  71. break
  72. }
  73. u.vers = int(vers)
  74. atable, err := d.parseAbbrev(b.uint32())
  75. if err != nil {
  76. if b.err == nil {
  77. b.err = err
  78. }
  79. break
  80. }
  81. u.atable = atable
  82. u.asize = int(b.uint8())
  83. u.off = b.off
  84. u.data = b.bytes(int(n - (2 + 4 + 1)))
  85. }
  86. if b.err != nil {
  87. return nil, b.err
  88. }
  89. return units, nil
  90. }