diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2015-09-24 18:24:20 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2015-09-24 18:24:20 +0300 |
commit | 27b3ea622f8bd313a8e2827dfec752bf2125566c (patch) | |
tree | f212e49d224ce8e1cfc3b17a64ae524711494391 /source/blender/blenlib/intern/system.c | |
parent | 372dff8d1dc7e24d4b2cd37de245588ecfce8bfa (diff) | |
parent | de80e687689032cb85179a1f7e89750573631d5d (diff) |
Merge remote-tracking branch 'origin/master' into cycles_camera_nodescycles_camera_nodes
Note: the branch currently crashes in blender_camera_nodes.cpp:
BL::NodeTree b_ntree = b_data.node_groups[nodes_tree_name];
The crash was introduced in:
cb7cf523e5c000609f32a382e2c0fcc57f635a42
Conflicts:
intern/cycles/SConscript
intern/cycles/blender/addon/__init__.py
intern/cycles/blender/addon/properties.py
intern/cycles/blender/blender_camera.cpp
intern/cycles/kernel/kernel_types.h
intern/cycles/kernel/svm/svm.h
intern/cycles/kernel/svm/svm_types.h
intern/cycles/render/camera.cpp
intern/cycles/render/camera.h
Diffstat (limited to 'source/blender/blenlib/intern/system.c')
-rw-r--r-- | source/blender/blenlib/intern/system.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/system.c b/source/blender/blenlib/intern/system.c index e6389bc68f3..5d1bdd6d978 100644 --- a/source/blender/blenlib/intern/system.c +++ b/source/blender/blenlib/intern/system.c @@ -22,9 +22,21 @@ * \ingroup bli */ +#include <stdio.h> +#include <stdlib.h> #include "BLI_system.h" +#include "MEM_guardedalloc.h" + +/* for backtrace */ +#if defined(__linux__) || defined(__APPLE__) +# include <execinfo.h> +#elif defined(WIN32) +# include <windows.h> +# include <DbgHelp.h> +#endif + int BLI_cpu_support_sse2(void) { #if defined(__x86_64__) || defined(_M_X64) @@ -57,3 +69,71 @@ int BLI_cpu_support_sse2(void) #endif } +/** + * Write a backtrace into a file for systems which support it. + */ +void BLI_system_backtrace(FILE *fp) +{ + /* ------------- */ + /* Linux / Apple */ +#if defined(__linux__) || defined(__APPLE__) + +#define SIZE 100 + void *buffer[SIZE]; + int nptrs; + char **strings; + int i; + + /* include a backtrace for good measure */ + nptrs = backtrace(buffer, SIZE); + strings = backtrace_symbols(buffer, nptrs); + for (i = 0; i < nptrs; i++) { + fputs(strings[i], fp); + fputc('\n', fp); + } + + free(strings); +#undef SIZE + + /* -------- */ + /* Windows */ +#elif defined(_MSC_VER) + +#ifndef NDEBUG +#define MAXSYMBOL 256 +#define SIZE 100 + unsigned short i; + void *stack[SIZE]; + unsigned short nframes; + SYMBOL_INFO *symbolinfo; + HANDLE process; + + process = GetCurrentProcess(); + + SymInitialize(process, NULL, TRUE); + + nframes = CaptureStackBackTrace(0, SIZE, stack, NULL); + symbolinfo = MEM_callocN(sizeof(SYMBOL_INFO) + MAXSYMBOL * sizeof(char), "crash Symbol table"); + symbolinfo->MaxNameLen = MAXSYMBOL - 1; + symbolinfo->SizeOfStruct = sizeof(SYMBOL_INFO); + + for (i = 0; i < nframes; i++) { + SymFromAddr(process, (DWORD64)(stack[i]), 0, symbolinfo); + + fprintf(fp, "%u: %s - 0x%0X\n", nframes - i - 1, symbolinfo->Name, symbolinfo->Address); + } + + MEM_freeN(symbolinfo); +#undef MAXSYMBOL +#undef SIZE +#else + fprintf(fp, "Crash backtrace not supported on release builds\n"); +#endif /* NDEBUG */ +#else /* _MSC_VER */ + /* ------------------ */ + /* non msvc/osx/linux */ + (void)fp; +#endif + +} +/* end BLI_system_backtrace */ |