]>
git.saurik.com Git - apple/dyld.git/blob - dyld3/Logging.cpp
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
35 static bool sVerboseLoading
= false;
36 static bool sVerboseInitializers
= false;
37 static bool sVerboseSegments
= false;
38 static bool sVerboseAPIs
= false;
39 static bool sVerboseNotifications
= false;
40 static bool sVerboseFixups
= false;
41 static bool sVerboseDOFs
= false;
43 static void vlog_default(const char* format
, va_list list
)
45 _simple_vdprintf(2, format
, list
);
48 static void (*sLogFunction
)(const char* format
, va_list list
) = &vlog_default
;
49 static void (*sHaltFunction
)(const char* message
) __attribute__((noreturn
)) = nullptr;
51 void halt(const char* message
)
53 (*sHaltFunction
)(message
);
56 static void vlog(const char* format
, va_list list
)
58 (*sLogFunction
)(format
, list
);
61 bool log_loads(const char* format
, ...)
63 if ( !sVerboseLoading
)
66 va_start(list
, format
);
72 bool log_segments(const char* format
, ...)
74 if ( !sVerboseSegments
)
77 va_start(list
, format
);
83 bool log_fixups(const char* format
, ...)
85 if ( !sVerboseFixups
)
88 va_start(list
, format
);
94 bool log_initializers(const char* format
, ...)
96 if ( !sVerboseInitializers
)
99 va_start(list
, format
);
105 bool log_apis(const char* format
, ...)
110 va_start(list
, format
);
116 bool log_notifications(const char* format
, ...)
118 if ( !sVerboseNotifications
)
121 va_start(list
, format
);
127 bool log_dofs(const char* format
, ...)
132 va_start(list
, format
);
140 void setLoggingFromEnvs(const char* envp
[])
142 for(const char** p
= envp
; *p
!= NULL
; p
++) {
143 const char* keyEqualsValue
= *p
;
144 const char* equals
= strchr(keyEqualsValue
, '=');
145 if ( equals
!= NULL
) {
146 //const char* value = &equals[1];
147 const size_t keyLen
= equals
-keyEqualsValue
;
149 strncpy(key
, keyEqualsValue
, keyLen
);
151 if ( strcmp(key
, "DYLD_PRINT_LIBRARIES") == 0 ) {
152 sVerboseLoading
= true;
154 else if ( strcmp(key
, "DYLD_PRINT_SEGMENTS") == 0 ) {
155 sVerboseSegments
= true;
157 else if ( strcmp(key
, "DYLD_PRINT_INITIALIZERS") == 0 ) {
158 sVerboseInitializers
= true;
160 else if ( strcmp(key
, "DYLD_PRINT_APIS") == 0 ) {
163 else if ( strcmp(key
, "DYLD_PRINT_NOTIFICATIONS") == 0 ) {
164 sVerboseNotifications
= true;
166 else if ( strcmp(key
, "DYLD_PRINT_BINDINGS") == 0 ) {
167 sVerboseFixups
= true;
169 else if ( strcmp(key
, "DYLD_PRINT_DOFS") == 0 ) {
176 void setLoggingFunction(void (*func
)(const char* format
, va_list list
))
181 void setHaltFunction(void (*func
)(const char* message
) __attribute__((noreturn
)))
183 sHaltFunction
= func
;