mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 01:33:06 +00:00
cbdf6094b7
The usage of the link register in DWARF is a little confusing. On entry
to a function, the link register contains the address that should be
returned to. However, for DWARF, the link register is usually used as
the CFI return_address_register, which means that in an unwound frame,
it will contain the same thing as the program counter. I initially
thought that this was a mistake, believing that the link register should
contain the _next_ return address. However, after a return (with the blr
instruction), the link register will indeed contain the same address as
the program counter. This is consistent with our documentation of
register values for function call frames: "the register values are the
values when control returns to this frame".
So, rename our internal "ra" register to "lr", expose it to the API, and
add a little more documentation to the ppc64 initial register code.
Fixes: 221a218704
("libdrgn: add powerpc stack trace support")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
23 lines
945 B
Python
23 lines
945 B
Python
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
REGISTERS = [
|
|
*[DrgnRegister(f"r{i}") for i in range(32)],
|
|
DrgnRegister("lr"),
|
|
*[DrgnRegister(f"cr{i}") for i in range(8)],
|
|
]
|
|
|
|
# There are two conflicting definitions of DWARF register numbers after 63. The
|
|
# original definition appears to be "64-bit PowerPC ELF Application Binary
|
|
# Interface Supplement" [1]. The GNU toolchain instead uses its own that was
|
|
# later codified in "Power Architecture 64-Bit ELF V2 ABI Specification" [2].
|
|
# We use the latter.
|
|
#
|
|
# 1: https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html
|
|
# 2: https://openpowerfoundation.org/specifications/64bitelfabi/
|
|
REGISTER_LAYOUT = [
|
|
DrgnRegisterLayout("lr", size=8, dwarf_number=65),
|
|
*[DrgnRegisterLayout(f"r{i}", size=8, dwarf_number=i) for i in range(32)],
|
|
*[DrgnRegisterLayout(f"cr{i}", size=8, dwarf_number=68 + i) for i in range(8)],
|
|
]
|