1 //===- debug.cpp ----------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of the ORC runtime support library.
11 //===----------------------------------------------------------------------===//
26 std::atomic
<const char *> DebugTypes
;
30 /// Sets the DebugState and DebugTypes values -- this function may be called
31 /// concurrently on multiple threads, but will always assign the same values so
32 /// this should be safe.
33 const char *initializeDebug() {
34 if (const char *DT
= getenv("ORC_RT_DEBUG")) {
35 // If ORC_RT_DEBUG=1 then log everything.
36 if (strcmp(DT
, "1") == 0) {
37 DebugTypes
.store(&DebugTypesAll
, std::memory_order_relaxed
);
38 return &DebugTypesAll
;
41 // If ORC_RT_DEBUG is non-empty then record the string for use in
43 if (strcmp(DT
, "") != 0) {
44 DebugTypes
.store(DT
, std::memory_order_relaxed
);
49 // If ORT_RT_DEBUG is undefined or defined as empty then log nothing.
50 DebugTypes
.store(&DebugTypesNone
, std::memory_order_relaxed
);
51 return &DebugTypesNone
;
54 bool debugTypeEnabled(const char *Type
, const char *Types
) {
55 assert(Types
&& Types
!= &DebugTypesAll
&& Types
!= &DebugTypesNone
&&
56 "Invalid Types value");
57 size_t TypeLen
= strlen(Type
);
58 const char *Start
= Types
;
59 const char *End
= Start
;
62 if (*End
== '\0' || *End
== ',') {
63 size_t ItemLen
= End
- Start
;
64 if (ItemLen
== TypeLen
&& memcmp(Type
, Start
, TypeLen
) == 0)
74 void printdbg(const char *format
, ...) {
76 va_start(Args
, format
);
77 vfprintf(stderr
, format
, Args
);
83 } // end namespace __orc_rt