Skip to content

Commit cd3184b

Browse files
committed
Extend debugging by returning program name and process id.
1 parent 6a80caf commit cd3184b

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

winsup/cygwin/exceptions.cc

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,45 @@ error_start_init (const char *buf)
116116
return;
117117
}
118118

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))
121122
#ifdef __MSYS__
122123
strcpy (pgm, "msys-2.0.dll");
123124
#else
124125
strcpy (pgm, "cygwin1.dll");
125126
#endif
126127
for (char *p = strchr (pgm, '\\'); p; p = strchr (p, '\\'))
127128
*p = '/';
129+
strcat(pgm,"\" ");
128130

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+
}
130158
}
131159

132160
void
@@ -468,7 +496,21 @@ try_to_debug (bool waitloop)
468496
return 0;
469497
}
470498

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+
}
472514

473515
LONG prio = GetThreadPriority (GetCurrentThread ());
474516
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);

0 commit comments

Comments
 (0)