Class: Dwarves::Parser::V4Parser

Inherits:
Parslet::Parser
  • Object
show all
Includes:
BasicRules
Defined in:
lib/dwarves/parser/4/parser.rb

Instance Method Summary collapse

Methods included from BasicRules

#colon, #digit, #filename, #hexadecimal, #integer, #lparen, #newline, #newlines, #rparen, #semicolon, #separator, #space, #space?, #word, #words

Instance Method Details

#archObject

Examples:

32-bit
64-bit


86
# File 'lib/dwarves/parser/4/parser.rb', line 86

rule(:arch) { digit.repeat >> str("-bit") }

#attributeObject

Examples:

<30>   DW_AT_name        : int


137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/dwarves/parser/4/parser.rb', line 137

rule :attribute do
  _ >>
    str("<") >>
    word.as(:address) >>
    str(">") >>
    _ >>
    word.as(:name) >>
    _ >>
    colon >>
    _ >>
    (newline.absent? >> any).repeat.as(:description) >>
    newline
end

#dieObject



152
# File 'lib/dwarves/parser/4/parser.rb', line 152

rule(:die) { die_header >> die_body.maybe }

#die_bodyObject

Examples:

<1><2d>: Abbrev Number: 2 (abbrev_number)
   <2e>   DW_AT_byte_size   : 4
   <2f>   DW_AT_encoding    : 5  (signed)
   <30>   DW_AT_name        : int


130
# File 'lib/dwarves/parser/4/parser.rb', line 130

rule(:die_body) { attribute.repeat.as :attributes }

#die_headerObject

Examples:

<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
<3><b8>: Abbrev Number: 0


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/dwarves/parser/4/parser.rb', line 103

rule :die_header do
  _ >>
    str("<") >>
    integer.as(:depth) >>
    str(">") >>
    str("<") >>
    word.as(:address) >>
    str(">") >>
    str(": Abbrev Number: ") >>
    integer.as(:abbrev_number) >>
    (
      _ >>
      str("(") >>
      words.as(:type) >>
      str(")")
    ).maybe >>
    newline
end

#endingObject



155
# File 'lib/dwarves/parser/4/parser.rb', line 155

rule(:ending) { any.repeat }

#formatObject

Examples:

elf64-x86-64


93
# File 'lib/dwarves/parser/4/parser.rb', line 93

rule(:format) { filename }

#inputObject

The entire input



16
17
18
# File 'lib/dwarves/parser/4/parser.rb', line 16

rule :input do
  prelude >> die.repeat.as(:dies) >> ending
end

#preludeObject

TODO:

convert numeric string results to numeric values

Examples:


contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0xf8 (32-bit)
   Version:       4
   Abbrev Offset: 0x0
   Pointer Size:  8


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dwarves/parser/4/parser.rb', line 62

rule :prelude do
  prelude_header >>
    str("Compilation Unit @ offset ") >>
    hexadecimal.as(:compilation_unit_offset) >> colon >>
    newline >>
    _ >> str("Length:") >> _ >> hexadecimal.as(:length) >> _ >>
    str("(") >> arch.as(:architecture) >> str(")") >>
    newline >>
    _ >> str("Version:") >> _ >> integer.as(:version) >>
    newline >>
    _ >> str("Abbrev Offset:") >> _ >> hexadecimal.as(:abbrev_offset) >>
    newline >>
    _ >> str("Pointer Size:") >> _ >> integer.as(:pointer_size) >>
    newline
end

#prelude_headerObject

The very beginning of input.

Examples:

contents of the .debug_info section:
tmp/everything.so:     file format elf64-x86-64

contents of the .debug_info section:


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dwarves/parser/4/parser.rb', line 32

rule :prelude_header do
  readelf =
    str("Contents of the .debug_info section:") >>
    newline >>
    _

  objdump =
    filename >> _ >> str("file format") >> _ >> format >>
    newline >>
    _ >> str("Contents of the .debug_info section:") >>
    newline >>
    _

  readelf | objdump
end

#rootObject



11
# File 'lib/dwarves/parser/4/parser.rb', line 11

root :input