xpcom/windbgdlg/windbgdlg.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/windbgdlg/windbgdlg.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + *
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/* Windows only app to show a modal debug dialog - launched by nsDebug.cpp */
    1.11 +#include <windows.h>
    1.12 +#include <stdlib.h>
    1.13 +#ifdef _MSC_VER
    1.14 +#include <strsafe.h>
    1.15 +#endif
    1.16 +#ifdef __MINGW32__
    1.17 +/* MingW currently does not implement a wide version of the
    1.18 +   startup routines.  Workaround is to implement something like
    1.19 +   it ourselves.  See bug 472063 */
    1.20 +#include <stdio.h>
    1.21 +#include <shellapi.h>
    1.22 +int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
    1.23 +
    1.24 +#undef __argc
    1.25 +#undef __wargv
    1.26 +
    1.27 +static int __argc;
    1.28 +static wchar_t** __wargv;
    1.29 +
    1.30 +int WINAPI
    1.31 +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    1.32 +        LPSTR lpszCommandLine, int nCmdShow)
    1.33 +{
    1.34 +  LPWSTR commandLine = GetCommandLineW();
    1.35 +
    1.36 +  /* parse for __argc and __wargv for compatibility, since mingw
    1.37 +   * doesn't claim to support it :(
    1.38 +   */
    1.39 +  __wargv = CommandLineToArgvW(commandLine, &__argc);
    1.40 +  if (!__wargv)
    1.41 +    return 127;
    1.42 +
    1.43 +  /* need to strip off any leading whitespace plus the first argument
    1.44 +   * (the executable itself) to match what should be passed to wWinMain
    1.45 +   */
    1.46 +  while ((*commandLine <= L' ') && *commandLine) {
    1.47 +    ++commandLine;
    1.48 +  }
    1.49 +  if (*commandLine == L'"') {
    1.50 +    ++commandLine;
    1.51 +    while ((*commandLine != L'"') && *commandLine) {
    1.52 +      ++commandLine;
    1.53 +    }
    1.54 +    if (*commandLine) {
    1.55 +      ++commandLine;
    1.56 +    }
    1.57 +  } else {
    1.58 +    while (*commandLine > L' ') {
    1.59 +      ++commandLine;
    1.60 +    }
    1.61 +  }
    1.62 +  while ((*commandLine <= L' ') && *commandLine) {
    1.63 +    ++commandLine;
    1.64 +  }
    1.65 +
    1.66 +  int result = wWinMain(hInstance, hPrevInstance, commandLine, nCmdShow);
    1.67 +  LocalFree(__wargv);
    1.68 +  return result;
    1.69 +}
    1.70 +#endif /* __MINGW32__ */
    1.71 +
    1.72 +
    1.73 +int WINAPI
    1.74 +wWinMain(HINSTANCE  hInstance, HINSTANCE  hPrevInstance,
    1.75 +         LPWSTR  lpszCmdLine, int  nCmdShow)
    1.76 +{
    1.77 +    /* support for auto answering based on words in the assertion.
    1.78 +     * the assertion message is sent as a series of arguements (words) to the commandline.
    1.79 +     * set a "word" to 0xffffffff to let the word not affect this code.
    1.80 +     * set a "word" to 0xfffffffe to show the dialog.
    1.81 +     * set a "word" to 0x5 to ignore (program should continue).
    1.82 +     * set a "word" to 0x4 to retry (should fall into debugger).
    1.83 +     * set a "word" to 0x3 to abort (die).
    1.84 +     */
    1.85 +    DWORD regType;
    1.86 +    DWORD regValue = -1;
    1.87 +    DWORD regLength = sizeof regValue;
    1.88 +    HKEY hkeyCU, hkeyLM;
    1.89 +    RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyCU);
    1.90 +    RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\mozilla.org\\windbgdlg", 0, KEY_READ, &hkeyLM);
    1.91 +    int argc =0;
    1.92 +    for (int i = __argc - 1; regValue == (DWORD)-1 && i; --i) {
    1.93 +        bool ok = false;
    1.94 +        if (hkeyCU)
    1.95 +            ok = RegQueryValueExW(hkeyCU, __wargv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
    1.96 +        if (!ok && hkeyLM)
    1.97 +            ok = RegQueryValueExW(hkeyLM, __wargv[i], 0, &regType, (LPBYTE)&regValue, &regLength) == ERROR_SUCCESS;
    1.98 +        if (!ok)
    1.99 +            regValue = -1;
   1.100 +    }
   1.101 +    if (hkeyCU)
   1.102 +        RegCloseKey(hkeyCU);
   1.103 +    if (hkeyLM)
   1.104 +        RegCloseKey(hkeyLM);
   1.105 +    if (regValue != (DWORD)-1 && regValue != (DWORD)-2)
   1.106 +        return regValue;
   1.107 +    static const int size = 4096;
   1.108 +    static WCHAR msg[size];
   1.109 +
   1.110 +#ifdef _MSC_VER
   1.111 +    StringCchPrintfW(msg,
   1.112 +#else
   1.113 +    snwprintf(msg,
   1.114 +#endif
   1.115 +              size,
   1.116 +              L"%s\n\nClick Abort to exit the Application.\n"
   1.117 +              L"Click Retry to Debug the Application.\n"
   1.118 +              L"Click Ignore to continue running the Application.",
   1.119 +              lpszCmdLine);
   1.120 +    msg[size - 1] = L'\0';
   1.121 +    return MessageBoxW(nullptr, msg, L"NSGlue_Assertion",
   1.122 +                       MB_ICONSTOP | MB_SYSTEMMODAL |
   1.123 +                       MB_ABORTRETRYIGNORE | MB_DEFBUTTON3);
   1.124 +}

mercurial