Skip to content

Commit

Permalink
scripts/readelf.py: Fix register display order in _dump_debug_frames_…
Browse files Browse the repository at this point in the history
…interp

According to binutils sources (function frame_display_row in
binutils/dwarf.c), the apparent ordering of the ra register after other
registers is merely a side effect of most architectures allocating a
larger DWARF register number for their respective ra registers. This has
no effect on all readelf test cases, but is necessary for a future
LoongArch test binary to pass comparisons.

Signed-off-by: WANG Xuerui <xen0n@gentoo.org>
  • Loading branch information
xen0n committed Sep 4, 2023
1 parent 1a2c203 commit 30aedff
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions scripts/readelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,24 +1457,20 @@ def _dump_frames_interp_info(self, section, cfi_entries):

# Look at the registers the decoded table describes.
# We build reg_order here to match readelf's order. In particular,
# registers are sorted by their number, and the register matching
# ra_regnum is always listed last with a special heading.
# registers are sorted by their number, so that the register
# matching ra_regnum is usually listed last with a special heading.
# (LoongArch is a notable exception in that its return register's
# DWARF register number is not greater than other GPRs.)
decoded_table = entry.get_decoded()
reg_order = sorted(filter(
lambda r: r != ra_regnum,
decoded_table.reg_order))
reg_order = sorted(decoded_table.reg_order)
if len(decoded_table.reg_order):

# Headings for the registers
for regnum in reg_order:
if regnum == ra_regnum:
self._emit('ra ')
continue
self._emit('%-6s' % describe_reg_name(regnum))
self._emitline('ra ')

# Now include ra_regnum in reg_order to print its values
# similarly to the other registers.
reg_order.append(ra_regnum)
else:
self._emitline()
self._emitline()

for line in decoded_table.table:
self._emit(self._format_hex(
Expand Down

0 comments on commit 30aedff

Please sign in to comment.