Skip to content

Commit 1f44fa3

Browse files
committed
Revert "[Dexter] Improve performance by evaluating expressions only when needed"
Reverted due to build failure on greendragon lldb build. This reverts commit 9bbc0c1.
1 parent cd2bff1 commit 1f44fa3

File tree

7 files changed

+26
-79
lines changed

7 files changed

+26
-79
lines changed

cross-project-tests/debuginfo-tests/dexter/dex/command/CommandBase.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
"""
1111

1212
import abc
13-
from collections import namedtuple
1413
from typing import List
1514

16-
StepExpectInfo = namedtuple('StepExpectInfo', 'expression, path, frame_idx, line_range')
17-
1815
class CommandBase(object, metaclass=abc.ABCMeta):
1916
def __init__(self):
2017
self.path = None

cross-project-tests/debuginfo-tests/dexter/dex/command/commands/DexExpectProgramState.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from itertools import chain
1212

13-
from dex.command.CommandBase import CommandBase, StepExpectInfo
13+
from dex.command.CommandBase import CommandBase
1414
from dex.dextIR import ProgramState, SourceLocation, StackFrame, DextIR
1515

1616
def frame_from_dict(source: dict) -> StackFrame:
@@ -56,23 +56,9 @@ def get_name():
5656
return __class__.__name__
5757

5858
def get_watches(self):
59-
frame_expects = set()
60-
for idx, frame in enumerate(self.expected_program_state.frames):
61-
path = (frame.location.path if
62-
frame.location and frame.location.path else self.path)
63-
line_range = (
64-
range(frame.location.lineno, frame.location.lineno + 1)
65-
if frame.location and frame.location.lineno else None)
66-
for watch in frame.watches:
67-
frame_expects.add(
68-
StepExpectInfo(
69-
expression=watch,
70-
path=path,
71-
frame_idx=idx,
72-
line_range=line_range
73-
)
74-
)
75-
return frame_expects
59+
frame_expects = chain.from_iterable(frame.watches
60+
for frame in self.expected_program_state.frames)
61+
return set(frame_expects)
7662

7763
def eval(self, step_collection: DextIR) -> bool:
7864
for step in step_collection.steps:

cross-project-tests/debuginfo-tests/dexter/dex/command/commands/DexExpectWatchBase.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
import abc
1313
import difflib
1414
import os
15-
from collections import namedtuple
1615

17-
from dex.command.CommandBase import CommandBase, StepExpectInfo
16+
from dex.command.CommandBase import CommandBase
1817
from dex.command.StepValueInfo import StepValueInfo
1918

2019

21-
2220
class DexExpectWatchBase(CommandBase):
2321
def __init__(self, *args, **kwargs):
2422
if len(args) < 2:
@@ -70,7 +68,7 @@ def __init__(self, *args, **kwargs):
7068

7169

7270
def get_watches(self):
73-
return [StepExpectInfo(self.expression, self.path, 0, range(self._from_line, self._to_line + 1))]
71+
return [self.expression]
7472

7573
@property
7674
def line_range(self):
@@ -151,11 +149,11 @@ def _check_watch_order(self, actual_watches, expected_values):
151149
return differences
152150

153151
def eval(self, step_collection):
154-
assert os.path.exists(self.path)
155152
for step in step_collection.steps:
156153
loc = step.current_location
157154

158155
if (loc.path and os.path.exists(loc.path) and
156+
os.path.exists(self.path) and
159157
os.path.samefile(loc.path, self.path) and
160158
loc.lineno in self.line_range):
161159
try:

cross-project-tests/debuginfo-tests/dexter/dex/debugger/DebuggerBase.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,11 @@
1313
import unittest
1414

1515
from types import SimpleNamespace
16-
from dex.command.CommandBase import StepExpectInfo
1716
from dex.dextIR import DebuggerIR, FrameIR, LocIR, StepIR, ValueIR
1817
from dex.utils.Exceptions import DebuggerException
1918
from dex.utils.Exceptions import NotYetLoadedDebuggerException
2019
from dex.utils.ReturnCode import ReturnCode
2120

22-
def watch_is_active(watch_info: StepExpectInfo, path, frame_idx, line_no):
23-
_, watch_path, watch_frame_idx, watch_line_range = watch_info
24-
# If this watch should only be active for a specific file...
25-
if watch_path and os.path.isfile(watch_path):
26-
# If the current path does not match the expected file, this watch is
27-
# not active.
28-
if not (path and os.path.isfile(path) and
29-
os.path.samefile(path, watch_path)):
30-
return False
31-
if watch_frame_idx != frame_idx:
32-
return False
33-
if watch_line_range and line_no not in list(watch_line_range):
34-
return False
35-
return True
3621

3722
class DebuggerBase(object, metaclass=abc.ABCMeta):
3823
def __init__(self, context):

cross-project-tests/debuginfo-tests/dexter/dex/debugger/dbgeng/dbgeng.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import platform
1111

12-
from dex.debugger.DebuggerBase import DebuggerBase, watch_is_active
12+
from dex.debugger.DebuggerBase import DebuggerBase
1313
from dex.dextIR import FrameIR, LocIR, StepIR, StopReason, ValueIR
1414
from dex.dextIR import ProgramState, StackFrame, SourceLocation
1515
from dex.utils.Exceptions import DebuggerException, LoadDebuggerException
@@ -133,14 +133,8 @@ def _get_step_info(self, watches, step_index):
133133
column=0),
134134
watches={})
135135
for expr in map(
136-
# Filter out watches that are not active in the current frame,
137-
# and then evaluate all the active watches.
138-
lambda watch_info, idx=i:
139-
self.evaluate_expression(watch_info.expression, idx),
140-
filter(
141-
lambda watch_info, idx=i, line_no=loc.lineno, path=loc.path:
142-
watch_is_active(watch_info, path, idx, line_no),
143-
watches)):
136+
lambda watch, idx=i: self.evaluate_expression(watch, idx),
137+
watches):
144138
state_frame.watches[expr.expression] = expr
145139
state_frames.append(state_frame)
146140

cross-project-tests/debuginfo-tests/dexter/dex/debugger/lldb/LLDB.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from subprocess import CalledProcessError, check_output, STDOUT
1313
import sys
1414

15-
from dex.debugger.DebuggerBase import DebuggerBase, watch_is_active
15+
from dex.debugger.DebuggerBase import DebuggerBase
1616
from dex.dextIR import FrameIR, LocIR, StepIR, StopReason, ValueIR
1717
from dex.dextIR import StackFrame, SourceLocation, ProgramState
1818
from dex.utils.Exceptions import DebuggerException, LoadDebuggerException
@@ -208,7 +208,6 @@ def _get_step_info(self, watches, step_index):
208208
'column': sb_line.GetColumn()
209209
}
210210
loc = LocIR(**loc_dict)
211-
valid_loc_for_watch = loc.path and os.path.exists(loc.path)
212211

213212
frame = FrameIR(
214213
function=function, is_inlined=sb_frame.IsInlined(), loc=loc)
@@ -224,18 +223,11 @@ def _get_step_info(self, watches, step_index):
224223
is_inlined=frame.is_inlined,
225224
location=SourceLocation(**loc_dict),
226225
watches={})
227-
if valid_loc_for_watch:
228-
for expr in map(
229-
# Filter out watches that are not active in the current frame,
230-
# and then evaluate all the active watches.
231-
lambda watch_info, idx=i:
232-
self.evaluate_expression(watch_info.expression, idx),
233-
filter(
234-
lambda watch_info, idx=i, line_no=loc.lineno, loc_path=loc.path:
235-
watch_is_active(watch_info, loc_path, idx, line_no),
236-
watches)):
237-
state_frame.watches[expr.expression] = expr
238-
state_frames.append(state_frame)
226+
for expr in map(
227+
lambda watch, idx=i: self.evaluate_expression(watch, idx),
228+
watches):
229+
state_frame.watches[expr.expression] = expr
230+
state_frames.append(state_frame)
239231

240232
if len(frames) == 1 and frames[0].function is None:
241233
frames = []

cross-project-tests/debuginfo-tests/dexter/dex/debugger/visualstudio/VisualStudio.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import os
1212
import sys
1313
from pathlib import PurePath
14-
from collections import defaultdict, namedtuple
14+
from collections import namedtuple
15+
from collections import defaultdict
1516

16-
from dex.command.CommandBase import StepExpectInfo
17-
from dex.debugger.DebuggerBase import DebuggerBase, watch_is_active
17+
from dex.debugger.DebuggerBase import DebuggerBase
1818
from dex.dextIR import FrameIR, LocIR, StepIR, StopReason, ValueIR
1919
from dex.dextIR import StackFrame, SourceLocation, ProgramState
2020
from dex.utils.Exceptions import Error, LoadDebuggerException
@@ -244,9 +244,6 @@ def _get_step_info(self, watches, step_index):
244244
state_frames = []
245245

246246

247-
loc = LocIR(**self._location)
248-
valid_loc_for_watch = loc.path and os.path.exists(loc.path)
249-
250247
for idx, sf in enumerate(stackframes):
251248
frame = FrameIR(
252249
function=self._sanitize_function_name(sf.FunctionName),
@@ -257,20 +254,20 @@ def _get_step_info(self, watches, step_index):
257254
if any(name in fname for name in self.frames_below_main):
258255
break
259256

257+
260258
state_frame = StackFrame(function=frame.function,
261259
is_inlined=frame.is_inlined,
262260
watches={})
263261

264-
if valid_loc_for_watch and idx == 0:
265-
for watch_info in watches:
266-
if watch_is_active(watch_info, loc.path, idx, loc.lineno):
267-
watch_expr = watch_info.expression
268-
state_frame.watches[watch_expr] = self.evaluate_expression(watch_expr, idx)
262+
for watch in watches:
263+
state_frame.watches[watch] = self.evaluate_expression(
264+
watch, idx)
269265

270266

271267
state_frames.append(state_frame)
272268
frames.append(frame)
273269

270+
loc = LocIR(**self._location)
274271
if frames:
275272
frames[0].loc = loc
276273
state_frames[0].location = SourceLocation(**self._location)
@@ -301,11 +298,9 @@ def frames_below_main(self):
301298
]
302299

303300
def evaluate_expression(self, expression, frame_idx=0) -> ValueIR:
304-
if frame_idx != 0:
305-
self.set_current_stack_frame(frame_idx)
301+
self.set_current_stack_frame(frame_idx)
306302
result = self._debugger.GetExpression(expression)
307-
if frame_idx != 0:
308-
self.set_current_stack_frame(0)
303+
self.set_current_stack_frame(0)
309304
value = result.Value
310305

311306
is_optimized_away = any(s in value for s in [

0 commit comments

Comments
 (0)