elf_utils 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 478f9074bd476ac8ef285d6c29495d396f94c8c9065d4877a7e03a65d3560aed
4
- data.tar.gz: 1a64b2adfbc19b1a8d2b8a975b516e9d5051a785be8a2f20ec69736eef555ca9
3
+ metadata.gz: ca6fa495dbda4f982713d3cd015abe94c0a292f0cfcf44a91cc13aeef85a4429
4
+ data.tar.gz: 6bbfb945c6cb8240f71f92c2b0db81f8df94c8837f76d9adc1a52613781ce663
5
5
  SHA512:
6
- metadata.gz: 0d651326a749d4cc5daf9b272824dd19d4547438e4313bc366549ad80d329c2de8077851eb4099a1ae0f03d0f17eb3fd943bbc19fc443a954e6c9bd1a6be0aae
7
- data.tar.gz: fe4eecc606cef5dded6e1e2178c0f3630b82943a433ca6503fb99e0afa269e1ab020dd3c8af402e2270f6780f029e8fcdd06efa5bc146fa759b189765b7e8581
6
+ metadata.gz: c0ed80f8d44d903cc4aa5835612b1bd9e6930643a7f5f371589caad5f97564832b90458fdb4628524dfb0f9a68f27ef8ee10d8098aedbf4e86a6220b6be04691
7
+ data.tar.gz: 3458490318399305bbefe45d957af6b4f4e8d2bb2b7a23f52efba27fb62c238d3ed69ef7f4c3909cf4bc28736fee6abd627ced01a868a1186fb2274c616e8034
@@ -137,15 +137,28 @@ module ElfUtils
137
137
  @attrs ||= parse_attrs
138
138
 
139
139
  raise "not a subrange DIE: %p" % [self] unless @tag == :subrange_type
140
- return @attrs[:count] if @attrs.has_key?(:count)
140
+ count = @attrs[:count]
141
+ case count
142
+ when Integer
143
+ return count
144
+ when Section::DebugInfo::Die
145
+ # return a size of nil for variable-length array
146
+ return nil if count.tag == :variable
147
+ raise ElfUtils::Error, "unexpected DIE type in subrange[:count]: %p" %
148
+ [count]
149
+ when nil
150
+ # fall through when there is no count attribute
151
+ else
152
+ raise ElfUtils::Error, "unexpected value in subrange[:count]: %p" %
153
+ [count]
154
+ end
141
155
 
142
156
  # upper bound may be DW_TAG_variable, so special handling
143
157
  if (upper_bound = @attrs[:upper_bound])
144
158
  return @attrs[:upper_bound] + 1 if upper_bound.is_a?(Integer)
145
159
  end
146
160
 
147
- # XXX we'll need to do some work to support flexible array members, or
148
- # arrays with an upper bound defined by DW_TAG_variable
161
+ # XXX we'll need to do some work to support flexible array members
149
162
  0
150
163
  end
151
164
 
@@ -173,12 +186,19 @@ module ElfUtils
173
186
  when :const_type
174
187
  "const #{@attrs[:type]&.type_name || "void"}"
175
188
  when :array_type
176
- sizes = children
177
- .inject("") do |buf, child|
178
- buf << "[%d]" % child.subrange_len if child.tag == :subrange_type
179
- buf
189
+ buf = "#{@attrs[:type]&.type_name}"
190
+ sizes = children.each do |child|
191
+ next unless child.tag == :subrange_type
192
+
193
+ # subrange_len may return nil for variable-length arrays
194
+ len = child.subrange_len
195
+ if len
196
+ buf << "[%d]" % len
197
+ else
198
+ buf << "[]"
199
+ end
180
200
  end
181
- "#{@attrs[:type].type_name}#{sizes}"
201
+ buf
182
202
  when :pointer_type
183
203
  inner = @attrs[:type]&.type_name || "void"
184
204
  if inner.end_with?("*")
@@ -221,8 +241,10 @@ module ElfUtils
221
241
  when :pointer_type, :subroutine_type
222
242
  @cu.addr_type
223
243
  when :array_type
244
+ # subrange_len may return nil for variable-length arrays
224
245
  sizes = children
225
- .filter_map { |c| c.subrange_len if c.tag == :subrange_type }
246
+ .select { |c| c.tag == :subrange_type }
247
+ .map { |c| c.subrange_len }
226
248
 
227
249
  # if we have a signed char array, we'll use a string to hold it
228
250
  inner_type = @attrs[:type].ctype
@@ -232,7 +254,7 @@ module ElfUtils
232
254
  inner_type = CTypes::String.new(size: sizes.pop)
233
255
  end
234
256
 
235
- while (size = sizes.pop)
257
+ sizes.reverse_each do |size|
236
258
  inner_type = CTypes::Array.new(type: inner_type, size:)
237
259
  end
238
260
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ElfUtils
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elf_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David M. Lary