libcwdversion 2.0.0
The C++ Debugging Support Library
Loading...
Searching...
No Matches
DebugObject_ThreadSpecificData.h
1// SPDX-FileCopyrightText: 2002-2004, 2006, 2018, 2020-2021, 2023, 2026 Carlo Wood
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#ifndef LIBCWD_STRUCT_DEBUG_TSD_H
7#define LIBCWD_STRUCT_DEBUG_TSD_H
8
9#include "ChannelSet.h"
10#include "DebugString.h"
11#include "private/DebugStack.h"
13#include "libcwd/config.h"
14
15#include <iosfwd>
16
17namespace libcwd {
18
19#if CWDEBUG_LOCATION
20namespace dwarf {
21bool ensure_initialization(LIBCWD_TSD_PARAM);
22} // namespace dwarf
23#endif // CWDEBUG_LOCATION
24
25class DebugObject;
26class Channel;
27class FatalChannel;
28class OutputState;
29
30//===================================================================================================
31// struct DebugObject_ThreadSpecificData
32//
33// Structure with Thread Specific Data of a debug object.
34//
35
36struct DebugObject_ThreadSpecificData
37{
38 friend class DebugObject;
39
40 bool tsd_initialized;
41 // Set after initialization is completed.
42
43#if CWDEBUG_DEBUGOUTPUT
44 // Since we start with _off is -1 instead of 0 when CWDEBUG_DEBUG is set,
45 // we need to ignore the call to on() the first time it is called.
46 bool first_time;
47#endif
48
49 OutputState* current;
50 // Current output state.
51
52 std::ostream* current_bufferstream;
53 // The stringstream of the current output state.
54 // This should be set to current->bufferstream at all times.
55
56 _private_::DebugStack<OutputState*> output_state_stack;
57 // Store for nested debug calls.
58
59 bool start_expected;
60 // Set to true when start() is expected, otherwise we expect a call to finish().
61
62 bool unfinished_expected;
63 // Set to true when start() should cause a <unfinished>.
64
65 int off_count;
66 // Number of nested and switched off continued channels till first switched on continued channel.
67
68 _private_::DebugStack<int> continued_stack;
69 // Stores the number of nested and switched off continued channels.
70
71 DebugString color_on;
72 // Colorization code for debug output.
73
74 DebugString color_off;
75 // Undo the effect of color_on.
76
77 DebugString margin;
78 // The margin string.
79
80 DebugString marker;
81 // The marker string.
82
83 DebugStringStackElement* margin_stack;
84 // Pointer to list of pushed margins.
85
86 DebugStringStackElement* marker_stack;
87 // Pointer to list of pushed markers.
88
89 unsigned short indent;
90 // Position at which debug message is printed.
91 // A value of 0 means directly behind the marker.
92
93 // Accessed from LibcwdDout.
94 void start(DebugObject& debug_object, ChannelSetData& channel_set, LIBCWD_TSD_PARAM);
95 void finish(DebugObject& debug_object, ChannelSetData& /*channel_set*/, LIBCWD_TSD_PARAM);
96 [[noreturn]] void fatal_finish(DebugObject& debug_object, ChannelSetData& channel_set, LIBCWD_TSD_PARAM);
97
98 // Initialization and de-initialization.
99 void init();
100 // In the non-threaded case, DebugObject contains a DebugObject_ThreadSpecificData which
101 // may already be initialized before. Therefore don't initialize
102 // these in the non-threaded case, but rely on tsd_initialized,
103 // current_bufferstream and _off to be zeroed as a result of being
104 // part of a global object.
105 DebugObject_ThreadSpecificData() : tsd_initialized(false), current_bufferstream(NULL) { }
106 ~DebugObject_ThreadSpecificData();
107};
108
109} // namespace libcwd
110
111#endif // LIBCWD_STRUCT_DEBUG_TSD_H
This object represents a debug channel, it has a fixed label. A debug channel can be viewed upon as a...
Definition Channel.h:74
The Debug Object class, this object represents one output device (ostream).
Definition DebugObject.h:110
namespace for libcwd.