osandov / drgn

Programmable debugger
Other
1.78k stars 165 forks source link

Confusing FaultErrors in CLI #440

Closed brenns10 closed 1 month ago

brenns10 commented 1 month ago

The example in #439 of objects with bad addresses, that cause a FaultError when displayed, is interesting.

Right now, if you print such an object (like the percpu variable cpuhp_state), you get the following error, which admittedly is small and does not crash the REPL like in #439.

>>> prog["cpuhp_state"]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/stepbren/repos/drgn/drgn/cli.py", line 141, in _displayhook
    text = value.format_(columns=shutil.get_terminal_size((0, 0)).columns)
_drgn.FaultError: could not read memory from kdump: Cannot get page I/O address: PDPT table not present: p4d[0] = 0x0: 0x202a0
>>>

It's not too confusing in this case, because there's no real code being executed except for the formatting of the variable. So it doesn't take too long to realize that this must be because it's a percpu variable, and drgn encountered the FaultError while it was trying to format it.

But I've had situations where I wrote some more complex logic, or called a function, which returned an object that can't be formatted. In those cases, I initially assume that the FaultError is in my code and frequently start debugging, until I realize that the error was just with the formatting: the logic was correct, but the object returned couldn't be formatted.

So I wonder if it wouldn't make sense to change the CLI behavior so that it catches these FaultErrors while formatting, and instead just prints the repr()?