Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement thread-related commands in pdb #85743

Open
pablogsal opened this issue Aug 17, 2020 · 5 comments
Open

Implement thread-related commands in pdb #85743

pablogsal opened this issue Aug 17, 2020 · 5 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir

Comments

@pablogsal
Copy link
Member

BPO 41571
Nosy @bharel, @corona10, @pablogsal, @iritkatriel, @cebtenzzre

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-08-17.23:48:01.888>
labels = ['library', '3.10']
title = 'Implement thread-related commands in pdb'
updated_at = <Date 2022-03-28.23:09:47.329>
user = 'https://github.com/pablogsal'

bugs.python.org fields:

activity = <Date 2022-03-28.23:09:47.329>
actor = 'cebtenzzre'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-08-17.23:48:01.888>
creator = 'pablogsal'
dependencies = []
files = []
hgrepos = []
issue_num = 41571
keywords = []
message_count = 5.0
messages = ['375579', '375585', '375587', '375589', '376633']
nosy_count = 5.0
nosy_names = ['bar.harel', 'corona10', 'pablogsal', 'iritkatriel', 'cebtenzzre']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue41571'
versions = ['Python 3.10']

@pablogsal
Copy link
Member Author

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).

@pablogsal pablogsal added 3.10 only security fixes stdlib Python modules in the Lib dir labels Aug 17, 2020
@pablogsal pablogsal changed the title Allow pdb to switch to a different thread Implement thread-related commands in pdb Aug 17, 2020
@pablogsal pablogsal changed the title Allow pdb to switch to a different thread Implement thread-related commands in pdb Aug 17, 2020
@pablogsal
Copy link
Member Author

  • 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.

@pablogsal
Copy link
Member Author

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.

@pablogsal
Copy link
Member Author

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.

@corona10
Copy link
Member

corona10 commented Sep 9, 2020

I am +1 on this project :)

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes stdlib Python modules in the Lib dir
Projects
Status: No status
Development

No branches or pull requests

2 participants