NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.38k stars 14.33k forks source link

gcc-arm-embedded-13: Python in gdb is broken, `import subprocess` fails #303651

Open lukash opened 7 months ago

lukash commented 7 months ago

Describe the bug

Importing Python's subprocess module in a gdb python script fails with an import error.

Note this is before python38 removal, now arm-none-eabi-gdb is broken altogether as reported in https://github.com/NixOS/nixpkgs/issues/299754.

Steps To Reproduce

$ arm-none-eabi-gdb
(gdb) python import subprocess; end
Traceback (most recent call last):
  File "/nix/store/zlsiqrqm823yp9r9zsbg6q9yrr129kfi-python3-3.8.18/lib/python3.8/subprocess.py", line 64, in <module>
    import msvcrt
ModuleNotFoundError: No module named 'msvcrt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/nix/store/zlsiqrqm823yp9r9zsbg6q9yrr129kfi-python3-3.8.18/lib/python3.8/subprocess.py", line 69, in <module>
    import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
Error while executing Python code.

Expected behavior

Importing the subprocess module works without error.

Notify maintainers

@mweinelt @prusnak

Metadata

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.69, NixOS, 23.11 (Tapir), 23.11.20240103.b0b2c54`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

mweinelt commented 7 months ago

@prusnak was telling me to go ahead and drop python38, and so I did. The ball is in his court.

Freed-Wu commented 7 months ago

In my situation, it is:

$ arm-none-eabi-gdb
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/nix/store/p4g8jhmqsx6wqzy70n8mxr965hndj4fs-python3-3.9.19/lib/python3.9/site.py", line 73, in <module>
    import os
  File "/nix/store/p4g8jhmqsx6wqzy70n8mxr965hndj4fs-python3-3.9.19/lib/python3.9/os.py", line 29, in <module>
    from _collections_abc import _check_methods
  File "/nix/store/p4g8jhmqsx6wqzy70n8mxr965hndj4fs-python3-3.9.19/lib/python3.9/_collections_abc.py", line 12, in <module>
    GenericAlias = type(list[int])
TypeError: 'type' object is not subscriptable
Mickael-Roger commented 4 months ago

I add the same issue.

If you bump the package version to '13.3.rel1', it works for arm-none-eabi-gdb but not for arm-none-eabi-gdb-py. Because arm-none-eabi-gdb-py still relies on python3.8. If you do not use gdb python like with the gef extension, gdb will work.

The other alternative is to use the gdb package that seems to be built for multiarch by default

maks commented 2 months ago

The other alternative is to use the gdb package that seems to be built for multiarch by default

Unfortunately that doesn't work as if I try to have both the gcc-arm-embedded-13 & gdb in home-manager packages I get:

ome-manager switch --flake nix/#$USER
warning: Git tree '/home/maks/nix' is dirty
error: builder for '/nix/store/pvcj3kfai9xxblj5gw7xih5ga7ckn260-home-manager-path.drv' failed with exit code 255;
       last 1 log lines:
       > error: collision between `/nix/store/wyqn0j2ly4w4mvpyfmkjnp48d9ax70f7-gdb-15.1/include/gdb/jit-reader.h' and `/nix/store/wzc93rl44c9vd55zmpgks1wyfzjr9p9k-gcc-arm-embedded-13.2.rel1/include/gdb/jit-reader.h'
       For full logs, run 'nix-store -l /nix/store/pvcj3kfai9xxblj5gw7xih5ga7ckn260-home-manager-path.drv'.
error: 1 dependencies of derivation '/nix/store/2n85g8rslnagya98sa6dsfd3ljm2dibc-home-manager-generation.drv' failed to build

With the suggestion about bumping the package version to 13.3.re1 how would I do that? (sorry I'm very new to Nix) note per above I pasted, I got 13.2.rel1 when I used gcc-arm-embedded-13 package.

prusnak commented 2 months ago

package version to 13.3.re1 how would I do that

I updated the version to 13.3.rel1 in https://github.com/NixOS/nixpkgs/pull/339744 but still the same issue persists (the binaries built by arm are still tied to python3.8 which we do not have in nixpkgs anymore).

haykodarb commented 2 months ago

Immediate solution for me was just to have gdb installed as a package and for building the project run nix-shell -p gcc-arm-embedded in a different terminal to the one used for GDB and then run make to compile the project.

PowerUser64 commented 1 month ago

A comment on another issue (https://github.com/NixOS/nixpkgs/issues/299754#issuecomment-2025419464) suggests this workaround:

As a workaround, you can use pkgsCross.arm-embedded.buildPackages.gdb instead of gcc-arm-embedded

mfiumara commented 1 month ago

Hi,

I have the same problem. For me this issue is resolved by just using gcc-arm-embedded-10: This does not have any python dependencies.

IMO the solution should be to remove the python dependency altogether from gcc-arm-embedded if it is not required.

prusnak commented 1 month ago

IMO the solution should be to remove the python dependency altogether from gcc-arm-embedded if it is not required.

It is required for arm-none-eabi-gdb-py

mfiumara commented 1 month ago

IMO the solution should be to remove the python dependency altogether from gcc-arm-embedded if it is not required.

It is required for arm-none-eabi-gdb-py

But not for arm-none-eabi-gdb. Currently the package is broken for users who do not need python support.

I am new to nix, but is there an option to build the package either with or without python support?

prusnak commented 1 month ago

Got it. I removed the Python scripting for GDB in https://github.com/NixOS/nixpkgs/pull/352408

@mfiumara Can you please try whether GDB works for you using the package from the PR?

mfiumara commented 1 month ago

Got it. I removed the Python scripting for GDB in #352408

@mfiumara Can you please try whether GDB works for you using the package from the PR?

How can I test this?

lukash commented 1 month ago

But what if one needs python support? (I do)

mfiumara commented 1 month ago

But what if one needs python support? (I do)

It makes sense if the package would build the same version as what arm-none-eabi-gdb-py is built for. So it seems python3.8.

prusnak commented 1 month ago

But what if one needs python support? (I do)

Then you are free to go and fix it (currently it does not work at all either).