Package Details: mips-harvard-os161-gdb 7.8+os161_2.1-4

Git Clone URL: https://aur.archlinux.org/mips-harvard-os161-gdb.git (read-only, click to copy)
Package Base: mips-harvard-os161-gdb
Description: The GNU Debugger modified for mips-harvard-os161 arquitecture. This is part of toolset for the course os161 from Harvard.
Upstream URL: http://os161.eecs.harvard.edu/
Licenses: GPL, LGPL
Groups: mips-harvard-os161-toolchain
Submitter: gerito
Maintainer: gerito
Last Packager: gerito
Votes: 3
Popularity: 0.000000
First Submitted: 2017-02-13 12:47 (UTC)
Last Updated: 2023-03-19 15:30 (UTC)

Latest Comments

1 2 Next › Last »

gerito commented on 2023-03-19 15:33 (UTC)

@lidlessey3 Hopefully it works now. Thanks for the patch. :)

lidlessey3 commented on 2023-03-19 01:22 (UTC) (edited on 2023-03-19 01:29 (UTC) by lidlessey3)

Thank you for your work. Here I cleaned up the diff with respect to your version to include only the relevant pieces of code for this particular time.

--- gdb-7.8+os161-2.1/gdb/python/python.c   2023-03-18 00:06:15.662640861 +0100
+++ gdb-7.8+os161-2.1-new/gdb/python/python.c   2023-03-18 22:44:41.254253907 +0100
@@ -272,8 +272,16 @@ ensure_python_env (struct gdbarch *gdbar
  static void
  gdbpy_clear_quit_flag (const struct extension_language_defn *extlang)
  {
+  if(!gdb_python_initialized)
+   return;
+  
+  PyGILState_STATE m_state;
+  m_state = PyGILState_Ensure();
+  
    /* This clears the flag as a side effect.  */
   PyOS_InterruptOccurred ();
+  PyGILState_Release(m_state);
+  return;
 }

  /* Set the quit flag.  */
@@ -289,7 +297,13 @@ gdbpy_set_quit_flag (const struct extens
 static int
 gdbpy_check_quit_flag (const struct extension_language_defn *extlang)
 {
-  return PyOS_InterruptOccurred ();
+  if (!gdb_python_initialized)
+   return 0;
+  PyGILState_STATE m_state;
+  m_state = PyGILState_Ensure();
+  int res = PyOS_InterruptOccurred ();
+  PyGILState_Release(m_state);
+  return res;
 }

  /* Evaluate a Python command like PyRun_SimpleString, but uses
@@ -1551,8 +1565,8 @@ finalize_python (void *ignore)
    python_language = current_language;

    Py_Finalize ();
-
+  gdb_python_initialized = 0;
  restore_active_ext_lang (previous_active);
 }
 #endif

@@ -1794,7 +1808,6 @@ message == an error message without a st
    goto fail;

   /* Release the GIL while gdb runs.  */
-  PyThreadState_Swap (NULL);
-  PyEval_ReleaseLock ();
+  PyEval_SaveThread();

  make_final_cleanup (finalize_python, NULL);

gerito commented on 2023-03-18 22:28 (UTC)

@lidlessey3 I will add it today at night/tomorrow.

Thank you for your work. Excellent job.

lidlessey3 commented on 2023-03-18 22:00 (UTC)

@lidlessey3 Okay I got it working by backporting another patch, apperantly Pyhon changed how PyOS works in more recent versions, here is a diff of what I had to change to get it to compile correctly:

diff old/gdb/python/python.c new/gdb/python/python.c
148c148
< static void gdbpy_clear_quit_flag (const struct extension_language_defn *);
---
> static int gdbpy_clear_quit_flag (const struct extension_language_defn *);
272c272
< static void
---
> static int
274a275,280
>   if(!gdb_python_initialized)
>    return 0;
>   static int count = 0;
>   PyGILState_STATE m_state;
>   m_state = PyGILState_Ensure();
>   
276c282,284
<   PyOS_InterruptOccurred ();
---
>   int res = PyOS_InterruptOccurred ();
>   PyGILState_Release(m_state);
>   return res;
292c300,306
<   return PyOS_InterruptOccurred ();
---
>   if (!gdb_python_initialized) 
>    return 0;
>   PyGILState_STATE m_state;
>   m_state = PyGILState_Ensure();
>   int res = PyOS_InterruptOccurred ();
>   PyGILState_Release(m_state);
>   return res;
1554c1568
< 
---
>   gdb_python_initialized = 0;
1558a1573,1579
> #ifdef IS_PY3K
> PyMODINIT_FUNC
> PyInit__gdb (void) {
>   return PyModule_Create(&GdbModuleDef);
> }
> #endif
> 
1679a1701,1703
> 
>  PyImport_AppendInittab("_gdb", PyInit__gdb);
> 
1689c1713
<   gdb_module = PyModule_Create (&GdbModuleDef);
---
>   gdb_module = PyImport_ImportModule ("_gdb");
1691c1715
<   _PyImport_FixupBuiltin (gdb_module, "_gdb");
---
>   
1785,1786c1809
<   PyThreadState_Swap (NULL);
<   PyEval_ReleaseLock ();
---
>   PyEval_SaveThread();

Note: Some of this modificantions are alredy present in the packet, as they are made wrt the original source, mostly of note here are the ones about handling the GIL. @gerito would it be possible to include them so to get the packet to work out of the box? Thanks.

lidlessey3 commented on 2023-03-18 14:40 (UTC) (edited on 2023-03-18 14:41 (UTC) by lidlessey3)

I get an error when I try to run it, I think it has something to do with the version of python, but I am not an expert:

 > mips-harvard-os161-gdb kernel
 Fatal Python error: _PyOS_InterruptOccurred: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: unknown

Cancelled (core dump created)

Output of python --version is

Python 3.10.10

gerito commented on 2019-09-18 04:02 (UTC)

@johnramsden Welp. I swear I couldn't find it. Yes, that one. XP

johnramsden commented on 2019-09-18 03:55 (UTC)

No worries, thanks for your time @gerito. In the meantime I was able to get it to build by building in a clean chroot with no python3.

Isn't this the emulator? https://aur.archlinux.org/packages/sys161/

gerito commented on 2019-09-18 03:42 (UTC)

@johnramsden I'm so sorry for the delay. I have been busy lately and stuff. I hope this fixes the build issue, unfortunately I discovered that the sys161 emulator is no longer available in aur anymore. I'm not sure if I should provide one or no. It is not difficult to set it up by yourself, once the toolchain, bmake and all other dependencies are installed. If you have any other problem I will try to answer but keep in mind it could take time. It took me most part of my afternoon to fix this, granted it wasn't difficult (I had to back-port a patch) but I had to set up my environment and stuff. Again I'm sorry for the delay.

johnramsden commented on 2019-09-11 01:24 (UTC)

I'm getting the following during builds:

../../gdb-7.8+os161-2.1/gdb/python/python.c: In function ‘_initialize_python’:
../../gdb-7.8+os161-2.1/gdb/python/python.c:1691:3: error: too few arguments to function ‘_PyImport_FixupBuiltin’
 1691 |   _PyImport_FixupBuiltin (gdb_module, "_gdb");
      |   ^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/python3.7m/Python.h:145,
                 from ../../gdb-7.8+os161-2.1/gdb/python/python-internal.h:97,
                 from ../../gdb-7.8+os161-2.1/gdb/python/python.c:94:
/usr/include/python3.7m/import.h:112:17: note: declared here
  112 | PyAPI_FUNC(int) _PyImport_FixupBuiltin(
      |                 ^~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [Makefile:2369: python.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/home/john/.cache/aurutils/sync/mips-harvard-os161-gdb/src/gdb-build/gdb'
make[1]: *** [Makefile:8668: all-gdb] Error 2
make[1]: Leaving directory '/home/john/.cache/aurutils/sync/mips-harvard-os161-gdb/src/gdb-build'
make: *** [Makefile:832: all] Error 2
==> ERROR: A failure occurred in build().
    Aborting...