2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv, targetPackages
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Build time
|
2022-06-16 17:23:12 +00:00
|
|
|
, fetchurl, pkg-config, perl, texinfo, setupDebugInfoDirs, buildPackages
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Run time
|
2021-09-18 10:52:07 +00:00
|
|
|
, ncurses, readline, gmp, mpfr, expat, libipt, zlib, dejagnu, sourceHighlight
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
, pythonSupport ? stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.hostPlatform.isCygwin, python3 ? null
|
2021-12-06 16:07:01 +00:00
|
|
|
, enableDebuginfod ? false, elfutils
|
2020-04-24 23:36:52 +00:00
|
|
|
, guile ? null
|
|
|
|
, safePaths ? [
|
|
|
|
# $debugdir:$datadir/auto-load are whitelisted by default by GDB
|
|
|
|
"$debugdir" "$datadir/auto-load"
|
|
|
|
# targetPackages so we get the right libc when cross-compiling and using buildPackages.gdb
|
|
|
|
targetPackages.stdenv.cc.cc.lib
|
|
|
|
]
|
2022-06-16 17:23:12 +00:00
|
|
|
, writeScript
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2020-09-25 04:45:31 +00:00
|
|
|
basename = "gdb";
|
2021-02-05 17:12:51 +00:00
|
|
|
targetPrefix = lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
|
2020-09-25 04:45:31 +00:00
|
|
|
"${stdenv.targetPlatform.config}-";
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
assert pythonSupport -> python3 != null;
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
2020-09-25 04:45:31 +00:00
|
|
|
pname = targetPrefix + basename;
|
2022-06-16 17:23:12 +00:00
|
|
|
version = "12.1";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2020-09-25 04:45:31 +00:00
|
|
|
url = "mirror://gnu/gdb/${basename}-${version}.tar.xz";
|
2022-06-16 17:23:12 +00:00
|
|
|
hash = "sha256-DheTv48rVNU/Rt6oTM/URvSPgbKXsoxPf8AXuBjWn+0=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
postPatch = lib.optionalString stdenv.isDarwin ''
|
2020-04-24 23:36:52 +00:00
|
|
|
substituteInPlace gdb/darwin-nat.c \
|
|
|
|
--replace '#include "bfd/mach-o.h"' '#include "mach-o.h"'
|
2022-06-16 17:23:12 +00:00
|
|
|
'' + lib.optionalString stdenv.hostPlatform.isMusl ''
|
|
|
|
substituteInPlace sim/erc32/erc32.c --replace sys/fcntl.h fcntl.h
|
|
|
|
substituteInPlace sim/erc32/interf.c --replace sys/fcntl.h fcntl.h
|
|
|
|
substituteInPlace sim/erc32/sis.c --replace sys/fcntl.h fcntl.h
|
2022-03-30 09:31:56 +00:00
|
|
|
substituteInPlace sim/ppc/emul_unix.c --replace sys/termios.h termios.h
|
2022-06-16 17:23:12 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
patches = [
|
|
|
|
./debug-info-from-env.patch
|
2021-02-05 17:12:51 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
2020-04-24 23:36:52 +00:00
|
|
|
./darwin-target-match.patch
|
2022-06-16 17:23:12 +00:00
|
|
|
# Does not nave to be conditional. We apply it conditionally
|
|
|
|
# to speed up inclusion to nearby nixos release.
|
|
|
|
] ++ lib.optionals stdenv.is32bit [
|
|
|
|
./32-bit-BFD_VMA-format.patch
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
nativeBuildInputs = [ pkg-config texinfo perl setupDebugInfoDirs ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-09-18 10:52:07 +00:00
|
|
|
buildInputs = [ ncurses readline gmp mpfr expat libipt zlib guile sourceHighlight ]
|
2021-02-05 17:12:51 +00:00
|
|
|
++ lib.optional pythonSupport python3
|
2021-12-06 16:07:01 +00:00
|
|
|
++ lib.optional doCheck dejagnu
|
|
|
|
++ lib.optional enableDebuginfod (elfutils.override { enableDebuginfod = true; });
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
propagatedNativeBuildInputs = [ setupDebugInfoDirs ];
|
|
|
|
|
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
# darwin build fails with format hardening since v7.12
|
2021-02-05 17:12:51 +00:00
|
|
|
hardeningDisable = lib.optionals stdenv.isDarwin [ "format" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
NIX_CFLAGS_COMPILE = "-Wno-format-nonliteral";
|
|
|
|
|
2021-05-20 23:08:51 +00:00
|
|
|
configurePlatforms = [ "build" "host" "target" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# GDB have to be built out of tree.
|
|
|
|
preConfigure = ''
|
|
|
|
mkdir _build
|
|
|
|
cd _build
|
|
|
|
'';
|
|
|
|
configureScript = "../configure";
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
configureFlags = with lib; [
|
2021-05-20 23:08:51 +00:00
|
|
|
# Set the program prefix to the current targetPrefix.
|
|
|
|
# This ensures that the prefix always conforms to
|
|
|
|
# nixpkgs' expectations instead of relying on the build
|
|
|
|
# system which only receives `config` which is merely a
|
|
|
|
# subset of the platform description.
|
|
|
|
"--program-prefix=${targetPrefix}"
|
|
|
|
|
2022-11-02 22:02:43 +00:00
|
|
|
"--disable-werror"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-targets=all" "--enable-64-bit-bfd"
|
|
|
|
"--disable-install-libbfd"
|
|
|
|
"--disable-shared" "--enable-static"
|
|
|
|
"--with-system-zlib"
|
|
|
|
"--with-system-readline"
|
|
|
|
|
|
|
|
"--with-gmp=${gmp.dev}"
|
|
|
|
"--with-mpfr=${mpfr.dev}"
|
|
|
|
"--with-expat" "--with-libexpat-prefix=${expat.dev}"
|
|
|
|
"--with-auto-load-safe-path=${builtins.concatStringsSep ":" safePaths}"
|
2021-02-24 18:30:23 +00:00
|
|
|
] ++ lib.optional (!pythonSupport) "--without-python"
|
2021-12-06 16:07:01 +00:00
|
|
|
++ lib.optional stdenv.hostPlatform.isMusl "--disable-nls"
|
2022-08-12 12:06:08 +00:00
|
|
|
++ lib.optional stdenv.hostPlatform.isStatic "--disable-inprocess-agent"
|
2021-12-06 16:07:01 +00:00
|
|
|
++ lib.optional enableDebuginfod "--with-debuginfod=yes";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postInstall =
|
|
|
|
'' # Remove Info files already provided by Binutils and other packages.
|
|
|
|
rm -v $out/share/info/bfd.info
|
|
|
|
'';
|
|
|
|
|
|
|
|
# TODO: Investigate & fix the test failures.
|
|
|
|
doCheck = false;
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
passthru = {
|
|
|
|
updateScript = writeScript "update-gdb" ''
|
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i bash -p curl pcre common-updater-scripts
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
# Expect the text in format of '<h3>GDB version 12.1</h3>'
|
|
|
|
new_version="$(curl -s https://www.sourceware.org/gdb/ |
|
|
|
|
pcregrep -o1 '<h3>GDB version ([0-9.]+)</h3>')"
|
|
|
|
update-source-version ${pname} "$new_version"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "The GNU Project debugger";
|
|
|
|
|
|
|
|
longDescription = ''
|
|
|
|
GDB, the GNU Project debugger, allows you to see what is going
|
|
|
|
on `inside' another program while it executes -- or what another
|
|
|
|
program was doing at the moment it crashed.
|
|
|
|
'';
|
|
|
|
|
|
|
|
homepage = "https://www.gnu.org/software/gdb/";
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
license = lib.licenses.gpl3Plus;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
platforms = with platforms; linux ++ cygwin ++ darwin;
|
|
|
|
maintainers = with maintainers; [ pierron globin lsix ];
|
|
|
|
};
|
|
|
|
}
|