debug_location.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_GPRPP_DEBUG_LOCATION_H
20 #define GRPC_CORE_LIB_GPRPP_DEBUG_LOCATION_H
21 
22 namespace grpc_core {
23 
24 // Used for tracking file and line where a call is made for debug builds.
25 // No-op for non-debug builds.
26 // Callers can use the DEBUG_LOCATION macro in either case.
27 #ifndef NDEBUG
28 // TODO(roth): See if there's a way to automatically populate this,
29 // similarly to how absl::SourceLocation::current() works, so that
30 // callers don't need to explicitly pass DEBUG_LOCATION anywhere.
32  public:
33  DebugLocation(const char* file, int line) : file_(file), line_(line) {}
34  const char* file() const { return file_; }
35  int line() const { return line_; }
36 
37  private:
38  const char* file_;
39  const int line_;
40 };
41 #define DEBUG_LOCATION ::grpc_core::DebugLocation(__FILE__, __LINE__)
42 #else
43 class DebugLocation {
44  public:
45  DebugLocation() {}
46  DebugLocation(const char* /* file */, int /* line */) {}
47  const char* file() const { return nullptr; }
48  int line() const { return -1; }
49 };
50 #define DEBUG_LOCATION ::grpc_core::DebugLocation()
51 #endif
52 
53 } // namespace grpc_core
54 
55 #endif /* GRPC_CORE_LIB_GPRPP_DEBUG_LOCATION_H */
grpc_core::DebugLocation
Definition: debug_location.h:31
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::DebugLocation::DebugLocation
DebugLocation(const char *file, int line)
Definition: debug_location.h:33
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
grpc_core::DebugLocation::file
const char * file() const
Definition: debug_location.h:34
grpc_core::DebugLocation::file_
const char * file_
Definition: debug_location.h:38
grpc_core::DebugLocation::line
int line() const
Definition: debug_location.h:35
grpc_core::DebugLocation::line_
const int line_
Definition: debug_location.h:39


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:02