diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index abfff8009afe..353535ed6823 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -416,6 +416,11 @@ in with passthru; stdenv.mkDerivation { # This allows build Python to import host Python's sysconfigdata mkdir -p "$out/${sitePackages}" ln -s "$out/lib/${libPrefix}/"_sysconfigdata*.py "$out/${sitePackages}/" + + # debug info can't be separated from a static library and would otherwise be + # left in place by a separateDebugInfo build. force its removal here to save + # space in output. + $STRIP -S $out/lib/${libPrefix}/config-*/libpython*.a || true '' + optionalString stripConfig '' rm -R $out/bin/python*-config $out/lib/python*/config-* '' + optionalString stripIdlelib '' @@ -445,6 +450,13 @@ in with passthru; stdenv.mkDerivation { find $out -name "*.py" | ${pythonForBuildInterpreter} -m compileall -q -f -x "lib2to3" -i - find $out -name "*.py" | ${pythonForBuildInterpreter} -O -m compileall -q -f -x "lib2to3" -i - find $out -name "*.py" | ${pythonForBuildInterpreter} -OO -m compileall -q -f -x "lib2to3" -i - + '' + '' + # *strip* shebang from libpython gdb script - it should be dual-syntax and + # interpretable by whatever python the gdb in question is using, which may + # not even match the major version of this python. doing this after the + # bytecode compilations for the same reason - we don't want bytecode generated. + mkdir -p $out/share/gdb + sed '/^#!/d' Tools/gdb/libpython.py > $out/share/gdb/libpython.py ''; preFixup = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' @@ -470,6 +482,8 @@ in with passthru; stdenv.mkDerivation { pythonForBuild buildPackages.bash ]; + separateDebugInfo = true; + inherit passthru; enableParallelBuilding = true; diff --git a/pkgs/development/interpreters/python/tests.nix b/pkgs/development/interpreters/python/tests.nix index 872123338f8c..764ab29e919b 100644 --- a/pkgs/development/interpreters/python/tests.nix +++ b/pkgs/development/interpreters/python/tests.nix @@ -94,12 +94,18 @@ let # Integration tests involving the package set. # All PyPy package builds are broken at the moment - integrationTests = lib.optionalAttrs (python.pythonAtLeast "3.7" && (!python.isPyPy)) rec { - # Before the addition of NIX_PYTHONPREFIX mypy was broken with typed packages - nix-pythonprefix-mypy = callPackage ./tests/test_nix_pythonprefix { - interpreter = python; - }; - }; + integrationTests = lib.optionalAttrs (!python.isPyPy) ( + lib.optionalAttrs (python.isPy3k && !stdenv.isDarwin) { # darwin has no split-debug + cpython-gdb = callPackage ./tests/test_cpython_gdb { + interpreter = python; + }; + } // lib.optionalAttrs (python.pythonAtLeast "3.7") rec { + # Before the addition of NIX_PYTHONPREFIX mypy was broken with typed packages + nix-pythonprefix-mypy = callPackage ./tests/test_nix_pythonprefix { + interpreter = python; + }; + } + ); # Tests to ensure overriding works as expected. overrideTests = let diff --git a/pkgs/development/interpreters/python/tests/test_cpython_gdb/default.nix b/pkgs/development/interpreters/python/tests/test_cpython_gdb/default.nix new file mode 100644 index 000000000000..0254d843a4cf --- /dev/null +++ b/pkgs/development/interpreters/python/tests/test_cpython_gdb/default.nix @@ -0,0 +1,22 @@ +{ interpreter, lib, gdb, writeText, runCommand }: + +let + crashme-py = writeText "crashme.py" '' + import ctypes + + def sentinel_foo_bar(): + ctypes.memset(0, 1, 1) + + sentinel_foo_bar() + ''; +in runCommand "python-gdb" {} '' + # test that gdb is able to recover the python stack frame of this segfault + ${gdb}/bin/gdb -batch -ex 'set debug-file-directory ${interpreter.debug}/lib/debug' \ + -ex 'source ${interpreter}/share/gdb/libpython.py' \ + -ex r \ + -ex py-bt \ + --args ${interpreter}/bin/python ${crashme-py} | grep 'in sentinel_foo_bar' > /dev/null + + # success. + touch $out +''