Allow running cpsr command on aarch64 (#1437)

Co-authored-by: Gulshan Singh <gsgx@google.com>
pull/1443/head
Gulshan Singh 3 years ago committed by GitHub
parent 00f09a7831
commit f49aa00f42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,31 +2,13 @@ import pwndbg.commands
import pwndbg.gdblib.arch
import pwndbg.gdblib.regs
from pwndbg.color import context
from pwndbg.color import message
@pwndbg.commands.ArgparsedCommand("Print out ARM CPSR or xPSR register")
@pwndbg.commands.ArgparsedCommand("Print out ARM CPSR or xPSR register", aliases=["xpsr", "pstate"])
@pwndbg.commands.OnlyWithArch(["arm", "armcm", "aarch64"])
@pwndbg.commands.OnlyWhenRunning
def cpsr():
arm_print_psr()
@pwndbg.commands.ArgparsedCommand("Print out ARM xPSR or CPSR register")
@pwndbg.commands.OnlyWhenRunning
def xpsr():
arm_print_psr()
def arm_print_psr():
if pwndbg.gdblib.arch.current not in ("arm", "armcm"):
print(message.warn("This is only available on ARM"))
return
reg = "cpsr" if pwndbg.gdblib.arch.current == "arm" else "xpsr"
print(
"%s %s"
% (
reg,
context.format_flags(getattr(pwndbg.gdblib.regs, reg), pwndbg.gdblib.regs.flags[reg]),
)
)
reg = "xpsr" if pwndbg.gdblib.arch.name == "armcm" else "cpsr"
reg_val = getattr(pwndbg.gdblib.regs, reg)
reg_flags = pwndbg.gdblib.regs.flags[reg]
print(f"{reg} {context.format_flags(reg_val, reg_flags)}")

@ -94,6 +94,25 @@ arm_xpsr_flags = collections.OrderedDict(
[("N", 31), ("Z", 30), ("C", 29), ("V", 28), ("Q", 27), ("T", 24)]
)
aarch64_cpsr_flags = collections.OrderedDict(
[
("N", 31),
("Z", 30),
("C", 29),
("V", 28),
("Q", 27),
("PAN", 22),
("IL", 20),
("D", 9),
("A", 8),
("I", 7),
("F", 6),
# TODO: EL is two bits
("EL", 2),
("SP", 0),
]
)
arm = RegisterSet(
retaddr=("lr",),
flags={"cpsr": arm_cpsr_flags},
@ -111,10 +130,10 @@ armcm = RegisterSet(
retval="r0",
)
# FIXME AArch64 does not have a CPSR register
# AArch64 has a PSTATE register, but GDB represents it as the CPSR register
aarch64 = RegisterSet(
retaddr=("lr",),
flags={"cpsr": {}},
flags={"cpsr": aarch64_cpsr_flags},
# X29 is the frame pointer register (FP) but setting it
# as frame here messes up the register order to the point
# it's confusing. Think about improving this if frame

Loading…
Cancel
Save