Table of Contents

Class: DebugClient ./Debugger/DebugClient.py

Class implementing the client side of the debugger.

It provides access to the Python interpeter from a debugger running in another process whether or not the Qt event loop is running.

The protocol between the debugger and the client assumes that there will be a single source of debugger commands and a single source of Python statements. Commands and statement are always exactly one line and may be interspersed.

The protocol is as follows. First the client opens a connection to the debugger and then sends a series of one line commands. A command is either >Load<, >Step<, >StepInto<, ... or a Python statement. See DebugProtocol.py for a listing of valid protocol tokens.

A Python statement consists of the statement to execute, followed (in a separate line) by >OK?<. If the statement was incomplete then the response is >Continue<. If there was an exception then the response is >Exception<. Otherwise the response is >OK<. The reason for the >OK?< part is to provide a sentinal (ie. the responding >OK<) after any possible output as a result of executing the command.

The client may send any other lines at any other time which should be interpreted as program output.

If the debugger closes the session there is no response from the client. The client may close the session at any time as a result of the script being debugged closing or crashing.

Base Classes   
AsyncIO
bdb.Bdb
Methods   
__init__
absPath
break_anywhere
break_here
connectDebugger
dispatch_exception
dispatch_return
dumpVariables
eventLoop
extract_stack
fix_frame_filename
formatVariablesList
handleException
handleLine
interact
progTerminated
raw_input
sessionClose
set_continue
startDebugger
stop_here
unhandled_exception
user_exception
user_line
user_return
write
  __init__ 
__init__ ( self )

Constructor

  absPath 
absPath ( self,  fn )

Private method to convert a filename to an absolute name.

sys.path is used as a set of possible prefixes. The name stays relative if a file could not be found.

Arguments

fn
filename (string)

Returns

the converted filename (string)

  break_anywhere 
break_anywhere ( self,  frame )

Reimplemented from bdb.py to fix the filename from the frame.

See fix_frame_filename for more info.

Arguments

frame
the frame object

Returns

flag indicating the break status (boolean)

  break_here 
break_here ( self,  frame )

Reimplemented from bdb.py to fix the filename from the frame.

See fix_frame_filename for more info.

Arguments

frame
the frame object

Returns

flag indicating the break status (boolean)

  connectDebugger 
connectDebugger (
        self,
        port,
        remoteAddress=None,
        )

Public method to establish a session with the debugger.

It opens a network connection to the debugger, connects it to stdin, stdout and stderr and saves these file objects in case the application being debugged redirects them itself.

Arguments

port
the port number to connect to (int)
remoteAddress
the network address of the debug server host (string)
  dispatch_exception 
dispatch_exception (
        self,
        frame,
        arg,
        )

Reimplemented from bdb.py to always call user_exception.

Exceptions   
bdb.BdbQuit
  dispatch_return 
dispatch_return (
        self,
        frame,
        arg,
        )

Reimplemented from bdb.py to handle passive mode cleanly.

Exceptions   
bdb.BdbQuit
  dumpVariables 
dumpVariables (
        self,
        frmnr,
        scope,
        filter,
        )

Private method to return the variables of a frame to the debug server.

Arguments

frmnr
distance of frame reported on. 0 is the current frame (int)
scope
1 to report global variables, 0 for local variables (int)
filter
the indices of variable types to be filtered (list of int)
  eventLoop 
eventLoop ( self )

Private method implementing our event loop.

  extract_stack 
extract_stack ( self,  exctb )

Protected member to return a list of stack frames.

Arguments

exctb
exception traceback

Returns

list of stack frames

  fix_frame_filename 
fix_frame_filename ( self,  frame )

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

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

Arguments

frame
the frame object
  formatVariablesList 
formatVariablesList (
        self,
        keylist,
        dict,
        filter=[],
        classdict=0,
        prefix='',
        )

Private method to produce a formated variables list.

The dictionary passed in to it is scanned. If classdict is false, it builds a list of all class instances in dict. If it is true, we are formatting a class dictionary. In this case we prepend prefix to the variable names. Variables are only added to the list, if their type is not contained in the filter list. The formated variables list (a list of tuples of 3 values) and the list of class instances is returned.

Arguments

keylist
keys of the dictionary
dict
the dictionary to be scanned
filter
the indices of variable types to be filtered. Variables are only added to the list, if their type is not contained in the filter list.
classdict
boolean indicating the formating of a class or module dictionary. If classdict is false, it builds a list of all class instances in dict. If it is true, we are formatting a class dictionary. In this case we prepend prefix to the variable names.
prefix
prefix to prepend to the variable names (string)

Returns

A tuple consisting of a list of formatted variables and a list of class instances. Each variable entry is a tuple of three elements, the variable name, its type and value.

  handleException 
handleException ( self )

Private method called in the case of an exception

It ensures that the debug server is informed of the raised exception.

  handleLine 
handleLine ( self,  line )

Private method to handle the receipt of a complete line.

It first looks for a valid protocol token at the start of the line. Thereafter it trys to execute the lines accumulated so far.

Arguments

line
the received line
  interact 
interact ( self )

Private method to Interact with the debugger.

  progTerminated 
progTerminated ( self,  status )

Private method to tell the debugger that the program has terminated.

Arguments

status
the return status
  raw_input 
raw_input ( self,  prompt )

Public method to implement raw_input() using the event loop.

Arguments

prompt
the prompt to be shown (string)

Returns the entered string

  sessionClose 
sessionClose ( self )

Private method to close the session with the debugger and terminate.

  set_continue 
set_continue ( self )

Reimplemented from bdb.py to always get informed of exceptions.

  startDebugger 
startDebugger (
        self,
        filename=None,
        host=None,
        port=None,
        )

Method used to start the remote debugger.

Arguments

filename
the program to be debugged (string)
host
hostname of the debug server (string)
port
portnumber of the debug server (int)
  stop_here 
stop_here ( self,  frame )

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.

Arguments

frame
the frame object

Returns

flag indicating whether the debugger should stop here

  unhandled_exception 
unhandled_exception (
        self,
        exctype,
        excval,
        exctb,
        )

Private method called to report an uncaught exception.

Arguments

exctype
the type of the exception
excval
data about the exception
exctb
traceback for the exception
  user_exception 
user_exception (
        self,
        frame,
        (,
        unhandled=0,
        )

Reimplemented to report an exception to the debug server.

Arguments

frame
the frame object
exctype
the type of the exception
excval
data about the exception
exctb
traceback for the exception
unhandled
flag indicating an uncaught exception
  user_line 
user_line ( self,  frame )

Reimplemented to handle the program about to execute a particular line.

Arguments

frame
the frame object
  user_return 
user_return (
        self,
        frame,
        retval,
        )

Reimplemented to report program termination to the debug server.

Arguments

frame
the frame object
retval
the return value of the program
  write 
write ( self,  s )

Private method to write data to the output stream.

Arguments

s
data to be written (string)

Table of Contents

This document was automatically generated on Fri Mar 14 19:54:45 2003 by HappyDoc version 2.1