MySQL 9.6.0
Source Code Documentation
my_scoped_trace.h
Go to the documentation of this file.
1// Copyright (c) 2025, Oracle and/or its affiliates.
2//
3// This program is free software; you can redistribute it and/or modify
4// it under the terms of the GNU General Public License, version 2.0,
5// as published by the Free Software Foundation.
6//
7// This program is designed to work with certain software (including
8// but not limited to OpenSSL) that is licensed under separate terms,
9// as designated in a particular file or component or in included license
10// documentation. The authors of MySQL hereby grant you an additional
11// permission to link the program and your derivative works with the
12// separately licensed software that they have either included with
13// the program or referenced in the documentation.
14//
15// This program is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License, version 2.0, for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with this program; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
24#ifndef MYSQL_DEBUGGING_MY_SCOPED_TRACE_H
25#define MYSQL_DEBUGGING_MY_SCOPED_TRACE_H
26
27/// @file
28/// Experimental API header
29
30#include <gtest/gtest.h> // SCOPED_TRACE
32
33/// @addtogroup GroupLibsMysqlDebugging
34/// @{
35
36// Use macros, because SCOPED_TRACE is a macro that relies on __FILE__ and
37// __LINE__
38// NOLINTBEGIN(cppcoreguidelines-macro-usage)
39
40/// "Thread-safe", multi-argument replacement for SCOPED_TRACE.
41///
42/// On some platforms, including Solaris, GTest does not define
43/// GTEST_IS_THREADSAFE. Then, use of SCOPED_TRACE in multiple threads results
44/// in random crashes because it compiles and runs without warnings but does not
45/// synchronize between threads.
46///
47/// To avoid random crashes, use MY_SCOPED_TRACE instead. The downside is that
48/// on those platforms, the "scoped traces" are empty, i.e., you see less debug
49/// info when a test assertion fails.
50///
51/// SCOPED_TRACE only takes one argument. Sometimes it is convenient to pass
52/// multiple arguments. This macro accepts multiple arguments and concatenates
53/// them using mysql::strconv::throwing::concat.
54#ifdef GTEST_IS_THREADSAFE
55#define MY_SCOPED_TRACE(...) \
56 SCOPED_TRACE(mysql::strconv::throwing::concat( \
57 mysql::strconv::Debug_format{}, __VA_ARGS__))
58#else
59// "make use" of the parameters, so that we do not get -Werror=unused-parameter
60// errors in functions where `SCOPED_TRACE(x)` is the only use of `x`.
61#define MY_SCOPED_TRACE(...) ([](auto &&...) {}(__VA_ARGS__))
62#endif
63
64// NOLINTEND(cppcoreguidelines-macro-usage)
65
66// addtogroup GroupLibsMysqlDebugging
67/// @}
68
69#endif // ifndef MYSQL_DEBUGGING_MY_SCOPED_TRACE_H
Experimental API header.