From 55026e07834c0d12396045b59878fc56a3a3ab49 Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Sun, 12 Jul 2020 14:40:09 +0100 Subject: [PATCH 1/3] cpython: set separateDebugInfo, explicitly stripping static libpython*.a 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. --- pkgs/development/interpreters/python/cpython/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 76a66a648d84..99d0ae24b7b8 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -411,6 +411,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 '' @@ -465,6 +470,8 @@ in with passthru; stdenv.mkDerivation { pythonForBuild buildPackages.bash ]; + separateDebugInfo = true; + inherit passthru; enableParallelBuilding = true; From 049444dc6b48fcebddbb90d7ab01c5a6fba85902 Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Tue, 26 Jan 2021 20:39:00 +0000 Subject: [PATCH 2/3] cpython: expose libpython.py for debugging from gdb --- pkgs/development/interpreters/python/cpython/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 99d0ae24b7b8..3d4cee22b2c2 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -445,6 +445,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) '' From f8831c10debea095db177c6d65c1b0e50434227e Mon Sep 17 00:00:00 2001 From: Robert Scott Date: Tue, 26 Jan 2021 20:41:39 +0000 Subject: [PATCH 3/3] python3.tests: add cpython-gdb test --- .../development/interpreters/python/tests.nix | 18 ++++++++++----- .../python/tests/test_cpython_gdb/default.nix | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 pkgs/development/interpreters/python/tests/test_cpython_gdb/default.nix 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 +''