@@ -27,47 +27,79 @@ def _mask_persistent_var(self, string: str) -> str:
27
27
before , after = self .PERSISTENT_VAR .split (string , maxsplit = 1 )
28
28
return re .escape (before ) + r"\$\d+" + re .escape (after )
29
29
30
- def _expect_cmd (self , expr : str , base_cmd : str ) -> None :
30
+ def _expect_cmd (
31
+ self ,
32
+ dwim_cmd : str ,
33
+ actual_cmd : str ,
34
+ ) -> None :
31
35
"""Run dwim-print and verify the output against the expected command."""
32
- cmd = f"{ base_cmd } { expr } "
33
- cmd_output = self ._run_cmd (cmd )
36
+ # Resolve the dwim-print command to either `expression` or `frame variable`.
37
+ substitute_cmd = dwim_cmd .replace ("dwim-print" , actual_cmd , 1 )
38
+ interp = self .dbg .GetCommandInterpreter ()
39
+ result = lldb .SBCommandReturnObject ()
40
+ interp .ResolveCommand (substitute_cmd , result )
41
+ self .assertTrue (result .Succeeded (), result .GetError ())
42
+
43
+ resolved_cmd = result .GetOutput ()
44
+ if actual_cmd == "frame variable" :
45
+ resolved_cmd = resolved_cmd .replace (" -- " , " " , 1 )
46
+
47
+ expected_output = self ._run_cmd (resolved_cmd )
34
48
35
49
# Verify dwim-print chose the expected command.
36
50
self .runCmd ("settings set dwim-print-verbosity full" )
37
- substrs = [f"note: ran `{ cmd } `" ]
51
+ substrs = [f"note: ran `{ resolved_cmd } `" ]
38
52
patterns = []
39
53
40
- if base_cmd == "expression -- " and self .PERSISTENT_VAR .search (cmd_output ):
41
- patterns .append (self ._mask_persistent_var (cmd_output ))
54
+ if actual_cmd == "expression" and self .PERSISTENT_VAR .search (expected_output ):
55
+ patterns .append (self ._mask_persistent_var (expected_output ))
42
56
else :
43
- substrs .append (cmd_output )
57
+ substrs .append (expected_output )
44
58
45
- self .expect (f"dwim-print { expr } " , substrs = substrs , patterns = patterns )
59
+ self .expect (dwim_cmd , substrs = substrs , patterns = patterns )
46
60
47
61
def test_variables (self ):
48
62
"""Test dwim-print with variables."""
49
63
self .build ()
50
64
lldbutil .run_to_name_breakpoint (self , "main" )
51
65
vars = ("argc" , "argv" )
52
66
for var in vars :
53
- self ._expect_cmd (var , "frame variable" )
67
+ self ._expect_cmd (f"dwim-print { var } " , "frame variable" )
54
68
55
69
def test_variable_paths (self ):
56
70
"""Test dwim-print with variable path expressions."""
57
71
self .build ()
58
72
lldbutil .run_to_name_breakpoint (self , "main" )
59
73
exprs = ("&argc" , "*argv" , "argv[0]" )
60
74
for expr in exprs :
61
- self ._expect_cmd (expr , "expression -- " )
75
+ self ._expect_cmd (f"dwim-print { expr } " , "expression" )
62
76
63
77
def test_expressions (self ):
64
78
"""Test dwim-print with expressions."""
65
79
self .build ()
66
80
lldbutil .run_to_name_breakpoint (self , "main" )
67
81
exprs = ("argc + 1" , "(void)argc" , "(int)abs(argc)" )
68
82
for expr in exprs :
69
- self ._expect_cmd (expr , "expression -- " )
83
+ self ._expect_cmd (f"dwim-print { expr } " , "expression" )
70
84
71
85
def test_dummy_target_expressions (self ):
72
86
"""Test dwim-print's ability to evaluate expressions without a target."""
73
- self ._expect_cmd ("1 + 2" , "expression --" )
87
+ self ._expect_cmd ("dwim-print 1 + 2" , "expression" )
88
+
89
+ def test_gdb_format (self ):
90
+ self .build ()
91
+ lldbutil .run_to_name_breakpoint (self , "main" )
92
+ self ._expect_cmd (f"dwim-print/x argc" , "frame variable" )
93
+ self ._expect_cmd (f"dwim-print/x argc + 1" , "expression" )
94
+
95
+ def test_format_flags (self ):
96
+ self .build ()
97
+ lldbutil .run_to_name_breakpoint (self , "main" )
98
+ self ._expect_cmd (f"dwim-print -fx -- argc" , "frame variable" )
99
+ self ._expect_cmd (f"dwim-print -fx -- argc + 1" , "expression" )
100
+
101
+ def test_display_flags (self ):
102
+ self .build ()
103
+ lldbutil .run_to_name_breakpoint (self , "main" )
104
+ self ._expect_cmd (f"dwim-print -T -- argc" , "frame variable" )
105
+ self ._expect_cmd (f"dwim-print -T -- argc + 1" , "expression" )
0 commit comments