Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aarch64 - Update gdb python to use ARMv8 registers #7985

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion hphp/tools/gdb/gdbutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ def string_data_val(val, keep_case=True):
else:
data = val['m_data']

s = data.string('utf-8', 'ignore', val['m_len'])
try:
s = data.string('utf-8', 'ignore', val['m_len'])
except:
s = "Unknown"

return s if keep_case else s.lower()


Expand Down Expand Up @@ -300,3 +304,14 @@ def deref(val):
return val.cast(rawtype(val.type))
else:
return deref(p.referenced_value())


def get_arch(self):
"""Get gdb Architecture Object name"""
try:
return gdb.selected_frame().architecture().name()
except:
return re.search('\(currently (.*)\)',
gdb.execute('show architecture', to_string=True)
).group(1)

14 changes: 11 additions & 3 deletions hphp/tools/gdb/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def invoke(self, args, from_tty):

# Set fp = $rbp, rip = $rip.
fp_type = T('uintptr_t').pointer()
fp = native_frame.read_register('rbp').cast(fp_type)
if get_arch(self) == 'aarch64':
fp = native_frame.read_register('x29').cast(fp_type)
else:
fp = native_frame.read_register('rbp').cast(fp_type)
rip = native_frame.pc()

if len(argv) == 1:
Expand Down Expand Up @@ -196,8 +199,13 @@ def invoke(self, args, from_tty):
return

fp_type = T('uintptr_t').pointer()
fp = gdb.parse_and_eval('$rbp').cast(fp_type)
rip = gdb.parse_and_eval('$rip').cast(T('uintptr_t'))
if get_arch(self) == 'aarch64':
fp = gdb.parse_and_eval('x29').cast(fp_type)
rip = gdb.parse_and_eval('x30').cast(T('uintptr_t'))
else:
fp = gdb.parse_and_eval('$rbp').cast(fp_type)
rip = gdb.parse_and_eval('$rip').cast(T('uintptr_t'))


if len(argv) >= 1:
fp = argv[0].cast(fp_type)
Expand Down
29 changes: 22 additions & 7 deletions hphp/tools/gdb/unwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ def __init__(self):
super(HHVMUnwinder, self).__init__('hhvm_unwinder')

def __call__(self, pending_frame):
fp = pending_frame.read_register('rbp')
sp = pending_frame.read_register('rsp')
ip = pending_frame.read_register('rip')
if get_arch(self) == 'aarch64':
fp = pending_frame.read_register('x29')
sp = pending_frame.read_register('x28')
ip = pending_frame.read_register('x30')
else:
fp = pending_frame.read_register('rbp')
sp = pending_frame.read_register('rsp')
ip = pending_frame.read_register('rip')

if not frame.is_jitted(fp, ip):
return None
Expand All @@ -53,18 +58,28 @@ def __call__(self, pending_frame):

# Restore the saved frame pointer and instruction pointer.
fp = fp.cast(T('uintptr_t').pointer())
unwind_info.add_saved_register('rbp', fp[0])
unwind_info.add_saved_register('rip', fp[1])
if get_arch(self) == 'aarch64':
unwind_info.add_saved_register('x29', fp[0])
unwind_info.add_saved_register('x30', fp[1])
else:
unwind_info.add_saved_register('rbp', fp[0])
unwind_info.add_saved_register('rip', fp[1])

if frame.is_jitted(fp[0], fp[1]):
# Our parent frame is jitted. Again, we are unable to track %rsp
# properly in the TC, so just preserve its value (just as we do in
# the TC's custom .eh_frame section).
unwind_info.add_saved_register('rsp', sp)
if get_arch(self) == 'aarch64':
unwind_info.add_saved_register('x28', sp)
else:
unwind_info.add_saved_register('rsp', sp)
else:
# Our parent frame is not jitted, so we're in enterTCHelper, and we
# can restore our parent's %rsp as usual.
unwind_info.add_saved_register('rsp', fp + 16)
if get_arch(self) == 'aarch64':
unwind_info.add_saved_register('x28', fp + 16)
else:
unwind_info.add_saved_register('rsp', fp + 16)

return unwind_info

Expand Down