Skip to content

gef.sh: warn about XDG init file taking precedence#1204

Merged
hugsy merged 2 commits intohugsy:mainfrom
Jvlegod:main
Feb 1, 2026
Merged

gef.sh: warn about XDG init file taking precedence#1204
hugsy merged 2 commits intohugsy:mainfrom
Jvlegod:main

Conversation

@Jvlegod
Copy link
Copy Markdown
Contributor

@Jvlegod Jvlegod commented Dec 16, 2025

description

On some systems, GDB may read the XDG init file (~/.config/gdb/gdbinit) instead of ~/.gdbinit.
In that case, the installer updates ~/.gdbinit correctly, but GEF still won’t auto-load on gdb startup, which is confusing for users.

This PR adds a minimal post-install hint: if ~/.config/gdb/gdbinit exists, print a note telling users to add source ~/.gef-<tag>.py to that file if GEF doesn't auto-load.

References

On non-Apple hosts the locations searched are:

$XDG_CONFIG_HOME/gdb/gdbinit
$HOME/.config/gdb/gdbinit
$HOME/.gdbinit
While on Apple hosts the locations searched are:

$HOME/Library/Preferences/gdb/gdbinit
$HOME/.gdbinit

https://sourceware.org/gdb/current/onlinedocs/gdb.html/Initialization-Files.html#Home-directory-initialization-files

@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 9047505 🔴

Old New
Commit ee605f9 9047505
Score 71.0775% 71.0582% (-0.0193)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/gdbinit after 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
Comment on lines +39 to +40
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}\""
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
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."
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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."

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 9f7a7b3 🟢

Old New
Commit c1e354e 9f7a7b3
Score 71.0582% 71.0775% (0.0193)

@Jvlegod
Copy link
Copy Markdown
Contributor Author

Jvlegod commented Dec 29, 2025

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}"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 9a3a730 🟢

Old New
Commit c1e354e 9a3a730
Score 71.0582% 71.0582% (0)

Signed-off-by: Jvle <keke.oerv@isrc.iscas.ac.cn>
@github-actions
Copy link
Copy Markdown

🤖 Coverage update for 1b67509 🟢

Old New
Commit c1e354e 1b67509
Score 71.0582% 71.0582% (0)

@Jvlegod
Copy link
Copy Markdown
Contributor Author

Jvlegod commented Dec 30, 2025

Hi @Grazfather, @hugsy.

I have refactored the installation script to address the concerns regarding configuration precedence and backup safety. Here are the key improvements:

  1. GDB Configuration Precedence

    The script now follows GDB's official loading order by prioritizing ~/.config/gdb/gdbinit over the legacy ~/.gdbinit. It dynamically identifies the active configuration file as target_init.

  2. Timestamped Backups

    To prevent overwriting existing backups during multiple installation attempts, I've replaced the simple .old extension with a timestamped suffix (e.g., _20251230_114500.old).

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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@hugsy hugsy merged commit 58de027 into hugsy:main Feb 1, 2026
7 checks passed
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.

4 participants