ipc/chromium/src/base/debug_on_start.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     2 // Use of this source code is governed by a BSD-style license that can be
     3 // found in the LICENSE file.
     5 // Define the necessary code and global data to look for kDebugOnStart command
     6 // line argument. When the command line argument is detected, it invokes the
     7 // debugger, if no system-wide debugger is registered, a debug break is done.
     9 #ifndef BASE_DEBUG_ON_START_H_
    10 #define BASE_DEBUG_ON_START_H_
    12 #include "base/basictypes.h"
    14 // This only works on MSVC.
    15 #if defined(COMPILER_MSVC)
    17 #ifndef DECLSPEC_SELECTANY
    18 #define DECLSPEC_SELECTANY  __declspec(selectany)
    19 #endif
    21 // Debug on start functions and data.
    22 class DebugOnStart {
    23  public:
    24   // Expected function type in the .CRT$XI* section.
    25   // Note: See VC\crt\src\internal.h for reference.
    26   typedef int  (__cdecl *PIFV)(void);
    28   // Looks at the command line for kDebugOnStart argument. If found, it invokes
    29   // the debugger, if this fails, it crashes.
    30   static int __cdecl Init();
    32   // Returns true if the 'argument' is present in the 'command_line'. It does
    33   // not use the CRT, only Kernel32 functions.
    34   static bool FindArgument(wchar_t* command_line, const wchar_t* argument);
    35 };
    37 // Set the function pointer to our function to look for a crash on start. The
    38 // XIB section is started pretty early in the program initialization so in
    39 // theory it should be called before any user created global variable
    40 // initialization code and CRT initialization code.
    41 // Note: See VC\crt\src\defsects.inc and VC\crt\src\crt0.c for reference.
    42 #ifdef _WIN64
    44 // "Fix" the segment. On x64, the .CRT segment is merged into the .rdata segment
    45 // so it contains const data only.
    46 #pragma const_seg(push, ".CRT$XIB")
    47 // Declare the pointer so the CRT will find it.
    48 extern const DebugOnStart::PIFV debug_on_start;
    49 DECLSPEC_SELECTANY const DebugOnStart::PIFV debug_on_start =
    50     &DebugOnStart::Init;
    51 // Fix back the segment.
    52 #pragma const_seg(pop)
    54 #else  // _WIN64
    56 // "Fix" the segment. On x86, the .CRT segment is merged into the .data segment
    57 // so it contains non-const data only.
    58 #pragma data_seg(push, ".CRT$XIB")
    59 // Declare the pointer so the CRT will find it.
    60 DECLSPEC_SELECTANY DebugOnStart::PIFV debug_on_start = &DebugOnStart::Init;
    61 // Fix back the segment.
    62 #pragma data_seg(pop)
    64 #endif  // _WIN64
    65 #endif  // defined(OS_WIN)
    67 #endif  // BASE_DEBUG_ON_START_H_

mercurial