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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a gdb wrapper capable of lazy loading pwndbg's gdbinit.py #307609

Closed
wants to merge 1 commit into from

Conversation

fidgetingbits
Copy link
Contributor

@fidgetingbits fidgetingbits commented Apr 29, 2024

Description of changes

Adds a gdb wrapper whose environment is capable of lazy loading pwndbg via gdbinit.py. The use case is that I very often have to run gdb without pwndbg in order to setup initial debugging and attach to remote targets, to avoid crashes/errors, but once I hit the state that I actually want to proper analysis I load pwndbg. Some of the things that caused this to be required can be (and have been) fixed upstream in pwndbg, but the reality is day-to-day I still need use this approach and have been for years.

So the idea is from your dev shell (or wherever) you would use gdb-with-pwndbg-env (via aliasing gdb cmd or manually running), then when you actually need pwndbg you source ~/.nix-profile/share/pwndbg/gdbinit.py. The way I've been dealing with this in my devshells is using something like this:

sed -e 's/^exec \(.*\)-x.*/export PWNDBG_VENV_PATH=PWNDBG_PLEASE_SKIP_VENV\nexec \1 "\$@"/g' ${pkgs.lib.getBin pkgs.pwndbg}/bin/pwndbg > debug/gdb-with-pwndbg-env

But, I'd rather have a solution in nixpkgs itself if possible, as it will benefit other pwndbg users.

I'm open to a different name for gdb-with-pwndbg-env; I'm not sure if there's precedent for this type of thing elsewhere in nixpkgs, so maybe there is a standard.

@Mic92 @patryk4815 @msanft

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 馃憤 reaction to pull requests you find important.

@Mic92
Copy link
Member

Mic92 commented Apr 29, 2024

Quiet a long name but I can also not think of a better one.

@Mic92
Copy link
Member

Mic92 commented Apr 29, 2024

I think the standard is usually to have a gdb.withPlugins wrapper. But potentially the gdb ecosystem is not big enough for that.

@patryk4815
Copy link
Contributor

maybe better option would be something like pwndbg --lazy-init

@Mic92
Copy link
Member

Mic92 commented Apr 29, 2024

What do you think about this solution? #307655
It should still allow you to load ~/.nix-profile/share/pwndbg/gdbinit.py but now you can just use the normal gdb executable.

@fidgetingbits
Copy link
Contributor Author

That's much better imo, tested and works fine afaict. Happy to go that route unless other maintainers see any issue. I'll close this PR.

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

Successfully merging this pull request may close these issues.

None yet

3 participants