this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow xtrace to print to the kernel message log

The new env var XTRACE_KPRINTF can be set, which will cause xtrace to print all tracing messages with kprintf (so you can view them with dmesg).

The current implementation just does a simple little substitution between regular printf and kprintf, which can result in messages being broken up over multiple lines due to the way kernel messages are presented. This should be fixed eventually (possibly by buffering output until a newline).

This commit also gets rid of xtrace's simple.{c,h}, using libsystem_kernel's "simple" functions instead.

+89 -347
-1
src/xtrace/CMakeLists.txt
··· 10 10 11 11 set(xtrace_sources 12 12 xtracelib.c 13 - simple.c 14 13 trampoline.S 15 14 mach_trace.cpp 16 15 bsd_trace.cpp
+2 -2
src/xtrace/bsd_trace.cpp
··· 1 - #include "simple.h" 1 + #include <darling/emulation/simple.h> 2 2 #include <unistd.h> 3 3 #include <fcntl.h> 4 4 #include <sys/mman.h> ··· 1026 1026 { 1027 1027 // For exit() or execve(), print an extra newline, 1028 1028 // as we're likely not going to see the return. 1029 - __simple_printf("\n"); 1029 + xtrace_printf("\n"); 1030 1030 } 1031 1031 } 1032 1032
+2 -2
src/xtrace/lock.c
··· 3 3 #include <stdbool.h> 4 4 5 5 #include "lock.h" 6 - #include "simple.h" 6 + #include <darling/emulation/simple.h> 7 7 8 8 #ifndef XTRACE_LOCK_DEBUG 9 9 #define XTRACE_LOCK_DEBUG 0 10 10 #endif 11 11 12 12 #if XTRACE_LOCK_DEBUG 13 - #define xtrace_lock_debug_internal(x, ...) __simple_printf(x "\n", ## __VA_ARGS__) 13 + #define xtrace_lock_debug_internal(x, ...) xtrace_printf(x "\n", ## __VA_ARGS__) 14 14 #undef XTRACE_INLINE 15 15 #define XTRACE_INLINE 16 16 #else
+17 -17
src/xtrace/mach_trace.cpp
··· 1 - #include "simple.h" 1 + #include <darling/emulation/simple.h> 2 2 #include <unistd.h> 3 3 #include <dlfcn.h> 4 4 #include <mach/message.h> ··· 427 427 428 428 static void print_mach_msg(const mach_msg_header_t* msg, mach_msg_size_t size) 429 429 { 430 - __simple_printf("{"); 430 + xtrace_printf("{"); 431 431 432 432 mach_msg_bits_t bits = msg->msgh_bits; 433 433 if (MACH_MSGH_BITS_HAS_REMOTE(bits)) 434 - __simple_printf("remote = %s %u, ", xtrace_msg_type_to_str(MACH_MSGH_BITS_REMOTE(bits), 0), msg->msgh_remote_port); 434 + xtrace_printf("remote = %s %u, ", xtrace_msg_type_to_str(MACH_MSGH_BITS_REMOTE(bits), 0), msg->msgh_remote_port); 435 435 if (MACH_MSGH_BITS_HAS_LOCAL(bits)) 436 - __simple_printf("local = %s %u, ", xtrace_msg_type_to_str(MACH_MSGH_BITS_LOCAL(bits), 0), msg->msgh_local_port); 436 + xtrace_printf("local = %s %u, ", xtrace_msg_type_to_str(MACH_MSGH_BITS_LOCAL(bits), 0), msg->msgh_local_port); 437 437 if (MACH_MSGH_BITS_HAS_VOUCHER(bits)) 438 - __simple_printf("voucher = %s %u, ", xtrace_msg_type_to_str(MACH_MSGH_BITS_VOUCHER(bits), 0), msg->msgh_voucher_port); 438 + xtrace_printf("voucher = %s %u, ", xtrace_msg_type_to_str(MACH_MSGH_BITS_VOUCHER(bits), 0), msg->msgh_voucher_port); 439 439 if (MACH_MSGH_BITS_IS_COMPLEX(bits)) 440 - __simple_printf("complex, "); 440 + xtrace_printf("complex, "); 441 441 442 - __simple_printf("id = %d}", msg->msgh_id); 442 + xtrace_printf("id = %d}", msg->msgh_id); 443 443 444 444 if (!MACH_MSGH_BITS_IS_COMPLEX(bits)) 445 445 { 446 - __simple_printf(", %lu bytes of inline data\n", size - sizeof(mach_msg_header_t)); 446 + xtrace_printf(", %lu bytes of inline data\n", size - sizeof(mach_msg_header_t)); 447 447 return; 448 448 } 449 449 ··· 456 456 if (type == MACH_MSG_PORT_DESCRIPTOR) 457 457 { 458 458 mach_msg_port_descriptor_t* port = (mach_msg_port_descriptor_t*) ptr; 459 - __simple_printf(", %s %u", xtrace_msg_type_to_str(port->disposition, 0), port->name); 459 + xtrace_printf(", %s %u", xtrace_msg_type_to_str(port->disposition, 0), port->name); 460 460 ptr = (mach_msg_descriptor_t*) (port + 1); 461 461 } 462 462 else if (type == MACH_MSG_OOL_DESCRIPTOR || type == MACH_MSG_OOL_VOLATILE_DESCRIPTOR) 463 463 { 464 464 mach_msg_ool_descriptor_t* ool = (mach_msg_ool_descriptor_t*) ptr; 465 - __simple_printf(", ool [%p; %u]", ool->address, ool->size); 465 + xtrace_printf(", ool [%p; %u]", ool->address, ool->size); 466 466 ptr = (mach_msg_descriptor_t*) (ool + 1); 467 467 } 468 468 else if (type == MACH_MSG_OOL_PORTS_DESCRIPTOR) 469 469 { 470 470 mach_msg_ool_ports_descriptor_t* ool_ports = (mach_msg_ool_ports_descriptor_t*) ptr; 471 - __simple_printf(", ool ports %s [%p; x%u]", 471 + xtrace_printf(", ool ports %s [%p; x%u]", 472 472 xtrace_msg_type_to_str(ool_ports->disposition, 0), 473 473 ool_ports->address, ool_ports->count); 474 474 ptr = (mach_msg_descriptor_t*) (ool_ports + 1); 475 475 } 476 476 else 477 477 { 478 - __simple_printf(", ???"); 478 + xtrace_printf(", ???"); 479 479 ptr++; 480 480 } 481 481 } 482 482 483 - __simple_printf(", %lu bytes of inline data\n", size - ((const char*) ptr - (const char*) msg)); 483 + xtrace_printf(", %lu bytes of inline data\n", size - ((const char*) ptr - (const char*) msg)); 484 484 } 485 485 486 486 static void print_mach_msg_entry(void* args[]) ··· 492 492 if (options & MACH_SEND_MSG) 493 493 { 494 494 set_request_port(message->msgh_remote_port); 495 - __simple_printf("\n"); 495 + xtrace_printf("\n"); 496 496 xtrace_start_line(8); 497 497 print_mach_msg(message, send_size); 498 498 xtrace_start_line(8); 499 499 xtrace_print_mig_message(message, get_request_port()); 500 - __simple_printf("\n"); 500 + xtrace_printf("\n"); 501 501 } 502 502 503 503 if (options & MACH_RCV_MSG) ··· 515 515 set_argument_ptr(args[0]); 516 516 break; 517 517 default: 518 - __simple_printf("Unexpected mach_call_nr"); 518 + xtrace_printf("Unexpected mach_call_nr"); 519 519 return; 520 520 } 521 521 } ··· 531 531 print_mach_msg(message, message->msgh_size); 532 532 xtrace_start_line(8); 533 533 xtrace_print_mig_message(message, get_request_port()); 534 - __simple_printf("\n"); 534 + xtrace_printf("\n"); 535 535 set_argument_ptr(NULL); 536 536 set_request_port(MACH_PORT_NULL); 537 537 }
+2 -2
src/xtrace/malloc.c
··· 9 9 10 10 #include "malloc.h" 11 11 #include "lock.h" 12 - #include "simple.h" 12 + #include <darling/emulation/simple.h> 13 13 14 14 #ifndef XTRACE_MALLOC_DEBUG 15 15 #define XTRACE_MALLOC_DEBUG 0 16 16 #endif 17 17 18 18 #if XTRACE_MALLOC_DEBUG 19 - #define xtrace_malloc_debug(x, ...) __simple_printf(x "\n", ## __VA_ARGS__) 19 + #define xtrace_malloc_debug(x, ...) xtrace_printf(x "\n", ## __VA_ARGS__) 20 20 #undef XTRACE_INLINE 21 21 #define XTRACE_INLINE 22 22 #else
+26 -26
src/xtrace/mig_trace.c
··· 7 7 8 8 #include <mach/mach.h> 9 9 10 - #include "simple.h" 10 + #include <darling/emulation/simple.h> 11 11 #include "xtracelib.h" 12 12 #include "mach_trace.h" 13 13 #include "bsd_trace.h" ··· 61 61 void* dylib_handle = dlopen(path, RTLD_LOCAL); 62 62 if (dylib_handle == NULL) 63 63 { 64 - fprintf(stderr, "xtrace: failed to dlopen %s: %s\n", path, dlerror()); 64 + xtrace_fprintf(fileno(stderr), "xtrace: failed to dlopen %s: %s\n", path, dlerror()); 65 65 subsystems[i] = NULL; 66 66 continue; 67 67 } 68 68 subsystems[i] = (struct xtrace_mig_subsystem*) dlsym(dylib_handle, "xtrace_mig_subsystem"); 69 69 if (subsystems[i] == NULL) 70 70 { 71 - fprintf(stderr, "xtrace: failed to dlsym(%s, \"xtrace_mig_subsystem\"): %s\n", path, dlerror()); 71 + xtrace_fprintf(fileno(stderr), "xtrace: failed to dlsym(%s, \"xtrace_mig_subsystem\"): %s\n", path, dlerror()); 72 72 // Leave NULL subsystem in place and continue. 73 73 } 74 74 } ··· 78 78 79 79 DEFINE_XTRACE_TLS_VAR(bool, is_first_arg); 80 80 81 - #define BEFORE if (!get_is_first_arg()) __simple_printf(", ") 81 + #define BEFORE if (!get_is_first_arg()) xtrace_printf(", ") 82 82 #define AFTER set_is_first_arg(false) 83 83 84 84 static void add_raw_arg(const char* format, ...) ··· 97 97 static void add_num_arg(unsigned long long n) 98 98 { 99 99 BEFORE; 100 - __simple_printf("%llu", n); 100 + xtrace_printf("%llu", n); 101 101 AFTER; 102 102 } 103 103 104 104 static void add_ptr_arg(void* ptr) 105 105 { 106 106 BEFORE; 107 - __simple_printf("%p", ptr); 107 + xtrace_printf("%p", ptr); 108 108 AFTER; 109 109 } 110 110 ··· 113 113 BEFORE; 114 114 char buf[1024]; 115 115 xtrace_format_string_literal(buf, s); 116 - __simple_printf("%s", buf); 116 + xtrace_printf("%s", buf); 117 117 AFTER; 118 118 } 119 119 ··· 121 121 { 122 122 BEFORE; 123 123 const unsigned char* b = (const unsigned char*) bytes; 124 - __simple_printf("bytes "); 124 + xtrace_printf("bytes "); 125 125 for (int i = 0; i < cnt; i++) 126 - __simple_printf("%x", b[i]); 126 + xtrace_printf("%x", b[i]); 127 127 AFTER; 128 128 } 129 129 ··· 132 132 BEFORE; 133 133 char buf[100]; 134 134 xtrace_kern_return_to_str(buf, code); 135 - __simple_printf("return %s", buf); 135 + xtrace_printf("return %s", buf); 136 136 AFTER; 137 137 } 138 138 139 139 static void add_port_arg(mach_port_name_t port_name, mach_msg_type_name_t disposition) 140 140 { 141 141 BEFORE; 142 - __simple_printf("%s %u", xtrace_msg_type_to_str(disposition, 0), port_name); 142 + xtrace_printf("%s %u", xtrace_msg_type_to_str(disposition, 0), port_name); 143 143 AFTER; 144 144 } 145 145 146 146 static void add_ool_mem_arg(const void* ptr, unsigned long size) 147 147 { 148 148 BEFORE; 149 - __simple_printf("mem [%p; %lu]", ptr, size); 149 + xtrace_printf("mem [%p; %lu]", ptr, size); 150 150 AFTER; 151 151 } 152 152 153 153 static void add_ool_ports_arg(const void* ptr, unsigned long cnt, mach_msg_type_name_t disposition) 154 154 { 155 155 BEFORE; 156 - __simple_printf("%s [%p; x%lu]", xtrace_msg_type_to_str(disposition, 0), ptr, cnt); 156 + xtrace_printf("%s [%p; x%lu]", xtrace_msg_type_to_str(disposition, 0), ptr, cnt); 157 157 AFTER; 158 158 } 159 159 ··· 182 182 { 183 183 BEFORE; 184 184 unsigned char* p = (unsigned char*) ptr; 185 - __simple_printf("{"); 185 + xtrace_printf("{"); 186 186 for (unsigned long i = 0; i < cnt; i++) 187 187 { 188 188 if (i != 0) 189 - __simple_printf(", "); 190 - __simple_printf("%llu", read_integer((void*) p, item_size)); 189 + xtrace_printf(", "); 190 + xtrace_printf("%llu", read_integer((void*) p, item_size)); 191 191 p += item_size; 192 192 } 193 - __simple_printf("}"); 193 + xtrace_printf("}"); 194 194 AFTER; 195 195 } 196 196 ··· 198 198 { 199 199 BEFORE; 200 200 unsigned char* p = (unsigned char*) ptr; 201 - __simple_printf("["); 201 + xtrace_printf("["); 202 202 for (unsigned long i = 0; i < cnt; i++) 203 203 { 204 204 if (i != 0) 205 - __simple_printf(", "); 206 - __simple_printf("%llu", read_integer((void*) p, item_size)); 205 + xtrace_printf(", "); 206 + xtrace_printf("%llu", read_integer((void*) p, item_size)); 207 207 p += item_size; 208 208 } 209 - __simple_printf("]"); 209 + xtrace_printf("]"); 210 210 AFTER; 211 211 } 212 212 ··· 215 215 BEFORE; 216 216 char buf[100]; 217 217 xtrace_kern_return_to_str(buf, code); 218 - __simple_printf("%s", buf); 218 + xtrace_printf("%s", buf); 219 219 AFTER; 220 220 } 221 221 ··· 343 343 return; 344 344 345 345 if (!is_reply) 346 - __simple_printf("%s::%s(", s->name, r->name); 346 + xtrace_printf("%s::%s(", s->name, r->name); 347 347 else 348 348 { 349 349 xtrace_set_gray_color(); 350 - __simple_printf("%s::%s() -> ", s->name, r->name); 350 + xtrace_printf("%s::%s() -> ", s->name, r->name); 351 351 xtrace_reset_color(); 352 352 } 353 353 ··· 355 355 r->routine(message, is_reply, &callbacks); 356 356 357 357 if (!is_reply) 358 - __simple_printf(")"); 358 + xtrace_printf(")"); 359 359 else 360 - __simple_printf(" "); 360 + xtrace_printf(" "); 361 361 }
-257
src/xtrace/simple.c
··· 1 - #include "simple.h" 2 - #include <stdarg.h> 3 - #include <stddef.h> 4 - #include <string.h> 5 - 6 - int __simple_vsprintf(char* buf, const char* format, va_list vl); 7 - 8 - // We cannot call standard write(), because it would loop back to xtrace 9 - extern int __write_for_xtrace(int fd, const void* mem, __SIZE_TYPE__ count); 10 - 11 - int __simple_strlen(const char* text) 12 - { 13 - int len = 0; 14 - while (*text++) 15 - len++; 16 - return len; 17 - } 18 - 19 - static inline int abs(int n) 20 - { 21 - return (n < 0) ? -n : n; 22 - } 23 - 24 - static inline void print_num(char** buf, long long num) 25 - { 26 - char temp[128]; 27 - int count = 0; 28 - 29 - if (num < 0) 30 - { 31 - *(*buf)++ = '-'; 32 - num = -num; 33 - } 34 - 35 - do 36 - { 37 - temp[count++] = '0' + (num % 10); 38 - num /= 10; 39 - } 40 - while (num > 0); 41 - 42 - while (count--) 43 - *(*buf)++ = temp[count]; 44 - } 45 - 46 - int __simple_vsprintf(char* buf, const char* format, va_list vl) 47 - { 48 - const char* initial_buf = buf; 49 - while (*format) 50 - { 51 - if (*format == '%') 52 - { 53 - format++; 54 - if (!*format) 55 - break; 56 - 57 - switch (*format) 58 - { 59 - case '%': 60 - *buf++ = '%'; 61 - break; 62 - case 'c': 63 - *buf++ = (char) va_arg(vl, int); 64 - break; 65 - case 's': 66 - { 67 - const char* str = va_arg(vl, const char*); 68 - if (!str) 69 - str = "(null)"; 70 - 71 - while (*str) 72 - { 73 - *buf++ = *str; 74 - str++; 75 - } 76 - break; 77 - } 78 - case 'd': 79 - { 80 - int num = va_arg(vl, int); 81 - print_num(&buf, num); 82 - break; 83 - } 84 - case 'u': 85 - { 86 - unsigned num = va_arg(vl, unsigned); 87 - print_num(&buf, num); 88 - break; 89 - } 90 - case 'l': 91 - { 92 - format++; 93 - if (*format == 'd') 94 - { 95 - long num = va_arg(vl, long); 96 - print_num(&buf, num); 97 - } 98 - else if (*format == 'u') 99 - { 100 - unsigned long num = va_arg(vl, unsigned long); 101 - print_num(&buf, num); 102 - } 103 - else if (*format == 'l') 104 - { 105 - format++; 106 - if (*format == 'd') 107 - { 108 - long long num = va_arg(vl, long long); 109 - print_num(&buf, num); 110 - } 111 - else if (*format == 'u') 112 - { 113 - unsigned long long num = va_arg(vl, unsigned long long); 114 - char temp[128]; 115 - int count = 0; 116 - do 117 - { 118 - temp[count++] = '0' + (num % 10); 119 - num /= 10; 120 - } 121 - while (num > 0); 122 - 123 - while (count--) 124 - *buf++ = temp[count]; 125 - } 126 - } 127 - break; 128 - } 129 - case 'p': 130 - case 'x': 131 - { 132 - unsigned long num = va_arg(vl, unsigned long); 133 - char temp[40]; 134 - int count = 0; 135 - 136 - if (*format == 'p') 137 - { 138 - *buf++ = '0'; 139 - *buf++ = 'x'; 140 - } 141 - 142 - do 143 - { 144 - int c = (num % 16); 145 - 146 - if (c < 10) 147 - temp[count++] = '0' + c; 148 - else 149 - temp[count++] = 'a' + (c - 10); 150 - num /= 16; 151 - } 152 - while (num > 0); 153 - 154 - while (count--) 155 - *buf++ = temp[count]; 156 - 157 - break; 158 - 159 - } 160 - } 161 - 162 - format++; 163 - } 164 - else 165 - { 166 - *buf++ = *format; 167 - format++; 168 - } 169 - } 170 - 171 - *buf = 0; 172 - return buf - initial_buf; 173 - } 174 - 175 - __attribute__ ((visibility ("default"))) 176 - void __simple_printf(const char* format, ...) 177 - { 178 - char buffer[512]; 179 - va_list vl; 180 - 181 - va_start(vl, format); 182 - __simple_vsprintf(buffer, format, vl); 183 - va_end(vl); 184 - 185 - __write_for_xtrace(2, buffer, __simple_strlen(buffer)); 186 - } 187 - 188 - int __simple_sprintf(char *buffer, const char* format, ...) 189 - { 190 - va_list vl; 191 - int res; 192 - 193 - va_start(vl, format); 194 - res = __simple_vsprintf(buffer, format, vl); 195 - va_end(vl); 196 - 197 - return res; 198 - } 199 - 200 - #ifdef isdigit 201 - #undef isdigit 202 - #endif 203 - 204 - static int isdigit(char c) 205 - { 206 - return c >= '0' && c <= '9'; 207 - } 208 - static int isdigit16(char c) 209 - { 210 - if (isdigit(c)) 211 - return 1; 212 - if (c >= 'a' && c <= 'f') 213 - return 1; 214 - if (c >= 'A' && c <= 'F') 215 - return 1; 216 - return 0; 217 - } 218 - 219 - unsigned long long __simple_atoi(const char* str, const char** endp) 220 - { 221 - unsigned long long value = 0; 222 - 223 - while (isdigit(*str)) 224 - { 225 - value *= 10; 226 - value += *str - '0'; 227 - str++; 228 - } 229 - if (endp) 230 - *endp = str; 231 - 232 - return value; 233 - } 234 - 235 - unsigned long long __simple_atoi16(const char* str, const char** endp) 236 - { 237 - unsigned long long value = 0; 238 - 239 - while (isdigit16(*str)) 240 - { 241 - value *= 16; 242 - 243 - if (*str >= '0' && *str <= '9') 244 - value += *str - '0'; 245 - else if (*str >= 'a' && *str <= 'f') 246 - value += 10 + (*str - 'a'); 247 - else if (*str >= 'A' && *str < 'F') 248 - value += 10 + (*str - 'A'); 249 - 250 - str++; 251 - } 252 - if (endp) 253 - *endp = str; 254 - 255 - return value; 256 - } 257 -
-23
src/xtrace/simple.h
··· 1 - #include <stdarg.h> 2 - 3 - #ifndef LINUX_DEBUG_H 4 - #define LINUX_DEBUG_H 5 - 6 - #ifdef __cplusplus 7 - extern "C" { 8 - #endif 9 - 10 - void __simple_printf(const char* format, ...) __attribute__((format(printf, 1, 2))); 11 - int __simple_sprintf(char* buffer, const char* format, ...) __attribute__((format(printf, 2, 3))); 12 - int __simple_vsprintf(char* buf, const char* format, va_list vl) __attribute__((format(printf, 2, 0))); 13 - int __simple_strlen(const char* str); 14 - 15 - unsigned long long __simple_atoi(const char* str, const char** endp); 16 - unsigned long long __simple_atoi16(const char* str, const char** endp); 17 - 18 - #ifdef __cplusplus 19 - } 20 - #endif 21 - 22 - #endif 23 -
+2 -2
src/xtrace/tls.c
··· 4 4 #include "tls.h" 5 5 #include "malloc.h" 6 6 #include "lock.h" 7 - #include "simple.h" 7 + #include <darling/emulation/simple.h> 8 8 9 9 #ifndef XTRACE_TLS_DEBUG 10 10 #define XTRACE_TLS_DEBUG 0 11 11 #endif 12 12 13 13 #if XTRACE_TLS_DEBUG 14 - #define xtrace_tls_debug(x, ...) __simple_printf(x "\n", ## __VA_ARGS__) 14 + #define xtrace_tls_debug(x, ...) xtrace_printf(x "\n", ## __VA_ARGS__) 15 15 #else 16 16 #define xtrace_tls_debug(x, ...) 17 17 #endif
+18 -15
src/xtrace/xtracelib.c
··· 4 4 #include <stdlib.h> 5 5 #include <pthread.h> 6 6 #include <string.h> 7 - #include "simple.h" 7 + #include <darling/emulation/simple.h> 8 8 #include "xtracelib.h" 9 9 #include "mig_trace.h" 10 10 #include "tls.h" ··· 52 52 53 53 static int xtrace_split_entry_and_exit = 0; 54 54 int xtrace_no_color = 0; 55 + int xtrace_kprintf = 0; 55 56 56 57 static void xtrace_setup_options(void) 57 58 { ··· 59 60 xtrace_split_entry_and_exit = 1; 60 61 if (getenv("XTRACE_NO_COLOR") != NULL) 61 62 xtrace_no_color = 1; 63 + if (getenv("XTRACE_KPRINTF") != NULL) 64 + xtrace_kprintf = 1; 62 65 } 63 66 64 67 ··· 118 121 if (xtrace_no_color) 119 122 return; 120 123 121 - __simple_printf("\033[37m"); 124 + xtrace_printf("\033[37m"); 122 125 } 123 126 124 127 void xtrace_reset_color(void) ··· 126 129 if (xtrace_no_color) 127 130 return; 128 131 129 - __simple_printf("\033[0m"); 132 + xtrace_printf("\033[0m"); 130 133 } 131 134 132 135 void xtrace_start_line(int indent) 133 136 { 134 137 xtrace_set_gray_color(); 135 138 136 - __simple_printf("[%d]", sys_thread_selfid()); 139 + xtrace_printf("[%d]", sys_thread_selfid()); 137 140 for (int i = 0; i < indent + 1; i++) 138 - __simple_printf(" "); 141 + xtrace_printf(" "); 139 142 140 143 xtrace_reset_color(); 141 144 } ··· 148 151 xtrace_set_gray_color(); 149 152 150 153 if (defs[nr].name != NULL) 151 - __simple_printf("%s", defs[nr].name); 154 + xtrace_printf("%s", defs[nr].name); 152 155 else 153 - __simple_printf("%s %d", type, nr); 156 + xtrace_printf("%s %d", type, nr); 154 157 155 158 // Leaves gray color on! 156 159 } ··· 177 180 if (get_ptr_nested_call()->previous_level < get_ptr_nested_call()->current_level && !xtrace_split_entry_and_exit) 178 181 { 179 182 // We are after an earlier entry without an exit. 180 - __simple_printf("\n"); 183 + xtrace_printf("\n"); 181 184 } 182 185 183 186 int indent = 4 * get_ptr_nested_call()->current_level; ··· 192 195 defs[nr].print_args(args_buf, nr, args); 193 196 else 194 197 strcpy(args_buf, "..."); 195 - __simple_printf("(%s)", args_buf); 198 + xtrace_printf("(%s)", args_buf); 196 199 } 197 200 else 198 - __simple_printf("(...)"); 201 + xtrace_printf("(...)"); 199 202 200 203 if (xtrace_split_entry_and_exit) 201 - __simple_printf("\n"); 204 + xtrace_printf("\n"); 202 205 203 206 get_ptr_nested_call()->previous_level = get_ptr_nested_call()->current_level++; 204 207 } ··· 221 224 { 222 225 int indent = 4 * get_ptr_nested_call()->current_level; 223 226 print_call(defs, type, nr, indent, 1); 224 - __simple_printf("()"); 227 + xtrace_printf("()"); 225 228 } 226 229 227 230 xtrace_set_gray_color(); 228 - __simple_printf(" -> "); 231 + xtrace_printf(" -> "); 229 232 xtrace_reset_color(); 230 233 231 234 if (defs[nr].name != NULL) ··· 235 238 defs[nr].print_retval(args_buf, nr, retval); 236 239 else 237 240 __simple_sprintf(args_buf, "0x%lx\n", retval); 238 - __simple_printf("%s\n", args_buf); 241 + xtrace_printf("%s\n", args_buf); 239 242 } 240 243 else 241 - __simple_printf("0x%lx\n", retval); 244 + xtrace_printf("0x%lx\n", retval); 242 245 } 243 246
+20
src/xtrace/xtracelib.h
··· 1 1 #ifndef _XTRACELIB_H_ 2 2 #define _XTRACELIB_H_ 3 3 #include <stdint.h> 4 + #include <darling/emulation/simple.h> 4 5 5 6 struct calldef 6 7 { ··· 17 18 void handle_generic_exit(const struct calldef* defs, const char* type, uintptr_t retval, int force_split); 18 19 19 20 extern int xtrace_no_color; 21 + extern int xtrace_kprintf; 20 22 void xtrace_set_gray_color(void); 21 23 void xtrace_reset_color(void); 22 24 23 25 void xtrace_start_line(int indent); 26 + 27 + // the kprintf output is prefixed with "xtrace: " for easy grepping on dmesg 28 + 29 + #define xtrace_printf(format, ...) ({ \ 30 + if (xtrace_kprintf) { \ 31 + __simple_kprintf("xtrace: " format, ##__VA_ARGS__); \ 32 + } else { \ 33 + __simple_printf(format, ##__VA_ARGS__); \ 34 + } \ 35 + }) 36 + 37 + #define xtrace_fprintf(fd, format, ...) ({ \ 38 + if (xtrace_kprintf) { \ 39 + __simple_kprintf("xtrace: " format, ##__VA_ARGS__); \ 40 + } else { \ 41 + __simple_fprintf(fd, format, ##__VA_ARGS__); \ 42 + } \ 43 + }) 24 44 25 45 #ifdef __cplusplus 26 46 }