Gimp/app-tools/gimp-debug-tool.c
Bruno Lopes 72cb583489
app, app-tools, libgimp: Fix GIMP not outputing on non-native shells
As per IEEE Std 1003.1-2017, Section 8.3, TERM and
SHELL vars says we are running GIMP on POSIX shell.
They are not set by either the deprecated Windows CMD
nor by Windows PowerShell since they are not POSIX.

POSIX shells are supported by us on Linux and macOS but
actually not on Windows, since they are non-native: they
rely on forking to Cygwin which have terrible performance
(##11385) and do other tricks to make deps believe they
are on Unix which breaks e.g. GObject Introspection (#11424).
Anyway, it is Unix emulation at its prime, tricky by nature.

Even so, does not hurt allow the output on these
unsupported shells on Windows so not disrupt workflows
of adventurous developers but they will be warned that
problems (like the ones above) can and indeed appear.
2025-11-01 14:24:01 -03:00

116 lines
3.2 KiB
C

/* gimpdebug
* Copyright (C) 2018 Jehan <jehan@gimp.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*
* GimpDebug simply displays a dialog with debug data (backtraces,
* version, etc.), proposing to create a bug report. The reason why it
* is a separate executable is simply that when the program crashed,
* even though some actions are possible before exit() by catching fatal
* errors and signals, it may not be possible to allocate memory
* anymore. Therefore creating a new dialog is an impossible action.
* So we call instead a separate program, then exit.
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib/gi18n.h>
#ifdef G_OS_WIN32
#include <windows.h>
#endif
#include <gtk/gtk.h>
#include "app/widgets/gimpcriticaldialog.h"
int
main (int argc,
char **argv)
{
const gchar *program;
const gchar *pid;
const gchar *reason;
const gchar *message;
const gchar *bt_file = NULL;
const gchar *last_version = NULL;
const gchar *release_date = NULL;
gchar *trace = NULL;
gchar *error;
GtkWidget *dialog;
#ifdef G_OS_WIN32
if (AttachConsole (ATTACH_PARENT_PROCESS) != 0 && ! g_getenv ("TERM") && ! g_getenv ("SHELL"))
{
freopen ("CONOUT$", "w", stdout);
freopen ("CONOUT$", "w", stderr);
_flushall ();
}
#endif
if (argc != 6 && argc != 8)
{
g_print ("Usage: gimp-debug-tool-%s [PROGRAM] [PID] [REASON] [MESSAGE] [BT_FILE] "
"([LAST_VERSION] [RELEASE_TIMESTAMP])\n", GIMP_APP_VERSION);
exit (EXIT_FAILURE);
}
program = argv[1];
pid = argv[2];
reason = argv[3];
message = argv[4];
error = g_strdup_printf ("%s: %s", reason, message);
bt_file = argv[5];
g_file_get_contents (bt_file, &trace, NULL, NULL);
if (trace == NULL || strlen (trace) == 0)
exit (EXIT_FAILURE);
if (argc == 8)
{
last_version = argv[6];
release_date = argv[7];
}
gtk_init (&argc, &argv);
dialog = gimp_critical_dialog_new (_("GIMP Crash Debug"), last_version,
release_date ? g_ascii_strtoll (release_date, NULL, 10) : -1);
gimp_critical_dialog_add (dialog, error, trace, TRUE, program,
g_ascii_strtoull (pid, NULL, 10));
g_free (error);
g_free (trace);
g_signal_connect (dialog, "delete-event",
G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (dialog, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
gtk_widget_show (dialog);
gtk_main ();
exit (EXIT_SUCCESS);
}