gef.sh: warn about XDG init file taking precedence#1204
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the GEF installer by adding a post-install warning when an XDG-style GDB init file is detected. Since GDB prioritizes ~/.config/gdb/gdbinit over ~/.gdbinit when both exist, users may experience confusion when GEF doesn't auto-load despite successful installation. The warning provides guidance on how to fix this issue.
Key changes:
- Detects existence of
~/.config/gdb/gdbinitafter installation - Displays informative warning message with suggested fix command
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
scripts/gef.sh
Outdated
| echo " If GEF doesn't auto-load on 'gdb' startup, GDB may be reading this file instead of ~/.gdbinit." | ||
| echo " Fix: echo \"source ~/.gef-${tag}.py\" >> \"${xdg_init}\"" |
There was a problem hiding this comment.
The suggested fix command uses append (>>) which could result in multiple duplicate entries if the user runs the installer multiple times or if they already have a source line. Consider checking whether GEF is already sourced in the XDG init file before suggesting this command, similar to how the script handles ~/.gdbinit on lines 24-33.
| echo " If GEF doesn't auto-load on 'gdb' startup, GDB may be reading this file instead of ~/.gdbinit." | |
| echo " Fix: echo \"source ~/.gef-${tag}.py\" >> \"${xdg_init}\"" | |
| if grep -q "source ~/.gef-" "${xdg_init}"; then | |
| echo " GEF is already sourced in ${xdg_init}." | |
| else | |
| echo " If GEF doesn't auto-load on 'gdb' startup, GDB may be reading this file instead of ~/.gdbinit." | |
| echo " Fix: grep -q \"source ~/.gef-\" \"${xdg_init}\" || echo \"source ~/.gef-${tag}.py\" >> \"${xdg_init}\"" | |
| fi |
scripts/gef.sh
Outdated
| xdg_init="${HOME}/.config/gdb/gdbinit" | ||
| if [ -f "${xdg_init}" ]; then | ||
| echo "[!] Detected ${xdg_init}" | ||
| echo " If GEF doesn't auto-load on 'gdb' startup, GDB may be reading this file instead of ~/.gdbinit." |
There was a problem hiding this comment.
The warning message could be more actionable. According to the GDB documentation referenced in the PR description, GDB reads init files in order and stops at the first one found. If the XDG init file exists, GDB will use it instead of ~/.gdbinit, not "may be reading." Consider rewording to be more definitive: "GDB will read this file instead of ~/.gdbinit" to avoid confusion.
| echo " If GEF doesn't auto-load on 'gdb' startup, GDB may be reading this file instead of ~/.gdbinit." | |
| echo " If GEF doesn't auto-load on 'gdb' startup, GDB will read this file instead of ~/.gdbinit." |
|
Okay, I've fixed the potential risks identified by the AI. |
scripts/gef.sh
Outdated
| if [ -f "${xdg_init}" ]; then | ||
| echo "[!] Detected ${xdg_init}" | ||
| if grep -q "source ~/.gef-" "${xdg_init}"; then | ||
| echo " GEF is already sourced in ${xdg_init}" |
There was a problem hiding this comment.
We could use the above update version logic above.
Probably better to get this whole block, first determine while file to use, maybe warn about the precedence, then either update or add the gef source line.
Signed-off-by: Jvle <keke.oerv@isrc.iscas.ac.cn>
Signed-off-by: Jvle <keke.oerv@isrc.iscas.ac.cn>
|
Hi @Grazfather, @hugsy. I have refactored the installation script to address the concerns regarding configuration precedence and backup safety. Here are the key improvements:
Please let me know if you have any further suggestions! Here I put my test results. # 1. when ${HOME}/.config/gdb/gdbinit exist.
$ ./scripts/gef.sh
[*] Existing gdbinit saved as /home/jvle/.config/gdb/gdbinit_20251230_105048.old
[+] Updated GEF version in /home/jvle/.config/gdb/gdbinit
# 2. when ${HOME}/.config/gdb/gdbinit not exist.
$ mv /home/jvle/.config/gdb/gdbinit /home/jvle/.config/gdb/gdbinit.old
$ ./scripts/gef.sh
[*] Existing gdbinit saved as /home/jvle/.gdbinit_20251230_105120.old
[+] Updated GEF version in /home/jvle/.gdbinit
# 3. when ${HOME}/.gdbinit don't have source
$ vim /home/jvle/.gdbinit
# delete source
$ ./scripts/gef.sh
[+] Added GEF source to /home/jvle/.gdbinit
# 4. when ${HOME}/.config/gdb/gdbinit don't have source
$ mv /home/jvle/.config/gdb/gdbinit.old /home/jvle/.config/gdb/gdbinit
$ vim /home/jvle/.config/gdb/gdbinit
# delete source
$ ./scripts/gef.sh
[*] Existing gdbinit saved as /home/jvle/.config/gdb/gdbinit_20251230_105201.old
[+] Added GEF source to /home/jvle/.config/gdb/gdbinit
# 5. show backups
$ ls /home/jvle/.config/gdb/
gdbinit gdbinit~ gdbinit_20251230_105048.old gdbinit_20251230_105201.old
$ ls /home/jvle/.gdb*
/home/jvle/.gdb_history /home/jvle/.gdbinit /home/jvle/.gdbinit_20251230_105120.old /home/jvle/.gdbinit.old |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
description
On some systems, GDB may read the XDG init file (
~/.config/gdb/gdbinit) instead of~/.gdbinit.In that case, the installer updates
~/.gdbinitcorrectly, but GEF still won’t auto-load ongdbstartup, which is confusing for users.This PR adds a minimal post-install hint: if
~/.config/gdb/gdbinitexists, print a note telling users to addsource ~/.gef-<tag>.pyto that file if GEF doesn't auto-load.References
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Initialization-Files.html#Home-directory-initialization-files