Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: gnu: Fix debugging when GDB fails to load because of Python #38749

Merged
merged 1 commit into from Sep 23, 2021

Conversation

carlescufi
Copy link
Member

@carlescufi carlescufi commented Sep 22, 2021

GDB can be built with or without Python support. When built with Python
support this can cause a particular problem: The gdb executable relies
on shared libraries that are bound to a specific Python version. But
since most Linux distributions typically ship with a single version, it
is very difficult to choose which one to target when building GDB.
When GDB executes, if it fails to load the shared libraries it will exit
immediately with an error code of 127 and output resembling this:

/home/carles/bin/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb:
error while loading shared libraries: libpython3.8.so.1.0: cannot open
shared object file: No such file or directory

There are two known approaches to shipping multiple gdb executables:

  • The Zephyr SDK ships a default gdb with Python enabled, and then a
    separate gdb-no-py executable with Python disabled
  • GNU Arm Embedded ships with a default gdb with Python disabled, and an
    additional gdb-py with Python enabled

To mitigate the problem of not being able to debug, fall back to a
'gdb-no-py' if it exists whenever the standard gdb executable fails to
even run.

Signed-off-by: Carles Cufi carles.cufi@nordicsemi.no

@carlescufi
Copy link
Member Author

CC @sylvainpelissier

@carlescufi
Copy link
Member Author

Note: I plan to extend this with support with both -py and -no-py in west itself as well, but post-2.7.0.

@carlescufi carlescufi added this to the v2.7.0 milestone Sep 22, 2021
@stephanosio stephanosio added area: Debugging area: DX Developer and User Experience labels Sep 22, 2021
Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable and will be very useful for the users who do not have the "correct" version of Python installed.

In the future, this issue can be further mitigated by allowing users to select which gdb to use through the west as @carlescufi noted. Also, we can look into making the default gdb provided by the Zephyr SDK Python-less as the GNU Arm Embedded toolchain does, since most users do not require the Python scripting capability.

cmake/bintools/gnu/target.cmake Outdated Show resolved Hide resolved
GDB can be built with or without Python support. When built with Python
support this can cause a particular problem: The gdb executable relies
on shared libraries that are bound to a specific Python version. But
since most Linux distributions typically ship with a single version, it
is very difficult to choose which one to target when building GDB.
When GDB executes, if it fails to load the shared libraries it will exit
immediately with an error code of 127 and output resembling this:

/home/carles/bin/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb:
error while loading shared libraries: libpython3.8.so.1.0: cannot open
shared object file: No such file or directory

There are two known approaches to shipping multiple gdb executables:

- The Zephyr SDK ships a default gdb with Python enabled, and then a
  separate gdb-no-py executable with Python disabled
- GNU Arm Embedded ships with a default gdb with Python disabled, and an
  additional gdb-py with Python enabled

To mitigate the problem of not being able to debug, fall back to a
'gdb-no-py' if it exists whenever the standard gdb executable fails to
even run.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
@carlescufi carlescufi merged commit 76c4591 into zephyrproject-rtos:main Sep 23, 2021
stephanosio added a commit to stephanosio/zephyr that referenced this pull request Jan 8, 2022
The GDB check routine added in the PR zephyrproject-rtos#38749 does not suppress the
console outputs (stdout and stderr) and may print out a misleading
error message during a CMake configuration when the required version
of Python is not available on the system:

  arm-zephyr-eabi-gdb: error while loading shared libraries:
  libpython3.8.so.1.0: cannot open shared object file: No such file or
  directory

This commit adds the `OUTPUT_QUIET` and `ERROR_QUIET` options when
executing the GDB process so that the console outputs during the GDB
executable validation are not displayed to the user.

In addition, this commit removes the unused `GDB_PY_NO_PY` standard
output redirection variable since it is unnecessary.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
MaureenHelm pushed a commit that referenced this pull request Jan 10, 2022
The GDB check routine added in the PR #38749 does not suppress the
console outputs (stdout and stderr) and may print out a misleading
error message during a CMake configuration when the required version
of Python is not available on the system:

  arm-zephyr-eabi-gdb: error while loading shared libraries:
  libpython3.8.so.1.0: cannot open shared object file: No such file or
  directory

This commit adds the `OUTPUT_QUIET` and `ERROR_QUIET` options when
executing the GDB process so that the console outputs during the GDB
executable validation are not displayed to the user.

In addition, this commit removes the unused `GDB_PY_NO_PY` standard
output redirection variable since it is unnecessary.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants