2
2
Test python scripted process in lldb
3
3
"""
4
4
5
- import os
5
+ import os , json , tempfile
6
6
7
7
import lldb
8
8
from lldbsuite .test .decorators import *
9
9
from lldbsuite .test .lldbtest import *
10
10
from lldbsuite .test import lldbutil
11
11
from lldbsuite .test import lldbtest
12
12
13
-
14
13
class ScriptedProcesTestCase (TestBase ):
15
14
16
15
mydir = TestBase .compute_mydir (__file__ )
17
16
18
17
def setUp (self ):
19
18
TestBase .setUp (self )
20
- self .source = "main.c"
21
19
22
20
def tearDown (self ):
23
21
TestBase .tearDown (self )
@@ -43,7 +41,7 @@ def test_python_plugin_package(self):
43
41
self .expect ('script dir(ScriptedProcess)' ,
44
42
substrs = ["launch" ])
45
43
46
- @skipIf (oslist = [ "linux" ], archs = [ "arm" , "aarch64" ] )
44
+ @skipIf (archs = no_match ([ 'x86_64' ]) )
47
45
def test_scripted_process_and_scripted_thread (self ):
48
46
"""Test that we can launch an lldb scripted process using the SBAPI,
49
47
check its process ID, read string from memory, check scripted thread
@@ -78,19 +76,29 @@ def test_scripted_process_and_scripted_thread(self):
78
76
self .assertGreater (thread .GetNumFrames (), 0 )
79
77
80
78
frame = thread .GetFrameAtIndex (0 )
79
+ GPRs = None
81
80
register_set = frame .registers # Returns an SBValueList.
82
81
for regs in register_set :
83
- if 'GPR ' in regs .name :
84
- registers = regs
82
+ if 'general purpose ' in regs .name . lower () :
83
+ GPRs = regs
85
84
break
86
85
87
- self .assertTrue (registers , "Invalid General Purpose Registers Set" )
88
- self .assertEqual (registers .GetNumChildren (), 21 )
89
- for idx , reg in enumerate (registers , start = 1 ):
86
+ self .assertTrue (GPRs , "Invalid General Purpose Registers Set" )
87
+ self .assertEqual (GPRs .GetNumChildren (), 21 )
88
+ for idx , reg in enumerate (GPRs , start = 1 ):
90
89
self .assertEqual (idx , int (reg .value , 16 ))
91
90
92
- @skipIfDarwin
91
+ def create_stack_skinny_corefile (self , file ):
92
+ self .build ()
93
+ target , process , thread , _ = lldbutil .run_to_source_breakpoint (self , "// break here" , lldb .SBFileSpec ("main.c" ))
94
+ self .assertTrue (process .IsValid (), "Process is invalid." )
95
+ # FIXME: Use SBAPI to save the process corefile.
96
+ self .runCmd ("process save-core -s stack " + file )
97
+ self .assertTrue (os .path .exists (file ), "No stack-only corefile found." )
98
+ self .assertTrue (self .dbg .DeleteTarget (target ), "Couldn't delete target" )
99
+
93
100
@skipUnlessDarwin
101
+ @skipIf (archs = no_match (['x86_64' ]))
94
102
def test_launch_scripted_process_stack_frames (self ):
95
103
"""Test that we can launch an lldb scripted process from the command
96
104
line, check its process ID and read string from memory."""
@@ -101,26 +109,45 @@ def test_launch_scripted_process_stack_frames(self):
101
109
for module in target .modules :
102
110
if 'a.out' in module .GetFileSpec ().GetFilename ():
103
111
main_module = module
112
+ break
104
113
105
114
self .assertTrue (main_module , "Invalid main module." )
106
115
error = target .SetModuleLoadAddress (main_module , 0 )
107
116
self .assertTrue (error .Success (), "Reloading main module at offset 0 failed." )
108
117
109
- scripted_process_example_relpath = ['..' ,'..' ,'..' ,'..' ,'examples' ,'python' ,'scripted_process' ,'my_scripted_process.py' ]
118
+ scripted_process_example_relpath = 'stack_core_scripted_process.py'
119
+ os .environ ['SKIP_SCRIPTED_PROCESS_LAUNCH' ] = '1'
110
120
self .runCmd ("command script import " + os .path .join (self .getSourceDir (),
111
- * scripted_process_example_relpath ))
121
+ scripted_process_example_relpath ))
122
+
123
+ corefile_process = None
124
+ with tempfile .NamedTemporaryFile () as file :
125
+ self .create_stack_skinny_corefile (file .name )
126
+ corefile_target = self .dbg .CreateTarget (None )
127
+ corefile_process = corefile_target .LoadCore (self .getBuildArtifact (file .name ))
128
+ self .assertTrue (corefile_process , PROCESS_IS_VALID )
129
+
130
+ structured_data = lldb .SBStructuredData ()
131
+ structured_data .SetFromJSON (json .dumps ({
132
+ "backing_target_idx" : self .dbg .GetIndexOfTarget (corefile_process .GetTarget ())
133
+ }))
134
+ launch_info = lldb .SBLaunchInfo (None )
135
+ launch_info .SetProcessPluginName ("ScriptedProcess" )
136
+ launch_info .SetScriptedProcessClassName ("stack_core_scripted_process.StackCoreScriptedProcess" )
137
+ launch_info .SetScriptedProcessDictionary (structured_data )
112
138
113
- process = target .GetProcess ()
139
+ error = lldb .SBError ()
140
+ process = target .Launch (launch_info , error )
141
+ self .assertTrue (error .Success (), error .GetCString ())
114
142
self .assertTrue (process , PROCESS_IS_VALID )
115
143
self .assertEqual (process .GetProcessID (), 42 )
116
- self .assertEqual (process .GetNumThreads (), 1 )
117
144
145
+ self .assertEqual (process .GetNumThreads (), 1 )
118
146
thread = process .GetSelectedThread ()
119
147
self .assertTrue (thread , "Invalid thread." )
120
- self .assertEqual (thread .GetThreadID (), 0x19 )
121
- self .assertEqual (thread .GetName (), "MyScriptedThread.thread-1" )
148
+ self .assertEqual (thread .GetName (), "StackCoreScriptedThread.thread-1" )
122
149
123
- self .assertEqual (thread .GetNumFrames (), 4 )
150
+ self .assertEqual (thread .GetNumFrames (), 3 )
124
151
frame = thread .GetSelectedFrame ()
125
152
self .assertTrue (frame , "Invalid frame." )
126
153
self .assertEqual (frame .GetFunctionName (), "bar" )
0 commit comments