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

fix: add a try catch around elftype reload so failure isn't fatal #2156

Merged
merged 1 commit into from
May 22, 2024

Conversation

fidgetingbits
Copy link
Contributor

I haven't been able to reliably reproduce this, but I ran into an exception a couple times during development:

pwndbg> add-symbol-file ~/dev/pwndbg/tests/gdb-tests/tests/binaries/musls/1.2.4/lib/ld-musl-x86_64.so.
1.debug
add symbol table from file "/home/aa/dev/pwndbg/tests/gdb-tests/tests/binaries/musls/1.2.4/lib/ld-musl
-x86_64.so.1.debug"
Reading symbols from /home/aa/dev/pwndbg/tests/gdb-tests/tests/binaries/musls/1.2.4/lib/ld-musl-x86_64
.so.1.debug...
Expanding full symbols from /home/aa/dev/pwndbg/tests/gdb-tests/tests/binaries/musls/1.2.4/lib/ld-musl
-x86_64.so.1.debug...
Exception occurred: Error: module pwndbg.lib.elftypes not in sys.modules (<class 'ImportError'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`
Traceback (most recent call last):
  File "/home/aa/source/pwndbg/result/share/pwndbg/pwndbg/gdblib/events.py", line 123, in caller
    raise e
  File "/home/aa/source/pwndbg/result/share/pwndbg/pwndbg/gdblib/events.py", line 118, in caller
    func()
  File "/home/aa/source/pwndbg/result/share/pwndbg/pwndbg/gdblib/elf.py", line 69, in update
    importlib.reload(pwndbg.lib.elftypes)
  File "/nix/store/glfr70gi7hfaj50mwj2431p8bg60fhqw-python3-3.11.9/lib/python3.11/importlib/__init__.p
y", line 148, in reload
    raise ImportError(msg.format(name), name=name)
ImportError: module pwndbg.lib.elftypes not in sys.modules

This just allows it to keep going if it's not able to reload, as I don't think it should be fatal.

Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 58.62%. Comparing base (5e77036) to head (c497d88).
Report is 5 commits behind head on dev.

Files Patch % Lines
pwndbg/gdblib/elf.py 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             dev    #2156       +/-   ##
==========================================
+ Coverage   3.65%   58.62%   +54.96%     
==========================================
  Files        196      196               
  Lines      25383    25637      +254     
  Branches    2597     2619       +22     
==========================================
+ Hits         928    15029    +14101     
+ Misses     24327     9783    -14544     
- Partials     128      825      +697     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@disconnect3d
Copy link
Member

Huh why is this module not in sys.modules in the first place? Sounds like a bug elsewhere?

@disconnect3d
Copy link
Member

Btw this module is reloaded bcoz the pwndbg.gdblib.ctypes.Structure may change endianess as part of https://github.com/pwndbg/pwndbg/blob/dev/pwndbg/gdblib/ctypes.py#L20-L32, right? We should probably add a comment about this somewhere in the file...

@disconnect3d
Copy link
Member

disconnect3d commented May 22, 2024

Eventually, since ctypes doesn't seem to support passing different endianess at runtime, should we maybe have both big and little endian types defined in and just have an if whenever it is instantiated to choose a proper endianess?

or a static method to create new object with proper endianess? - this is not great bcoz we would have 2 classes for each type so static method would be meh. just a normal func call is probably the way to go.

I don't like that reload module hack.

@disconnect3d
Copy link
Member

We can also create an issue for this and merge this fix in for now.

Let's do it now.

@fidgetingbits can u create an issue describing above, please?

@disconnect3d disconnect3d merged commit 213bc8b into pwndbg:dev May 22, 2024
15 checks passed
@fidgetingbits
Copy link
Contributor Author

Huh why is this module not in sys.modules in the first place? Sounds like a bug elsewhere?

Ya, because I haven't been able to reproduce it again I'm not really sure why yet. Hopefully will know why next time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants