# eric7.DebugClients.Python.DebugBase

Module implementing the debug base class which based originally on bdb.

### Global Attributes

GENERATOR_AND_COROUTINE_FLAGS
gRecursionLimit

### Classes

DebugBase | Class implementing base class of the debugger.

### Functions

printerr | Module function used for debugging the debug client.
setRecursionLimit | Module function to set the recursion limit.

## DebugBase

Class implementing base class of the debugger.

Provides methods for the 'owning' client to call to step etc.

### Derived from

None

### Class Attributes

_fnCache
filesToSkip
lib
pathsToSkip
pollTimerEnabled

### Class Methods

None

### Methods

DebugBase | Constructor
__checkBreakInFrame | Private method to check if the function / method has a line number which is a breakpoint.
__disassemble | Private method to generate a disassembly of the given code object.
__do_clearBreak | Private method called to clear a temporary breakpoint.
__do_clearWatch | Private method called to clear a temporary watch expression.
__eventPollTimer | Private method to set a flag every 0.5 s to check for new messages.
__extractExceptionName | Private method to extract the exception name given the exception type object.
__extractSystemExitMessage | Private method to get the SystemExit code and message.
__extract_stack | Private member to return a list of stack frames.
__sendCallTrace | Private method to send a call/return trace.
__skipFrame | Private method to filter out debugger files.
_set_stopinfo | Protected method to update the frame pointers.
bootstrap | Public method to bootstrap a thread.
break_here | Public method reimplemented from bdb.py to fix the filename from the frame.
fix_frame_filename | Public method used to fixup the filename for a given frame.
getFrame | Public method to return the frame "frmnr" down the stack.
getFrameLocals | Public method to return the locals dictionary of the current frame or a frame below.
getStack | Public method to get the stack.
go | Public method to resume the thread.
move_instruction_pointer | Public method to move the instruction pointer to another line.
profile | Public method used to trace some stuff independent of the debugger trace function.
profileWithRecursion | Public method used to trace some stuff independent of the debugger trace function.
run | Public method to start a given command under debugger control.
setRecursionDepth | Public method to determine the current recursion depth.
set_continue | Public method to stop only on next breakpoint.
set_next | Public method to stop on the next line in or below the given frame.
set_quit | Public method to quit.
set_return | Public method to stop when returning from the given frame.
set_step | Public method to stop after one line of code.
set_trace | Public method to start debugging from 'frame'.
set_until | Public method to stop when the line with the lineno greater than the current one is reached or when returning from current frame.
step | Public method to perform a step operation in this thread.
stepOut | Public method to perform a step out of the current call.
stop_here | Public method reimplemented to filter out debugger files.
storeFrameLocals | Public method to store the locals into the frame, so an access to frame.f_locals returns the last data.
tracePythonLibs | Public method to update the settings to trace into Python libraries.
trace_dispatch | Public method reimplemented from bdb.py to do some special things.
user_exception | Public method reimplemented to report an exception to the debug server.
user_line | Public method reimplemented to handle the program about to execute a particular line.

### Static Methods

None

#### DebugBase (Constructor)

DebugBase(dbgClient)

Constructor

dbgClient (DebugClient)
  the owning client

#### DebugBase.__checkBreakInFrame

__checkBreakInFrame(frame)

Private method to check if the function / method has a line number which is a breakpoint.

frame (frame object)
  the frame object

Return:
  Flag indicating a function / method with breakpoint

Return Type:
  bool

#### DebugBase.__disassemble

__disassemble(frame)

Private method to generate a disassembly of the given code object.

frame (code)
  frame object to be disassembled

Return:
  dictionary containing the disassembly information

Return Type:
  dict

#### DebugBase.__do_clearBreak

__do_clearBreak(filename, lineno)

Private method called to clear a temporary breakpoint.

filename (str)
  name of the file the bp belongs to
lineno (int)
  linenumber of the bp

#### DebugBase.__do_clearWatch

__do_clearWatch(cond)

Private method called to clear a temporary watch expression.

cond (str)
  expression of the watch expression to be cleared

#### DebugBase.__eventPollTimer

__eventPollTimer()

Private method to set a flag every 0.5 s to check for new messages.

#### DebugBase.__extractExceptionName

__extractExceptionName(exctype)

Private method to extract the exception name given the exception type object.

exctype (type)
  type of the exception

Return:
  exception name

Return Type:
  str

#### DebugBase.__extractSystemExitMessage

__extractSystemExitMessage(excinfo)

Private method to get the SystemExit code and message.

excinfo (tuple(Exception, excval object, traceback frame object))
  details about the SystemExit exception

Return:
  SystemExit code and message

Return Type:
  int, str

#### DebugBase.__extract_stack

__extract_stack(exctb)

Private member to return a list of stack frames.

exctb (traceback)
  exception traceback

Return:
  list of stack frames

Return Type:
  list of frame

#### DebugBase.__sendCallTrace

__sendCallTrace(event, fromFrame, toFrame)

Private method to send a call/return trace.

event (str)
  trace event
fromFrame (frame object)
  originating frame
toFrame (frame object)
  destination frame

#### DebugBase.__skipFrame

__skipFrame(frame)

Private method to filter out debugger files.

Tracing is turned off for files that are part of the debugger that are called from the application being debugged.

frame (frame object)
  the frame object

Return:
  flag indicating whether the debugger should skip this frame

Return Type:
  bool

#### DebugBase._set_stopinfo

_set_stopinfo(stopframe, returnframe, stoplineno=0)

Protected method to update the frame pointers.

stopframe (frame object)
  the frame object where to stop
returnframe (frame object)
  the frame object where to stop on a function return
stoplineno (int)
  line number to stop at. If stoplineno is greater than or equal to 0, then stop at line greater than or equal to the stopline. If stoplineno is -1, then don't stop at all.

#### DebugBase.bootstrap

bootstrap(target, args, kwargs)

Public method to bootstrap a thread.

It wraps the call to the user function to enable tracing before hand.

target (function pointer)
  function which is called in the new created thread
args (tuple)
  arguments to pass to target
kwargs (dict)
  keyword arguments to pass to target

#### DebugBase.break_here

break_here(frame)

Public method reimplemented from bdb.py to fix the filename from the frame.

See fix_frame_filename for more info.

frame (frame object)
  the frame object

Return:
  flag indicating the break status

Return Type:
  bool

#### DebugBase.fix_frame_filename

fix_frame_filename(frame)

Public method used to fixup the filename for a given frame.

The logic employed here is that if a module was loaded from a .pyc file, then the correct .py to operate with should be in the same path as the .pyc. The reason this logic is needed is that when a .pyc file is generated, the filename embedded and thus what is readable in the code object of the frame object is the fully qualified filepath when the pyc is generated. If files are moved from machine to machine this can break debugging as the .pyc will refer to the .py on the original machine. Another case might be sharing code over a network... This logic deals with that.

frame (frame object)
  the frame object

Return:
  fixed up file name

Return Type:
  str

#### DebugBase.getFrame

getFrame(frmnr=0)

Public method to return the frame "frmnr" down the stack.

frmnr (int)
  distance of frames down the stack. 0 is the current frame

Return:
  the current frame

Return Type:
  frame object

#### DebugBase.getFrameLocals

getFrameLocals(frmnr=0)

Public method to return the locals dictionary of the current frame or a frame below.

frmnr (int)
  distance of frame to get locals dictionary of. 0 is the current frame

Return:
  locals dictionary of the frame

Return Type:
  dict

#### DebugBase.getStack

getStack(frame=None, applyTrace=False)

Public method to get the stack.

frame (frame object or list)
  frame object to inspect
applyTrace (bool)
  flag to assign trace function to fr.f_trace

Return:
  list of lists with file name, line number, function name and function arguments

Return Type:
  list of list of [str, int, str, str]

#### DebugBase.go

go(special)

Public method to resume the thread.

It resumes the thread stopping only at breakpoints or exceptions.

special (bool)
  flag indicating a special continue operation

#### DebugBase.move_instruction_pointer

move_instruction_pointer(lineno)

Public method to move the instruction pointer to another line.

lineno (int)
  new line number

#### DebugBase.profile

profile(frame, event, arg)

Public method used to trace some stuff independent of the debugger trace function.

frame (frame object)
  current stack frame
event (str)
  trace event
arg (depends on the previous event parameter)
  arguments

#### DebugBase.profileWithRecursion

profileWithRecursion(frame, event, arg)

Public method used to trace some stuff independent of the debugger trace function.

frame (frame object)
  current stack frame
event (str)
  trace event
arg (depends on the previous event parameter)
  arguments

Raises RuntimeError:
  raised to indicate too many recursions

#### DebugBase.run

run(cmd, globalsDict=None, localsDict=None, debug=True, closeSession=True)

Public method to start a given command under debugger control.

cmd (str or CodeType)
  command / code to execute under debugger control
globalsDict (dict)
  dictionary of global variables for cmd
localsDict (dict)
  dictionary of local variables for cmd
debug (bool)
  flag if command should run under debugger control
closeSession (bool)
  flag indicating to close the debugger session at exit

Return:
  exit code of the program

Return Type:
  int

#### DebugBase.setRecursionDepth

setRecursionDepth(frame)

Public method to determine the current recursion depth.

frame (frame object)
  The current stack frame.

#### DebugBase.set_continue

set_continue(special)

Public method to stop only on next breakpoint.

special (bool)
  flag indicating a special continue operation

#### DebugBase.set_next

set_next(frame)

Public method to stop on the next line in or below the given frame.

frame (frame object)
  the frame object

#### DebugBase.set_quit

set_quit()

Public method to quit.

Disables the trace functions and resets all frame pointer.

#### DebugBase.set_return

set_return(frame)

Public method to stop when returning from the given frame.

frame (frame object)
  the frame object

#### DebugBase.set_step

set_step()

Public method to stop after one line of code.

#### DebugBase.set_trace

set_trace(frame=None)

Public method to start debugging from 'frame'.

If frame is not specified, debugging starts from caller's frame. Because of jump optimizations it's not possible to use sys.breakpoint() as last instruction in a function or method.

frame (frame object)
  frame to start debugging from

#### DebugBase.set_until

set_until(frame=None, lineno=None)

Public method to stop when the line with the lineno greater than the current one is reached or when returning from current frame.

frame (frame object)
  reference to the frame object
lineno (int)
  line number to continue to

#### DebugBase.step

step(traceMode)

Public method to perform a step operation in this thread.

traceMode (bool)
  If it is True, then the step is a step into, otherwise it is a step over.

#### DebugBase.stepOut

stepOut()

Public method to perform a step out of the current call.

#### DebugBase.stop_here

stop_here(frame)

Public method reimplemented to filter out debugger files.

Tracing is turned off for files that are part of the debugger that are called from the application being debugged.

frame (frame object)
  the frame object

Return:
  flag indicating whether the debugger should stop here

Return Type:
  bool

#### DebugBase.storeFrameLocals

storeFrameLocals(frmnr=0)

Public method to store the locals into the frame, so an access to frame.f_locals returns the last data.

frmnr (int)
  distance of frame to store locals dictionary to. 0 is the current frame

#### DebugBase.tracePythonLibs

tracePythonLibs(enable)

Public method to update the settings to trace into Python libraries.

enable (bool)
  flag to debug into Python libraries

#### DebugBase.trace_dispatch

trace_dispatch(frame, event, arg)

Public method reimplemented from bdb.py to do some special things.

This specialty is to check the connection to the debug server for new events (i.e. new breakpoints) while we are going through the code.

frame (frame object)
  The current stack frame
event (str)
  The trace event
arg (depends on the previous event parameter)
  The arguments

Return:
  local trace function

Return Type:
  trace function or None

Raises SystemExit:

#### DebugBase.user_exception

user_exception(excinfo, unhandled=False)

Public method reimplemented to report an exception to the debug server.

excinfo (tuple(Exception, excval object, traceback frame object))
  details about the exception
unhandled (bool)
  flag indicating an uncaught exception

#### DebugBase.user_line

user_line(frame)

Public method reimplemented to handle the program about to execute a particular line.

frame (frame object)
  reference to the frame object

Up

## printerr

printerr(s)

Module function used for debugging the debug client.

s (str)
  data to be printed

Up

## setRecursionLimit

setRecursionLimit(limit)

Module function to set the recursion limit.

limit (int)
  recursion limit

Up