diff mbox series

[bug#42882] system: Modify GDB skeleton to find debug files for any profile.

Message ID 20200816053947.30110-1-maxim.cournoyer@gmail.com
State Accepted
Headers show
Series [bug#42882] system: Modify GDB skeleton to find debug files for any profile. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Maxim Cournoyer Aug. 16, 2020, 5:39 a.m. UTC
Instead of hard coding the debug directory to that of the user profile, use
Guile scripting to derive the debug file directories from the LIBRARY_PATH
environment variable.

* gnu/system/shadow.scm (default-skeletons)[gdbinit]: Derive the value of
DEBUG-FILE-DIRECTORY via the environment variable LIBRARY_PATH, so that debug
files from any profile can be found.
* doc/guix.texi (Installing Debugging Files): Document it.
---
 doc/guix.texi         | 17 +++++++++++++++++
 gnu/system/shadow.scm | 11 ++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

Comments

Mathieu Othacehe Aug. 16, 2020, 8:21 a.m. UTC | #1
Hello Maxim,

> +Below is an alternative GDB script that can be useful when working with
> +other profiles.  It takes advantage of the Guile integration available
> +in GDB.

You could say the "optional Guile integration", because it is (sadly)
disabled on Ubuntu's gdb build for instance.

> +
> +@example
> +guile
> +(begin
> +  (use-modules (gdb)
> +               (srfi srfi-26))
> +  (let* ((library-paths (string-split (getenv "LIBRARY_PATH") #\:))
> +         (debug-paths (map (cut string-append <> "/debug")
> +                           library-paths)))
> +    (execute (format #f "set debug-file-directory ~a"
> +                     (string-join debug-paths ":")))))
> +end
> +@example

And maybe precise that this very snippet will be installed by default as
.gdbinit on Guix System?

Otherwise it looks fine to me.

Thanks,

Mathieu
Maxim Cournoyer Aug. 16, 2020, 7:18 p.m. UTC | #2
Hello Mathieu,

Thanks for the review!  I've taken into account your suggestions and improved
the mechanism a bit, so that we can now simply use the
GDB_DEBUG_FILE_DIRECTORY environment variable (which is set up by a new search
path specification defined on the gdb package). I think this is better as
otherwise you'd need to ensure the gcc-toolchain is installed in the profile
you want GDB to find the debug files (because GCC is responsible for setting
the LIBRARY_PATH environment variable).

I hope it makes sense :-).

This will need to go to core-updates as gdb is has about 1500 dependents.

Thanks!

Maxim
Mathieu Othacehe Aug. 24, 2020, 8:48 a.m. UTC | #3
Hey Maxim,

> Thanks for the review!  I've taken into account your suggestions and improved
> the mechanism a bit, so that we can now simply use the
> GDB_DEBUG_FILE_DIRECTORY environment variable (which is set up by a new search
> path specification defined on the gdb package). I think this is better as
> otherwise you'd need to ensure the gcc-toolchain is installed in the profile
> you want GDB to find the debug files (because GCC is responsible for setting
> the LIBRARY_PATH environment variable).
>
> I hope it makes sense :-).

I think it makes! Your last revision seems fine to me.

Thanks,

Mathieu
Maxim Cournoyer Aug. 24, 2020, 1:58 p.m. UTC | #4
Mathieu Othacehe <othacehe@gnu.org> writes:

> Hey Maxim,
>
>> Thanks for the review!  I've taken into account your suggestions and improved
>> the mechanism a bit, so that we can now simply use the
>> GDB_DEBUG_FILE_DIRECTORY environment variable (which is set up by a new search
>> path specification defined on the gdb package). I think this is better as
>> otherwise you'd need to ensure the gcc-toolchain is installed in the profile
>> you want GDB to find the debug files (because GCC is responsible for setting
>> the LIBRARY_PATH environment variable).
>>
>> I hope it makes sense :-).
>
> I think it makes! Your last revision seems fine to me.
>
> Thanks,
>
> Mathieu

Thanks for taking a look!  I've now pushed this change into the
core-updates branch as commit 720a4adc91.

Thank you,

Maxim
diff mbox series

Patch

diff --git a/doc/guix.texi b/doc/guix.texi
index 587c004bee..53b85418fb 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -30145,6 +30145,23 @@  GDB}):
 From there on, GDB will pick up debugging information from the
 @file{.debug} files under @file{~/.guix-profile/lib/debug}.
 
+Below is an alternative GDB script that can be useful when working with
+other profiles.  It takes advantage of the Guile integration available
+in GDB.
+
+@example
+guile
+(begin
+  (use-modules (gdb)
+               (srfi srfi-26))
+  (let* ((library-paths (string-split (getenv "LIBRARY_PATH") #\:))
+         (debug-paths (map (cut string-append <> "/debug")
+                           library-paths)))
+    (execute (format #f "set debug-file-directory ~a"
+                     (string-join debug-paths ":")))))
+end
+@example
+
 In addition, you will most likely want GDB to be able to show the source
 code being debugged.  To do that, you will have to unpack the source
 code of the package of interest (obtained with @code{guix build
diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index a69339bc07..d31cd37077 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -162,7 +162,16 @@  XTerm*utf8: always
 XTerm*metaSendsEscape: true\n"))
         (gdbinit   (plain-file "gdbinit" "\
 # Tell GDB where to look for separate debugging files.
-set debug-file-directory ~/.guix-profile/lib/debug
+guile
+(begin
+  (use-modules (gdb)
+               (srfi srfi-26))
+  (let* ((library-paths (string-split (getenv \"LIBRARY_PATH\") #\\:))
+         (debug-paths (map (cut string-append <> \"/debug\")
+                           library-paths)))
+    (execute (format #f \"set debug-file-directory ~a\"
+                     (string-join debug-paths \":\")))))
+end
 
 # Authorize extensions found in the store, such as the
 # pretty-printers of libstdc++.