this repo has no description
1
fork

Configure Feed

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

Improvements in xtrace

+41 -13
+1 -1
src/xtrace/CMakeLists.txt
··· 2 2 3 3 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti -std=c++11") 4 4 5 - add_definitions(-nostdinc) 5 + add_definitions(-nostdinc -fvisibility=hidden) 6 6 7 7 include_directories( 8 8 ${CMAKE_CURRENT_SOURCE_DIR}/include
+2 -6
src/xtrace/bsd_trace.cpp
··· 7 7 #include "xtracelib.h" 8 8 #include "bsd_trace.h" 9 9 10 - _Thread_local int bsd_call_nr = -1; 11 - 12 10 static void print_errno(char* buf, int nr, uintptr_t rv); 13 11 static void print_errno_num(char* buf, int nr, uintptr_t rv); 14 12 static void print_errno_ptr(char* buf, int nr, uintptr_t rv); ··· 1022 1020 extern "C" 1023 1021 void darling_bsd_syscall_entry_print(int nr, void* args[]) 1024 1022 { 1025 - bsd_call_nr = nr; 1026 - handle_generic_entry(bsd_defs, "bsd", bsd_call_nr, args); 1023 + handle_generic_entry(bsd_defs, "bsd", nr, args); 1027 1024 1028 1025 if (nr == 1 || nr == 59) 1029 1026 { ··· 1036 1033 extern "C" 1037 1034 void darling_bsd_syscall_exit_print(uintptr_t retval) 1038 1035 { 1039 - handle_generic_exit(bsd_defs, "bsd", bsd_call_nr, retval, 0); 1040 - bsd_call_nr = -1; 1036 + handle_generic_exit(bsd_defs, "bsd", retval, 0); 1041 1037 } 1042 1038 1043 1039 const char* error_strings[128] = {
+1 -1
src/xtrace/mach_trace.cpp
··· 217 217 void darling_mach_syscall_exit_print(uintptr_t retval) 218 218 { 219 219 int is_msg = mach_call_nr == 31 || mach_call_nr == 32; 220 - handle_generic_exit(mach_defs, "mach", mach_call_nr, retval, is_msg); 220 + handle_generic_exit(mach_defs, "mach", retval, is_msg); 221 221 if (retval == KERN_SUCCESS && is_msg) 222 222 print_mach_msg_exit(); 223 223 mach_call_nr = -1;
+1 -1
src/xtrace/simple.c
··· 1 1 #include "simple.h" 2 2 #include <stdarg.h> 3 3 #include <stddef.h> 4 + #include <string.h> 4 5 5 6 int __simple_vsprintf(char* buf, const char* format, va_list vl); 6 - extern char* memchr(char* buf, int c, __SIZE_TYPE__ n); 7 7 8 8 // We cannot call standard write(), because it would loop back to xtrace 9 9 extern int __write_for_xtrace(int fd, const void* mem, __SIZE_TYPE__ count);
+35 -3
src/xtrace/xtracelib.c
··· 151 151 // Leaves gray color on! 152 152 } 153 153 154 + 155 + _Thread_local struct { 156 + // We're inside this many calls. In other words, we have printed this many 157 + // call entries without matching exits. 158 + int current_level; 159 + // What that value was the last time. if we've just handled an entry or an 160 + // exit, this will be greater/less than current_level. 161 + int previous_level; 162 + // Call numbers, indexed by current level. 163 + int nrs[64]; 164 + } nested_call; 165 + 154 166 void handle_generic_entry(const struct calldef* defs, const char* type, int nr, void* args[]) 155 167 { 156 168 if (xtrace_ignore) 157 169 return; 158 170 159 - print_call(defs, type, nr, 0, 0); 171 + if (nested_call.previous_level < nested_call.current_level && !xtrace_split_entry_and_exit) 172 + { 173 + // We are after an earlier entry without an exit. 174 + __simple_printf("\n"); 175 + } 176 + 177 + int indent = 4 * nested_call.current_level; 178 + nested_call.nrs[nested_call.current_level] = nr; 179 + 180 + print_call(defs, type, nr, indent, 0); 160 181 161 182 if (defs[nr].name != NULL) 162 183 { ··· 172 193 173 194 if (xtrace_split_entry_and_exit) 174 195 __simple_printf("\n"); 196 + 197 + nested_call.previous_level = nested_call.current_level++; 175 198 } 176 199 177 200 178 - void handle_generic_exit(const struct calldef* defs, const char* type, int nr, uintptr_t retval, int force_split) 201 + void handle_generic_exit(const struct calldef* defs, const char* type, uintptr_t retval, int force_split) 179 202 { 180 203 if (xtrace_ignore) 181 204 return; 182 205 206 + if (nested_call.previous_level > nested_call.current_level) 207 + { 208 + // We are after an exit, so our call has been split up. 209 + force_split = 1; 210 + } 211 + nested_call.previous_level = nested_call.current_level--; 212 + int nr = nested_call.nrs[nested_call.current_level]; 213 + 183 214 if (xtrace_split_entry_and_exit || force_split) 184 215 { 185 - print_call(defs, type, nr, 4, 1); 216 + int indent = 4 * nested_call.current_level; 217 + print_call(defs, type, nr, indent, 1); 186 218 __simple_printf("()"); 187 219 } 188 220
+1 -1
src/xtrace/xtracelib.h
··· 14 14 #endif 15 15 16 16 void handle_generic_entry(const struct calldef* defs, const char* type, int nr, void* args[]); 17 - void handle_generic_exit(const struct calldef* defs, const char* type, int nr, uintptr_t retval, int force_split); 17 + void handle_generic_exit(const struct calldef* defs, const char* type, uintptr_t retval, int force_split); 18 18 19 19 extern int xtrace_no_color; 20 20 void xtrace_set_gray_color(void);