-
Notifications
You must be signed in to change notification settings - Fork 229
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
Added option to hide importlib frames in stack #246
base: main
Are you sure you want to change the base?
Conversation
Hiding them for everything seems like a good solution, especially since they don't even have source to show. |
I tested it and it appears to work. Should we add the setting to the preferences UI? |
Actually the behavior of However, this does make it at least usable in Python 3, which it wasn't before, so I'm +1 to merge as is, unless you have any ideas on the above issues. |
Maybe yes. Or at least mention the setting at README.
I think I need to do some investigation on these bugs. I didn't notice them before =) But I don't think it's related to current PR. |
I think it has to do with the behavior that we are hiding in this PR. The debugger still thinks that it is being stopped inside the import, not after it. In master if you |
Actually, I misspoke above. You have to press |
@asmeurer I got it. I need some time to try to provide the correct behaviour. I'd like to ask you not to merge this PR until I understand how I can hack it. |
bae3106
to
7518a93
Compare
Hi there! I've finally get it work. The problem was with that we set a breakpoint at |
Does this still rely on the importlib hiding in the UI? I think we should remove that if it isn't used. |
Yes it does. I don't see any way to clean-up importlib frames from system stack (and also, don't think it's good idea). What we do:
|
pudb/debugger.py
Outdated
self.botframe.f_trace = self.trace_dispatch | ||
|
||
stack, _ = self.get_stack(frame, None) | ||
if stack: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is this empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well. Normally it shouldn't. But what if it would happen that all of frames were called from importlib._bootstrap
? Sounds weird, but I don't think we have guarantee that stack list has at least one element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the check is fine. I agree it shouldn't happen, unless you do something really weird (like inject a set_trace in the importlib._bootstrap code). Might make the code easier to read if you inverted the check to avoid indenting the whole block:
if not stack:
return
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks for idea.
OK, I tested it and it seems to work. I have no preference about having the flag in the settings, but we should probably at least document it (we have real docs now, so you can add it somewhere in there). |
The flag is necessary if somebody wants to debug imporlib frames (for example a custom import finder or loader). In that case he would be able to switch to extreme-pro-mode :-)
Okay, I'll do that. |
You would have to be really pro, since the importlib code is frozen, so PuDB shows no source code for it, meaning you either have to insert some code for it or debug blind. |
I'm sorry to say I'm not a fan of this endeavor. The frames are there, and pretending they aren't is going to involve handling all sorts of poorly tested corner cases. (What if you step into a hidden frame? Out of one? Return through one?) I don't know |
Of course, that's an ugly hack, but I don't see any other way to fix the bug. And it's also the way that, that cpython solves this problem.
You will get to the top unhidden one.
The same. That is why I'm overriding the |
@inducer I think that PuDB codebase has a bug in
As for me, I'd vote for the first one. And I'm open to discuss any other way to fix it. The least desired for me is to pretend that it's not a bug, but a feature. I'd like to know what is your point of view? |
From my point of view, the ideal way to fix the bug would be to leave the stack frames alone, but move the debugger to the right frame on |
The same for me. At first I thought that we just need to calculate the I also tried to wrap the |
Agree with @asmeurer that
What do you mean by "it didn't work"? Can we recognize the "right" frame (or the frame before that) by the function or module names? |
At first I've played with stack depth in
Here is the current
It seems that we can skip these 5 imporlib frames and with 7 level depth will get to the
|
I just noticed today that bdb has a builtin |
Hi, some 2 years later, how can we hide importlib now ? |
I've made some research and here are the results:
_call_with_frames_removed
that marks you code forimport.c
machinery that it must be cleaned up after__import__
call. But I guess it doesn't work for our case, because we interrupt code inside the import.I think that best solution for us is to add optional stack clean-up of importlib trash frames at the view level. It would hide some inner python magic for most of users, but will also leave a way to debug importlib machinery (for example when custom import Finders and Loaders are being developed).
Before:
After:
Fixes #109