The Gaudi Framework  v40r0 (475e45c1)
Debugger.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #if defined( _WIN32 )
12 
13 # if _MSC_VER < 1500
14 // This causes a problem with VC9
15 // http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/cfb5a608-cc6c-49b5-8e9e-6e2cbeef43a3
16 namespace Win {
17 # else
18 // Empty macro to hide the references to the 'Win' namespace
19 # define Win
20 # endif
21 
22 // Avoid conflicts between Windows' headers and MSG.
23 # ifndef NOMSG
24 # define NOMSG
25 # ifndef NOGDI
26 # define NOGDI
27 # endif
28 # endif
29 # include <process.h>
30 # include <windows.h>
31 
32 # if _MSC_VER < 1500
33 }; // namespace Win
34 # endif
35 
36 #else
37 # include <unistd.h>
38 #endif
39 
40 #include <GaudiKernel/Debugger.h>
41 
44 #ifdef _WIN32
45  _asm int 3 return 1;
46 #else
47  // I have no clue how to do this in linux
48  return 0;
49 #endif
50 }
51 
53 long System::breakExecution( long pid ) {
54 #ifdef _WIN32
55  long result = 0;
56  if ( pid == Win::_getpid() ) {
57  _asm int 3 return 1;
58  } else {
59  Win::LPTHREAD_START_ROUTINE fun;
60  Win::HANDLE th, ph;
61  Win::HINSTANCE mh;
62  Win::DWORD id;
63  mh = Win::LoadLibrary( "Kernel32" );
64  if ( 0 != mh ) {
65  fun = (Win::LPTHREAD_START_ROUTINE)Win::GetProcAddress( mh, "DebugBreak" );
66  if ( 0 != fun ) {
67  ph = Win::OpenProcess( PROCESS_ALL_ACCESS, TRUE, pid );
68  if ( 0 != ph ) {
69  th = Win::CreateRemoteThread( ph, NULL, 0, fun, 0, 0, &id );
70  if ( 0 != th ) {
71  Win::CloseHandle( th );
72  result = 1;
73  }
74  Win::CloseHandle( ph );
75  }
76  }
77  Win::FreeLibrary( mh );
78  }
79  }
80  if ( result != 1 ) result = Win::GetLastError();
81  return result;
82 #else
83  // I have no clue how to do this in linux
84  return pid;
85 #endif
86 }
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:43
GaudiKernel.Constants.TRUE
TRUE
Definition: Constants.py:37
Debugger.h