Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Debugger.cpp
Go to the documentation of this file.
1 //====================================================================
2 // Debugger.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : System (The LHCb System service)
6 //
7 // Description: Invoke interactively the debugger from a
8 // running application
9 //
10 // Author : M.Frank
11 // Created : 13/1/99
12 // Changes :
13 //====================================================================
14 #if defined( _WIN32 )
15 
16 # if _MSC_VER < 1500
17 // This causes a problem with VC9
18 // http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/cfb5a608-cc6c-49b5-8e9e-6e2cbeef43a3
19 namespace Win {
20 # else
21 // Empty macro to hide the references to the 'Win' namespace
22 # define Win
23 # endif
24 
25 // Avoid conflicts between Windows' headers and MSG.
26 # ifndef NOMSG
27 # define NOMSG
28 # ifndef NOGDI
29 # define NOGDI
30 # endif
31 # endif
32 # include "process.h"
33 # include "windows.h"
34 
35 # if _MSC_VER < 1500
36 }; // namespace Win
37 # endif
38 
39 #else
40 # include <unistd.h>
41 #endif
42 
43 // Framework include files
44 #include "GaudiKernel/Debugger.h"
45 
48 #ifdef _WIN32
49  _asm int 3 return 1;
50 #else
51  // I have no clue how to do this in linux
52  return 0;
53 #endif
54 }
55 
57 long System::breakExecution( long pid ) {
58 #ifdef _WIN32
59  long result = 0;
60  if ( pid == Win::_getpid() ) {
61  _asm int 3 return 1;
62  } else {
63  Win::LPTHREAD_START_ROUTINE fun;
64  Win::HANDLE th, ph;
65  Win::HINSTANCE mh;
66  Win::DWORD id;
67  mh = Win::LoadLibrary( "Kernel32" );
68  if ( 0 != mh ) {
69  fun = (Win::LPTHREAD_START_ROUTINE)Win::GetProcAddress( mh, "DebugBreak" );
70  if ( 0 != fun ) {
71  ph = Win::OpenProcess( PROCESS_ALL_ACCESS, TRUE, pid );
72  if ( 0 != ph ) {
73  th = Win::CreateRemoteThread( ph, NULL, 0, fun, 0, 0, &id );
74  if ( 0 != th ) {
75  Win::CloseHandle( th );
76  result = 1;
77  }
78  Win::CloseHandle( ph );
79  }
80  }
81  Win::FreeLibrary( mh );
82  }
83  }
84  if ( result != 1 ) result = Win::GetLastError();
85  return result;
86 #else
87  // I have no clue how to do this in linux
88  return pid;
89 #endif
90 }
GAUDI_API long breakExecution()
Break the execution of the application and invoke the debugger.
Definition: Debugger.cpp:47
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26