aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-debug-link)
  #:use-module (guix elf)
  #:use-module (guix build utils)
  #:use-module (guix build debug-link)
  #:use-module (guix gexp)
  #:use-module (guix store)
  #:use-module (guix tests)
  #:use-module (guix monads)
  #:use-module (guix derivations)
  #:use-module (gnu packages bootstrap)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-64)
  #:use-module (rnrs io ports)
  #:use-module (ice-9 match))

(define %guile-executable
  (match (false-if-exception (readlink "/proc/self/exe"))
    ((? string? program)
     (and (file-exists? program) (elf-file? program)
          program))
    (_
     #f)))

(define read-elf
  (compose parse-elf get-bytevector-all))


(test-begin "debug-link")

(unless %guile-executable (test-skip 1))
(test-assert "elf-debuglink"
  (let ((elf (call-with-input-file %guile-executable read-elf)))
    (match (call-with-values (lambda () (elf-debuglink elf)) list)
      ((#f #f)                                    ;no '.gnu_debuglink' section
       (pk 'no-debuglink #t))
      (((? string? file) (? integer? crc))
       (string-suffix? ".debug" file)))))

;; Since we need %BOOTSTRAP-GCC and co., we have to skip the following tests
;; when networking is unreachable because we'd fail to download it.
(unless (network-reachable?) (test-skip 1))
(test-assertm "elf-debuglink"
  ;; Check whether we can compute the CRC just like objcopy, and whether we
  ;; can retrieve it.
  (let* ((code (plain-file "test.c" "int main () { return 42; }"))
         (exp  (with-imported-modules '((guix build utils)
                                        (guix build debug-link)
                                        (guix elf))
                 #~(begin
                     (use-modules (guix build utils)
                                  (guix build debug-link)
                                  (guix elf)
                                  (rnrs io ports))

                     (define read-elf
                       (compose parse-elf get-bytevector-all))

                     (setenv "PATH" (string-join '(#$%bootstrap-gcc
                                                   #$%bootstrap-binutils)
                                                 "/bin:" 'suffix))
                     (invoke "gcc" "-O0" "-g" #$code "-o" "exe")
                     (copy-file "exe" "exe.debug")
                     (invoke "strip" "--only-keep-debug" "exe.debug")
                     (invoke "strip" "--strip-debug" "exe")
                     (invoke "objcopy" "--add-gnu-debuglink=exe.debug"
                             "exe")
                     (call-with-values (lambda ()
                                         (elf-debuglink
                                          (call-with-input-file "exe"
                                            read-elf)))
                       (lambda (file crc)
                         (call-with-output-file #$output
                           (lambda (port)
                             (let ((expected (call-with-input-file "exe.debug"
                                               debuglink-crc32)))
                               (write (list file (= crc expected))
                                      port))))))))))
    (mlet* %store-monad ((drv (gexp->derivation "debuglink" exp))
                         (x   (built-derivations (list drv))))
      (call-with-input-file (derivation->output-path drv)
        (lambda (port)
          (return (match (read port)
                    (("exe.debug" #t) #t)
                    (x                (pk 'fail x #f)))))))))

(unless (network-reachable?) (test-skip 1))
(test-assertm "set-debuglink-crc"
  ;; Check whether 'set-debuglink-crc' successfully updates the CRC.
  (let* ((code  (plain-file "test.c" "int main () { return 42; }"))
         (debug (plain-file "exe.debug" "a"))
         (exp   (with-imported-modules '((guix build utils)
                                         (guix build debug-link)
                                         (guix elf))
                  #~(begin
                      (use-modules (guix build utils)
                                   (guix build debug-link)
                                   (guix elf)
                                   (rnrs io ports))

                      (define read-elf
                        (compose parse-elf get-bytevector-all))

                      (setenv "PATH" (string-join '(#$%bootstrap-gcc
                                                    #$%bootstrap-binutils)
                                                  "/bin:" 'suffix))
                      (invoke "gcc" "-O0" "-g" #$code "-o" "exe")
                      (copy-file "exe" "exe.debug")
                      (invoke "strip" "--only-keep-debug" "exe.debug")
                      (invoke "strip" "--strip-debug" "exe")
                      (invoke "objcopy" "--add-gnu-debuglink=exe.debug"
                              "exe")
                      (set-debuglink-crc "exe" #$debug)
                      (call-with-values (lambda ()
                                          (elf-debuglink
                                           (call-with-input-file "exe"
                                             read-elf)))
                        (lambda (file crc)
                          (call-with-output-file #$output
                            (lambda (port)
                              (write (list file crc) port)))))))))
    (mlet* %store-monad ((drv (gexp->derivation "debuglink" exp))
                         (x   (built-derivations (list drv))))
      (call-with-input-file (derivation->output-path drv)
        (lambda (port)
          (return (match (read port)
                    (("exe.debug" crc)
                     (= crc (debuglink-crc32 (open-input-string "a"))))
                    (x
                     (pk 'fail x #f)))))))))

(test-end "debug-link")
ss='msg-tooltip'>* gnu/packages/text-editors.scm (mg)[inputs]: Add diffutils. [arguments]: Refer to it in the 'correct-location-of-diff phase. Tobias Geerinckx-Rice 2021-07-18Merge branch 'master' into core-updatesLudovic Courtès 2021-07-14gnu: mg: Enable cross-compilation....* gnu/packages/text-editors.scm (mg)[arguments]: Use cc-for-target. Add phase to substitute pkg-config with the target's pkg-config. Remote #t return from phases. Pierre Langlois 2021-07-11gnu: Add parinfer-rust....* gnu/packages/text-editors.scm (parinfer-rust): New variable. Signed-off-by: Efraim Flashner <efraim@flashner.co.il> aecepoglu 2021-07-02gnu: scintilla: Update to 5.1.0....* gnu/packages/text-editors.scm (scintilla): Update to 5.1.0. Nicolas Goaziou 2021-06-30gnu: ghostwriter: Update to 2.0.2....* gnu/packages/text-editors.scm (ghostwriter): Update to 2.0.2. Tobias Geerinckx-Rice 2021-06-29gnu: editorconfig-core-c: Update to 0.12.5....* gnu/packages/text-editors.scm (editorconfig-core-c): Update to 0.12.5. Tobias Geerinckx-Rice 2021-06-23Merge branch 'master' into core-updates...Conflicts: gnu/packages/cups.scm gnu/packages/python-web.scm gnu/packages/web.scm guix/build/maven/pom.scm Tobias Geerinckx-Rice 2021-06-23gnu: texmacs: Update to 2.1....* gnu/packages/text-editors.scm (texmacs): Update to 2.1. [arguments]: Remove #t at the end of phases. Nicolas Goaziou 2021-06-19Merge branch 'master' into core-updates...Note: this merge actually changes the 'curl' and 'python-attrs' derivations, as part of solving caf4a7a2770ef4d05a6e18f40d602e51da749ddc and 12964df69a99de6190422c752fef65ef813f3b6b respectively. 4604d43c0e (gnu: gnutls@3.6.16: Fix cross-compilation.) was ignored because it cannot currently be tested. Conflicts: gnu/local.mk gnu/packages/aidc.scm gnu/packages/boost.scm gnu/packages/curl.scm gnu/packages/nettle.scm gnu/packages/networking.scm gnu/packages/python-xyz.scm gnu/packages/tls.scm Marius Bakke 2021-06-14gnu: Rename qtbase to qtbase-5....This change was automated via the following command: $ git ls-files | xargs sed -i 's/,qtbase)/,qtbase-5)/g' $ git ls-files | xargs sed -i 's/inherit qtbase)/inherit qtbase-5)/g' $ git ls-files | xargs sed -i 's/package-version qtbase)/package-version qtbase-5)/g' $ git checkout etc # to clear some spurious changes This is done so the qtbase package can be upgraded to version 6 in the following commit. Maxim Cournoyer 2021-06-07gnu: Add l3afpad....* gnu/packages/text-editors.scm (l3afpad): New variable. Leo Famulari 2021-06-07gnu: ghostwriter: Update to 2.0.1....* gnu/packages/text-editors.scm (ghostwriter): Update to 2.0.1. Leo Famulari 2021-06-06Merge branch 'master' into core-updates... Conflicts: gnu/local.mk gnu/packages/algebra.scm gnu/packages/bioinformatics.scm gnu/packages/curl.scm gnu/packages/docbook.scm gnu/packages/emacs-xyz.scm gnu/packages/maths.scm gnu/packages/plotutils.scm gnu/packages/python-web.scm gnu/packages/python-xyz.scm gnu/packages/radio.scm gnu/packages/readline.scm gnu/packages/tls.scm gnu/packages/xml.scm gnu/packages/xorg.scm Marius Bakke 2021-06-04gnu: qemacs: Use 'native-inputs' instead of '%build-inputs'....In build phases, the former (or 'inputs', as appropriate) is preferred. * gnu/packages/text-editors.scm (qemacs)[arguments]<#:phases>{install-extra-documentation}: Use 'native-inputs' argument instead of '%build-inputs'. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> Maxime Devos 2021-05-31gnu: texmacs: Update to 1.99.21....* gnu/packages/text-editors.scm (texmacs): Update to 1.99.21. Nicolas Goaziou 2021-05-09Merge branch 'master' into core-updates... Conflicts: gnu/local.mk gnu/packages/bioinformatics.scm gnu/packages/django.scm gnu/packages/gtk.scm gnu/packages/llvm.scm gnu/packages/python-web.scm gnu/packages/python.scm gnu/packages/tex.scm guix/build-system/asdf.scm guix/build/emacs-build-system.scm guix/profiles.scm Marius Bakke 2021-05-07gnu: texmacs: Update to 1.99.20....* gnu/packages/text-editors.scm (texmacs): Update to 1.99.20. Nicolas Goaziou 2021-05-07gnu: manuskript: Update to 0.12.0....* gnu/packages/text-editors.scm (manuskript): Update to 0.12.0. Nicolas Goaziou 2021-04-20gnu: jucipp: Update clang version....* gnu/packages/text-editors.scm (jucipp)[inputs]: Use clang-11. Tobias Geerinckx-Rice 2021-04-20gnu: jucipp: Fix description mark-up....* gnu/packages/text-editors.scm (jucipp)[description]: Substitute @acronym for @dfn. Tobias Geerinckx-Rice 2021-04-20gnu: jucipp: Update to 1.6.3....* gnu/packages/text-editors.scm (jucipp): Update to 1.6.3. Tobias Geerinckx-Rice 2021-04-16Merge remote-tracking branch 'origin/master' into core-updates... Conflicts: gnu/local.mk gnu/packages/boost.scm gnu/packages/chez.scm gnu/packages/compression.scm gnu/packages/crates-io.scm gnu/packages/docbook.scm gnu/packages/engineering.scm gnu/packages/gcc.scm gnu/packages/gl.scm gnu/packages/gtk.scm gnu/packages/nettle.scm gnu/packages/python-check.scm gnu/packages/python-xyz.scm gnu/packages/radio.scm gnu/packages/rust.scm gnu/packages/sqlite.scm guix/build-system/node.scm Efraim Flashner 2021-04-11gnu: scintilla: Update to 5.0.1....* gnu/packages/text-editors.scm (scintilla): Update to 5.0.1. Nicolas Goaziou 2021-04-01gnu: fe: Fix hash....* gnu/packages/text-editors.scm (fe): Update hash. Development version (2.0) has been rebased on top of latest stable release (1.9). Nicolas Goaziou 2021-03-24Merge remote-tracking branch 'origin/master' into core-updatesEfraim Flashner 2021-03-19gnu: vis: Update to 0.7....* gnu/packages/text-editors.scm (vis): Update to 0.7. [home-page, source]: Use sourcehut upstream URIs instead of github. Signed-off-by: Ludovic Courtès <ludo@gnu.org> jgart 2021-03-06gnu: ne: Use HTTPS home page URI....* gnu/packages/text-editors.scm (ne)[home-page]: Use HTTPS URI. Nicolas Goaziou 2021-03-06gnu: texmacs: Update to 1.99.19....* gnu/packages/text-editors.scm (texmacs): Update to 1.99.19. Nicolas Goaziou 2021-03-06Merge branch 'master' into core-updatesChristopher Baines