From 79687fb0f597abe7d33c20a92dd6d277387513df Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Sun, 9 Feb 2014 01:16:08 +0000 Subject: [PATCH] Expand $CYGWIN error_start processing. .. so that custom commandlines can be passed to the debugger program using '|' as an argument delimiter and and as special tokens. --- winsup/cygwin/exceptions.cc | 50 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index b4365cd..0ccc9a3 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -113,13 +113,41 @@ error_start_init (const char *buf) return; } - char pgm[NT_MAX_PATH]; - if (!GetModuleFileName (NULL, pgm, NT_MAX_PATH)) + char pgm[NT_MAX_PATH+5]; + strcpy(pgm," \""); + if (!GetModuleFileName (NULL, pgm+2, NT_MAX_PATH)) strcpy (pgm, "msys-2.0.dll"); for (char *p = strchr (pgm, '\\'); p; p = strchr (p, '\\')) *p = '/'; + strcat(pgm,"\" "); - __small_sprintf (debugger_command, "%s \"%s\"", buf, pgm); + strcpy(debugger_command, buf); + /* Turn all '|' into ' ' */ + char* bar = debugger_command; + while ((bar = strchr(debugger_command, '|'))) + { + *bar = ' '; + } + + /* If either or appears then don't + append hardcoded arguments. */ + int new_style = (strstr (debugger_command, "") != NULL || + strstr (debugger_command, "" ) != NULL) ? 1 : 0; + + /* Only supports one instance of as we're space-restricted. */ + char* pname = strstr (debugger_command, ""); + if (pname !=0) + { + char debugger_command_rest[2 * NT_MAX_PATH + 20]; + strcpy (debugger_command_rest, pname + strlen("")); + strcpy (pname, pgm); + strcat (pname, debugger_command_rest); + } + + if (new_style == 0) + { + strcat(debugger_command, pgm); + } } void @@ -447,7 +475,21 @@ try_to_debug (bool waitloop) return 0; } - __small_sprintf (strchr (debugger_command, '\0'), " %u", GetCurrentProcessId ()); + char* pid = strstr (debugger_command, ""); + if (pid != NULL) + { + int count = __small_sprintf (pid, " %u ", GetCurrentProcessId ()); + pid += count; + count = strlen("") - count; + while (count-->0) + { + *pid++ = ' '; + } + } + else + { + __small_sprintf (strchr (debugger_command, '\0'), " %u", GetCurrentProcessId ()); + } LONG prio = GetThreadPriority (GetCurrentThread ()); SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST); -- 1.8.5.4