diff options
Diffstat (limited to 'source/creator')
-rw-r--r-- | source/creator/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/creator/creator.c | 12 | ||||
-rw-r--r-- | source/creator/creator_args.c | 121 | ||||
-rw-r--r-- | source/creator/creator_signals.c | 40 |
4 files changed, 157 insertions, 17 deletions
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 177e9744510..1adef28f2c8 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -26,6 +26,7 @@ setup_libdirs() blender_include_dirs( + ../../intern/clog ../../intern/guardedalloc ../../intern/glew-mx ../blender/blenlib diff --git a/source/creator/creator.c b/source/creator/creator.c index 78bab14cd96..2aa60c3e2a7 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -42,6 +42,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #include "DNA_genfile.h" #include "BLI_args.h" @@ -49,6 +51,7 @@ #include "BLI_utildefines.h" #include "BLI_callbacks.h" #include "BLI_string.h" +#include "BLI_system.h" /* mostly init functions */ #include "BKE_appdir.h" @@ -180,6 +183,11 @@ static void callback_main_atexit(void *user_data) #endif } +static void callback_clg_fatal(void *fp) +{ + BLI_system_backtrace(fp); +} + /** \} */ @@ -304,6 +312,10 @@ int main( sdlewInit(); #endif + /* Initialize logging */ + CLG_init(); + CLG_fatal_fn_set(callback_clg_fatal); + C = CTX_create(); #ifdef WITH_PYTHON_MODULE diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index df4946a8175..3a478d0b9d4 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -30,6 +30,8 @@ #include "MEM_guardedalloc.h" +#include "CLG_log.h" + #ifdef WIN32 # include "BLI_winstuff.h" #endif @@ -528,6 +530,12 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo BLI_argsPrintArgDoc(ba, "--python-exit-code"); BLI_argsPrintArgDoc(ba, "--addons"); + printf("\n"); + printf("Logging Options:\n"); + BLI_argsPrintArgDoc(ba, "--log"); + BLI_argsPrintArgDoc(ba, "--log-level"); + BLI_argsPrintArgDoc(ba, "--log-show-basename"); + BLI_argsPrintArgDoc(ba, "--log-file"); printf("\n"); printf("Debug Options:\n"); @@ -702,6 +710,109 @@ static int arg_handle_background_mode_set(int UNUSED(argc), const char **UNUSED( return 0; } +static const char arg_handle_log_level_set_doc[] = +"<level>\n" +"\n" +"\tSet the logging verbosity level (higher for more details) defaults to 1." +; +static int arg_handle_log_level_set(int argc, const char **argv, void *UNUSED(data)) +{ + const char *arg_id = "--log-level"; + if (argc > 1) { + const char *err_msg = NULL; + if (!parse_int_clamp(argv[1], NULL, 0, INT_MAX, &G.log.level, &err_msg)) { + printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]); + } + return 1; + } + else { + printf("\nError: '%s' no args given.\n", arg_id); + return 0; + } +} + +static const char arg_handle_log_show_basename_set_doc[] = +"\n\tOnly show file name in output (not the leading path)." +; +static int arg_handle_log_show_basename_set(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data)) +{ + CLG_output_use_basename_set(true); + return 0; +} + +static const char arg_handle_log_file_set_doc[] = +"<filename>\n" +"\n" +"\tSet a file to output the log to." +; +static int arg_handle_log_file_set(int argc, const char **argv, void *UNUSED(data)) +{ + const char *arg_id = "--log-file"; + if (argc > 1) { + errno = 0; + FILE *fp = BLI_fopen(argv[1], "w"); + if (fp == NULL) { + const char *err_msg = errno ? strerror(errno) : "unknown"; + printf("\nError: %s '%s %s'.\n", err_msg, arg_id, argv[1]); + } + else { + if (UNLIKELY(G.log.file != NULL)) { + fclose(G.log.file); + } + G.log.file = fp; + CLG_output_set(G.log.file); + } + return 1; + } + else { + printf("\nError: '%s' no args given.\n", arg_id); + return 0; + } +} + +static const char arg_handle_log_set_doc[] = +"<match>\n" +"\tEnable logging categories, taking a single comma separated argument.\n" +"\tMultiple categories can be matched using a '.*' suffix,\n" +"\tso '--log \"wm.*\"' logs every kind of window-manager message.\n" +"\tUse \"^\" prefix to ignore, so '--log \"*,^wm.operator.*\"' logs all except for 'wm.operators.*'\n" +"\tUse \"*\" to log everything." +; +static int arg_handle_log_set(int argc, const char **argv, void *UNUSED(data)) +{ + const char *arg_id = "--log"; + if (argc > 1) { + const char *str_step = argv[1]; + while (*str_step) { + const char *str_step_end = strchr(str_step, ','); + int str_step_len = str_step_end ? (str_step_end - str_step) : strlen(str_step); + + if (str_step[0] == '^') { + CLG_type_filter_exclude(str_step + 1, str_step_len - 1); + } + else { + CLG_type_filter_include(str_step, str_step_len); + } + + if (str_step_end) { + /* typically only be one, but don't fail on multiple.*/ + while (*str_step_end == ',') { + str_step_end++; + } + str_step = str_step_end; + } + else { + break; + } + } + return 1; + } + else { + printf("\nError: '%s' no args given.\n", arg_id); + return 0; + } +} + static const char arg_handle_debug_mode_set_doc[] = "\n" "\tTurn debugging on.\n" @@ -1657,7 +1768,7 @@ static int arg_handle_python_console_run(int UNUSED(argc), const char **argv, vo } static const char arg_handle_python_exit_code_set_doc[] = -"\n" +"<code>\n" "\tSet the exit-code in [0..255] to exit if a Python exception is raised\n" "\t(only for scripts executed from the command line), zero disables." ; @@ -1683,7 +1794,8 @@ static int arg_handle_python_exit_code_set(int argc, const char **argv, void *UN } static const char arg_handle_addons_set_doc[] = -"\n\tComma separated list of add-ons (no spaces)." +"<addon(s)>\n" +"\tComma separated list of add-ons (no spaces)." ; static int arg_handle_addons_set(int argc, const char **argv, void *data) { @@ -1803,6 +1915,11 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) BLI_argsAdd(ba, 1, "-a", NULL, CB(arg_handle_playback_mode), NULL); + BLI_argsAdd(ba, 1, NULL, "--log", CB(arg_handle_log_set), ba); + BLI_argsAdd(ba, 1, NULL, "--log-level", CB(arg_handle_log_level_set), ba); + BLI_argsAdd(ba, 1, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba); + BLI_argsAdd(ba, 1, NULL, "--log-file", CB(arg_handle_log_file_set), ba); + BLI_argsAdd(ba, 1, "-d", "--debug", CB(arg_handle_debug_mode_set), ba); #ifdef WITH_FFMPEG diff --git a/source/creator/creator_signals.c b/source/creator/creator_signals.c index 81e6178c502..feb108da289 100644 --- a/source/creator/creator_signals.c +++ b/source/creator/creator_signals.c @@ -64,6 +64,7 @@ #include "BKE_main.h" #include "BKE_report.h" + /* for passing information between creator and gameengine */ #ifdef WITH_GAMEENGINE # include "BL_System.h" @@ -75,6 +76,12 @@ #include "creator_intern.h" /* own include */ +// #define USE_WRITE_CRASH_BLEND +#ifdef USE_WRITE_CRASH_BLEND +# include "BKE_undo_system.h" +# include "BLO_undofile.h" +#endif + /* set breakpoints here when running in debug mode, useful to catch floating point errors */ #if defined(__linux__) || defined(_WIN32) || defined(OSX_SSE_FPE) static void sig_handle_fpe(int UNUSED(sig)) @@ -110,29 +117,32 @@ static void sig_handle_crash_backtrace(FILE *fp) static void sig_handle_crash(int signum) { + wmWindowManager *wm = G.main->wm.first; -#if 0 - { - char fname[FILE_MAX]; +#ifdef USE_WRITE_CRASH_BLEND + if (wm->undo_stack) { + struct MemFile *memfile = BKE_undosys_stack_memfile_get_active(wm->undo_stack); + if (memfile) { + char fname[FILE_MAX]; - if (!G.main->name[0]) { - BLI_make_file_string("/", fname, BKE_tempdir_base(), "crash.blend"); - } - else { - BLI_strncpy(fname, G.main->name, sizeof(fname)); - BLI_replace_extension(fname, sizeof(fname), ".crash.blend"); - } + if (!G.main->name[0]) { + BLI_make_file_string("/", fname, BKE_tempdir_base(), "crash.blend"); + } + else { + BLI_strncpy(fname, G.main->name, sizeof(fname)); + BLI_replace_extension(fname, sizeof(fname), ".crash.blend"); + } - printf("Writing: %s\n", fname); - fflush(stdout); + printf("Writing: %s\n", fname); + fflush(stdout); - BKE_undo_save_file(fname); + BLO_memfile_write_file(memfile, fname); + } } #endif FILE *fp; char header[512]; - wmWindowManager *wm = G.main->wm.first; char fname[FILE_MAX]; @@ -338,4 +348,4 @@ void main_signal_setup_fpe(void) #endif } -#endif /* WITH_PYTHON_MODULE */
\ No newline at end of file +#endif /* WITH_PYTHON_MODULE */ |