-
Notifications
You must be signed in to change notification settings - Fork 199
Crash command: bt #555
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
base: main
Are you sure you want to change the base?
Crash command: bt #555
Changes from 1 commit
34913da
c4e0ce4
70fd5f1
971b94e
1638d22
3a384f5
0f98b72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,10 +11,10 @@ | |||||
|
|
||||||
| from typing import Any, Dict | ||||||
|
|
||||||
| from drgn import FaultError, PlatformFlags, StackTrace | ||||||
| from drgn import Architecture, FaultError, PlatformFlags, Program, StackTrace | ||||||
| from drgn.helpers.common.memory import identify_address | ||||||
|
|
||||||
| __all__ = ("print_annotated_stack",) | ||||||
| __all__ = ("print_annotated_stack", "print_registers") | ||||||
|
|
||||||
|
|
||||||
| def print_annotated_stack(trace: StackTrace) -> None: | ||||||
|
|
@@ -136,3 +136,98 @@ def print_annotated_stack(trace: StackTrace) -> None: | |||||
| print(line_format.format(addr, word_val, identified)) | ||||||
|
|
||||||
| start = end | ||||||
|
|
||||||
|
|
||||||
| def print_registers(prog: Program, regs: Dict[str, int], indent: int = 4) -> None: | ||||||
| """ | ||||||
| Print a CPU register dump, in a format similar to that of crash | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| :param regs: a dictionary of registers, named in a similar way to the | ||||||
| dictionary returned by :py:class:`drgn.StackTrace.registers`. | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this references a method, I think it could be
Suggested change
|
||||||
| :param indent: the number of spaces to indent the output | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we take the indentation string, similar to |
||||||
| """ | ||||||
| if not prog.platform: | ||||||
| raise RuntimeError("Unknown platform & architecture") | ||||||
|
|
||||||
| widths = {} | ||||||
| formats = {} | ||||||
| if prog.platform.arch == Architecture.X86_64: | ||||||
| rows = [ | ||||||
| ("rip", "rsp", "rflags"), | ||||||
| ("rax", "rbx", "rcx"), | ||||||
| ("rdx", "rsi", "rdi"), | ||||||
| ("rbp", "r8", "r9"), | ||||||
| ("r10", "r11", "r12"), | ||||||
| ("r13", "r14", "r15"), | ||||||
| ("cs", "ss"), | ||||||
| ] | ||||||
| widths = {"cs": 4, "ss": 4, "rflags": 8} | ||||||
| elif prog.platform.arch == Architecture.AARCH64: | ||||||
| rows = [ | ||||||
| ("pc", "lr", "sp"), | ||||||
| ("x29", "x28", "x27"), | ||||||
| ("x26", "x25", "x24"), | ||||||
| ("x23", "x22", "x21"), | ||||||
| ("x20", "x19", "x18"), | ||||||
| ("x17", "x16", "x15"), | ||||||
| ("x14", "x13", "x12"), | ||||||
| ("x11", "x10", "x9"), | ||||||
| ("x8", "x7", "x6"), | ||||||
| ("x5", "x4", "x3"), | ||||||
| ("x2", "x1", "x0"), | ||||||
| ] | ||||||
| elif prog.platform.arch == Architecture.ARM: | ||||||
| rows = [ | ||||||
| ("pc", "lr", "sp", "fp"), | ||||||
| ("r10", "r9", "r8"), | ||||||
| ("r7", "r6", "r5", "r4"), | ||||||
| ("r3", "r2", "r1", "r0"), | ||||||
| ] | ||||||
| elif prog.platform.arch == Architecture.S390X: | ||||||
| rows = [ | ||||||
| ("pswm", "pswa", "r0"), | ||||||
| ("r1", "r3", "r3"), | ||||||
| ("r4", "r5", "r6"), | ||||||
| ("r7", "r8", "r9"), | ||||||
| ("r10", "r11", "r12"), | ||||||
| ("r13", "r14", "r15"), | ||||||
| ] | ||||||
| elif prog.platform.arch == Architecture.PPC64: | ||||||
| rows = [ | ||||||
| ("r0", "r1", "r2"), | ||||||
| ("r3", "r4", "r5"), | ||||||
| ("r6", "r7", "r8"), | ||||||
| ("r9", "r10", "r11"), | ||||||
| ("r12", "r13", "r14"), | ||||||
| ("r15", "r16", "r17"), | ||||||
| ("r18", "r19", "r20"), | ||||||
| ("r21", "r22", "r23"), | ||||||
| ("r24", "r25", "r26"), | ||||||
| ("r27", "r28", "r29"), | ||||||
| ("r30", "r31"), | ||||||
| # This departs from the crash format significantly. Crash recovers | ||||||
| # registers like CTR, XER, LR, and a few others. However, drgn | ||||||
| # doesn't provide these in stack frame registers. They are available | ||||||
| # in struct pt_regs. | ||||||
| ("cr0", "cr1", "cr2", "cr3"), | ||||||
| ("cr4", "cr5", "cr6", "cr7"), | ||||||
| ] | ||||||
| widths = {f"cr{i}": 4 for i in range(8)} | ||||||
| formats = {f"cr{i}": "b" for i in range(8)} | ||||||
| else: | ||||||
| raise RuntimeError(f"Unsupported architecture: {prog.platform.arch}") | ||||||
|
|
||||||
| default_width = 16 if prog.platform.flags & PlatformFlags.IS_64_BIT else 8 | ||||||
|
|
||||||
| for row in rows: | ||||||
| row_text = [] | ||||||
| for i, reg in enumerate(row): | ||||||
| width = widths.get(reg, default_width) | ||||||
| if reg in regs: | ||||||
| value = regs[reg] | ||||||
| fmt = formats.get(reg, "x") | ||||||
| row_text.append(f"{reg.upper():>3s}: {value:0{width}{fmt}}") | ||||||
| else: | ||||||
| row_text.append(f"{reg.upper():>3s}: {'?' * width}") | ||||||
|
|
||||||
| print(f"{'':{indent}s}{' '.join(row_text)}") | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For CLI convenience: