Skip to content

Commit b1c0400

Browse files
medismailbenJDevlieghere
authored andcommitted
[lldb] Fix assertion when ScriptedProcess have no pid after launch
This patch should fix an assertion that causes some test failures: https://ci.swift.org/view/LLDB/job/llvm-org-lldb-release-debuginfo/3587/console This was caused by the changes introduces in `88f409194d5a` where we replaced `DidLaunch` by `DidResume` in the `ScriptedProcess` class. However, by the time we resume the process, the pid should be already set. To address this, this patch brings back `DidLaunch` which will initialize the ScriptedProcess pid with a placeholder value. That value will be updated in `DidResume` to the final pid. Note, this 2 stage PID initialization is necessary sometimes, when the scripted process gets stopped at entry (launch) and gets assigned an object that contains the PID value. In this case, we need to update the PID when we resume the process after we've stopped at entry. This also replaces the default scripted process id to an arbitrary number (42) since the current value (0) is considered invalid. Differential Revision: https://reviews.llvm.org/D148153 Signed-off-by: Med Ismail Bennani <[email protected]> (cherry picked from commit 9cbdfcd)
1 parent 2f98ebd commit b1c0400

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

lldb/examples/python/scripted_process/crashlog_scripted_process.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ def get_loaded_images(self):
101101
# from it.
102102
return self.loaded_images
103103

104-
def get_process_id(self) -> int:
105-
return self.pid
106-
107104
def should_stop(self) -> bool:
108105
return True
109106

lldb/examples/python/scripted_process/scripted_process.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, exe_ctx, args):
4747
self.loaded_images = []
4848
self.metadata = {}
4949
self.capabilities = {}
50+
self.pid = 42
5051

5152
def get_capabilities(self):
5253
""" Get a dictionary containing the process capabilities.
@@ -138,7 +139,7 @@ def get_process_id(self):
138139
Returns:
139140
int: The scripted process identifier.
140141
"""
141-
return 0
142+
return self.pid
142143

143144
def launch(self):
144145
""" Simulate the scripted process launch.

lldb/source/Plugins/Process/scripted/ScriptedProcess.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ Status ScriptedProcess::DoLaunch(Module *exe_module,
161161
return error;
162162
}
163163

164+
void ScriptedProcess::DidLaunch() { m_pid = GetInterface().GetProcessID(); }
165+
164166
void ScriptedProcess::DidResume() {
167+
// Update the PID again, in case the user provided a placeholder pid at launch
165168
m_pid = GetInterface().GetProcessID();
166169
GetLoadedDynamicLibrariesInfos();
167170
}

lldb/source/Plugins/Process/scripted/ScriptedProcess.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class ScriptedProcess : public Process {
4747

4848
Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
4949

50+
void DidLaunch() override;
51+
5052
void DidResume() override;
5153

5254
Status DoResume() override;

0 commit comments

Comments
 (0)