This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Implement thread-related commands in pdb
Type: Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: bar.harel, cebtenzzre, corona10, iritkatriel, pablogsal
Priority: normal Keywords:

Created on 2020-08-17 23:48 by pablogsal, last changed 2022-04-11 14:59 by admin.

Messages (5)
msg375579 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-08-17 23:48
Unfortunately, the thread experience with pdb is not as good as it could be due to the lack of thread-related commands. In other debuggers like gdb, is common to be able to do some of the following operations:

* list all threads
* switch the context to a different thread.
* Stop all threads when attaching.
* Place a breakpoint in a specific thread.

I think the user experience will improve considerably if we could implement at least these features (and maybe some others that we deem useful).
msg375585 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-08-18 03:08
* Displaying all threads is trivial.

* Stopping all threads is trivial because of the GIL. When pdb runs in a thread all other threads cannot execute python code. They can execute native code bit there is not much we can do about it.

* Switching threads is the interesting one. The easiest way is to set the pdb trace function in the target thread and run until they thread executes python code. This has the following considerations:

  - All PSB commands will automatically work on that thread once the trace function is executed.
  - There will be a delay between the command and the thread being switched. This is due to the fact that we do not control what thread will run and we need to wait until the thread executes Python code.
  - Switching to a thread that is blocked on something (on a lock or on C code) will hang.

For this reason, this method can work only for setting breakpoints on threads, not for 'switching threads'. The breakpoint will work because that's the expected behaviour: the day and the possibility of not hitting it is justified on the nature of the breakpoint.

For switching threads, the best way would be to 'virtually switch threads'. This means that somehow we switch internally to the thread stack but we keep executing on the main thread, we merely switch our internal context.
msg375587 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-08-18 03:13
We may need to think as well how some commands interest when you are in a different thread context. For instance, stepping into something when you are in a different thread is equivalent to setting a breakpoints in the next thread instruction, so this has the same considerations as the breakpoints. We may want to disallow this or to emit some warning in this case.
msg375589 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-08-18 03:28
Another possibility would be accept the reality of the switching delay (so all the other commands work without extra changes) and working to minimize it by setting sys.setswitchinterval() to something ridiculously low and then switching it back to the previous value once we are in the thread that we want. If this is not enough we could sed modify the Gil-adquire code to do something similar to what the Python 2 implementation did when signals arrive that is basically switch constantly between threads until the one that we want runs.
msg376633 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-09-09 12:37
I am +1 on this project :)
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85743
2022-03-28 23:09:47cebtenzzresetnosy: + cebtenzzre
2020-09-09 13:28:53iritkatrielsetnosy: + iritkatriel
2020-09-09 12:37:53corona10setmessages: + msg376633
2020-09-09 12:37:01corona10setnosy: + corona10
2020-09-06 17:28:11bar.harelsetnosy: + bar.harel
2020-08-18 03:28:08pablogsalsetmessages: + msg375589
2020-08-18 03:13:51pablogsalsetmessages: + msg375587
2020-08-18 03:08:24pablogsalsetmessages: + msg375585
2020-08-18 00:02:54pablogsalsetmessages: - msg375580
2020-08-17 23:49:04pablogsalsetmessages: + msg375580
2020-08-17 23:48:34pablogsalsettitle: Allow pdb to switch to a different thread -> Implement thread-related commands in pdb
2020-08-17 23:48:13pablogsalsetcomponents: + Library (Lib)
2020-08-17 23:48:01pablogsalcreate