This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] * winsup/cygwin/exceptions.cc: Expand $CYGWIN error_start processing so that custom commandlines can be passed to the debugger program using '|' as an argument delimiter and <program-name> and <process-id> 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 ceddbbc..99392a7 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, "cygwin1.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 <program-name> or <process-id> appears then don't
+     append hardcoded arguments. */
+  int new_style =  (strstr (debugger_command, "<program-name>") != NULL ||
+                    strstr (debugger_command, "<process-id>" ) != NULL) ? 1 : 0;
+
+  /* Only supports one instance of <program-name> as we're space-restricted.  */
+  char* pname = strstr (debugger_command, "<program-name>");
+  if (pname !=0)
+    {
+      char debugger_command_rest[2 * NT_MAX_PATH + 20];
+      strcpy (debugger_command_rest, pname + strlen("<program-name>"));
+      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, "<process-id>");
+  if (pid != NULL)
+    {
+      int count = __small_sprintf (pid, " %u ", GetCurrentProcessId ());
+      pid += count;
+      count = strlen("<process-id>") - 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.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]