• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
31 class DebugLocation {
32  public:
DebugLocation(const char * file,int line)33   DebugLocation(const char* file, int line) : file_(file), line_(line) {}
file()34   const char* file() const { return file_; }
line()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   const char* file() const { return nullptr; }
46   int line() const { return -1; }
47 };
48 #define DEBUG_LOCATION ::grpc_core::DebugLocation()
49 #endif
50 
51 }  // namespace grpc_core
52 
53 #endif /* GRPC_CORE_LIB_GPRPP_DEBUG_LOCATION_H */
54