Reduce stack pressure throughout Cygwin
* dcrt0.cc (initial_env): Reduce size of local path buffers to PATH_MAX. Allocate debugger_command from process heap. (init_windows_system_directory): Very early initialize new global variable global_progname. * dll_init.cc (dll_list::alloc): Make path buffer static. Explain why. (dll_list::populate_deps): Use tmp_pathbuf for local path buffer. * exceptions.cc (debugger_command): Convert to PWCHAR. (error_start_init): Allocate debugger_command and fill with wide char strings. Only allocate if NULL. (try_to_debug): Just check if debugger_command is a NULL pointer to return. Drop conversion from char to WCHAR and drop local variable dbg_cmd. * globals.cc (global_progname): New global variable to store Windows application path. * pinfo.cc (pinfo_basic::pinfo_basic): Just copy progname over from global_progname. (pinfo::status_exit): Let path_conv create the POSIX path to avoid local buffer. * pseudo_reloc.cc (__report_error): Utilize global_progname, drop local buffer. * smallprint.cc (__small_vsprintf): Just utilize global_progname for %P format specifier. (__small_vswprintf): Ditto. * strace.cc (PROTECT): Change to reflect x being a pointer. Reformat. (CHECK): Ditto. Reformat. (strace::activate): Utilize global_progname, drop local buffer. Fix formatting. (strace::vsprntf): Reduce size of local progname buffer to NAME_MAX. Copy and, if necessary, convert only the last path component to progname. (strace_buf_guard): New muto. (buf): New static pointer. (strace::vprntf): Use buf under strace_buf_guard lock only. Allocate buffer space for buf on Windows heap. * wow64.cc (wow64_respawn_process): Utilize global_progname, drop local path buffer. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
@ -46,7 +46,7 @@ details. */
|
||||
#define CALL_HANDLER_RETRY_OUTER 10
|
||||
#define CALL_HANDLER_RETRY_INNER 10
|
||||
|
||||
char debugger_command[2 * NT_MAX_PATH + 20];
|
||||
PWCHAR debugger_command;
|
||||
extern u_char _sigbe;
|
||||
extern u_char _sigdelayed_end;
|
||||
|
||||
@ -112,18 +112,19 @@ extern "C" void
|
||||
error_start_init (const char *buf)
|
||||
{
|
||||
if (!buf || !*buf)
|
||||
{
|
||||
debugger_command[0] = '\0';
|
||||
return;
|
||||
}
|
||||
return;
|
||||
if (!debugger_command &&
|
||||
!(debugger_command = (PWCHAR) malloc ((2 * NT_MAX_PATH + 20)
|
||||
* sizeof (WCHAR))))
|
||||
return;
|
||||
|
||||
char pgm[NT_MAX_PATH];
|
||||
if (!GetModuleFileName (NULL, pgm, NT_MAX_PATH))
|
||||
strcpy (pgm, "cygwin1.dll");
|
||||
for (char *p = strchr (pgm, '\\'); p; p = strchr (p, '\\'))
|
||||
*p = '/';
|
||||
|
||||
__small_sprintf (debugger_command, "%s \"%s\"", buf, pgm);
|
||||
PWCHAR cp = debugger_command
|
||||
+ sys_mbstowcs (debugger_command, NT_MAX_PATH, buf) - 1;
|
||||
cp = wcpcpy (cp, L" \"");
|
||||
wcpcpy (cp, global_progname);
|
||||
for (PWCHAR p = wcschr (cp, L'\\'); p; p = wcschr (p, L'\\'))
|
||||
*p = L'/';
|
||||
wcscat (cp, L"\"");
|
||||
}
|
||||
|
||||
void
|
||||
@ -474,9 +475,9 @@ cygwin_stackdump ()
|
||||
extern "C" int
|
||||
try_to_debug (bool waitloop)
|
||||
{
|
||||
debug_printf ("debugger_command '%s'", debugger_command);
|
||||
if (*debugger_command == '\0')
|
||||
if (!debugger_command)
|
||||
return 0;
|
||||
debug_printf ("debugger_command '%W'", debugger_command);
|
||||
if (being_debugged ())
|
||||
{
|
||||
extern void break_here ();
|
||||
@ -484,8 +485,8 @@ try_to_debug (bool waitloop)
|
||||
return 0;
|
||||
}
|
||||
|
||||
__small_sprintf (strchr (debugger_command, '\0'), " %u",
|
||||
GetCurrentProcessId ());
|
||||
PWCHAR dbg_end = wcschr (debugger_command, L'\0');
|
||||
__small_swprintf (dbg_end, L" %u", GetCurrentProcessId ());
|
||||
|
||||
LONG prio = GetThreadPriority (GetCurrentThread ());
|
||||
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_HIGHEST);
|
||||
@ -529,10 +530,8 @@ try_to_debug (bool waitloop)
|
||||
console_printf ("*** starting debugger for pid %u, tid %u\n",
|
||||
cygwin_pid (GetCurrentProcessId ()), GetCurrentThreadId ());
|
||||
BOOL dbg;
|
||||
WCHAR dbg_cmd[strlen(debugger_command) + 1];
|
||||
sys_mbstowcs (dbg_cmd, strlen(debugger_command) + 1, debugger_command);
|
||||
dbg = CreateProcessW (NULL,
|
||||
dbg_cmd,
|
||||
debugger_command,
|
||||
NULL,
|
||||
NULL,
|
||||
FALSE,
|
||||
@ -542,6 +541,7 @@ try_to_debug (bool waitloop)
|
||||
&si,
|
||||
&pi);
|
||||
|
||||
*dbg_end = L'\0';
|
||||
if (!dbg)
|
||||
system_printf ("Failed to start debugger, %E");
|
||||
else
|
||||
|
Reference in New Issue
Block a user