Giter Club home page Giter Club logo

Comments (7)

ipython3 avatar ipython3 commented on May 28, 2024 1

Thank you for the informative answer! It really helps me a lot!

from gdb-dashboard.

cyrus-and avatar cyrus-and commented on May 28, 2024

Does the commands in this wiki page work? They need to be executed within GDB.

Also what's the output of the following?

gdb --batch -ex 'python import sys; print(sys.version)'

from gdb-dashboard.

ipython3 avatar ipython3 commented on May 28, 2024

Hi @cyrus-and,

Here is the output:

(.venv) myname@debian12:~/learn/learn-gdb$ gdb --batch -ex 'python import sys; print(sys.version)'
3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]

I tried the commands in this wiki page and error ModuleNotFoundError: No module named 'pygments' occurs:
屏幕截图 2024-05-11 163603

To make sure that I didn't forget to install pygments, I created a test.py file:

from pygments.styles import *
for style in get_all_styles():
    print(style)

It runs successfully:

(.venv) myname@debian12:~/learn/learn-gdb$ which python3
/home/myname/.venv/bin/python3
(.venv) myname@debian12:~/learn/learn-gdb$ python3 test.py 
abap
algol
algol_nu
arduino
autumn
bw
borland
colorful
default
dracula
emacs
friendly_grayscale
friendly
fruity
github-dark
gruvbox-dark
gruvbox-light
igor
inkpot
lightbulb
lilypond
lovelace
manni
material
monokai
murphy
native
nord-darker
nord
one-dark
paraiso-dark
paraiso-light
pastie
perldoc
rainbow_dash
rrt
sas
solarized-dark
solarized-light
staroffice
stata-dark
stata-light
tango
trac
vim
vs
xcode
zenburn
(.venv) myname@debian12:~/learn/learn-gdb$

from gdb-dashboard.

cyrus-and avatar cyrus-and commented on May 28, 2024

In a nutshell, Pygments must be available for the version of Python that runs inside GDB (in your case 3.11.2).

from gdb-dashboard.

ipython3 avatar ipython3 commented on May 28, 2024

Hi @cyrus-and,

Thank you so much! I was not familiar with Python integration in GDB and now I see where the problem is.

I didn't install Pygments system-wide, because the reason listed here.

In the Quickstart section of README.md of gdb-dashboard, it says we can install Pygments by pip install pygments, but I did some search and found this. It says that the Python interpreter that GDB uses is linked into GDB, in the form of libpython3.4.a or libpython3.4.so, etc.

I'm very confused. Even if I run pip install pygments system-wide, that would only install pygments in to the system Python, instead of the Python that runs inside GDB. How could I let Pygments be available for the Python that runs inside GDB?

Is there anything wrong with my understanding? I really appreciate it if you can correct me.

By the way, Python version in my system and in the venv are also 3.11.2:

myname@debian12:~/learn/learn-gdb$ which python3
/usr/bin/python3
myname@debian12:~/learn/learn-gdb$ python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
myname@debian12:~/learn/learn-gdb$ source ~/.venv/bin/activate
(.venv) myname@debian12:~/learn/learn-gdb$ which python3
/home/myname/.venv/bin/python3
(.venv) myname@debian12:~/learn/learn-gdb$ python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
(.venv) myname@debian12:~/learn/learn-gdb$

from gdb-dashboard.

cyrus-and avatar cyrus-and commented on May 28, 2024

OK so, the question is then, how to use Pygments in Python GDB using venv? What I said holds for packages installed systemwide. And in fact, installing Pygments systemwide will fix your issue.

But if you want to use venv, you just need to tell the GDB Python that you want to use that instead, apparently all you have to do is to add the venv path to the sys.path inside Python GDB, that is, in my case:

(.venv) user@cc547d5a0dfc:~$ python3 -c 'import sys; print(sys.path)'
['', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/user/.venv/lib/python3.10/site-packages']

So in GDB (this is the part that should be in your configuration file, something inside ~/.gdbinit.d/, either a .py file or a GDB file):

python import sys; sys.path += ['/home/user/.venv/lib/python3.10/site-packages']

After that, you should be able to import Pygments and all of that. Hope it helps!

from gdb-dashboard.

cyrus-and avatar cyrus-and commented on May 28, 2024

Feel free to post your exact solution so to help others, if you want.

from gdb-dashboard.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.