Changes in libcfa/src/interpose.cfa [6011658:8a13c47]
- File:
-
- 1 edited
-
libcfa/src/interpose.cfa (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/interpose.cfa
r6011658 r8a13c47 10 10 // Created On : Wed Mar 29 16:10:31 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Mar 13 17:35:37202013 // Update Count : 1 7812 // Last Modified On : Thu Jan 30 17:47:32 2020 13 // Update Count : 156 14 14 // 15 15 16 16 #include <stdarg.h> // va_start, va_end 17 #include <stdio.h>18 17 #include <string.h> // strlen 19 18 #include <unistd.h> // _exit, getpid … … 30 29 #include "bits/signal.hfa" // sigHandler_? 31 30 #include "startup.hfa" // STARTUP_PRIORITY_CORE 32 #include <assert.h>33 31 34 32 //============================================================================================= … … 42 40 43 41 typedef void (* generic_fptr_t)(void); 44 generic_fptr_t interpose_symbol( const char symbol[], const char version[]) {42 generic_fptr_t interpose_symbol( const char * symbol, const char * version ) { 45 43 const char * error; 46 44 … … 144 142 void abort( const char fmt[], ... ) __attribute__(( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 145 143 void abort( bool signalAbort, const char fmt[], ... ) __attribute__(( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )); 146 void __abort( bool signalAbort, const char fmt[], va_list args ) __attribute__(( __nothrow__, __leaf__, __noreturn__ ));147 144 148 145 extern "C" { 149 146 void abort( void ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) { 150 abort( false, "%s", "" );147 abort( false, NULL ); // FIX ME: 0p does not work 151 148 } 152 149 … … 154 151 va_list argp; 155 152 va_start( argp, fmt ); 156 __abort( false, fmt, argp );153 abort( false, fmt, argp ); 157 154 va_end( argp ); 158 155 } … … 164 161 165 162 void * kernel_abort( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 0p; } 166 void kernel_abort_msg( void * data, char buffer[], int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}163 void kernel_abort_msg( void * data, char * buffer, int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {} 167 164 // See concurrency/kernel.cfa for strong definition used in multi-processor mode. 168 165 int kernel_abort_lastframe( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 4; } … … 172 169 173 170 static void __cfaabi_backtrace( int start ) { 174 enum { Frames = 50, }; // maximum number of stack frames 171 enum { 172 Frames = 50, // maximum number of stack frames 173 }; 175 174 int last = kernel_abort_lastframe(); // skip last N stack frames 176 175 177 176 void * array[Frames]; 178 177 size_t size = backtrace( array, Frames ); 179 char ** messages = backtrace_symbols( array, size ); // does not demangle names178 char ** messages = backtrace_symbols( array, size ); 180 179 181 180 *index( messages[0], '(' ) = '\0'; // find executable name … … 185 184 char * name = 0p, * offset_begin = 0p, * offset_end = 0p; 186 185 187 for ( char * p = messages[i]; *p; p += 1 ) {// find parantheses and +offset186 for ( char * p = messages[i]; *p; ++p ) { // find parantheses and +offset 188 187 //__cfaabi_bits_print_nolock( "X %s\n", p); 189 188 if ( *p == '(' ) { … … 220 219 } 221 220 222 static volatile int __abort_stage = 0; 223 224 // Cannot forward va_list. 225 void __abort( bool signalAbort, const char fmt[], va_list args ) { 226 int stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST ); 227 228 // First stage: stop the cforall kernel and print 229 if(stage == 1) { 230 // increment stage 231 stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST ); 232 233 // must be done here to lock down kernel 234 void * kernel_data = kernel_abort(); 235 int len; 236 237 signal( SIGABRT, SIG_DFL ); // prevent final "real" abort from recursing to handler 238 239 len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid) 221 void abort( bool signalAbort, const char fmt[], ... ) { 222 void * kernel_data = kernel_abort(); // must be done here to lock down kernel 223 int len; 224 225 signal( SIGABRT, SIG_DFL ); // prevent final "real" abort from recursing to handler 226 227 len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid) 228 __cfaabi_bits_write( STDERR_FILENO, abort_text, len ); 229 230 if ( fmt ) { 231 va_list args; 232 va_start( args, fmt ); 233 234 len = vsnprintf( abort_text, abort_text_size, fmt, args ); 235 va_end( args ); 240 236 __cfaabi_bits_write( STDERR_FILENO, abort_text, len ); 241 237 242 assert( fmt ); 243 len = vsnprintf( abort_text, abort_text_size, fmt, args ); 244 __cfaabi_bits_write( STDERR_FILENO, abort_text, len ); 245 246 // add optional newline if missing at the end of the format text 247 if ( fmt[strlen( fmt ) - 1] != '\n' ) { 248 __cfaabi_bits_write( STDERR_FILENO, "\n", 1 ); 249 } // if 250 kernel_abort_msg( kernel_data, abort_text, abort_text_size ); 251 } 252 253 // Second stage: print the backtrace 254 if(stage == 2) { 255 // increment stage 256 stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST ); 257 258 // print stack trace in handler 259 __cfaabi_backtrace( signalAbort ? 4 : 2 ); 260 } 261 262 do { 263 // Finally call abort 264 __cabi_libc.abort(); 265 266 // Loop so that we never return 267 } while(true); 238 if ( fmt[strlen( fmt ) - 1] != '\n' ) { // add optional newline if missing at the end of the format text 239 __cfaabi_dbg_write( "\n", 1 ); 240 } 241 } 242 243 kernel_abort_msg( kernel_data, abort_text, abort_text_size ); 244 __cfaabi_backtrace( signalAbort ? 4 : 3 ); 245 246 __cabi_libc.abort(); // print stack trace in handler 268 247 } 269 248 … … 271 250 va_list args; 272 251 va_start( args, fmt ); 273 __abort( false, fmt, args ); 274 // CONTROL NEVER REACHES HERE! 252 abort( false, fmt, args ); 275 253 va_end( args ); 276 }277 278 void abort( bool signalAbort, const char fmt[], ... ) {279 va_list args;280 va_start( args, fmt );281 __abort( signalAbort, fmt, args );282 // CONTROL NEVER REACHES HERE!283 va_end( args );284 254 } 285 255
Note:
See TracChangeset
for help on using the changeset viewer.