This is an archive of the discontinued LLVM Phabricator instance.

[lldb/crashlog] Fix arm64 register parsing on crashlog.py
ClosedPublic

Authored by mib on Feb 7 2022, 11:22 AM.

Details

Summary

This patch fixes the register parser for arm64 crashlogs.

Compared to x86_64 crashlogs, the arm64 crashlogs nests the general
purpose registers into a separate dictionary within thread_state
dictionary. It uses the dictionary key as the the register number.

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>

Diff Detail

Event Timeline

mib created this revision.Feb 7 2022, 11:22 AM
mib requested review of this revision.Feb 7 2022, 11:22 AM

I recently modified this function to support parsing the rosetta registers. To do that I call parse_thread_registers recursively, and I think we should do the same here and add an optional argument for the prefix. So the result would look something like:

def parse_thread_registers(self, json_thread_state, prefix=None):
    registers = dict()
    for key, state in json_thread_state.items():
        if key == "rosetta":
           registers.update(self.parse_thread_registers(state))
           continue
        if key == "x":
           registers.update(self.parse_thread_registers(state), prefix="x")
           continue
        try:
           value = int(state['value'])
           registers["{}{}".format(prefix,key)] = value
        except (KeyError, ValueError, TypeError):
           pass
    return registers
mib updated this revision to Diff 406666.Feb 7 2022, 6:08 PM

Use the same approach as rosetta.

shafik added a subscriber: shafik.Feb 8 2022, 8:16 AM
shafik added inline comments.
lldb/examples/python/crashlog.py
530

nitpick: Is there a better way to format this code or rewrite it so that is reads better?

mib added inline comments.Feb 8 2022, 10:21 AM
lldb/examples/python/crashlog.py
530

@shafik I didn't feel like creating a variable on top of that but if you think it can improve readability, I can do that.

mib updated this revision to Diff 406899.Feb 8 2022, 11:04 AM

Address @shafik comment.

mib marked an inline comment as done.Feb 8 2022, 11:42 AM
This revision is now accepted and ready to land.Feb 8 2022, 12:39 PM
This revision was automatically updated to reflect the committed changes.