@@ -58,3 +58,54 @@ def test_platform_process_launch_gdb_server(self):
5858
5959 self .runCmd ("target create {}" .format (self .getBuildArtifact ("a.out" )))
6060 self .expect ("run" , substrs = ["unable to launch a GDB server on" ], error = True )
61+
62+ @skipIfRemote
63+ # Windows cannot delete the executable while it is running.
64+ # On Darwin we may be using debugserver.
65+ @skipUnlessPlatform (["linux" ])
66+ @add_test_categories (["lldb-server" ])
67+ def test_platform_process_launch_gdb_server (self ):
68+ self .build ()
69+
70+ hostname = socket .getaddrinfo ("localhost" , 0 , proto = socket .IPPROTO_TCP )[0 ][4 ][0 ]
71+ listen_url = "[%s]:0" % hostname
72+
73+ port_file = self .getBuildArtifact ("port" )
74+ commandline_args = [
75+ "platform" ,
76+ "--listen" ,
77+ listen_url ,
78+ "--socket-file" ,
79+ port_file ,
80+ "--" ,
81+ self .getBuildArtifact ("a.out" ),
82+ "foo" ,
83+ ]
84+
85+ # Run lldb-server from a symlink without any binary called "lldb-server" in the directory.
86+ llgs_hiding_directory = self .getBuildArtifact ("hiding-directory" )
87+ new_lldb_server_link = self .getBuildArtifact (
88+ "lldb-server-with-an-unconventional-name"
89+ )
90+ new_lldb_server = os .path .join (llgs_hiding_directory , "lldb-server" )
91+ os .makedirs (llgs_hiding_directory )
92+ shutil .copy (lldbgdbserverutils .get_lldb_server_exe (), new_lldb_server )
93+ os .symlink (new_lldb_server , new_lldb_server_link )
94+
95+ self .spawnSubprocess (new_lldb_server_link , commandline_args )
96+ socket_id = lldbutil .wait_for_file_on_target (self , port_file )
97+
98+ new_platform = lldb .SBPlatform ("remote-" + self .getPlatform ())
99+ self .dbg .SetSelectedPlatform (new_platform )
100+
101+ connect_url = "connect://[%s]:%s" % (hostname , socket_id )
102+ self .runCmd ("platform connect %s" % connect_url )
103+
104+ # First connect to lldb-server which spawn a process to handle the connection.
105+ # Then remove our new lldb-server so that when it tries to invoke itself as a
106+ # gdbserver, it fails.
107+ os .remove (new_lldb_server_link )
108+ shutil .rmtree (llgs_hiding_directory )
109+
110+ self .runCmd ("target create {}" .format (self .getBuildArtifact ("a.out" )))
111+ self .expect ("run" , substrs = ["unable to launch a GDB server on" ], error = True )
0 commit comments