Generic Python debugger base class. This class takes care of details of the trace facility; a derived class should implement user interaction. The standard debugger class (pdb.Pdb) is an example. The optional skip argument must be an iterable of glob-style module name pa
| 15 | |
| 16 | |
| 17 | class Bdb: |
| 18 | """Generic Python debugger base class. |
| 19 | |
| 20 | This class takes care of details of the trace facility; |
| 21 | a derived class should implement user interaction. |
| 22 | The standard debugger class (pdb.Pdb) is an example. |
| 23 | |
| 24 | The optional skip argument must be an iterable of glob-style |
| 25 | module name patterns. The debugger will not step into frames |
| 26 | that originate in a module that matches one of these patterns. |
| 27 | Whether a frame is considered to originate in a certain module |
| 28 | is determined by the __name__ in the frame globals. |
| 29 | """ |
| 30 | |
| 31 | def __init__(self, skip=None): |
| 32 | self.skip = set(skip) if skip else None |
| 33 | self.breaks = {} |
| 34 | self.fncache = {} |
| 35 | self.frame_returning = None |
| 36 | |
| 37 | self._load_breaks() |
| 38 | |
| 39 | def canonic(self, filename): |
| 40 | """Return canonical form of filename. |
| 41 | |
| 42 | For real filenames, the canonical form is a case-normalized (on |
| 43 | case insensitive filesystems) absolute path. 'Filenames' with |
| 44 | angle brackets, such as "<stdin>", generated in interactive |
| 45 | mode, are returned unchanged. |
| 46 | """ |
| 47 | if filename == "<" + filename[1:-1] + ">": |
| 48 | return filename |
| 49 | canonic = self.fncache.get(filename) |
| 50 | if not canonic: |
| 51 | canonic = os.path.abspath(filename) |
| 52 | canonic = os.path.normcase(canonic) |
| 53 | self.fncache[filename] = canonic |
| 54 | return canonic |
| 55 | |
| 56 | def reset(self): |
| 57 | """Set values of attributes as ready to start debugging.""" |
| 58 | import linecache |
| 59 | linecache.checkcache() |
| 60 | self.botframe = None |
| 61 | self._set_stopinfo(None, None) |
| 62 | |
| 63 | def trace_dispatch(self, frame, event, arg): |
| 64 | """Dispatch a trace function for debugged frames based on the event. |
| 65 | |
| 66 | This function is installed as the trace function for debugged |
| 67 | frames. Its return value is the new trace function, which is |
| 68 | usually itself. The default implementation decides how to |
| 69 | dispatch a frame, depending on the type of event (passed in as a |
| 70 | string) that is about to be executed. |
| 71 | |
| 72 | The event can be one of the following: |
| 73 | line: A new line of code is going to be executed. |
| 74 | call: A function is about to be called or another code block |