debug.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // (C) Copyright Gennadiy Rozental 2001.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. //! @file
  8. //! @brief defines portable debug interfaces
  9. //!
  10. //! Intended to standardize interface of programs with debuggers
  11. // ***************************************************************************
  12. #ifndef BOOST_TEST_DEBUG_API_HPP_112006GER
  13. #define BOOST_TEST_DEBUG_API_HPP_112006GER
  14. // Boost.Test
  15. #include <boost/test/detail/config.hpp>
  16. #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
  17. // Boost
  18. #include <boost/function/function1.hpp>
  19. // STL
  20. #include <string>
  21. #include <boost/test/detail/suppress_warnings.hpp>
  22. //____________________________________________________________________________//
  23. namespace boost {
  24. /// Contains debugger and debug C Runtime interfaces
  25. namespace debug {
  26. /// @defgroup DebuggerInterface Debugger and debug C Runtime portable interfaces
  27. /// @{
  28. /// These interfaces are intended to be used by application to:
  29. /// - check if we are running under debugger
  30. /// - attach the debugger to itself
  31. ///
  32. /// Unfortunately these actions differ widely between different debuggers available in a field. These interface present generalized standard form of
  33. /// performing these actions. Implementation depends a lot on the environment application is running in and thus there are several custom implementations
  34. /// supported by the Boost.Test
  35. ///
  36. /// In addition here you find interfaces for memory leaks detection and reporting.
  37. ///
  38. /// All these interfaces are defined in namespace boost::debug
  39. // ************************************************************************** //
  40. /// Checks if programs runs under debugger
  41. /// @returns true if current process is under debugger. False otherwise
  42. // ************************************************************************** //
  43. bool BOOST_TEST_DECL under_debugger();
  44. // ************************************************************************** //
  45. /// Cause program to break execution in debugger at call point
  46. // ************************************************************************** //
  47. void BOOST_TEST_DECL debugger_break();
  48. // ************************************************************************** //
  49. /// Collection of data, which is used by debugger starter routine
  50. // ************************************************************************** //
  51. struct dbg_startup_info {
  52. long pid; ///< pid of a program to attach to
  53. bool break_or_continue; ///< what to do after debugger is attached
  54. unit_test::const_string binary_path; ///< path to executable for current process
  55. unit_test::const_string display; ///< if debugger has a GUI, which display to use (on UNIX)
  56. unit_test::const_string init_done_lock; ///< path to a uniquely named lock file, which is used to pause current application while debugger is being initialized
  57. };
  58. /// Signature of debugger starter routine. Takes an instance of dbg_startup_into as only argument
  59. typedef boost::function<void (dbg_startup_info const&)> dbg_starter;
  60. // ************************************************************************** //
  61. /// Specifies which debugger to use when attaching and optionally what routine to use to start that debugger
  62. /// There are many different debuggers available for different platforms. Some of them also can be used in a different setups/configuratins.
  63. /// For example, gdb can be used in plain text mode, inside ddd, inside (x)emacs or in a separate xterm window.
  64. /// Boost.Test identifies each configuration with unique string.
  65. /// Also different debuggers configurations require different routines which is specifically tailored to start that debugger configuration.
  66. /// Boost.Test comes with set of predefined configuration names and corresponding routines for these configurations:
  67. /// - TODO
  68. ///
  69. /// You can use this routine to select which one of the predefined debugger configurations to use in which case you do not need to provide starter
  70. /// routine (the one provided by Boost.Test will be used). You can also use this routine to select your own debugger by providing unique configuration
  71. /// id and starter routine for this configuration.
  72. ///
  73. /// @param[in] dbg_id Unique id for debugger configuration (for example, gdb)
  74. /// @param[in] s Optional starter routine for selected configuration (use only you want to define your own configuration)
  75. /// @returns Id of previously selected debugger configuration
  76. std::string BOOST_TEST_DECL set_debugger( unit_test::const_string dbg_id, dbg_starter s = dbg_starter() );
  77. // ************************************************************************** //
  78. /// Attaches debugger to the current process
  79. /// Using currently selected debugger, this routine attempts to attach the debugger to this process.
  80. /// @param[in] break_or_continue tells what we wan to do after the debugger is attached. If true - process execution breaks
  81. /// in the point in invocation of this function. Otherwise execution continues, but now it is
  82. /// under the debugger
  83. /// @returns true if debugger successfully attached. False otherwise
  84. // ************************************************************************** //
  85. bool BOOST_TEST_DECL attach_debugger( bool break_or_continue = true );
  86. // ************************************************************************** //
  87. /// Switches on/off memory leaks detection
  88. /// On platforms where memory leak detection is possible inside of running application (at the moment this is only Windows family) you can
  89. /// switch this feature on and off using this interface. In addition you can specify the name of the file to write a report into. Otherwise
  90. /// the report is going to be generated in standard error stream.
  91. /// @param[in] on_off boolean switch
  92. /// @param[in] report_file file, where the report should be directed to
  93. // ************************************************************************** //
  94. void BOOST_TEST_DECL detect_memory_leaks( bool on_off, unit_test::const_string report_file = unit_test::const_string() );
  95. // ************************************************************************** //
  96. /// Causes program to break execution in debugger at specific allocation point
  97. /// On some platforms/memory managers (at the moment only on Windows/Visual Studio) one can tell a C Runtime to break
  98. /// on specific memory allocation. This can be used in combination with memory leak detection (which reports leaked memory
  99. /// allocation number) to locate the place where leak initiated.
  100. /// @param[in] mem_alloc_order_num Specific memory allocation number
  101. // ************************************************************************** //
  102. void BOOST_TEST_DECL break_memory_alloc( long mem_alloc_order_num );
  103. } // namespace debug
  104. /// @}
  105. } // namespace boost
  106. #include <boost/test/detail/enable_warnings.hpp>
  107. #endif