ipc/chromium/src/base/debug_on_start.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ipc/chromium/src/base/debug_on_start.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
     1.5 +// Use of this source code is governed by a BSD-style license that can be
     1.6 +// found in the LICENSE file.
     1.7 +
     1.8 +// Define the necessary code and global data to look for kDebugOnStart command
     1.9 +// line argument. When the command line argument is detected, it invokes the
    1.10 +// debugger, if no system-wide debugger is registered, a debug break is done.
    1.11 +
    1.12 +#ifndef BASE_DEBUG_ON_START_H_
    1.13 +#define BASE_DEBUG_ON_START_H_
    1.14 +
    1.15 +#include "base/basictypes.h"
    1.16 +
    1.17 +// This only works on MSVC.
    1.18 +#if defined(COMPILER_MSVC)
    1.19 +
    1.20 +#ifndef DECLSPEC_SELECTANY
    1.21 +#define DECLSPEC_SELECTANY  __declspec(selectany)
    1.22 +#endif
    1.23 +
    1.24 +// Debug on start functions and data.
    1.25 +class DebugOnStart {
    1.26 + public:
    1.27 +  // Expected function type in the .CRT$XI* section.
    1.28 +  // Note: See VC\crt\src\internal.h for reference.
    1.29 +  typedef int  (__cdecl *PIFV)(void);
    1.30 +
    1.31 +  // Looks at the command line for kDebugOnStart argument. If found, it invokes
    1.32 +  // the debugger, if this fails, it crashes.
    1.33 +  static int __cdecl Init();
    1.34 +
    1.35 +  // Returns true if the 'argument' is present in the 'command_line'. It does
    1.36 +  // not use the CRT, only Kernel32 functions.
    1.37 +  static bool FindArgument(wchar_t* command_line, const wchar_t* argument);
    1.38 +};
    1.39 +
    1.40 +// Set the function pointer to our function to look for a crash on start. The
    1.41 +// XIB section is started pretty early in the program initialization so in
    1.42 +// theory it should be called before any user created global variable
    1.43 +// initialization code and CRT initialization code.
    1.44 +// Note: See VC\crt\src\defsects.inc and VC\crt\src\crt0.c for reference.
    1.45 +#ifdef _WIN64
    1.46 +
    1.47 +// "Fix" the segment. On x64, the .CRT segment is merged into the .rdata segment
    1.48 +// so it contains const data only.
    1.49 +#pragma const_seg(push, ".CRT$XIB")
    1.50 +// Declare the pointer so the CRT will find it.
    1.51 +extern const DebugOnStart::PIFV debug_on_start;
    1.52 +DECLSPEC_SELECTANY const DebugOnStart::PIFV debug_on_start =
    1.53 +    &DebugOnStart::Init;
    1.54 +// Fix back the segment.
    1.55 +#pragma const_seg(pop)
    1.56 +
    1.57 +#else  // _WIN64
    1.58 +
    1.59 +// "Fix" the segment. On x86, the .CRT segment is merged into the .data segment
    1.60 +// so it contains non-const data only.
    1.61 +#pragma data_seg(push, ".CRT$XIB")
    1.62 +// Declare the pointer so the CRT will find it.
    1.63 +DECLSPEC_SELECTANY DebugOnStart::PIFV debug_on_start = &DebugOnStart::Init;
    1.64 +// Fix back the segment.
    1.65 +#pragma data_seg(pop)
    1.66 +
    1.67 +#endif  // _WIN64
    1.68 +#endif  // defined(OS_WIN)
    1.69 +
    1.70 +#endif  // BASE_DEBUG_ON_START_H_

mercurial