@@ -116,17 +116,45 @@ error_start_init (const char *buf)
116
116
return ;
117
117
}
118
118
119
- char pgm[NT_MAX_PATH];
120
- if (!GetModuleFileName (NULL , pgm, NT_MAX_PATH))
119
+ char pgm[NT_MAX_PATH+5 ];
120
+ strcpy (pgm," \" " );
121
+ if (!GetModuleFileName (NULL , pgm+2 , NT_MAX_PATH))
121
122
#ifdef __MSYS__
122
123
strcpy (pgm, " msys-2.0.dll" );
123
124
#else
124
125
strcpy (pgm, " cygwin1.dll" );
125
126
#endif
126
127
for (char *p = strchr (pgm, ' \\ ' ); p; p = strchr (p, ' \\ ' ))
127
128
*p = ' /' ;
129
+ strcat (pgm," \" " );
128
130
129
- __small_sprintf (debugger_command, " %s \" %s\" " , buf, pgm);
131
+ strcpy (debugger_command, buf);
132
+ /* Turn all '|' into ' ' */
133
+ char * bar = debugger_command;
134
+ while ((bar = strchr (debugger_command, ' |' )))
135
+ {
136
+ *bar = ' ' ;
137
+ }
138
+
139
+ /* If either <program-name> or <process-id> appears then don't
140
+ append hardcoded arguments. */
141
+ int new_style = (strstr (debugger_command, " <program-name>" ) != NULL ||
142
+ strstr (debugger_command, " <process-id>" ) != NULL ) ? 1 : 0 ;
143
+
144
+ /* Only supports one instance of <program-name> as we're space-restricted. */
145
+ char * pname = strstr (debugger_command, " <program-name>" );
146
+ if (pname !=0 )
147
+ {
148
+ char debugger_command_rest[2 * NT_MAX_PATH + 20 ];
149
+ strcpy (debugger_command_rest, pname + strlen (" <program-name>" ));
150
+ strcpy (pname, pgm);
151
+ strcat (pname, debugger_command_rest);
152
+ }
153
+
154
+ if (new_style == 0 )
155
+ {
156
+ strcat (debugger_command, pgm);
157
+ }
130
158
}
131
159
132
160
void
@@ -468,7 +496,21 @@ try_to_debug (bool waitloop)
468
496
return 0 ;
469
497
}
470
498
471
- __small_sprintf (strchr (debugger_command, ' \0 ' ), " %u" , GetCurrentProcessId ());
499
+ char * pid = strstr (debugger_command, " <process-id>" );
500
+ if (pid != NULL )
501
+ {
502
+ int count = __small_sprintf (pid, " %u " , GetCurrentProcessId ());
503
+ pid += count;
504
+ count = strlen (" <process-id>" ) - count;
505
+ while (count-->0 )
506
+ {
507
+ *pid++ = ' ' ;
508
+ }
509
+ }
510
+ else
511
+ {
512
+ __small_sprintf (strchr (debugger_command, ' \0 ' ), " %u" , GetCurrentProcessId ());
513
+ }
472
514
473
515
LONG prio = GetThreadPriority (GetCurrentThread ());
474
516
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);
0 commit comments