Skip to content

Conversation

ktowen
Copy link

@ktowen ktowen commented Oct 7, 2025

Add two new commands to pdb for skipping frames from specified modules:

  • ignore_module [module_name]: Add modules to skip during debugging
  • unignore_module [module_name]: Remove modules from skip list

When a module is ignored, the debugger automatically skips over its frames during step, next, continue, up, and down commands. Supports wildcard patterns via fnmatch for flexible module matching.

This feature improves debugging productivity when working with frameworks by allowing developers to hide framework-internal frames and focus on application code.

Issue: #139721

@python-cla-bot
Copy link

python-cla-bot bot commented Oct 7, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

ktowen added 3 commits October 8, 2025 08:40
Add two new commands to pdb for skipping frames from specified modules:
- ignore_module [module_name]: Add modules to skip during debugging
- unignore_module [module_name]: Remove modules from skip list

When a module is ignored, the debugger automatically skips over its
frames during step, next, continue, up, and down commands. Supports
wildcard patterns via fnmatch for flexible submodule matching.
Fix pdbcmd_sig_re to include underscores for commands like ignore_module
@ktowen ktowen force-pushed the feature/pdb-ignore-modules branch from 401e1e3 to e3d97d0 Compare October 8, 2025 06:47
@ktowen ktowen marked this pull request as ready for review October 8, 2025 12:32
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the "unignore" verb (but I don't have a really better suggestion). How about ignore-module X on/off. Or "[show/hide]-module-frames"? (though you need to write more characters, but you can use autocompletion otherwise).

# Support for documenting pdb commands

pdbcmd_sig_re = re.compile(r'([a-z()!]+)\s*(.*)')
pdbcmd_sig_re = re.compile(r'([a-z()!_]+)\s*(.*)')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commands usually have dashes instead of underscores. At least most UNIX commands would be with dashes so I think it's better to have dashes in general. (also gdb uses dashes and not underscores for commands with multiple words)

Copy link
Author

@ktowen ktowen Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to follow the convention of using snake case, the other option I was thinking is not using separator as pdb does with the commands longlist, whatis and retval. Adding dashes will imply changing how the commands are defined and discovered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For CLI-like options, I would prefer using dashes. Those are not really variables (even though they are stored in variables in the end). I'll leave the decision to Tian but we could also consider not having dashes/underscores at all if we find better words (showmodule, hidemodule would be fine I think although we're not really hiding them per se, just hiding them in the traceback).

> <doctest test.test_pdb.test_pdb_skip_modules_with_callback[0]>(5)skip_module()
-> mod.foo_pony(callback)
(Pdb) step
[... skipped 1 ignored module(s)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I know why we have an ignored module here although the test uses the default parameters?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an skipped module in the Pdb initialization

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, it wasn't part of the diff. If we already have skip=... to parametrize this, I would suggest that we use skipmodule and unskipmodule for the commands instead.


newframe = i
if module_skipped:
self.message(f'[... skipped {module_skipped} frame(s) '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest indicating which module was ignored if there is only 1 module being ignored.

try:
self.skip.remove(module_name)
self.message(f'No longer ignoring module: {module_name}')
except KeyError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be emitted after .remove was called (in case .message raises a KeyError for some obscure reasons)

@@ -0,0 +1,5 @@
Add ``ignore_module`` and ``unignore_module`` commands to :mod:`pdb` to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also need a What's New entry because it's a new feature for 3.15.

- Skip standard library modules (``threading``, ``multiprocessing``, ``logging.*``)
- Skip test framework internals (``*pytest*``, ``unittest.*``)

.. versionadded:: 3.15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. versionadded:: 3.15
.. versionadded:: next

@hugovk hugovk removed their request for review October 8, 2025 13:00
@ktowen
Copy link
Author

ktowen commented Oct 11, 2025

I don't really like the "unignore" verb (but I don't have a really better suggestion). How about ignore-module X on/off. Or "[show/hide]-module-frames"? (though you need to write more characters, but you can use autocompletion otherwise).

I'm not a big fan of that verb either but I tried to keep the functionality and naming consistent with other "oposite" commands like alias/unalias and display/undisplay

@AA-Turner
Copy link
Member

I'd prefer the hide-module-frames form, it's immediately clearer on what it does (unlike ignore-module), and the antonym form is better too.

A

@AA-Turner AA-Turner requested review from Copilot and removed request for AA-Turner and Copilot October 11, 2025 12:46
@gaogaotiantian
Copy link
Member

Please take a look at my comment #139721 (comment) before spending more time on this feature. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants