New submission from Volker Weißmann <volker.weissm...@gmx.de>:

Note: I'm not sure if this is a bug in python or in gdb. I will also submit a 
bug report to gdb and post a link here.

Pythons documentation says that sys.executable is always either None, empty 
string or a path to the python interpreter. Using gdb and python, we can 
produce situations where this is not true.

Simple but unrealistic way to reproduce this bug:
Install gdb with python support. E.g using
$ pacman -S gdb
Remove all the python binaries:
$ rm /usr/bin/python
$ rm /usr/bin/python3
$ rm /usr/bin/python3.8
Run $gdb -x gdbinit$ with the contents of gdbinit being:
python
import sys
import os
print(sys.executable)
print(os.path.exists(sys.executable))
end

Result:
/usr/bin/python
False

Here, sys.executable is /usr/bin/python, but there is no python executable in 
/usr/bin/python, because we just deleted it.

Complicated but realistic way to reproduce this bug:
Build gdb with
../configure --with-python=python2
and run gdb with the gdbinit being:
python
import sys
print(sys.executable)
print(sys.version)
end
Result:
/usr/bin/python
2.7.17 (default, Mar 21 2020, 00:47:07) 
[GCC 9.3.0]
Here it says that the python2 executable lies in "/usr/bin/python", even if 
there is no python2 executable in /usr/bin/python.

----------
messages: 365934
nosy: Volker Weißmann
priority: normal
severity: normal
status: open
title: sys.executable is a non existing path if python is executed from gdb

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40218>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to