Skip to content

Commit

Permalink
Persistence for Retain trace file on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
perdrix52 committed Dec 22, 2024
1 parent fd14b23 commit a78c2d6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 180 deletions.
178 changes: 6 additions & 172 deletions DeepSkyStacker/DeepSkyStacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,177 +691,6 @@ constexpr size_t backPocketSize{ 1024 * 1024 };

static char const* global_program_name;

//namespace
//{
// void writeOutput(const char* text)
// {
// fputs(text, stderr);
// ZTRACE_RUNTIME(text);
// };
//
//#if defined(_WINDOWS)
//#define EXCEPTION_CASE(code) \
// case code: \
// exceptionString = #code "\n"; \
// break
//
// DSSStackWalker sw;
//
// LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS* ExceptionInfo)
// {
// const char* exceptionString = NULL;
//
// switch (ExceptionInfo->ExceptionRecord->ExceptionCode)
// {
// EXCEPTION_CASE(EXCEPTION_ACCESS_VIOLATION);
// EXCEPTION_CASE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
// EXCEPTION_CASE(EXCEPTION_BREAKPOINT);
// EXCEPTION_CASE(EXCEPTION_DATATYPE_MISALIGNMENT);
// EXCEPTION_CASE(EXCEPTION_FLT_DENORMAL_OPERAND);
// EXCEPTION_CASE(EXCEPTION_FLT_DIVIDE_BY_ZERO);
// EXCEPTION_CASE(EXCEPTION_FLT_INEXACT_RESULT);
// EXCEPTION_CASE(EXCEPTION_FLT_INVALID_OPERATION);
// EXCEPTION_CASE(EXCEPTION_FLT_OVERFLOW);
// EXCEPTION_CASE(EXCEPTION_FLT_STACK_CHECK);
// EXCEPTION_CASE(EXCEPTION_FLT_UNDERFLOW);
// EXCEPTION_CASE(EXCEPTION_ILLEGAL_INSTRUCTION);
// EXCEPTION_CASE(EXCEPTION_IN_PAGE_ERROR);
// EXCEPTION_CASE(EXCEPTION_INT_DIVIDE_BY_ZERO);
// EXCEPTION_CASE(EXCEPTION_INT_OVERFLOW);
// EXCEPTION_CASE(EXCEPTION_INVALID_DISPOSITION);
// EXCEPTION_CASE(EXCEPTION_NONCONTINUABLE_EXCEPTION);
// EXCEPTION_CASE(EXCEPTION_PRIV_INSTRUCTION);
// EXCEPTION_CASE(EXCEPTION_SINGLE_STEP);
// EXCEPTION_CASE(EXCEPTION_STACK_OVERFLOW);
// case 0xE06D7363:
// exceptionString = "Unhandled C++ Exception ...\n";
// break;
// default:
// exceptionString = "Error: Unrecognized Exception\n";
// break;
// }
// writeOutput(exceptionString);
// fflush(stderr);
// /* If this is a stack overflow then we can't walk the stack, so just show
// where the error happened */
// if (EXCEPTION_STACK_OVERFLOW != ExceptionInfo->ExceptionRecord->ExceptionCode)
// {
// sw.ShowCallstack();
// }
// else
// {
// char buffer[128]{};
// snprintf(buffer, sizeof(buffer), "Stack Overflow Exception address: %p\n", (void*)ExceptionInfo->ContextRecord->Rip);
// writeOutput(buffer);
// }
// DeepSkyStacker::instance()->close();
// return EXCEPTION_EXECUTE_HANDLER;
// }
//
// LONG WINAPI RedirectedSetUnhandledExceptionFilter(EXCEPTION_POINTERS* /*ExceptionInfo*/)
// {
// // When the CRT calls SetUnhandledExceptionFilter with NULL parameter, our handler will not get removed.
// return 0;
// }
//#else
// /* Resolve symbol name and source location given the path to the executable
// and an address */
// int addr2line(char const* const program_name, void const* const addr)
// {
// char addr2line_cmd[512] { 0 };
//
// /* have addr2line map the address to the relevant line in the code */
// #ifdef __APPLE__
// /* apple does things differently... */
// sprintf(addr2line_cmd, "atos -o %.256s %p", program_name, addr);
// #else
// sprintf(addr2line_cmd, "addr2line -f -p -e %.256s %p", program_name, addr);
// #endif
//
// /* This will print a nicely formatted string specifying the
// function and source line of the address */
// FILE* in;
// char buff[512];
// // is this the check for command execution exited with not 0?
// if (!(in = popen(addr2line_cmd, "r"))) {
// // I want to return the exit code and error message too if any
// return 1;
// }
// // this part echoes the output of the command that's executed
// while (fgets(buff, sizeof(buff), in) != NULL)
// {
// writeOutput(buff);
// }
// return WEXITSTATUS(pclose(in));
// }
//
// constexpr size_t MAX_STACK_FRAMES{ 64 };
// static void* stack_traces[MAX_STACK_FRAMES];
// void posix_print_stack_trace()
// {
// int i, trace_size = 0;
// char** messages = (char**)NULL;
// char buffer[1024]{}; // buffer for error message
//
//
// trace_size = backtrace(stack_traces, MAX_STACK_FRAMES);
// messages = backtrace_symbols(stack_traces, trace_size);
//
// /* skip the first couple stack frames (as they are this function and
// our handler) and also skip the last frame as it's (always?) junk. */
// // for (i = 3; i < (trace_size - 1); ++i)
// // we'll use this for now so you can see what's going on
// for (i = 0; i < trace_size; ++i)
// {
// if (addr2line(global_program_name, stack_traces[i]) != 0)
// {
// snprintf(buffer, sizeof(buffer)/sizeof(char),
// " error determining line # for: %s\n", messages[i]);
// writeOutput(buffer);
// }
//
// }
// if (messages) { free(messages); }
// }
//
// void signalHandler(int signal)
// {
// if (backPocket)
// {
// free(backPocket);
// backPocket = nullptr;
// }
//
// char name[8]{};
// switch (signal)
// {
// case SIGINT:
// strcpy(name, "SIGINT");
// break;
// case SIGILL:
// strcpy(name, "SIGILL");
// break;
// case SIGFPE:
// strcpy(name, "SIGFPE");
// break;
// case SIGSEGV:
// strcpy(name, "SIGSEGV");
// break;
// case SIGTERM:
// strcpy(name, "SIGTERM");
// break;
// default:
// snprintf(name, sizeof(name)/sizeof(char), "%d", signal);
// }
//
// ZTRACE_RUNTIME("In signalHandler(%s)", name);
//
// posix_print_stack_trace();
// DeepSkyStacker::instance()->close();
// }
//#endif
//}

