The Gaudi Framework  master (37c0b60a)
Debugger.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 //====================================================================
12 // Debugger.cpp
13 //--------------------------------------------------------------------
14 //
15 // Package : System (The LHCb System service)
16 //
17 // Description: Invoke interactively the debugger from a
18 // running application
19 //
20 // Author : M.Frank
21 // Created : 13/1/99
22 // Changes :
23 //====================================================================
24 #if defined( _WIN32 )
25 
26 # if _MSC_VER < 1500
27 // This causes a problem with VC9
28 // http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/cfb5a608-cc6c-49b5-8e9e-6e2cbeef43a3
29 namespace Win {
30 # else
31 // Empty macro to hide the references to the 'Win' namespace
32 # define Win
33 # endif
34 
35 // Avoid conflicts between Windows' headers and MSG.
36 # ifndef NOMSG
37 # define NOMSG
38 # ifndef NOGDI
39 # define NOGDI
40 # endif
41 # endif
42 # include <process.h>
43 # include <windows.h>
44 
45 # if _MSC_VER < 1500
46 }; // namespace Win
47 # endif
48 
49 #else
50 # include <unistd.h>
51 #endif
52 
53 // Framework include files
54 #include <GaudiKernel/Debugger.h>
55 
58 #ifdef _WIN32
59  _asm int 3 return 1;
60 #else
61  // I have no clue how to do this in linux
62  return 0;
63 #endif
64 }
65 
67 long System::breakExecution( long pid ) {
68 #ifdef _WIN32
69  long result = 0;
70  if ( pid == Win::_getpid() ) {
71  _asm int 3 return 1;
72  } else {
73  Win::LPTHREAD_START_ROUTINE fun;
74  Win::HANDLE th, ph;
75  Win::HINSTANCE mh;
76  Win::DWORD id;
77  mh = Win::LoadLibrary( "Kernel32" );
78  if ( 0 != mh ) {
79  fun = (Win::LPTHREAD_START_ROUTINE)Win::GetProcAddress( mh, "DebugBreak" );
80  if ( 0 != fun ) {
81  ph = Win::OpenProcess( PROCESS_ALL_ACCESS, TRUE, pid );
82  if ( 0 != ph ) {
83  th = Win::CreateRemoteThread( ph, NULL, 0, fun, 0, 0, &id );
84  if ( 0 != th ) {
85  Win::CloseHandle( th );
86  result = 1;
87  }
88  Win::CloseHandle( ph );
89  }
90  }
91  Win::FreeLibrary( mh );
92  }
93  }
94  if ( result != 1 ) result = Win::GetLastError();
95  return result;
96 #else
97  // I have no clue how to do this in linux
98  return pid;
99 #endif
100 }
GaudiPartProp.tests.id
id
Definition: tests.py:111
System::breakExecution
GAUDI_API long breakExecution()
Break the execution of the application and invoke the debugger.
Definition: Debugger.cpp:57
GaudiKernel.Constants.TRUE
TRUE
Definition: Constants.py:37
Debugger.h