1
Fork 0

Fix PEP8 in lldb_batchmode.py

This commit is contained in:
Richo Healey 2015-01-27 00:12:06 -08:00
parent 958dea1745
commit f697a06da4

View file

@ -30,12 +30,12 @@ import sys
import threading import threading
import thread import thread
import re import re
import atexit
import time import time
# Set this to True for additional output # Set this to True for additional output
DEBUG_OUTPUT = False DEBUG_OUTPUT = False
def print_debug(s): def print_debug(s):
"Print something if DEBUG_OUTPUT is True" "Print something if DEBUG_OUTPUT is True"
global DEBUG_OUTPUT global DEBUG_OUTPUT
@ -48,10 +48,9 @@ def normalize_whitespace(s):
return re.sub("\s+", " ", s) return re.sub("\s+", " ", s)
# This callback is registered with every breakpoint and makes sure that the frame containing the
# breakpoint location is selected
def breakpoint_callback(frame, bp_loc, dict): def breakpoint_callback(frame, bp_loc, dict):
"Called whenever a breakpoint is hit" """This callback is registered with every breakpoint and makes sure that the
frame containing the breakpoint location is selected"""
print("Hit breakpoint " + str(bp_loc)) print("Hit breakpoint " + str(bp_loc))
# Select the frame and the thread containing it # Select the frame and the thread containing it
@ -70,6 +69,7 @@ new_breakpoints = []
# used to avoid hooking callbacks into breakpoints more than once # used to avoid hooking callbacks into breakpoints more than once
registered_breakpoints = set() registered_breakpoints = set()
def execute_command(command_interpreter, command): def execute_command(command_interpreter, command):
"Executes a single CLI command" "Executes a single CLI command"
global new_breakpoints global new_breakpoints
@ -83,29 +83,35 @@ def execute_command(command_interpreter, command):
if res.HasResult(): if res.HasResult():
print(normalize_whitespace(res.GetOutput()), end='\n') print(normalize_whitespace(res.GetOutput()), end='\n')
# If the command introduced any breakpoints, make sure to register them with the breakpoint # If the command introduced any breakpoints, make sure to register
# them with the breakpoint
# callback # callback
while len(new_breakpoints) > 0: while len(new_breakpoints) > 0:
res.Clear() res.Clear()
breakpoint_id = new_breakpoints.pop() breakpoint_id = new_breakpoints.pop()
if breakpoint_id in registered_breakpoints: if breakpoint_id in registered_breakpoints:
print_debug("breakpoint with id %s is already registered. Ignoring." % str(breakpoint_id)) print_debug("breakpoint with id %s is already registered. Ignoring." %
str(breakpoint_id))
else: else:
print_debug("registering breakpoint callback, id = " + str(breakpoint_id)) print_debug("registering breakpoint callback, id = " + str(breakpoint_id))
callback_command = "breakpoint command add -F breakpoint_callback " + str(breakpoint_id) callback_command = ("breakpoint command add -F breakpoint_callback " +
str(breakpoint_id))
command_interpreter.HandleCommand(callback_command, res) command_interpreter.HandleCommand(callback_command, res)
if res.Succeeded(): if res.Succeeded():
print_debug("successfully registered breakpoint callback, id = " + str(breakpoint_id)) print_debug("successfully registered breakpoint callback, id = " +
str(breakpoint_id))
registered_breakpoints.add(breakpoint_id) registered_breakpoints.add(breakpoint_id)
else: else:
print("Error while trying to register breakpoint callback, id = " + str(breakpoint_id)) print("Error while trying to register breakpoint callback, id = " +
str(breakpoint_id))
else: else:
print(res.GetError()) print(res.GetError())
def start_breakpoint_listener(target): def start_breakpoint_listener(target):
"Listens for breakpoints being added and adds new ones to the callback registration list" """Listens for breakpoints being added and adds new ones to the callback
registration list"""
listener = lldb.SBListener("breakpoint listener") listener = lldb.SBListener("breakpoint listener")
def listen(): def listen():
@ -133,7 +139,8 @@ def start_breakpoint_listener(target):
def start_watchdog(): def start_watchdog():
"Starts a watchdog thread that will terminate the process after a certain period of time" """Starts a watchdog thread that will terminate the process after a certain
period of time"""
watchdog_start_time = time.clock() watchdog_start_time = time.clock()
watchdog_max_time = watchdog_start_time + 30 watchdog_max_time = watchdog_start_time + 30
@ -181,8 +188,8 @@ target_error = lldb.SBError()
target = debugger.CreateTarget(target_path, None, None, True, target_error) target = debugger.CreateTarget(target_path, None, None, True, target_error)
if not target: if not target:
print("Could not create debugging target '" + target_path + "': " + str(target_error) + print("Could not create debugging target '" + target_path + "': " +
". Aborting.", file=sys.stderr) str(target_error) + ". Aborting.", file=sys.stderr)
sys.exit(1) sys.exit(1)
@ -210,4 +217,3 @@ except IOError as e:
sys.exit(1) sys.exit(1)
finally: finally:
script_file.close() script_file.close()