Coverage Report

Created: 2025-10-14 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/Debugger.h
Line
Count
Source
1
//
2
// Debugger.h
3
//
4
// Library: Foundation
5
// Package: Core
6
// Module:  Debugger
7
//
8
// Definition of the Debugger class.
9
//
10
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Foundation_Debugger_INCLUDED
18
#define Foundation_Debugger_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
#include <string_view>
23
24
25
namespace Poco {
26
27
28
class Foundation_API Debugger
29
  /// The Debugger class provides an interface to the debugger.
30
  /// The presence of a debugger can be checked for,
31
  /// messages can be written to the debugger's log window
32
  /// and a break into the debugger can be enforced.
33
  /// The methods only work if the program is compiled
34
  /// in debug mode (the macro _DEBUG is defined).
35
{
36
public:
37
  static bool isAvailable();
38
    /// Returns true if a debugger is available, false otherwise.
39
    /// On Windows, this function uses the IsDebuggerPresent()
40
    /// function.
41
    /// On Unix, this function returns true if the environment
42
    /// variable POCO_ENABLE_DEBUGGER is set.
43
44
  static void message(const std::string& msg);
45
    /// Writes a message to the debugger log, if available, otherwise to
46
    /// standard error output.
47
48
  static void message(const std::string& msg, const char* file, LineNumber line);
49
    /// Writes a message to the debugger log, if available, otherwise to
50
    /// standard error output.
51
52
  static void enter();
53
    /// Breaks into the debugger, if it is available.
54
    /// On Windows, this is done using the DebugBreak() function.
55
    /// On Unix, the SIGINT signal is raised.
56
57
  static void enter(const std::string& msg);
58
    /// Writes a debug message to the debugger log and breaks into it.
59
60
  static void enter(const std::string& msg, const char* file, LineNumber line);
61
    /// Writes a debug message to the debugger log and breaks into it.
62
63
  static void enter(const char* file, LineNumber line);
64
    /// Writes a debug message to the debugger log and breaks into it.
65
66
  static constexpr std::string_view sourceFile(const std::string_view& fileName)
67
    /// Utility function for reporting the source file name. The file path is
68
    /// truncated and only the source file name (with extension) is returned.
69
    ///
70
    /// For full location reporting (including function name and line number),
71
    /// see `poco_src_loc` macro.
72
0
  {
73
0
    std::size_t pos = fileName.find_last_of("/\\");
74
0
    if (pos == std::string_view::npos) pos = 0;
75
0
    else if (fileName.length() > 1) ++pos;
76
0
    return std::string_view(fileName.substr(pos));
77
0
  }
78
};
79
80
81
} // namespace Poco
82
83
84
0
#define poco_src_loc std::string(Poco::Debugger::sourceFile(__FILE__)) \
85
0
  .append("::").append(__func__) \
86
  .append("():").append(std::to_string(__LINE__))
87
88
89
#endif // Foundation_Debugger_INCLUDED