Table of Contents

Class: DebugClient ./Debugger/DebugClientThreads.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
Methods   
__init__
absPath
attachThread
connectDebugger
dumpVariables
eventLoop
formatVariablesList
getRunning
handleException
handleLine
interact
lockClient
progTerminated
raw_input
sessionClose
setCurrentThread
set_quit
shouldSkip
startDebugger
threadTerminated
unhandled_exception
unlockClient
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)

  attachThread 
attachThread (
        self,
        target=None,
        args=None,
        kwargs=None,
        mainThread=0,
        )

Public method to setup a thread for DebugClient to debug.

If mainThread is non-zero, then we are attaching to the already started mainthread of the app and the rest of the args are ignored.

Arguments

target
the start function of the target thread (i.e. the user code)
args
arguments to pass to target
kwargs
keyword arguments to pass to target
mainThread
non-zero, if we are attaching to the already started mainthread of the app

Returns

The identifier of the created thread

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

  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.

  getRunning 
getRunning ( self )

Public method to return the main script we are currently running.

  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.

Returns

Never

  lockClient 
lockClient ( self )

Public method to acquire the lock for this client.

  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.

  setCurrentThread 
setCurrentThread ( self,  id )

Private method to set the current thread.

Arguments

id
the id the current thread should be set to.
  set_quit 
set_quit ( self )

Private method to do a set quit on all threads.

  shouldSkip 
shouldSkip ( self,  fn )

Public method to check if a file should be skipped.

Arguments

fn
filename to be checked

Returns non-zero if fn represents a file we are skipping, zero otherwise.

  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)
  threadTerminated 
threadTerminated ( self,  dbgThread )

Public method called when a DebugThread has exited.

Arguments

dbgThread
the DebugThread that has exited
  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
  unlockClient 
unlockClient ( self )

Public method to release the lock for this client.

  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