cs01 / gdbgui

Browser-based frontend to gdb (gnu debugger). Add breakpoints, view the stack, visualize data structures, and more in C, C++, Go, Rust, and Fortran. Run gdbgui from the terminal and a new tab will open in your browser.
https://gdbgui.com
GNU General Public License v3.0
9.86k stars 498 forks source link

Can't build from source on Mac #321

Open jamesyc opened 4 years ago

jamesyc commented 4 years ago

MacOS Catalina 10.15.4

$ python3 --version 
Python 3.7.7

and

$ pip3 list --format freeze
appdirs==1.4.3
argcomplete==1.11.1
colorlog==4.1.0
distlib==0.3.0
filelock==3.0.12
importlib-metadata==1.6.0
nox==2019.11.9
pip==20.0.2
py==1.8.1
setuptools==46.1.3
six==1.14.0
virtualenv==20.0.18
wheel==0.34.2
zipp==3.1.0

I'm currently following the instructions under https://www.gdbgui.com/contributing/ with the latest version cloned from github.

At the step:

$ source .nox/develop-3.7/bin/activate
source: no such file or directory: .nox/develop-3.7/bin/activate

The folder doesn't exist. Mild annoyance with a typo in the docs, it works with running:

$ source .nox/develop-3-7/bin/activate
(develop-3-7) $

For the next part, the docs says to do a yarn install. After that, i then try to load the backend:

(develop-3-7) $ python3 -m gdbgui --debug
[...]
failed to initialize socketio app with async mode "eventlet". Continuing with async mode "threading".
View gdbgui at http://127.0.0.1:5000
exit gdbgui by pressing CTRL+C
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
WARNING - You may need to set startup-with-shell off when running on a mac. i.e.
  gdbgui --gdb-args='--init-eval-command="set startup-with-shell off"'
see http://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra
and https://sourceware.org/gdb/onlinedocs/gdb/Starting.html
failed to initialize socketio app with async mode "eventlet". Continuing with async mode "threading".
View gdbgui at http://127.0.0.1:5000
exit gdbgui by pressing CTRL+C
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Debugger is active!
 * Debugger PIN: 190-794-937

It looks like eventlet and gevent-websocket are missing. Interestingly, gevent is already installed in pip, though. I'm not sure why the virtualenv doesn't install the other two, but some configuration should probably be changed to add these.

After installing those 2 in pip, now going to http://127.0.0.1:5000 works.

The next thing I tried was building from source. Running nox -s build_executable_current_os seems to succeed. From what I can tell, make_executable.py outputs the pyinstaller spec to gdbgui.spec, and runs write_spec_with_gdbgui_version_in_name which outputs the binary to executable/mac/.

So I tried to run this file:

(develop-3-7) $ executable/mac/gdbgui_0.13.2.0
Fatal Python error: initfsencoding: unable to load the file system codec
zipimport.ZipImportError: can't find module 'encodings'

Current thread 0x000000010622adc0 (most recent call first):
[1]    86798 abort      executable/mac/gdbgui_0.13.2.0

This error isn't very helpful. I tried manually running pyinstaller instead:

(develop-3-7) $ pyinstaller gdbgui.spec
[...]
23222 INFO: Building EXE from EXE-00.toc completed successfully.

The binary technically does get built, and is dropped into dist/ but it seems like there are issues. Running the binary results in this error:

(develop-3-7) $ dist/gdbgui_0.13.2.0
Traceback (most recent call last):
  File "PyInstaller/loader/rthooks/pyi_rth_pkgres.py", line 13, in <module>
  File "/Users/jamesyc/git/gdbgui/gdbgui/.nox/develop-3-7/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "pkg_resources/__init__.py", line 86, in <module>
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
[87058] Failed to execute script pyi_rth_pkgres

Some googling shows a workaround is to add 'pkg_resources.py2_warn' to the hiddenimports in gdbgui.spec.

After I add that, the after the build the binary will at least start running gdbgui, but then immediately crashes:

