2020import java .util .concurrent .CompletionException ;
2121import java .util .logging .Logger ;
2222
23+ import org .apache .commons .lang3 .StringUtils ;
24+ import org .apache .commons .lang3 .SystemUtils ;
25+
2326import com .google .gson .JsonObject ;
2427import com .microsoft .java .debug .core .Configuration ;
2528import com .microsoft .java .debug .core .DebugException ;
4750import com .sun .jdi .connect .Connector ;
4851import com .sun .jdi .connect .IllegalConnectorArgumentsException ;
4952import com .sun .jdi .connect .ListeningConnector ;
53+ import com .sun .jdi .connect .TransportTimeoutException ;
5054import com .sun .jdi .connect .VMStartException ;
5155
5256public class LaunchWithDebuggingDelegate implements ILaunchDelegate {
5357
5458 protected static final Logger logger = Logger .getLogger (Configuration .LOGGER_NAME );
55- private static final int ACCEPT_TIMEOUT = 10 * 1000 ;
59+ private static final int ATTACH_TERMINAL_TIMEOUT = 20 * 1000 ;
5660 private static final String TERMINAL_TITLE = "Java Debug Console" ;
5761 protected static final long RUNINTERMINAL_TIMEOUT = 10 * 1000 ;
5862
@@ -67,7 +71,7 @@ public CompletableFuture<Response> launchInTerminal(LaunchArguments launchArgume
6771 List <ListeningConnector > connectors = vmProvider .getVirtualMachineManager ().listeningConnectors ();
6872 ListeningConnector listenConnector = connectors .get (0 );
6973 Map <String , Connector .Argument > args = listenConnector .defaultArguments ();
70- ((Connector .IntegerArgument ) args .get ("timeout" )).setValue (ACCEPT_TIMEOUT );
74+ ((Connector .IntegerArgument ) args .get ("timeout" )).setValue (ATTACH_TERMINAL_TIMEOUT );
7175 String address = listenConnector .startListening (args );
7276
7377 String [] cmds = LaunchRequestHandler .constructLaunchCommands (launchArguments , false , address );
@@ -101,6 +105,29 @@ public CompletableFuture<Response> launchInTerminal(LaunchArguments launchArgume
101105 context .setDebugSession (new DebugSession (vm ));
102106 logger .info ("Launching debuggee in terminal console succeeded." );
103107 resultFuture .complete (response );
108+ } catch (TransportTimeoutException e ) {
109+ int commandLength = StringUtils .length (launchArguments .cwd ) + 1 ;
110+ for (String cmd : cmds ) {
111+ commandLength += StringUtils .length (cmd ) + 1 ;
112+ }
113+
114+ final int threshold = SystemUtils .IS_OS_WINDOWS ? 8092 : 32 * 1024 ;
115+ String errorMessage = String .format (launchInTerminalErrorFormat , e .toString ());
116+ if (commandLength >= threshold ) {
117+ errorMessage = "Failed to launch debuggee in terminal. The possible reason is the command line too long. "
118+ + "More details: " + e .toString ();
119+ logger .severe (errorMessage
120+ + "\r \n "
121+ + "The estimated command line length is " + commandLength + ". "
122+ + "Try to enable shortenCommandLine option in the debug launch configuration." );
123+ }
124+
125+ resultFuture .completeExceptionally (
126+ new DebugException (
127+ errorMessage ,
128+ ErrorCode .LAUNCH_IN_TERMINAL_FAILURE .getId ()
129+ )
130+ );
104131 } catch (IOException | IllegalConnectorArgumentsException e ) {
105132 resultFuture .completeExceptionally (
106133 new DebugException (
0 commit comments