mirror of https://github.com/pwndbg/pwndbg.git
Fix source code display (#638)
* Fix source code display Fixes and simplifies source code display in `context code`. The reasoning below. --- It turns out that we determine the source code line for known code in a tricky and buggy way. It is wrong when we are deep inside many calls and we go to upper frame via e.g. `up` and then display the `context code`. And this also occurs after applying the PR #637 before/after this fix. We also do `except` all exceptions happening in the source code retrieval which makes it hard to spot potential bugs in this code path. This commit removes the `except` path and checks for particular edge cases where we wouldn't have sources available. --- Also note the `FileNotFoundError` path - in this case the debug symbols have a source file path there, but it hasn't been found by us. It might be because the program (or anything else) removed it OR maybe we debug remotely etc (not sure if this is the case). This being said, we could potentially inform the users about that BUT... GDB already does that by itself - maybe in a bit vague way, as it does it before us displaying the context e.g.: ``` pwndbg> r Starting program: /home/dc/pwndbg/a.out Program received signal SIGSEGV, Segmentation fault. 0x000055555555460a in foo () at ./a.c:2 2 ./a.c: No such file or directory. LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA // (the rest of the context here) ``` But I am fine with that for now - and I am not sure if we could even suppress this warning (oh, maybe this string comes to us into prompt hook/event? I don't know) * Fix wrong code line if source startswith newlines For some reason the `pygments.hightlight` remove newlines at start. We need to preserve them in order to keep proper code lines. * Use lexer's stripnl=Falsepull/641/head
parent
b02dad2fe0
commit
90b8a4f2b9
Loading…
Reference in new issue