(develop-3-7) $ pyinstaller gdbgui.spec
47 INFO: PyInstaller: 3.6
47 INFO: Python: 3.7.7
54 INFO: Platform: Darwin-19.4.0-x86_64-i386-64bit
56 INFO: UPX is not available.
57 INFO: Extending PYTHONPATH with paths
['/Users/jamesyc/git/gdbgui/gdbgui', '/Users/jamesyc/git/gdbgui/gdbgui']
57 INFO: checking Analysis
76 INFO: Building because hiddenimports changed
76 INFO: Initializing module dependency graph...
78 INFO: Caching module graph hooks...
83 INFO: Analyzing base_library.zip ...
1797 INFO: Processing pre-find module path hook   distutils
1798 INFO: distutils: retargeting to non-venv dir '/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7'
2868 INFO: Caching module dependency graph...
2951 INFO: running Analysis Analysis-00.toc
2957 INFO: Analyzing gdbgui/backend.py
5489 INFO: Processing pre-safe import module hook   six.moves
7576 INFO: Analyzing hidden import 'engineio.async_gevent'
7576 ERROR: Hidden import 'engineio.async_gevent' not found
7576 INFO: Analyzing hidden import 'engineio.async_threading'
7577 ERROR: Hidden import 'engineio.async_threading' not found
7577 INFO: Analyzing hidden import 'pkg_resources.py2_warn'
7578 INFO: Processing module hooks...
7578 INFO: Loading module hook "hook-pkg_resources.py"...
7937 INFO: Processing pre-safe import module hook   win32com
7965 INFO: Excluding import '__main__'
7966 INFO:   Removing import of __main__ from module pkg_resources
7966 INFO: Loading module hook "hook-encodings.py"...
8023 INFO: Loading module hook "hook-jinja2.py"...
8058 INFO: Loading module hook "hook-gevent.py"...
8236 INFO: Determining a mapping of distributions to packages...
13216 WARNING: Unable to find package for requirement greenlet from package gevent.
13217 INFO: Packages required by gevent:
[]
14396 INFO: Processing pre-find module path hook   site
14397 INFO: site: retargeting to fake-dir '/Users/jamesyc/git/gdbgui/gdbgui/.nox/develop-3-7/lib/python3.7/site-packages/PyInstaller/fake-modules'
14835 INFO: Loading module hook "hook-sysconfig.py"...
14843 INFO: Loading module hook "hook-xml.py"...
14908 INFO: Loading module hook "hook-pydoc.py"...
14909 INFO: Loading module hook "hook-distutils.py"...
14909 INFO: Loading module hook "hook-pygments.py"...
16648 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
16649 INFO: Loading module hook "hook-lib2to3.py"...
16652 INFO: Loading module hook "hook-_tkinter.py"...
16656 INFO: checking Tree
16661 INFO: checking Tree
16720 INFO: Looking for ctypes DLLs
16737 WARNING: Ignoring /usr/lib/libc.dylib imported from /Users/jamesyc/git/gdbgui/gdbgui/.nox/develop-3-7/lib/python3.7/site-packages/monotonic.py - ctypes imports are only supported using bare filenames
16783 INFO: Analyzing run-time hooks ...
16792 INFO: Including run-time hook 'pyi_rth_pkgres.py'
16793 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
16796 INFO: Including run-time hook 'pyi_rth__tkinter.py'
16814 INFO: Looking for dynamic libraries
16936 INFO: Looking for eggs
16936 INFO: Using Python library /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/Python
16947 INFO: Warnings written to /Users/jamesyc/git/gdbgui/gdbgui/build/gdbgui/warn-gdbgui.txt
17029 INFO: Graph cross-reference written to /Users/jamesyc/git/gdbgui/gdbgui/build/gdbgui/xref-gdbgui.html
17087 INFO: Appending 'datas' from .spec
17091 INFO: checking PYZ
17100 INFO: Building because toc changed
17101 INFO: Building PYZ (ZlibArchive) /Users/jamesyc/git/gdbgui/gdbgui/build/gdbgui/PYZ-00.pyz
18113 INFO: Building PYZ (ZlibArchive) /Users/jamesyc/git/gdbgui/gdbgui/build/gdbgui/PYZ-00.pyz completed successfully.
18146 INFO: checking PKG
18159 INFO: Building because toc changed
18159 INFO: Building PKG (CArchive) PKG-00.pkg
21589 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
21623 INFO: Bootloader /Users/jamesyc/git/gdbgui/gdbgui/.nox/develop-3-7/lib/python3.7/site-packages/PyInstaller/bootloader/Darwin-64bit/run
21623 INFO: checking EXE
21634 INFO: Rebuilding EXE-00.toc because gdbgui_0.13.2.0 missing
21634 INFO: Building EXE from EXE-00.toc
21634 INFO: Appending archive to EXE /Users/jamesyc/git/gdbgui/gdbgui/dist/gdbgui_0.13.2.0
21651 INFO: Fixing EXE for code signing /Users/jamesyc/git/gdbgui/gdbgui/dist/gdbgui_0.13.2.0
21654 INFO: Building EXE from EXE-00.toc completed successfully.

