forked from OSchip/llvm-project
				
			[sanitizer] Expose __sanitizer_print_stack_trace().
Expose a new interface function for debugging code built with sanitizer tools. Add an ASan implementation. llvm-svn: 196302
This commit is contained in:
		
							parent
							
								
									8e5283ad1d
								
							
						
					
					
						commit
						d8fb4d8f91
					
				| 
						 | 
				
			
			@ -85,6 +85,9 @@ extern "C" {
 | 
			
		|||
                                                 const void *old_mid,
 | 
			
		||||
                                                 const void *new_mid);
 | 
			
		||||
 | 
			
		||||
  // Print the stack trace leading to this call. Useful for debugging user code.
 | 
			
		||||
  void __sanitizer_print_stack_trace();
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}  // extern "C"
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,3 +45,9 @@ bool __asan_symbolize(const void *pc, char *out_buffer, int out_size) {
 | 
			
		|||
  return false;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
SANITIZER_INTERFACE_ATTRIBUTE
 | 
			
		||||
extern "C" void __sanitizer_print_stack_trace() {
 | 
			
		||||
  using namespace __asan;
 | 
			
		||||
  PRINT_CURRENT_STACK();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,8 +79,7 @@ void PrintStack(const uptr *trace, uptr size);
 | 
			
		|||
 | 
			
		||||
#define PRINT_CURRENT_STACK()   \
 | 
			
		||||
  {                             \
 | 
			
		||||
    GET_STACK_TRACE(kStackTraceMax,              \
 | 
			
		||||
      common_flags()->fast_unwind_on_fatal);     \
 | 
			
		||||
    GET_STACK_TRACE_FATAL_HERE; \
 | 
			
		||||
    PrintStack(&stack);         \
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
// RUN: %clangxx_asan -O0 %s -o %t && %t 2>&1 | FileCheck %s
 | 
			
		||||
// RUN: %clangxx_asan -O3 %s -o %t && %t 2>&1 | FileCheck %s
 | 
			
		||||
 | 
			
		||||
#include <sanitizer/asan_interface.h>
 | 
			
		||||
 | 
			
		||||
void FooBarBaz() {
 | 
			
		||||
  __sanitizer_print_stack_trace();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
  FooBarBaz();
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
// CHECK: {{    #0 0x.* in __sanitizer_print_stack_trace}}
 | 
			
		||||
// CHECK: {{    #1 0x.* in FooBarBaz\(\) .*print-stack-trace.cc:7}}
 | 
			
		||||
// CHECK: {{    #2 0x.* in main .*print-stack-trace.cc:11}}
 | 
			
		||||
		Loading…
	
		Reference in New Issue