bool LoadTranslationUnit(QApplication& app, QTranslator& translator, const char* prefix, const QString& path, const QString& language)
{
QString translatorFileName(prefix);
Expand Down Expand Up @@ -968,7 +797,12 @@ int main(int argc, char* argv[])
QCoreApplication::setOrganizationDomain("deepskystacker.free.fr");
QCoreApplication::setApplicationName("DeepSkyStacker5");

QSettings settings;
//
// Set up retention of the trace based on user settings
//
QSettings settings;
auto retainTrace{ settings.value("RetainTraceFile", false).toBool() };
traceControl.setDeleteOnExit(!retainTrace);

g_bShowRefStars = settings.value("ShowRefStars", false).toBool();

Expand Down
2 changes: 2 additions & 0 deletions DeepSkyStacker/ExplorerBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ namespace DSS
void ExplorerBar::keepTraceChanged(int state)
{
bool retainTrace{ Qt::Checked == static_cast<Qt::CheckState>(state) };
QSettings settings;
settings.setValue("RetainTraceFile", retainTrace);

traceControl.setDeleteOnExit(!retainTrace);

Expand Down
18 changes: 10 additions & 8 deletions DeepSkyStackerKernel/tracecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ namespace DSS
else if ("DeepSkyStackerLive" == path) start = "DSSLiveTrace";
else ZASSERT(false);

(void) _putenv(traceTo.toStdString().c_str()); // set Z_TRACETO=FILE

std::time_t time = std::time({});
char timeString[std::size("yyyy-mm-ddThh-mm-ssZ")];
std::strftime(std::data(timeString), std::size(timeString), "%FT%H-%M-%SZ", std::gmtime(&time));
Expand All @@ -77,12 +75,16 @@ namespace DSS
create_directories(file);
file /= name.toStdU16String();

QString traceFile = QString{ "Z_TRACEFILE=%1" }.arg(file.generic_u16string().c_str());
#if defined(_WIN32)
(void) _wputenv(traceFile.toStdWString().c_str());
#else
(void)putenv(tracefile.toStdString().c_str());
#endif
//
// Set the trace file location
//
qputenv("Z_TRACEFILE", file.generic_string().c_str());

//
// Enable trace to a file
//
ZTrace::enableTrace();
ZTrace::writeToFile();

}

Expand Down
1 change: 1 addition & 0 deletions DeepSkyStackerKernel/tracecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace DSS
{
erase = v;
}

private:
std::string fileName;
const QString dirName;
Expand Down

0 comments on commit a78c2d6

Please sign in to comment.