mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 18:26:19 +01:00
Convert the crash handler to UTF-16, mostly
This commit is contained in:
parent
6d9c3e3226
commit
5c187b9385
@ -18,16 +18,16 @@
|
|||||||
|
|
||||||
/* Copy @cmdline into @debugger, and substitute @pid for `%p`
|
/* Copy @cmdline into @debugger, and substitute @pid for `%p`
|
||||||
* and @event for `%e`.
|
* and @event for `%e`.
|
||||||
* If @debugger_size (in bytes) is overflowed, return %FALSE.
|
* If @debugger_size (in wchar_ts) is overflowed, return %FALSE.
|
||||||
* Also returns %FALSE when `%` is followed by anything other
|
* Also returns %FALSE when `%` is followed by anything other
|
||||||
* than `e` or `p`.
|
* than `e` or `p`.
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
_g_win32_subst_pid_and_event (char *debugger,
|
_g_win32_subst_pid_and_event_w (wchar_t *debugger,
|
||||||
gsize debugger_size,
|
gsize debugger_size,
|
||||||
const char *cmdline,
|
const wchar_t *cmdline,
|
||||||
DWORD pid,
|
DWORD pid,
|
||||||
guintptr event)
|
guintptr event)
|
||||||
{
|
{
|
||||||
gsize i = 0, dbg_i = 0;
|
gsize i = 0, dbg_i = 0;
|
||||||
/* These are integers, and they can't be longer than 20 characters
|
/* These are integers, and they can't be longer than 20 characters
|
||||||
@ -35,31 +35,31 @@ _g_win32_subst_pid_and_event (char *debugger,
|
|||||||
* Use 30 just to be sure.
|
* Use 30 just to be sure.
|
||||||
*/
|
*/
|
||||||
#define STR_BUFFER_SIZE 30
|
#define STR_BUFFER_SIZE 30
|
||||||
char pid_str[STR_BUFFER_SIZE] = {0};
|
wchar_t pid_str[STR_BUFFER_SIZE] = {0};
|
||||||
gsize pid_str_len;
|
gsize pid_str_len;
|
||||||
char event_str[STR_BUFFER_SIZE] = {0};
|
wchar_t event_str[STR_BUFFER_SIZE] = {0};
|
||||||
gsize event_str_len;
|
gsize event_str_len;
|
||||||
|
|
||||||
_snprintf_s (pid_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), "%lu", pid);
|
_snwprintf_s (pid_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), L"%lu", pid);
|
||||||
pid_str[G_N_ELEMENTS (pid_str) - 1] = 0;
|
pid_str[G_N_ELEMENTS (pid_str) - 1] = 0;
|
||||||
pid_str_len = strlen (pid_str);
|
pid_str_len = wcslen (pid_str);
|
||||||
_snprintf_s (event_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), "%Iu", event);
|
_snwprintf_s (event_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), L"%Iu", event);
|
||||||
event_str[G_N_ELEMENTS (pid_str) - 1] = 0;
|
event_str[G_N_ELEMENTS (pid_str) - 1] = 0;
|
||||||
event_str_len = strlen (event_str);
|
event_str_len = wcslen (event_str);
|
||||||
#undef STR_BUFFER_SIZE
|
#undef STR_BUFFER_SIZE
|
||||||
|
|
||||||
while (cmdline[i] != 0 && dbg_i < debugger_size)
|
while (cmdline[i] != 0 && dbg_i < debugger_size)
|
||||||
{
|
{
|
||||||
if (cmdline[i] != '%')
|
if (cmdline[i] != L'%')
|
||||||
debugger[dbg_i++] = cmdline[i++];
|
debugger[dbg_i++] = cmdline[i++];
|
||||||
else if (cmdline[i + 1] == 'p')
|
else if (cmdline[i + 1] == L'p')
|
||||||
{
|
{
|
||||||
gsize j = 0;
|
gsize j = 0;
|
||||||
while (j < pid_str_len && dbg_i < debugger_size)
|
while (j < pid_str_len && dbg_i < debugger_size)
|
||||||
debugger[dbg_i++] = pid_str[j++];
|
debugger[dbg_i++] = pid_str[j++];
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
else if (cmdline[i + 1] == 'e')
|
else if (cmdline[i + 1] == L'e')
|
||||||
{
|
{
|
||||||
gsize j = 0;
|
gsize j = 0;
|
||||||
while (j < event_str_len && dbg_i < debugger_size)
|
while (j < event_str_len && dbg_i < debugger_size)
|
||||||
|
@ -1039,7 +1039,7 @@ static void *WinVEH_handle = NULL;
|
|||||||
|
|
||||||
#define DEBUGGER_BUFFER_SIZE (MAX_PATH + 1)
|
#define DEBUGGER_BUFFER_SIZE (MAX_PATH + 1)
|
||||||
/* This is the debugger that we'll run on crash */
|
/* This is the debugger that we'll run on crash */
|
||||||
static char debugger[DEBUGGER_BUFFER_SIZE];
|
static wchar_t debugger[DEBUGGER_BUFFER_SIZE];
|
||||||
|
|
||||||
static gsize number_of_exceptions_to_catch = 0;
|
static gsize number_of_exceptions_to_catch = 0;
|
||||||
static DWORD *exceptions_to_catch = NULL;
|
static DWORD *exceptions_to_catch = NULL;
|
||||||
@ -1101,14 +1101,14 @@ copy_chars (char *buffer,
|
|||||||
* as the handler is installed. Therefore, it's imperative that
|
* as the handler is installed. Therefore, it's imperative that
|
||||||
* it does as little as possible. Preferably, all the work that can be
|
* it does as little as possible. Preferably, all the work that can be
|
||||||
* done in advance (when the program is not crashing yet) should be done
|
* done in advance (when the program is not crashing yet) should be done
|
||||||
* in advance. And this function certainly does not need to use Unicode.
|
* in advance.
|
||||||
*/
|
*/
|
||||||
static LONG __stdcall
|
static LONG __stdcall
|
||||||
g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
|
g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
|
||||||
{
|
{
|
||||||
EXCEPTION_RECORD *er;
|
EXCEPTION_RECORD *er;
|
||||||
gsize i;
|
gsize i;
|
||||||
STARTUPINFOA si;
|
STARTUPINFOW si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
#define ITOA_BUFFER_SIZE 100
|
#define ITOA_BUFFER_SIZE 100
|
||||||
char itoa_buffer[ITOA_BUFFER_SIZE];
|
char itoa_buffer[ITOA_BUFFER_SIZE];
|
||||||
@ -1147,7 +1147,7 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
|
|||||||
si.cb = sizeof (si);
|
si.cb = sizeof (si);
|
||||||
|
|
||||||
/* Run the debugger */
|
/* Run the debugger */
|
||||||
if (0 != CreateProcessA (NULL, debugger, NULL, NULL, TRUE, debugger_spawn_flags, NULL, NULL, &si, &pi))
|
if (0 != CreateProcessW (NULL, debugger, NULL, NULL, TRUE, debugger_spawn_flags, NULL, NULL, &si, &pi))
|
||||||
{
|
{
|
||||||
CloseHandle (pi.hProcess);
|
CloseHandle (pi.hProcess);
|
||||||
CloseHandle (pi.hThread);
|
CloseHandle (pi.hThread);
|
||||||
@ -1229,25 +1229,25 @@ g_win32_veh_handler (PEXCEPTION_POINTERS ExceptionInfo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gsize
|
static gsize
|
||||||
parse_catch_list (const char *catch_buffer,
|
parse_catch_list (const wchar_t *catch_buffer,
|
||||||
DWORD *exceptions,
|
DWORD *exceptions,
|
||||||
gsize num_exceptions)
|
gsize num_exceptions)
|
||||||
{
|
{
|
||||||
const char *catch_list = catch_buffer;
|
const wchar_t *catch_list = catch_buffer;
|
||||||
gsize result = 0;
|
gsize result = 0;
|
||||||
gsize i = 0;
|
gsize i = 0;
|
||||||
|
|
||||||
while (catch_list != NULL &&
|
while (catch_list != NULL &&
|
||||||
catch_list[0] != 0)
|
catch_list[0] != 0)
|
||||||
{
|
{
|
||||||
unsigned long catch_code;
|
unsigned long catch_code;
|
||||||
char *end;
|
wchar_t *end;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
catch_code = strtoul (catch_list, &end, 16);
|
catch_code = wcstoul (catch_list, &end, 16);
|
||||||
if (errno != NO_ERROR)
|
if (errno != NO_ERROR)
|
||||||
break;
|
break;
|
||||||
catch_list = end;
|
catch_list = end;
|
||||||
if (catch_list != NULL && catch_list[0] == ',')
|
if (catch_list != NULL && catch_list[0] == L',')
|
||||||
catch_list++;
|
catch_list++;
|
||||||
if (exceptions && i < num_exceptions)
|
if (exceptions && i < num_exceptions)
|
||||||
exceptions[i++] = catch_code;
|
exceptions[i++] = catch_code;
|
||||||
@ -1259,9 +1259,9 @@ parse_catch_list (const char *catch_buffer,
|
|||||||
void
|
void
|
||||||
g_crash_handler_win32_init (void)
|
g_crash_handler_win32_init (void)
|
||||||
{
|
{
|
||||||
char debugger_env[DEBUGGER_BUFFER_SIZE];
|
wchar_t debugger_env[DEBUGGER_BUFFER_SIZE];
|
||||||
#define CATCH_BUFFER_SIZE 1024
|
#define CATCH_BUFFER_SIZE 1024
|
||||||
char catch_buffer[CATCH_BUFFER_SIZE];
|
wchar_t catch_buffer[CATCH_BUFFER_SIZE];
|
||||||
SECURITY_ATTRIBUTES sa;
|
SECURITY_ATTRIBUTES sa;
|
||||||
|
|
||||||
if (WinVEH_handle != NULL)
|
if (WinVEH_handle != NULL)
|
||||||
@ -1273,7 +1273,7 @@ g_crash_handler_win32_init (void)
|
|||||||
* code. See: http://www.windows-tech.info/13/785f590867bd6316.php
|
* code. See: http://www.windows-tech.info/13/785f590867bd6316.php
|
||||||
*/
|
*/
|
||||||
debugger_env[0] = 0;
|
debugger_env[0] = 0;
|
||||||
if (!GetEnvironmentVariableA ("G_DEBUGGER", debugger_env, DEBUGGER_BUFFER_SIZE))
|
if (!GetEnvironmentVariableW (L"G_DEBUGGER", debugger_env, DEBUGGER_BUFFER_SIZE))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Create an inheritable event */
|
/* Create an inheritable event */
|
||||||
@ -1283,19 +1283,19 @@ g_crash_handler_win32_init (void)
|
|||||||
debugger_wakeup_event = CreateEvent (&sa, FALSE, FALSE, NULL);
|
debugger_wakeup_event = CreateEvent (&sa, FALSE, FALSE, NULL);
|
||||||
|
|
||||||
/* Put process ID and event handle into debugger commandline */
|
/* Put process ID and event handle into debugger commandline */
|
||||||
if (!_g_win32_subst_pid_and_event (debugger, G_N_ELEMENTS (debugger),
|
if (!_g_win32_subst_pid_and_event_w (debugger, G_N_ELEMENTS (debugger),
|
||||||
debugger_env, GetCurrentProcessId (),
|
debugger_env, GetCurrentProcessId (),
|
||||||
(guintptr) debugger_wakeup_event))
|
(guintptr) debugger_wakeup_event))
|
||||||
{
|
{
|
||||||
CloseHandle (debugger_wakeup_event);
|
CloseHandle (debugger_wakeup_event);
|
||||||
debugger_wakeup_event = 0;
|
debugger_wakeup_event = 0;
|
||||||
debugger[0] = 0;
|
debugger[0] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
debugger[MAX_PATH] = '\0';
|
debugger[MAX_PATH] = L'\0';
|
||||||
|
|
||||||
catch_buffer[0] = 0;
|
catch_buffer[0] = 0;
|
||||||
if (GetEnvironmentVariableA ("G_VEH_CATCH", catch_buffer, CATCH_BUFFER_SIZE))
|
if (GetEnvironmentVariableW (L"G_VEH_CATCH", catch_buffer, CATCH_BUFFER_SIZE))
|
||||||
{
|
{
|
||||||
number_of_exceptions_to_catch = parse_catch_list (catch_buffer, NULL, 0);
|
number_of_exceptions_to_catch = parse_catch_list (catch_buffer, NULL, 0);
|
||||||
if (number_of_exceptions_to_catch > 0)
|
if (number_of_exceptions_to_catch > 0)
|
||||||
@ -1305,7 +1305,7 @@ g_crash_handler_win32_init (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetEnvironmentVariableA ("G_DEBUGGER_OLD_CONSOLE", (char *) &debugger_spawn_flags, 1))
|
if (GetEnvironmentVariableW (L"G_DEBUGGER_OLD_CONSOLE", (wchar_t *) &debugger_spawn_flags, 1))
|
||||||
debugger_spawn_flags = 0;
|
debugger_spawn_flags = 0;
|
||||||
else
|
else
|
||||||
debugger_spawn_flags = CREATE_NEW_CONSOLE;
|
debugger_spawn_flags = CREATE_NEW_CONSOLE;
|
||||||
|
Loading…
Reference in New Issue
Block a user