mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-03 09:22:01 +00:00 
			
		
		
		
	ggml : Print backtrace on uncaught C++ exceptions (ggml/1232)
The goal is to have what users call "full logs" contain the backtrace. This is registered upon ggml_init. Also fixes a minor fd leak on Linux.
This commit is contained in:
		
				
					committed by
					
						
						Georgi Gerganov
					
				
			
			
				
	
			
			
			
						parent
						
							8726392d3d
						
					
				
				
					commit
					fedf034a98
				
			
							
								
								
									
										26
									
								
								ggml/src/ggml.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								ggml/src/ggml.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#include "ggml-impl.h"
 | 
			
		||||
 | 
			
		||||
#include <cstdlib>
 | 
			
		||||
#include <exception>
 | 
			
		||||
 | 
			
		||||
static std::terminate_handler previous_terminate_handler;
 | 
			
		||||
 | 
			
		||||
GGML_NORETURN static void ggml_uncaught_exception() {
 | 
			
		||||
    ggml_print_backtrace();
 | 
			
		||||
    if (previous_terminate_handler) {
 | 
			
		||||
        previous_terminate_handler();
 | 
			
		||||
    }
 | 
			
		||||
    abort(); // unreachable unless previous_terminate_handler was nullptr
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool ggml_uncaught_exception_init = []{
 | 
			
		||||
    const char * GGML_NO_BACKTRACE = getenv("GGML_NO_BACKTRACE");
 | 
			
		||||
    if (GGML_NO_BACKTRACE) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    const auto prev{std::get_terminate()};
 | 
			
		||||
    GGML_ASSERT(prev != ggml_uncaught_exception);
 | 
			
		||||
    previous_terminate_handler = prev;
 | 
			
		||||
    std::set_terminate(ggml_uncaught_exception);
 | 
			
		||||
    return true;
 | 
			
		||||
}();
 | 
			
		||||
		Reference in New Issue
	
	Block a user