bebbo / amiga-gcc

The GNU C-Compiler with Binutils and other useful tools for cross development for Amiga
GNU General Public License v2.0
312 stars 66 forks source link

Enabling python in gdb #338

Closed mheyer32 closed 2 months ago

mheyer32 commented 1 year ago

Whats the proper way to enable python support in the compiled m68-amigaos-gdb. I used to know it, but have long forgotten. Could we enable it by default? I'm using QtCreator which needs python support in gdb .

bebbo commented 1 year ago

I don't see what's missing:

[stefan@HP amiga-gcc]$ /opt/amiga/bin/m68k-amigaos-gdb
GNU gdb (GDB) 13.0.50.230219-201801-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=m68k-amigaos".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) python print(23)
23
(gdb) 
mheyer32 commented 2 months ago

Can I reopen this request? Its not working.

➜  amiga-gcc git:(master) m68k-amigaos-gdb
GNU gdb (GDB) 13.0.50.240619-160654-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=m68k-amigaos".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) python print(23)
Python scripting is not supported in this copy of GDB.
(gdb) 
mheyer32 commented 2 months ago

I think, I'm missing something on my side, I just don't know what

bebbo commented 2 months ago

I think, I'm missing something on my side, I just don't know what

install python + python-development stuff?

configure:11052: checking whether to use python
configure:11054: result: auto
configure:11103: checking for python
configure:11121: found /usr/bin/python
configure:11134: result: /usr/bin/python
configure:11252: checking for python
configure:11275: gcc -o conftest -g    -I/usr/include/python3.12 -I/usr/include/python3.12   conftest.c -lpython3.12 -ldl -lm -Xlinker -export-dynamic -lncursesw -lm  >&5
configure:11275: $? = 0
configure:11285: result: yes

Can you compile this one:

/* end confdefs.h.  */
#include "Python.h"
int
main ()
{

                    #if PY_MAJOR_VERSION != 3
                    # error "We only support Python 3"
                    #endif
                    Py_Initialize ();

  ;
  return 0;
}
mheyer32 commented 2 months ago

After looking more closely at the configure log, I found that it was looking for a "distutils" python library. I installed python3-distutils-extra and its now attempting to compile python support. But it gets stuck at a warning-as-error:


  CXX    python/py-arch.o
  CXX    python/py-auto-load.o
  CXX    python/py-block.o
  CXX    python/py-bpevent.o
  CXX    python/py-breakpoint.o
In file included from /home/matze/amigatoolchain/amiga-gcc/projects/binutils/gdb/python/py-arch.c:24:
/home/matze/amigatoolchain/amiga-gcc/projects/binutils/gdb/python/python-internal.h: In function ‘void gdb_PySys_SetPath(const wchar_t*)’:
/home/matze/amigatoolchain/amiga-gcc/projects/binutils/gdb/python/python-internal.h:189:17: error: ‘void PySys_SetPath(const wchar_t*)’ is deprecated [-Werror=deprecated-declarations]
  189 |   PySys_SetPath (const_cast<GDB_PYSYS_SETPATH_CHAR *> (path));
      |   ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/python3.12/Python.h:96,
                 from /home/matze/amigatoolchain/amiga-gcc/projects/binutils/gdb/python/python-internal.h:86:
/usr/include/python3.12/sysmodule.h:15:38: note: declared here
   15 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetPath(const wchar_t *);
      |                                      ^~~~~~~~~~~~~
  CXX    python/py-cmd.o
cc1plus: all warnings being treated as errors
make[2]: *** [Makefile:1897: python/py-arch.o] Error 1
make binutils gdb...failed
use less "log/make binutils gdb.log" to view the full log and search for ***
make: *** [Makefile:434: /home/matze/amigatoolchain/amiga-gcc/build-Linux-m68k-amigaos/binutils/_gdb] Error 2

IDK if the path forward is to fix the API usage or just disable the warning. I attempted to do the latter but haven't found a way to inject that into the gdb build.

bebbo commented 2 months ago

I'd rather disable the -Werror=deprecated-declarations flag somehow...

mheyer32 commented 2 months ago

I found a hopefully good way to workaround the issue with: https://github.com/bebbo/binutils-gdb/pull/42

nvmheyer commented 2 months ago

I successfully compiled a toolchain with Python support and bgdbserver/QtCreator were happy with it. Thank you!

bebbo commented 2 months ago

I successfully compiled a toolchain with Python support and bgdbserver/QtCreator were happy with it. Thank you!

Using Fedora, python support was always there...

bebbo commented 2 months ago

If it's missing, also ensure that python3 is the default.

Configure it using update-alternatives --config python, if nothing is configured, add a python config. e.g. like

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 20