(develop-3-7) $ dist/gdbgui_0.13.2.0
WARNING - You may need to set startup-with-shell off when running on a mac. i.e.
  gdbgui --gdb-args='--init-eval-command="set startup-with-shell off"'
see http://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra
and https://sourceware.org/gdb/onlinedocs/gdb/Starting.html
failed to initialize socketio app with async mode "gevent". Continuing with async mode "threading".
Traceback (most recent call last):
  File "gdbgui/backend.py", line 217, in setup_backend
    socketio.init_app(app)
  File "flask_socketio/__init__.py", line 213, in init_app
  File "socketio/server.py", line 111, in __init__
  File "engineio/server.py", line 140, in __init__
ValueError: Invalid async_mode specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "gdbgui/backend.py", line 986, in <module>
    main()
  File "gdbgui/backend.py", line 967, in main
    certificate=args.cert,
  File "gdbgui/backend.py", line 224, in setup_backend
    socketio.init_app(app)
  File "flask_socketio/__init__.py", line 213, in init_app
  File "socketio/server.py", line 111, in __init__
  File "engineio/server.py", line 140, in __init__
ValueError: Invalid async_mode specified
[87196] Failed to execute script backend

And i'm stuck here. I can't seem to figure out how to get past this point. It seems like pyinstaller isn't loading gevent and greenlet for some reason, but I have no clue why. It works fine when running from python directly. The packages are definitely installed in pip inside the virtualenv:

altgraph==0.17
appdirs==1.4.3
attrs==19.3.0
black==19.10b0
check-manifest==0.41
click==7.1.1
dnspython==1.16.0
entrypoints==0.3
eventlet==0.25.2
flake8==3.7.9
Flask==0.12.5
Flask-Compress==1.4.0
Flask-SocketIO==2.9.6
future==0.18.2
gdbgui==0.13.2.0
gevent==1.5.0
gevent-websocket==0.10.1
greenlet==0.4.15
importlib-metadata==1.6.0
itsdangerous==1.1.0
Jinja2==2.11.2
joblib==0.14.1
livereload==2.6.1
lunr==0.5.6
macholib==1.14
Markdown==3.2.1
MarkupSafe==1.1.1
mccabe==0.6.1
mkdocs==1.1
mkdocs-material==5.1.1
mkdocs-material-extensions==1.0b2
monotonic==1.5
mypy==0.770
mypy-extensions==0.4.3
nltk==3.5
pathspec==0.8.0
pep517==0.8.2
pip==20.0.2
pycodestyle==2.5.0
pyflakes==2.1.1
pygdbmi==0.9.0.3
Pygments==2.6.1
PyInstaller==3.6
pymdown-extensions==7.1
python-engineio==3.12.1
python-socketio==4.5.1
PyYAML==5.3.1
regex==2020.4.4
setuptools==46.1.3
six==1.14.0
toml==0.10.0
tornado==6.0.4
tqdm==4.45.0
typed-ast==1.4.1
typing-extensions==3.7.4.2
Werkzeug==0.16.1
wheel==0.34.2
zipp==3.1.0

Any clue how to fix this?

jamesyc commented 4 years ago

See PR #322 for fixes. It looks like pyinstaller needed to specify exactly what is called from inside engineio, or else it doesn't load the package into the executable, which causes the exception at runtime.