我正试图在NixOS上进行cython调试。我可以很容易地在nix中安装cython (为示例的简单性而选择),如下所示:
$ nix-shell -p 'python27.withPackages( p: [ p.cython ])'
$ cat /nix/store/s0w3phb2saixi0a9bzk8pjbczjaz8d7r-python-2.7.14-env/bin/python
#! /nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12/bin/bash -e
export PYTHONHOME="/nix/store/s0w3phb2saixi0a9bzk8pjbczjaz8d7r-python-2.7.14-env"
export PYTHONNOUSERSITE="true"
exec "/nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python" "${extraFlagsArray[@]}" "$@"然后我们对python做一个普通的nix,看看我们得到了哪个版本的python。
[henry@bollum:~/Projects/eyeserver/nixshell]$ nix-shell -p 'python27'
$ which python
/nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python
# ^^^^^^^
# non-debug一切都很好--在这两种情况下,我们都得到了一个非调试的python。如果我们使用gdb,我们会得到(没有找到调试符号)。看最后一行。
$ gdb
/nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python...(no debugging symbols found)...done.当我们在python上单独使用enableDebugging时,我们得到了不同的结果。$ nix-shell -p 'enableDebugging python27‘
$ which python
/nix/store/a4wd8mcpqr54hmw0x95fw8fhvk8avh5a-python-2.7.14/bin/python
# ^^^^^^
# debug
$ gdb
/nix/store/a4wd8mcpqr54hmw0x95fw8fhvk8avh5a-python-2.7.14/bin/python
GNU gdb (GDB) 8.0.1
...
Reading symbols from /nix/store/a4wd8mcpqr54hmw0x95fw8fhvk8avh5a-python-2.7.14/bin/python...done.当我们尝试使用包括cython (或任何其他包)时,就会出现问题。
$ nix-shell -p '(enableDebugging python27).withPackages( p: [ p.cython ])'$ cat `which python`
#! /nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12/bin/bash -e
export PYTHONHOME="/nix/store/s0w3phb2saixi0a9bzk8pjbczjaz8d7r-python-2.7.14-env"
export PYTHONNOUSERSITE="true"
exec "/nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python" "${extraFlagsArray[@]}" "$@"
# ^^^^^^^
# non-debug
$ gdb /nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python
GNU gdb (GDB) 8.0.1
...
Reading symbols from /nix/store/i3bx1iw2d0i3vh9sa1nf92ynlrw324w8-python-2.7.14/bin/python...(no debugging symbols found)...done.
(gdb)
quit环境中的python版本现在是不调试的,试图调试它会让人感到恐惧(没有找到调试符号)。这使得gdb对于调试cython程序的用处要小得多。
发布于 2018-07-19 18:17:07
解决方案
with import <nixpkgs> {};
let
self = enableDebugging python;
in [ gdb ((python.override{inherit self;}).withPackages(ps: with ps; [ cython ])) ]包装器中引用的可执行文件现在具有调试符号。
背景
如果我们查看pkgs/all-packages.nix,就会看到enableDebugging函数的实现:
enableDebugging = pkg: pkg.override { stdenv = stdenvAdapters.keepDebugInfo pkg.stdenv; };它重写一个派生来使用不同的stdenv。在您的示例中,您希望重写Python解释器,它是python.withPackages获得的派生的依赖项。
您对enableDebugging python的尝试是正确的,但是,python.withPackages使用了对python的引用,该引用也需要更新。
发布于 2018-10-22 07:21:27
@fridh答案需要额外的少量代码才能使其可用。
基本上,您需要一个包含以下内容的shell.nix:
with import <nixpkgs> {};
let
python = enableDebugging pkgs.python;
in
stdenv.mkDerivation {
name = "test";
buildInputs = [ python ];
}然后,当您输入nix-shell时,您可以运行gdb -p <pid of python process>。
请注意,这只会调试Python解释器本身。这不启用gdb的python扩展,允许您调试应用程序级别的python代码。
enableDebugging也不会传播到依赖项。如果要启用这些调试符号,每个依赖项都需要自己的enableDebugging。是否应该有一个函数来递归地启用调试?
https://stackoverflow.com/questions/51333232
复制相似问题