Store command history when terminating with an error
authorClifford Wolf <clifford@clifford.at>
Tue, 20 Jun 2017 02:41:58 +0000 (04:41 +0200)
committerClifford Wolf <clifford@clifford.at>
Tue, 20 Jun 2017 02:41:58 +0000 (04:41 +0200)
kernel/driver.cc
kernel/log.cc
kernel/log.h

index 7d714d079ce4de0df41e1d66c3d216a0e29372a8..0d331712cef2d2574a15784442e3a127cfca89cf 100644 (file)
@@ -119,6 +119,29 @@ const char *prompt()
 
 #else /* EMSCRIPTEN */
 
+#ifdef YOSYS_ENABLE_READLINE
+int history_offset = 0;
+std::string history_file;
+#endif
+
+void yosys_atexit()
+{
+#ifdef YOSYS_ENABLE_READLINE
+       if (!history_file.empty()) {
+               if (history_offset > 0) {
+                       history_truncate_file(history_file.c_str(), 100);
+                       append_history(where_history() - history_offset, history_file.c_str());
+               } else
+                       write_history(history_file.c_str());
+       }
+
+       clear_history();
+       HIST_ENTRY **hist_list = history_list();
+       if (hist_list != NULL)
+               free(hist_list);
+#endif
+}
+
 int main(int argc, char **argv)
 {
        std::string frontend_command = "auto";
@@ -137,8 +160,6 @@ int main(int argc, char **argv)
        bool mode_q = false;
 
 #ifdef YOSYS_ENABLE_READLINE
-       int history_offset = 0;
-       std::string history_file;
        if (getenv("HOME") != NULL) {
                history_file = stringf("%s/.yosys_history", getenv("HOME"));
                read_history(history_file.c_str());
@@ -379,6 +400,7 @@ int main(int argc, char **argv)
                log_hasher = new SHA1;
 
        yosys_setup();
+       log_error_atexit = yosys_atexit;
 
        for (auto &fn : plugin_filenames)
                load_plugin(fn, {});
@@ -509,25 +531,12 @@ int main(int argc, char **argv)
        }
 #endif
 
+       yosys_atexit();
+
        memhasher_off();
        if (call_abort)
                abort();
 
-#ifdef YOSYS_ENABLE_READLINE
-       if (!history_file.empty()) {
-               if (history_offset > 0) {
-                       history_truncate_file(history_file.c_str(), 100);
-                       append_history(where_history() - history_offset, history_file.c_str());
-               } else
-                       write_history(history_file.c_str());
-       }
-
-       clear_history();
-       HIST_ENTRY **hist_list = history_list();
-       if (hist_list != NULL)
-               free(hist_list);
-#endif
-
        log_flush();
 #if defined(_MSC_VER)
        _exit(0);
index c7240d54035279ef726a0a91c9e39e41f11ef478..3768922cdf6c3a76ad77d0d15c07c86fbcc80b9c 100644 (file)
@@ -52,6 +52,7 @@ bool log_cmd_error_throw = false;
 bool log_quiet_warnings = false;
 int log_verbose_level;
 string log_last_error;
+void (*log_error_atexit)() = NULL;
 
 vector<int> header_count;
 pool<RTLIL::IdString> log_id_cache;
@@ -244,6 +245,9 @@ void logv_error(const char *format, va_list ap)
        log("ERROR: %s", log_last_error.c_str());
        log_flush();
 
+       if (log_error_atexit)
+               log_error_atexit();
+
 #ifdef EMSCRIPTEN
        log_files = backup_log_files;
        throw 0;
index 34c30901619b54fb43f0716494c923c3240992d4..6cae4431d42480ffc13080735f48322e4e2cdcc1 100644 (file)
@@ -60,6 +60,7 @@ extern bool log_cmd_error_throw;
 extern bool log_quiet_warnings;
 extern int log_verbose_level;
 extern string log_last_error;
+extern void (*log_error_atexit)();
 
 void logv(const char *format, va_list ap);
 void logv_header(RTLIL::Design *design, const char *format, va_list ap);