Skip to content

Commit 53f565d

Browse files
committed
---
yaml --- r: 177062 b: refs/heads/auto c: f697a06 h: refs/heads/master v: v3
1 parent 2a457fd commit 53f565d

File tree

2 files changed

+113
-107
lines changed

2 files changed

+113
-107
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 958dea1745b9000becaeed728f78daec3b9c13ba
13+
refs/heads/auto: f697a06da43374c94a20bbc9e60ed45c4bda6fd4
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/etc/lldb_batchmode.py

Lines changed: 112 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,35 @@
3030
import threading
3131
import thread
3232
import re
33-
import atexit
3433
import time
3534

3635
# Set this to True for additional output
3736
DEBUG_OUTPUT = False
3837

38+
3939
def print_debug(s):
40-
"Print something if DEBUG_OUTPUT is True"
41-
global DEBUG_OUTPUT
42-
if DEBUG_OUTPUT:
43-
print("DEBUG: " + str(s))
40+
"Print something if DEBUG_OUTPUT is True"
41+
global DEBUG_OUTPUT
42+
if DEBUG_OUTPUT:
43+
print("DEBUG: " + str(s))
4444

4545

4646
def normalize_whitespace(s):
47-
"Replace newlines, tabs, multiple spaces, etc with exactly one space"
48-
return re.sub("\s+", " ", s)
47+
"Replace newlines, tabs, multiple spaces, etc with exactly one space"
48+
return re.sub("\s+", " ", s)
4949

5050

51-
# This callback is registered with every breakpoint and makes sure that the frame containing the
52-
# breakpoint location is selected
5351
def breakpoint_callback(frame, bp_loc, dict):
54-
"Called whenever a breakpoint is hit"
55-
print("Hit breakpoint " + str(bp_loc))
52+
"""This callback is registered with every breakpoint and makes sure that the
53+
frame containing the breakpoint location is selected"""
54+
print("Hit breakpoint " + str(bp_loc))
5655

57-
# Select the frame and the thread containing it
58-
frame.thread.process.SetSelectedThread(frame.thread)
59-
frame.thread.SetSelectedFrame(frame.idx)
56+
# Select the frame and the thread containing it
57+
frame.thread.process.SetSelectedThread(frame.thread)
58+
frame.thread.SetSelectedFrame(frame.idx)
6059

61-
# Returning True means that we actually want to stop at this breakpoint
62-
return True
60+
# Returning True means that we actually want to stop at this breakpoint
61+
return True
6362

6463

6564
# This is a list of breakpoints that are not registered with the breakpoint callback. The list is
@@ -70,91 +69,99 @@ def breakpoint_callback(frame, bp_loc, dict):
7069
# used to avoid hooking callbacks into breakpoints more than once
7170
registered_breakpoints = set()
7271

