Skip to content

Commit 487ab53

Browse files
committed
[dexter] Add keyword argument 'on_line' to DexLabel
Add optional keyword argument 'on_line' to DexLabel to label the specifed line instead of the line the command is found on. This will be helpful when used alongside DexDeclareFile (D99651). Reviewed By: TWeaver Differential Revision: https://reviews.llvm.org/D101055
1 parent 2fdedf9 commit 487ab53

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

debuginfo-tests/dexter/Commands.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,17 @@ large test cases that would normally take much longer to complete.
205205

206206
----
207207
## DexLabel
208-
DexLabel(name)
208+
DexLabel(name [, **on_line])
209209

210210
Args:
211211
name (str): A unique name for this line.
212212

213+
Keyword args:
214+
on_line (int): Specify a line number to label.
215+
213216
### Description
214-
Name the line this command is found on. Line names can be referenced by other
215-
commands expecting line number arguments.
217+
Name the line this command is found on or 'on_line' if it is provided. Line
218+
names can be referenced by other commands expecting line number arguments.
216219
For example, `DexExpectWatchValues(..., on_line='my_line_name')`.
217220

218221
### Heuristic

debuginfo-tests/dexter/dex/command/commands/DexLabel.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,27 @@
1212

1313

1414
class DexLabel(CommandBase):
15-
def __init__(self, label):
15+
def __init__(self, label, **kwargs):
1616

1717
if not isinstance(label, str):
1818
raise TypeError('invalid argument type')
1919

20+
try:
21+
self.on_line = kwargs.pop('on_line')
22+
except KeyError:
23+
# We cannot use self.lineno because it hasn't been set yet.
24+
pass
25+
if kwargs:
26+
raise TypeError(f'unexpected named args: {", ".join(kwargs)}')
27+
2028
self._label = label
2129
super(DexLabel, self).__init__()
2230

31+
def get_line(self):
32+
return getattr(self, 'on_line', self.lineno)
33+
2334
def get_as_pair(self):
24-
return (self._label, self.lineno)
35+
return (self._label, self.get_line())
2536

2637
@staticmethod
2738
def get_name():
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Purpose:
2+
// Check that bad keyword args in \DexLabel are reported.
3+
// Use --binary switch to trick dexter into skipping the build step.
4+
//
5+
// RUN: not %dexter_base test --binary %s --debugger 'lldb' -- %s | FileCheck %s
6+
// CHECK: parser error:{{.*}}err_label_kwarg.cpp(8): unexpected named args: bad_arg
7+
8+
// DexLabel('test', bad_arg=0)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Purpose:
2+
// Check that the optional keyword argument 'on_line' makes a \DexLabel label
3+
// that line instead of the line the command is found on.
4+
//
5+
// RUN: %dexter_regression_test -- %s | FileCheck %s
6+
// CHECK: label_another_line.cpp: (1.0000)
7+
8+
int main() {
9+
int result = 0;
10+
return result;
11+
}
12+
13+
// DexLabel('test', on_line=10)
14+
// DexExpectWatchValue('result', '0', on_line='test')

0 commit comments

Comments
 (0)