Skip to content

Commit fabb7d6

Browse files
committed
[lldb-dap] Give attach test binaries unique names
Give the test binaries used for attaching unique names to avoid accidentally attaching to the wrong binary. Fixes #138197
1 parent e276216 commit fabb7d6

File tree

3 files changed

+32
-40
lines changed

3 files changed

+32
-40
lines changed

lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def create_debug_adapter(self, lldbDAPEnv=None, connection=None):
2828
env=lldbDAPEnv,
2929
)
3030

31-
def build_and_create_debug_adapter(self, lldbDAPEnv=None):
32-
self.build()
31+
def build_and_create_debug_adapter(self, lldbDAPEnv=None, dictionary=None):
32+
self.build(dictionary=dictionary)
3333
self.create_debug_adapter(lldbDAPEnv)
3434

3535
def set_source_breakpoints(self, source_path, lines, data=None):

lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
Test lldb-dap attach request
33
"""
44

5-
65
import dap_server
76
from lldbsuite.test.decorators import *
87
from lldbsuite.test.lldbtest import *
98
from lldbsuite.test import lldbutil
109
import lldbdap_testcase
1110
import os
11+
import uuid
1212
import shutil
1313
import subprocess
1414
import tempfile
@@ -25,7 +25,7 @@ def spawn_and_wait(program, delay):
2525
process.wait()
2626

2727

28-
@skipIf
28+
@skip
2929
class TestDAP_attach(lldbdap_testcase.DAPTestCaseBase):
3030
def set_and_hit_breakpoint(self, continueToExit=True):
3131
source = "main.c"
@@ -45,8 +45,9 @@ def test_by_pid(self):
4545
"""
4646
Tests attaching to a process by process ID.
4747
"""
48-
self.build_and_create_debug_adapter()
49-
program = self.getBuildArtifact("a.out")
48+
unique_name = str(uuid.uuid4())
49+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
50+
program = self.getBuildArtifact(unique_name)
5051
self.process = subprocess.Popen(
5152
[program],
5253
stdin=subprocess.PIPE,
@@ -61,34 +62,17 @@ def test_by_name(self):
6162
"""
6263
Tests attaching to a process by process name.
6364
"""
64-
self.build_and_create_debug_adapter()
65-
orig_program = self.getBuildArtifact("a.out")
66-
# Since we are going to attach by process name, we need a unique
67-
# process name that has minimal chance to match a process that is
68-
# already running. To do this we use tempfile.mktemp() to give us a
69-
# full path to a location where we can copy our executable. We then
70-
# run this copy to ensure we don't get the error "more that one
71-
# process matches 'a.out'".
72-
program = tempfile.mktemp()
73-
shutil.copyfile(orig_program, program)
74-
shutil.copymode(orig_program, program)
65+
unique_name = str(uuid.uuid4())
66+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
67+
program = self.getBuildArtifact(unique_name)
7568

7669
# Use a file as a synchronization point between test and inferior.
7770
pid_file_path = lldbutil.append_to_process_working_directory(
7871
self, "pid_file_%d" % (int(time.time()))
7972
)
8073

81-
def cleanup():
82-
if os.path.exists(program):
83-
os.unlink(program)
84-
self.run_platform_command("rm %s" % (pid_file_path))
85-
86-
# Execute the cleanup function during test case tear down.
87-
self.addTearDownHook(cleanup)
88-
8974
popen = self.spawnSubprocess(program, [pid_file_path])
90-
91-
pid = lldbutil.wait_for_file_on_target(self, pid_file_path)
75+
lldbutil.wait_for_file_on_target(self, pid_file_path)
9276

9377
self.attach(program=program)
9478
self.set_and_hit_breakpoint(continueToExit=True)
@@ -136,8 +120,10 @@ def test_commands(self):
136120
"terminateCommands" are a list of LLDB commands that get executed when
137121
the debugger session terminates.
138122
"""
139-
self.build_and_create_debug_adapter()
140-
program = self.getBuildArtifact("a.out")
123+
unique_name = str(uuid.uuid4())
124+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
125+
program = self.getBuildArtifact(unique_name)
126+
141127
# Here we just create a target and launch the process as a way to test
142128
# if we are able to use attach commands to create any kind of a target
143129
# and use it for debugging
@@ -209,8 +195,10 @@ def test_terminate_commands(self):
209195
Tests that the "terminateCommands", that can be passed during
210196
attach, are run when the debugger is disconnected.
211197
"""
212-
self.build_and_create_debug_adapter()
213-
program = self.getBuildArtifact("a.out")
198+
unique_name = str(uuid.uuid4())
199+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
200+
program = self.getBuildArtifact(unique_name)
201+
214202
# Here we just create a target and launch the process as a way to test
215203
# if we are able to use attach commands to create any kind of a target
216204
# and use it for debugging

lldb/test/API/tools/lldb-dap/attach/TestDAP_attachByPortNum.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Test lldb-dap "port" configuration to "attach" request
33
"""
44

5-
65
import dap_server
76
from lldbsuite.test.decorators import *
87
from lldbsuite.test.lldbtest import *
@@ -11,6 +10,7 @@
1110
from lldbgdbserverutils import Pipe
1211
import lldbdap_testcase
1312
import os
13+
import uuid
1414
import shutil
1515
import subprocess
1616
import tempfile
@@ -59,8 +59,9 @@ def test_by_port(self):
5959
"""
6060
Tests attaching to a process by port.
6161
"""
62-
self.build_and_create_debug_adapter()
63-
program = self.getBuildArtifact("a.out")
62+
unique_name = str(uuid.uuid4())
63+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
64+
program = self.getBuildArtifact(unique_name)
6465

6566
debug_server_tool = self.getBuiltinDebugServerTool()
6667

@@ -91,8 +92,9 @@ def test_by_port_and_pid(self):
9192
"""
9293
Tests attaching to a process by process ID and port number.
9394
"""
94-
self.build_and_create_debug_adapter()
95-
program = self.getBuildArtifact("a.out")
95+
unique_name = str(uuid.uuid4())
96+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
97+
program = self.getBuildArtifact(unique_name)
9698

9799
# It is not necessary to launch "lldb-server" to obtain the actual port and pid for attaching.
98100
# However, when providing the port number and pid directly, "lldb-dap" throws an error message, which is expected.
@@ -119,8 +121,9 @@ def test_by_invalid_port(self):
119121
"""
120122
Tests attaching to a process by invalid port number 0.
121123
"""
122-
self.build_and_create_debug_adapter()
123-
program = self.getBuildArtifact("a.out")
124+
unique_name = str(uuid.uuid4())
125+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
126+
program = self.getBuildArtifact(unique_name)
124127

125128
port = 0
126129
response = self.attach(
@@ -138,8 +141,9 @@ def test_by_illegal_port(self):
138141
"""
139142
Tests attaching to a process by illegal/greater port number 65536
140143
"""
141-
self.build_and_create_debug_adapter()
142-
program = self.getBuildArtifact("a.out")
144+
unique_name = str(uuid.uuid4())
145+
self.build_and_create_debug_adapter(dictionary={"EXE": unique_name})
146+
program = self.getBuildArtifact(unique_name)
143147

144148
port = 65536
145149
args = [program]

0 commit comments

Comments
 (0)