72+
7373
def execute_command(command_interpreter, command):
74-
"Executes a single CLI command"
75-
global new_breakpoints
76-
global registered_breakpoints
77-
78-
res = lldb.SBCommandReturnObject()
79-
print(command)
80-
command_interpreter.HandleCommand(command, res)
81-
82-
if res.Succeeded():
83-
if res.HasResult():
84-
print(normalize_whitespace(res.GetOutput()), end = '\n')
85-
86-
# If the command introduced any breakpoints, make sure to register them with the breakpoint
87-
# callback
88-
while len(new_breakpoints) > 0:
89-
res.Clear()
90-
breakpoint_id = new_breakpoints.pop()
91-
92-
if breakpoint_id in registered_breakpoints:
93-
print_debug("breakpoint with id %s is already registered. Ignoring." % str(breakpoint_id))
94-
else:
95-
print_debug("registering breakpoint callback, id = " + str(breakpoint_id))
96-
callback_command = "breakpoint command add -F breakpoint_callback " + str(breakpoint_id)
97-
command_interpreter.HandleCommand(callback_command, res)
98-
if res.Succeeded():
99-
print_debug("successfully registered breakpoint callback, id = " + str(breakpoint_id))
100-
registered_breakpoints.add(breakpoint_id)
101-
else:
102-
print("Error while trying to register breakpoint callback, id = " + str(breakpoint_id))
103-
else:
104-
print(res.GetError())
74+
"Executes a single CLI command"
75+
global new_breakpoints
76+
global registered_breakpoints
77+
78+
res = lldb.SBCommandReturnObject()
79+
print(command)
80+
command_interpreter.HandleCommand(command, res)
81+
82+
if res.Succeeded():
83+
if res.HasResult():
84+
print(normalize_whitespace(res.GetOutput()), end='\n')
85+
86+
# If the command introduced any breakpoints, make sure to register
87+
# them with the breakpoint
88+
# callback
89+
while len(new_breakpoints) > 0:
90+
res.Clear()
91+
breakpoint_id = new_breakpoints.pop()
92+
93+
if breakpoint_id in registered_breakpoints:
94+
print_debug("breakpoint with id %s is already registered. Ignoring." %
95+
str(breakpoint_id))
96+
else:
97+
print_debug("registering breakpoint callback, id = " + str(breakpoint_id))
98+
callback_command = ("breakpoint command add -F breakpoint_callback " +
99+
str(breakpoint_id))
100+
command_interpreter.HandleCommand(callback_command, res)
101+
if res.Succeeded():
102+
print_debug("successfully registered breakpoint callback, id = " +
103+
str(breakpoint_id))
104+
registered_breakpoints.add(breakpoint_id)
105+
else:
106+
print("Error while trying to register breakpoint callback, id = " +
107+
str(breakpoint_id))
108+
else:
109+
print(res.GetError())
105110

106111

107112
def start_breakpoint_listener(target):
108-
"Listens for breakpoints being added and adds new ones to the callback registration list"
109-
listener = lldb.SBListener("breakpoint listener")
110-
111-
def listen():
112-
event = lldb.SBEvent()
113-
try:
114-
while True:
115-
if listener.WaitForEvent(120, event):
116-
if lldb.SBBreakpoint.EventIsBreakpointEvent(event) and \
117-
lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent(event) == \
118-
lldb.eBreakpointEventTypeAdded:
119-
global new_breakpoints
120-
breakpoint = lldb.SBBreakpoint.GetBreakpointFromEvent(event)
121-
print_debug("breakpoint added, id = " + str(breakpoint.id))
122-
new_breakpoints.append(breakpoint.id)
123-
except:
124-
print_debug("breakpoint listener shutting down")
125-
126-
# Start the listener and let it run as a daemon
127-
listener_thread = threading.Thread(target = listen)
128-
listener_thread.daemon = True
129-
listener_thread.start()
130-
131-
# Register the listener with the target
132-
target.GetBroadcaster().AddListener(listener, lldb.SBTarget.eBroadcastBitBreakpointChanged)
113+
"""Listens for breakpoints being added and adds new ones to the callback
114+
registration list"""
115+
listener = lldb.SBListener("breakpoint listener")
116+
117+
def listen():
118+
event = lldb.SBEvent()
119+
try:
120+
while True:
121+
if listener.WaitForEvent(120, event):
122+
if lldb.SBBreakpoint.EventIsBreakpointEvent(event) and \
123+
lldb.SBBreakpoint.GetBreakpointEventTypeFromEvent(event) == \
124+
lldb.eBreakpointEventTypeAdded:
125+
global new_breakpoints
126+
breakpoint = lldb.SBBreakpoint.GetBreakpointFromEvent(event)
127+
print_debug("breakpoint added, id = " + str(breakpoint.id))
128+
new_breakpoints.append(breakpoint.id)
129+
except:
130+
print_debug("breakpoint listener shutting down")
131+
132+
# Start the listener and let it run as a daemon
133+
listener_thread = threading.Thread(target=listen)
134+
listener_thread.daemon = True
135+
listener_thread.start()
136+
137+
# Register the listener with the target
138+
target.GetBroadcaster().AddListener(listener, lldb.SBTarget.eBroadcastBitBreakpointChanged)
133139

