# eric3.Debugger.DebugClientBase

Module implementing a debug client base class.

### Classes

DebugClientBase | Class implementing the client side of the debugger.

### Functions

DebugClientInput | Replacement for the standard input builtin.
DebugClientRawInput | Replacement for the standard raw_input builtin.

## DebugClientBase

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. Note: This class is meant to be subclassed by individual DebugClient classes. Do not instantiate it directly.

### Derived from

None

### Methods

DebugClientBase | Constructor
absPath | Private method to convert a filename to an absolute name.
attachThread | Public method to setup a thread for DebugClient to debug.
completionList | Private slot to handle the request for a commandline completion list.
connectDebugger | Public method to establish a session with the debugger.
dumpVariable | Private method to return the variables of a frame to the debug server.
dumpVariables | Private method to return the variables of a frame to the debug server.
eventLoop | Private method implementing our event loop.
eventPoll | Private method to poll for events like 'set break point'.
formatQtVariable | Private method to produce a formated output of a simple Qt type.
formatVariablesList | Private method to produce a formated variables list.
generateFilterObjects | Private slot to convert a filter string to a list of filter objects.
getRunning | Public method to return the main script we are currently running.
get_coding | Function to get the coding of a python file.
handleException | Private method called in the case of an exception
handleLine | Private method to handle the receipt of a complete line.
input | Public method to implement input() using the event loop.
interact | Private method to Interact with the debugger.
main | Public method implementing the main method.
progTerminated | Private method to tell the debugger that the program has terminated.
raw_input | Public method to implement raw_input() using the event loop.
run_call | Public method used to start the remote debugger and call a function.
sessionClose | Private method to close the session with the debugger and terminate.
shouldSkip | Public method to check if a file should be skipped.
startDebugger | Method used to start the remote debugger.
startProgInDebugger | Method used to start the remote debugger.
unhandled_exception | Private method called to report an uncaught exception.
write | Private method to write data to the output stream.

### DebugClientBase (Constructor)

DebugClientBase()

Constructor

### DebugClientBase.absPath

absPath(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.

fn
  filename (string)

Returns:
  the converted filename (string)

### DebugClientBase.attachThread

attachThread(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. This is just an empty function and is overridden in the threaded debugger.

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
target
  the start function of the target thread (i.e. the user code)

Returns:
  The identifier of the created thread

### DebugClientBase.completionList

completionList(text)

Private slot to handle the request for a commandline completion list.

text
  the text to be completed (string)

### DebugClientBase.connectDebugger

connectDebugger(port, remoteAddress=None, redirect=1)

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.

port
  the port number to connect to (int)
redirect
  flag indicating redirection of stdin, stdout and stderr (boolean)
remoteAddress
  the network address of the debug server host (string)

### DebugClientBase.dumpVariable

dumpVariable(var, frmnr, scope, filter)

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

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

### DebugClientBase.dumpVariables

dumpVariables(frmnr, scope, filter)

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

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

### DebugClientBase.eventLoop

eventLoop()

Private method implementing our event loop.

### DebugClientBase.eventPoll

eventPoll()

Private method to poll for events like 'set break point'.

### DebugClientBase.formatQtVariable

formatQtVariable(value)

Private method to produce a formated output of a simple Qt type.

value
  variable to be formated

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

### DebugClientBase.formatVariablesList

formatVariablesList(keylist, dict, scope, filter = [], formatSequences = 0)

Private method to produce a formated variables list. The dictionary passed in to it is scanned. Variables are only added to the list, if their type is not contained in the filter list and their name doesn't match any of the filter expressions. The formated variables list (a list of tuples of 3 values) is returned.

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.
formatSequences
  flag indicating, that sequence or dictionary variables should be formatted. If it is 0 (or false), just the number of items contained in these variables is returned. (boolean)
keylist
  keys of the dictionary
scope
  1 to filter using the globals filter, 0 using the locals filter (int). Variables are only added to the list, if their name do not match any of the filter expressions.

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

### DebugClientBase.generateFilterObjects

generateFilterObjects(scope, filterString)

Private slot to convert a filter string to a list of filter objects.

filterString
  string of filter patterns separated by ';'
scope
  1 to generate filter for global variables, 0 for local variables (int)

### DebugClientBase.getRunning

getRunning()

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

### DebugClientBase.get_coding

get_coding(filename)

Function to get the coding of a python file.

filename
  name of the file to inspect (string)

Returns:
  coding string (default utf-8)

### DebugClientBase.handleException

handleException()

Private method called in the case of an exception It ensures that the debug server is informed of the raised exception.

### DebugClientBase.handleLine

handleLine(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.

line
  the received line

### DebugClientBase.input

input(prompt)

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

prompt
  the prompt to be shown (string)

Returns:
  the entered string evaluated as a Python expresion

### DebugClientBase.interact

interact()

Private method to Interact with the debugger.

### DebugClientBase.main

main()

Public method implementing the main method.

### DebugClientBase.progTerminated

progTerminated(status)

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

status
  the return status

### DebugClientBase.raw_input

raw_input(prompt, echo)

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

echo
  Flag indicating echoing of the input (boolean)
prompt
  the prompt to be shown (string)

Returns:
  the entered string

### DebugClientBase.run_call

run_call(scriptname, func, *args)

Public method used to start the remote debugger and call a function.

*args
  arguments being passed to func
func
  function to be called
scriptname
  name of the script to be debugged (string)

Returns:
  result of the function call

### DebugClientBase.sessionClose

sessionClose()

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

### DebugClientBase.shouldSkip

shouldSkip(fn)

Public method to check if a file should be skipped.

fn
  filename to be checked

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

### DebugClientBase.startDebugger

startDebugger(filename=None, host=None, port=None, enableTrace=1, exceptions=1)

Method used to start the remote debugger.

enableTrace
  flag to enable the tracing function (boolean)
exceptions
  flag to enable exception reporting of the IDE (boolean)
filename
  the program to be debugged (string)
host
  hostname of the debug server (string)
port
  portnumber of the debug server (int)

### DebugClientBase.startProgInDebugger

startProgInDebugger(progargs, wd = '', host=None, port=None, exceptions=1, tracePython=0, redirect=1)

Method used to start the remote debugger.

exceptions
  flag to enable exception reporting of the IDE (boolean)
host
  hostname of the debug server (string)
port
  portnumber of the debug server (int)
progargs
  commandline for the program to be debugged (list of strings)
redirect
  flag indicating redirection of stdin, stdout and stderr (boolean)
tracePython
  flag to enable tracing into the Python library (boolean)
wd
  working directory for the program execution (string)

### DebugClientBase.unhandled_exception

unhandled_exception(exctype, excval, exctb)

Private method called to report an uncaught exception.

exctb
  traceback for the exception
exctype
  the type of the exception
excval
  data about the exception

### DebugClientBase.write

write(s)

Private method to write data to the output stream.

s
  data to be written (string)

Up

## DebugClientInput

DebugClientInput(prompt="")

Replacement for the standard input builtin. This function works with the split debugger.

prompt
  The prompt to be shown. (string)

Up

## DebugClientRawInput

DebugClientRawInput(prompt="", echo=1)

Replacement for the standard raw_input builtin. This function works with the split debugger.

echo
  Flag indicating echoing of the input (boolean)
prompt
  The prompt to be shown. (string)

Up