1 // (C) Copyright Gennadiy Rozental 2001.
2 // Use, modification, and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : debug interfaces implementation
13 // ***************************************************************************
15 #ifndef BOOST_TEST_DEBUG_API_IPP_112006GER
16 #define BOOST_TEST_DEBUG_API_IPP_112006GER
19 #include <boost/test/detail/config.hpp>
20 #include <boost/test/detail/workaround.hpp>
21 #include <boost/test/detail/global_typedef.hpp>
23 #include <boost/test/debug.hpp>
24 #include <boost/test/debug_config.hpp>
26 // Implementation on Windows
27 #if defined(_WIN32) && !defined(UNDER_CE) && !defined(BOOST_DISABLE_WIN32) // ******* WIN32
29 # define BOOST_WIN32_BASED_DEBUG
37 # if !defined(NDEBUG) && defined(_MSC_VER)
38 # define BOOST_MS_CRT_BASED_DEBUG
43 # ifdef BOOST_NO_STDC_NAMESPACE
44 namespace std { using ::memset; using ::sprintf; }
47 #elif defined(unix) || defined(__unix) // ********************* UNIX
49 # define BOOST_UNIX_BASED_DEBUG
52 #include <boost/test/utils/class_properties.hpp>
53 #include <boost/test/utils/algorithm.hpp>
56 #include <cstring> // std::memcpy
59 #include <stdarg.h> // !! ?? cstdarg
66 # include <sys/types.h>
67 # include <sys/stat.h>
68 # include <sys/wait.h>
69 # include <sys/time.h>
73 # if defined(sun) || defined(__sun)
75 # define BOOST_SUN_BASED_DEBUG
77 # ifndef BOOST_TEST_DBG_LIST
78 # define BOOST_TEST_DBG_LIST dbx;gdb
81 # define BOOST_TEST_CNL_DBG dbx
82 # define BOOST_TEST_GUI_DBG dbx-ddd
86 # elif defined(linux) || defined(__linux)
88 # define BOOST_LINUX_BASED_DEBUG
90 # include <sys/ptrace.h>
92 # ifndef BOOST_TEST_STAT_LINE_MAX
93 # define BOOST_TEST_STAT_LINE_MAX 500
96 # ifndef BOOST_TEST_DBG_LIST
97 # define BOOST_TEST_DBG_LIST gdb
100 # define BOOST_TEST_CNL_DBG gdb
101 # define BOOST_TEST_GUI_DBG gdb-xterm
107 #include <boost/test/detail/suppress_warnings.hpp>
109 //____________________________________________________________________________//
114 using unit_test::const_string;
116 // ************************************************************************** //
117 // ************** debug::info_t ************** //
118 // ************************************************************************** //
122 #if defined(BOOST_WIN32_BASED_DEBUG) // *********************** WIN32
126 dyn_symbol( T& res, char const* module_name, char const* symbol_name )
128 HMODULE m = ::GetModuleHandleA( module_name );
131 m = ::LoadLibraryA( module_name );
133 res = reinterpret_cast<T>( ::GetProcAddress( m, symbol_name ) );
136 //____________________________________________________________________________//
138 static struct info_t {
139 typedef BOOL (WINAPI* IsDebuggerPresentT)();
140 typedef LONG (WINAPI* RegQueryValueExT)( HKEY, char const* /*LPTSTR*/, LPDWORD, LPDWORD, LPBYTE, LPDWORD );
141 typedef LONG (WINAPI* RegOpenKeyT)( HKEY, char const* /*LPCTSTR*/, PHKEY );
142 typedef LONG (WINAPI* RegCloseKeyT)( HKEY );
146 IsDebuggerPresentT m_is_debugger_present;
147 RegOpenKeyT m_reg_open_key;
148 RegQueryValueExT m_reg_query_value;
149 RegCloseKeyT m_reg_close_key;
153 //____________________________________________________________________________//
157 dyn_symbol( m_is_debugger_present, "kernel32", "IsDebuggerPresent" );
158 dyn_symbol( m_reg_open_key, "advapi32", "RegOpenKeyA" );
159 dyn_symbol( m_reg_query_value, "advapi32", "RegQueryValueExA" );
160 dyn_symbol( m_reg_close_key, "advapi32", "RegCloseKey" );
163 //____________________________________________________________________________//
165 #elif defined(BOOST_UNIX_BASED_DEBUG)
167 // ************************************************************************** //
168 // ************** fd_holder ************** //
169 // ************************************************************************** //
172 explicit fd_holder( int fd ) : m_fd( fd ) {}
179 operator int() { return m_fd; }
187 // ************************************************************************** //
188 // ************** process_info ************** //
189 // ************************************************************************** //
191 struct process_info {
193 explicit process_info( int pid );
196 int parent_pid() const { return m_parent_pid; }
197 const_string binary_name() const { return m_binary_name; }
198 const_string binary_path() const { return m_binary_path; }
203 const_string m_binary_name;
204 const_string m_binary_path;
206 #if defined(BOOST_SUN_BASED_DEBUG)
208 char m_binary_path_buff[500+1]; // !! ??
209 #elif defined(BOOST_LINUX_BASED_DEBUG)
210 char m_stat_line[BOOST_TEST_STAT_LINE_MAX+1];
211 char m_binary_path_buff[500+1]; // !! ??
215 //____________________________________________________________________________//
217 process_info::process_info( int pid )
220 #if defined(BOOST_SUN_BASED_DEBUG)
223 ::snprintf( fname_buff, sizeof(fname_buff), "/proc/%d/psinfo", pid );
225 fd_holder psinfo_fd( ::open( fname_buff, O_RDONLY ) );
227 if( psinfo_fd == -1 )
230 if( ::read( psinfo_fd, &m_psi, sizeof(m_psi) ) == -1 )
233 m_parent_pid = m_psi.pr_ppid;
235 m_binary_name.assign( m_psi.pr_fname );
237 //-------------------------- //
239 ::snprintf( fname_buff, sizeof(fname_buff), "/proc/%d/as", pid );
241 fd_holder as_fd( ::open( fname_buff, O_RDONLY ) );
242 uintptr_t binary_name_pos;
244 // !! ?? could we avoid reading whole m_binary_path_buff?
246 ::lseek( as_fd, m_psi.pr_argv, SEEK_SET ) == -1 ||
247 ::read ( as_fd, &binary_name_pos, sizeof(binary_name_pos) ) == -1 ||
248 ::lseek( as_fd, binary_name_pos, SEEK_SET ) == -1 ||
249 ::read ( as_fd, m_binary_path_buff, sizeof(m_binary_path_buff) ) == -1 )
252 m_binary_path.assign( m_binary_path_buff );
254 #elif defined(BOOST_LINUX_BASED_DEBUG)
257 ::snprintf( fname_buff, sizeof(fname_buff), "/proc/%d/stat", pid );
259 fd_holder psinfo_fd( ::open( fname_buff, O_RDONLY ) );
261 if( psinfo_fd == -1 )
264 ssize_t num_read = ::read( psinfo_fd, m_stat_line, sizeof(m_stat_line)-1 );
268 m_stat_line[num_read] = 0;
270 char const* name_beg = m_stat_line;
271 while( *name_beg && *name_beg != '(' )
274 char const* name_end = name_beg+1;
275 while( *name_end && *name_end != ')' )
278 std::sscanf( name_end+1, "%*s%d", &m_parent_pid );
280 m_binary_name.assign( name_beg+1, name_end );
282 ::snprintf( fname_buff, sizeof(fname_buff), "/proc/%d/exe", pid );
283 num_read = ::readlink( fname_buff, m_binary_path_buff, sizeof(m_binary_path_buff)-1 );
288 m_binary_path_buff[num_read] = 0;
289 m_binary_path.assign( m_binary_path_buff, num_read );
293 //____________________________________________________________________________//
295 // ************************************************************************** //
296 // ************** prepare_window_title ************** //
297 // ************************************************************************** //
300 prepare_window_title( dbg_startup_info const& dsi )
302 typedef unit_test::const_string str_t;
304 static char title_str[50];
306 str_t path_sep( "\\/" );
308 str_t::iterator it = unit_test::utils::find_last_of( dsi.binary_path.begin(), dsi.binary_path.end(),
309 path_sep.begin(), path_sep.end() );
311 if( it == dsi.binary_path.end() )
312 it = dsi.binary_path.begin();
316 ::snprintf( title_str, sizeof(title_str), "%*s %ld", (int)(dsi.binary_path.end()-it), it, dsi.pid );
321 //____________________________________________________________________________//
323 // ************************************************************************** //
324 // ************** save_execlp ************** //
325 // ************************************************************************** //
327 typedef unit_test::basic_cstring<char> mbuffer;
330 copy_arg( mbuffer& dest, const_string arg )
332 if( dest.size() < arg.size()+1 )
335 char* res = dest.begin();
337 std::memcpy( res, arg.begin(), arg.size()+1 );
339 dest.trim_left( arg.size()+1 );
344 //____________________________________________________________________________//
347 safe_execlp( char const* file, ... )
349 static char* argv_buff[200];
354 // first calculate actual number of arguments
355 int num_args = 2; // file name and 0 at least
357 va_start( args, file );
358 while( !!(arg = va_arg( args, char const* )) )
362 // reserve space for the argument pointers array
363 char** argv_it = argv_buff;
364 mbuffer work_buff( reinterpret_cast<char*>(argv_buff), sizeof(argv_buff) );
365 work_buff.trim_left( num_args * sizeof(char*) );
367 // copy all the argument values into local storage
368 if( !(*argv_it++ = copy_arg( work_buff, file )) )
371 printf( "!! %s\n", file );
373 va_start( args, file );
374 while( !!(arg = va_arg( args, char const* )) ) {
375 printf( "!! %s\n", arg );
376 if( !(*argv_it++ = copy_arg( work_buff, arg )) ) {
385 return ::execvp( file, argv_buff ) != -1;
388 //____________________________________________________________________________//
390 // ************************************************************************** //
391 // ************** start_debugger_in_emacs ************** //
392 // ************************************************************************** //
395 start_debugger_in_emacs( dbg_startup_info const& dsi, char const* emacs_name, char const* dbg_command )
397 char const* title = prepare_window_title( dsi );
402 dsi.display.is_empty()
403 ? safe_execlp( emacs_name, "-title", title, "--eval", dbg_command, 0 )
404 : safe_execlp( emacs_name, "-title", title, "-display", dsi.display.begin(), "--eval", dbg_command, 0 );
407 //____________________________________________________________________________//
409 // ************************************************************************** //
410 // ************** gdb starters ************** //
411 // ************************************************************************** //
414 prepare_gdb_cmnd_file( dbg_startup_info const& dsi )
418 ::snprintf( pid_buff, sizeof(pid_buff), "%ld", dsi.pid );
419 unit_test::const_string pid_str( pid_buff );
421 static char cmd_file_name[] = "/tmp/btl_gdb_cmd_XXXXXX"; // !! ??
424 fd_holder cmd_fd( ::mkstemp( cmd_file_name ) );
429 #define WRITE_STR( str ) if( ::write( cmd_fd, str.begin(), str.size() ) == -1 ) return 0;
430 #define WRITE_CSTR( str ) if( ::write( cmd_fd, str, sizeof( str )-1 ) == -1 ) return 0;
432 WRITE_CSTR( "file " );
433 WRITE_STR( dsi.binary_path );
434 WRITE_CSTR( "\nattach " );
435 WRITE_STR( pid_str );
436 WRITE_CSTR( "\nshell unlink " );
437 WRITE_STR( dsi.init_done_lock );
438 WRITE_CSTR( "\ncont" );
439 if( dsi.break_or_continue )
440 WRITE_CSTR( "\nup 4" );
442 WRITE_CSTR( "\necho \\n" ); // !! ??
443 WRITE_CSTR( "\nlist -" );
444 WRITE_CSTR( "\nlist" );
445 WRITE_CSTR( "\nshell unlink " );
446 WRITE_CSTR( cmd_file_name );
448 return cmd_file_name;
451 //____________________________________________________________________________//
454 start_gdb_in_console( dbg_startup_info const& dsi )
456 char const* cmnd_file_name = prepare_gdb_cmnd_file( dsi );
458 if( !cmnd_file_name )
461 safe_execlp( "gdb", "-q", "-x", cmnd_file_name, 0 );
464 //____________________________________________________________________________//
467 start_gdb_in_xterm( dbg_startup_info const& dsi )
469 char const* title = prepare_window_title( dsi );
470 char const* cmnd_file_name = prepare_gdb_cmnd_file( dsi );
472 if( !title || !cmnd_file_name )
475 safe_execlp( "xterm", "-T", title, "-display", dsi.display.begin(),
476 "-bg", "black", "-fg", "white", "-geometry", "88x30+10+10", "-fn", "9x15", "-e",
477 "gdb", "-q", "-x", cmnd_file_name, 0 );
480 //____________________________________________________________________________//
483 start_gdb_in_emacs( dbg_startup_info const& dsi )
485 char const* cmnd_file_name = prepare_gdb_cmnd_file( dsi );
486 if( !cmnd_file_name )
489 char dbg_cmd_buff[500]; // !! ??
490 ::snprintf( dbg_cmd_buff, sizeof(dbg_cmd_buff), "(progn (gdb \"gdb -q -x %s\"))", cmnd_file_name );
492 start_debugger_in_emacs( dsi, "emacs", dbg_cmd_buff );
495 //____________________________________________________________________________//
498 start_gdb_in_xemacs( dbg_startup_info const& )
503 //____________________________________________________________________________//
505 // ************************************************************************** //
506 // ************** dbx starters ************** //
507 // ************************************************************************** //
510 prepare_dbx_cmd_line( dbg_startup_info const& dsi, bool list_source = true )
512 static char cmd_line_buff[500]; // !! ??
514 ::snprintf( cmd_line_buff, sizeof(cmd_line_buff), "unlink %s;cont;%s%s",
515 dsi.init_done_lock.begin(),
516 dsi.break_or_continue ? "up 2;": "",
517 list_source ? "echo \" \";list -w3;" : "" );
519 return cmd_line_buff;
522 //____________________________________________________________________________//
525 start_dbx_in_console( dbg_startup_info const& dsi )
528 ::snprintf( pid_buff, sizeof(pid_buff), "%ld", dsi.pid );
530 safe_execlp( "dbx", "-q", "-c", prepare_dbx_cmd_line( dsi ), dsi.binary_path.begin(), pid_buff, 0 );
533 //____________________________________________________________________________//
536 start_dbx_in_xterm( dbg_startup_info const& dsi )
538 char const* title = prepare_window_title( dsi );
542 char pid_buff[16]; // !! ??
543 ::snprintf( pid_buff, sizeof(pid_buff), "%ld", dsi.pid );
545 safe_execlp( "xterm", "-T", title, "-display", dsi.display.begin(),
546 "-bg", "black", "-fg", "white", "-geometry", "88x30+10+10", "-fn", "9x15", "-e",
547 "dbx", "-q", "-c", prepare_dbx_cmd_line( dsi ), dsi.binary_path.begin(), pid_buff, 0 );
550 //____________________________________________________________________________//
553 start_dbx_in_emacs( dbg_startup_info const& /*dsi*/ )
555 // char dbg_cmd_buff[500]; // !! ??
557 // ::snprintf( dbg_cmd_buff, sizeof(dbg_cmd_buff), "(progn (dbx \"dbx -q -c cont %s %ld\"))", dsi.binary_path.begin(), dsi.pid );
559 // start_debugger_in_emacs( dsi, "emacs", dbg_cmd_buff );
562 //____________________________________________________________________________//
565 start_dbx_in_xemacs( dbg_startup_info const& )
570 //____________________________________________________________________________//
573 start_dbx_in_ddd( dbg_startup_info const& dsi )
575 char const* title = prepare_window_title( dsi );
579 char pid_buff[16]; // !! ??
580 ::snprintf( pid_buff, sizeof(pid_buff), "%ld", dsi.pid );
582 safe_execlp( "ddd", "-display", dsi.display.begin(),
583 "--dbx", "-q", "-c", prepare_dbx_cmd_line( dsi, false ), dsi.binary_path.begin(), pid_buff, 0 );
586 //____________________________________________________________________________//
588 // ************************************************************************** //
589 // ************** debug::info_t ************** //
590 // ************************************************************************** //
592 static struct info_t {
597 unit_test::readwrite_property<std::string> p_dbg;
600 std::map<std::string,dbg_starter> m_dbg_starter_reg;
603 //____________________________________________________________________________//
607 p_dbg.value = ::getenv( "DISPLAY" )
608 ? std::string( BOOST_STRINGIZE( BOOST_TEST_GUI_DBG ) )
609 : std::string( BOOST_STRINGIZE( BOOST_TEST_CNL_DBG ) );
611 m_dbg_starter_reg[std::string("gdb")] = &start_gdb_in_console;
612 m_dbg_starter_reg[std::string("gdb-emacs")] = &start_gdb_in_emacs;
613 m_dbg_starter_reg[std::string("gdb-xterm")] = &start_gdb_in_xterm;
614 m_dbg_starter_reg[std::string("gdb-xemacs")] = &start_gdb_in_xemacs;
616 m_dbg_starter_reg[std::string("dbx")] = &start_dbx_in_console;
617 m_dbg_starter_reg[std::string("dbx-emacs")] = &start_dbx_in_emacs;
618 m_dbg_starter_reg[std::string("dbx-xterm")] = &start_dbx_in_xterm;
619 m_dbg_starter_reg[std::string("dbx-xemacs")] = &start_dbx_in_xemacs;
620 m_dbg_starter_reg[std::string("dbx-ddd")] = &start_dbx_in_ddd;
623 //____________________________________________________________________________//
629 // ************************************************************************** //
630 // ************** check if program is running under debugger ************** //
631 // ************************************************************************** //
636 #if defined(BOOST_WIN32_BASED_DEBUG) // *********************** WIN32
638 return !!s_info.m_is_debugger_present && s_info.m_is_debugger_present();
640 #elif defined(BOOST_UNIX_BASED_DEBUG) // ********************** UNIX
642 // !! ?? could/should we cache the result somehow?
643 const_string dbg_list = BOOST_TEST_STRINGIZE( BOOST_TEST_DBG_LIST );
645 pid_t pid = ::getpid();
648 process_info pi( pid );
650 // !! ?? should we use tokenizer here instead?
651 if( dbg_list.find( pi.binary_name() ) != const_string::npos )
654 pid = (pi.parent_pid() == pid ? 0 : pi.parent_pid());
659 #else // ****************************************************** default
666 //____________________________________________________________________________//
668 // ************************************************************************** //
669 // ************** cause program to break execution ************** //
670 // ************** in debugger at call point ************** //
671 // ************************************************************************** //
676 // !! ?? auto-start debugger?
678 #if defined(BOOST_WIN32_BASED_DEBUG) // *********************** WIN32
680 #if defined(__GNUC__) && !defined(__MINGW32__) || \
681 defined(__INTEL_COMPILER)
682 # define BOOST_DEBUG_BREAK __debugbreak
684 # define BOOST_DEBUG_BREAK DebugBreak
688 if( !under_debugger() ) {
693 __except( UnhandledExceptionFilter(GetExceptionInformation()) )
695 // User opted to ignore the breakpoint
699 __except (EXCEPTION_EXECUTE_HANDLER)
701 // If we got here, the user has pushed Debug. Debugger is already attached to our process and we
702 // continue to let the another BOOST_DEBUG_BREAK to be called.
709 #elif defined(BOOST_UNIX_BASED_DEBUG) // ********************** UNIX
711 ::kill( ::getpid(), SIGTRAP );
713 #else // ****************************************************** default
718 //____________________________________________________________________________//
720 // ************************************************************************** //
721 // ************** console debugger setup ************** //
722 // ************************************************************************** //
724 #if defined(BOOST_UNIX_BASED_DEBUG) // ************************ UNIX
727 set_debugger( unit_test::const_string dbg_id, dbg_starter s )
729 std::string old = s_info.p_dbg;
731 assign_op( s_info.p_dbg.value, dbg_id, 0 );
734 s_info.m_dbg_starter_reg[s_info.p_dbg.get()] = s;
739 #else // ***************************************************** default
742 set_debugger( unit_test::const_string, dbg_starter )
744 return std::string();
749 //____________________________________________________________________________//
751 // ************************************************************************** //
752 // ************** attach debugger to the current process ************** //
753 // ************************************************************************** //
755 #if defined(BOOST_WIN32_BASED_DEBUG)
757 struct safe_handle_helper
760 safe_handle_helper(HANDLE &handle_) : handle(handle_) {}
764 if( handle != INVALID_HANDLE_VALUE )
766 ::CloseHandle( handle );
767 handle = INVALID_HANDLE_VALUE;
771 ~safe_handle_helper()
779 attach_debugger( bool break_or_continue )
781 if( under_debugger() )
784 #if defined(BOOST_WIN32_BASED_DEBUG) // *********************** WIN32
786 const int MAX_CMD_LINE = 200;
788 // *************************************************** //
789 // Debugger "ready" event
791 SECURITY_ATTRIBUTES attr;
792 attr.nLength = sizeof(attr);
793 attr.lpSecurityDescriptor = NULL;
794 attr.bInheritHandle = true;
796 // manual resettable, initially non signaled, unnamed event,
797 // that will signal me that debugger initialization is done
798 HANDLE dbg_init_done_ev = ::CreateEvent(
799 &attr, // pointer to security attributes
800 true, // flag for manual-reset event
801 false, // flag for initial state
802 NULL // pointer to event-object name
805 if( !dbg_init_done_ev )
808 safe_handle_helper safe_handle_obj( dbg_init_done_ev );
810 // *************************************************** //
811 // Debugger command line format
815 if( !s_info.m_reg_open_key || (*s_info.m_reg_open_key)(
816 HKEY_LOCAL_MACHINE, // handle of open key
817 "Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", // name of subkey to open
818 ®_key ) != ERROR_SUCCESS ) // address of handle of open key
821 char format[MAX_CMD_LINE];
822 DWORD format_size = MAX_CMD_LINE;
825 bool b_read_key = s_info.m_reg_query_value &&
826 ((*s_info.m_reg_query_value)(
827 reg_key, // handle of open key
828 "Debugger", // name of subkey to query
831 (LPBYTE)format, // buffer for returned string
832 &format_size ) == ERROR_SUCCESS ); // in: buffer size; out: actual size of returned string
834 if( !s_info.m_reg_close_key || (*s_info.m_reg_close_key)( reg_key ) != ERROR_SUCCESS )
840 // *************************************************** //
841 // Debugger command line
843 char cmd_line[MAX_CMD_LINE];
844 std::sprintf( cmd_line, format, ::GetCurrentProcessId(), dbg_init_done_ev );
846 // *************************************************** //
847 // Debugger window parameters
849 STARTUPINFOA startup_info;
850 std::memset( &startup_info, 0, sizeof(startup_info) );
852 startup_info.cb = sizeof(startup_info);
853 startup_info.dwFlags = STARTF_USESHOWWINDOW;
854 startup_info.wShowWindow = SW_SHOWNORMAL;
856 // debugger process s_info
857 PROCESS_INFORMATION debugger_info;
859 bool created = !!::CreateProcessA(
860 NULL, // pointer to name of executable module; NULL - use the one in command line
861 cmd_line, // pointer to command line string
862 NULL, // pointer to process security attributes; NULL - debugger's handle can't be inherited
863 NULL, // pointer to thread security attributes; NULL - debugger's handle can't be inherited
864 true, // debugger inherit opened handles
865 0, // priority flags; 0 - normal priority
866 NULL, // pointer to new environment block; NULL - use this process environment
867 NULL, // pointer to current directory name; NULL - use this process correct directory
868 &startup_info, // pointer to STARTUPINFO that specifies main window appearance
869 &debugger_info // pointer to PROCESS_INFORMATION that will contain the new process identification
872 bool debugger_run_ok = false;
875 DWORD ret_code = ::WaitForSingleObject( dbg_init_done_ev, INFINITE );
876 debugger_run_ok = ( ret_code == WAIT_OBJECT_0 );
879 safe_handle_obj.close_handle();
881 if( !created || !debugger_run_ok )
884 if( break_or_continue )
889 #elif defined(BOOST_UNIX_BASED_DEBUG) // ********************** UNIX
891 char init_done_lock_fn[] = "/tmp/btl_dbg_init_done_XXXXXX";
892 fd_holder init_done_lock_fd( ::mkstemp( init_done_lock_fn ) );
894 if( init_done_lock_fd == -1 )
897 pid_t child_pid = fork();
899 if( child_pid == -1 )
902 if( child_pid != 0 ) { // parent process - here we will start the debugger
903 dbg_startup_info dsi;
905 process_info pi( child_pid );
906 if( pi.binary_path().is_empty() )
910 dsi.break_or_continue = break_or_continue;
911 dsi.binary_path = pi.binary_path();
912 dsi.display = ::getenv( "DISPLAY" );
913 dsi.init_done_lock = init_done_lock_fn;
915 dbg_starter starter = s_info.m_dbg_starter_reg[s_info.p_dbg];
919 ::perror( "Boost.Test execution monitor failed to start a debugger:" );
924 // child process - here we will continue our test module execution ; // !! ?? should it be vice versa
926 while( ::access( init_done_lock_fn, F_OK ) == 0 ) {
927 struct timeval to = { 0, 100 };
929 ::select( 0, 0, 0, 0, &to );
933 // while( ::read( init_done_lock_fd, &dummy, sizeof(char) ) == 0 );
935 if( break_or_continue )
940 #else // ****************************************************** default
947 //____________________________________________________________________________//
949 // ************************************************************************** //
950 // ************** switch on/off detect memory leaks feature ************** //
951 // ************************************************************************** //
954 detect_memory_leaks( bool on_off, unit_test::const_string report_file )
956 unit_test::ut_detail::ignore_unused_variable_warning( on_off );
958 #ifdef BOOST_MS_CRT_BASED_DEBUG
959 int flags = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
962 flags &= ~_CRTDBG_LEAK_CHECK_DF;
964 flags |= _CRTDBG_LEAK_CHECK_DF;
965 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
967 if( report_file.is_empty() )
968 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
970 HANDLE hreport_f = ::CreateFileA( report_file.begin(),
971 GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
972 _CrtSetReportFile(_CRT_WARN, hreport_f );
976 _CrtSetDbgFlag ( flags );
978 unit_test::ut_detail::ignore_unused_variable_warning( report_file );
979 #endif // BOOST_MS_CRT_BASED_DEBUG
982 //____________________________________________________________________________//
984 // ************************************************************************** //
985 // ************** cause program to break execution in ************** //
986 // ************** debugger at specific allocation point ************** //
987 // ************************************************************************** //
990 break_memory_alloc( long mem_alloc_order_num )
992 unit_test::ut_detail::ignore_unused_variable_warning( mem_alloc_order_num );
994 #ifdef BOOST_MS_CRT_BASED_DEBUG
995 // only set the value if one was supplied (do not use default used by UTF just as a indicator to enable leak detection)
996 if( mem_alloc_order_num > 1 )
997 _CrtSetBreakAlloc( mem_alloc_order_num );
998 #endif // BOOST_MS_CRT_BASED_DEBUG
1001 //____________________________________________________________________________//
1003 } // namespace debug
1004 } // namespace boost
1006 #include <boost/test/detail/enable_warnings.hpp>
1008 #endif // BOOST_TEST_DEBUG_API_IPP_112006GER