134140

135141
def start_watchdog():
136-
"Starts a watchdog thread that will terminate the process after a certain period of time"
137-
watchdog_start_time = time.clock()
138-
watchdog_max_time = watchdog_start_time + 30
139-
140-
def watchdog():
141-
while time.clock() < watchdog_max_time:
142-
time.sleep(1)
143-
print("TIMEOUT: lldb_batchmode.py has been running for too long. Aborting!")
144-
thread.interrupt_main()
145-
146-
# Start the listener and let it run as a daemon
147-
watchdog_thread = threading.Thread(target = watchdog)
148-
watchdog_thread.daemon = True
149-
watchdog_thread.start()
142+
"""Starts a watchdog thread that will terminate the process after a certain
143+
period of time"""
144+
watchdog_start_time = time.clock()
145+
watchdog_max_time = watchdog_start_time + 30
146+
147+
def watchdog():
148+
while time.clock() < watchdog_max_time:
149+
time.sleep(1)
150+
print("TIMEOUT: lldb_batchmode.py has been running for too long. Aborting!")
151+
thread.interrupt_main()
152+
153+
# Start the listener and let it run as a daemon
154+
watchdog_thread = threading.Thread(target=watchdog)
155+
watchdog_thread.daemon = True
156+
watchdog_thread.start()
150157

151158
####################################################################################################
152159
# ~main
153160
####################################################################################################
154161

155162
if len(sys.argv) != 3:
156-
print("usage: python lldb_batchmode.py target-path script-path")
157-
sys.exit(1)
163+
print("usage: python lldb_batchmode.py target-path script-path")
164+
sys.exit(1)
158165

159166
target_path = sys.argv[1]
160167
script_path = sys.argv[2]
@@ -181,9 +188,9 @@ def watchdog():
181188
target = debugger.CreateTarget(target_path, None, None, True, target_error)
182189

183190
if not target:
184-
print("Could not create debugging target '" + target_path + "': " + str(target_error) +
185-
". Aborting.", file=sys.stderr)
186-
sys.exit(1)
191+
print("Could not create debugging target '" + target_path + "': " +
192+
str(target_error) + ". Aborting.", file=sys.stderr)
193+
sys.exit(1)
187194

188195

189196
# Register the breakpoint callback for every breakpoint
@@ -192,22 +199,21 @@ def watchdog():
192199
command_interpreter = debugger.GetCommandInterpreter()
193200

194201
try:
195-
script_file = open(script_path, 'r')
202+
script_file = open(script_path, 'r')
196203

197-
for line in script_file:
198-
command = line.strip()
199-
if command == "run" or command == "r" or re.match("^process\s+launch.*", command):
200-
# Before starting to run the program, let the thread sleep a bit, so all
201-
# breakpoint added events can be processed
202-
time.sleep(0.5)
203-
if command != '':
204-
execute_command(command_interpreter, command)
204+
for line in script_file:
205+
command = line.strip()
206+
if command == "run" or command == "r" or re.match("^process\s+launch.*", command):
207+
# Before starting to run the program, let the thread sleep a bit, so all
208+
# breakpoint added events can be processed
209+
time.sleep(0.5)
210+
if command != '':
211+
execute_command(command_interpreter, command)
205212

206213
except IOError as e:
207-
print("Could not read debugging script '%s'." % script_path, file = sys.stderr)
208-
print(e, file = sys.stderr)
209-
print("Aborting.", file = sys.stderr)
210-
sys.exit(1)
214+
print("Could not read debugging script '%s'." % script_path, file=sys.stderr)
215+
print(e, file=sys.stderr)
216+
print("Aborting.", file=sys.stderr)
217+
sys.exit(1)
211218
finally:
212-
script_file.close()
213-
219+
script_file.close()

0 commit comments

Comments
 (0)