Shorten crash output to fit on screen

This commit is contained in:
Christian Göttsche 2021-08-08 19:47:17 +02:00 committed by Benny Baumann
parent 16faf82739
commit 4ed3ab5c2c
2 changed files with 70 additions and 65 deletions

17
CRT.c
View File

@ -792,7 +792,7 @@ static void dumpStderr(void) {
if (res > 0) { if (res > 0) {
if (!header) { if (!header) {
fprintf(stderr, ">>>>>>>>>> stderr output >>>>>>>>>>\n\n"); fprintf(stderr, ">>>>>>>>>> stderr output >>>>>>>>>>\n");
header = true; header = true;
} }
(void)! write(STDERR_FILENO, buffer, res); (void)! write(STDERR_FILENO, buffer, res);
@ -1006,8 +1006,7 @@ void CRT_handleSIGSEGV(int signal) {
"============================\n" "============================\n"
"Please check at https://htop.dev/issues whether this issue has already been reported.\n" "Please check at https://htop.dev/issues whether this issue has already been reported.\n"
"If no similar issue has been reported before, please create a new issue with the following information:\n" "If no similar issue has been reported before, please create a new issue with the following information:\n"
"\n" " - Your "PACKAGE" version: '"VERSION"'\n"
"- Your "PACKAGE" version ("PACKAGE" --version)\n"
" - Your OS and kernel version (uname -a)\n" " - Your OS and kernel version (uname -a)\n"
" - Your distribution and release (lsb_release -a)\n" " - Your distribution and release (lsb_release -a)\n"
" - Likely steps to reproduce (How did it happen?)\n" " - Likely steps to reproduce (How did it happen?)\n"
@ -1037,14 +1036,12 @@ void CRT_handleSIGSEGV(int signal) {
"Setting information:\n" "Setting information:\n"
"--------------------\n"); "--------------------\n");
Settings_write(CRT_crashSettings, true); Settings_write(CRT_crashSettings, true);
fprintf(stderr, "\n"); fprintf(stderr, "\n\n");
#ifdef HAVE_EXECINFO_H #ifdef HAVE_EXECINFO_H
fprintf(stderr, fprintf(stderr,
"Backtrace information:\n" "Backtrace information:\n"
"----------------------\n" "----------------------\n"
"The following function calls were active when the issue was detected:\n"
"---\n"
); );
void* backtraceArray[256]; void* backtraceArray[256];
@ -1052,10 +1049,9 @@ void CRT_handleSIGSEGV(int signal) {
size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray)); size_t size = backtrace(backtraceArray, ARRAYSIZE(backtraceArray));
backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO); backtrace_symbols_fd(backtraceArray, size, STDERR_FILENO);
fprintf(stderr, fprintf(stderr,
"---\n"
"\n" "\n"
"To make the above information more practical to work with,\n" "To make the above information more practical to work with, "
"please also provide a disassembly of your "PACKAGE" binary.\n" "please also provide a disassembly of your "PACKAGE" binary. "
"This can usually be done by running the following command:\n" "This can usually be done by running the following command:\n"
"\n" "\n"
); );
@ -1069,7 +1065,6 @@ void CRT_handleSIGSEGV(int signal) {
fprintf(stderr, fprintf(stderr,
"\n" "\n"
"Please include the generated file in your report.\n" "Please include the generated file in your report.\n"
"\n"
); );
#endif #endif
@ -1078,8 +1073,6 @@ void CRT_handleSIGSEGV(int signal) {
"\n" "\n"
"Thank you for helping to improve "PACKAGE"!\n" "Thank you for helping to improve "PACKAGE"!\n"
"\n" "\n"
PACKAGE " " VERSION " aborting.\n"
"\n"
); );
/* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */

View File

@ -307,7 +307,7 @@ static bool Settings_read(Settings* this, const char* fileName, unsigned int ini
return didReadAny; return didReadAny;
} }
static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns, const char* name) { static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns, const char* name, char separator) {
fprintf(fd, "%s=", name); fprintf(fd, "%s=", name);
const char* sep = ""; const char* sep = "";
for (unsigned int i = 0; fields[i]; i++) { for (unsigned int i = 0; fields[i]; i++) {
@ -320,93 +320,105 @@ static void writeFields(FILE* fd, const ProcessField* fields, Hashtable* columns
} }
sep = " "; sep = " ";
} }
fprintf(fd, "\n"); fputc(separator, fd);
} }
static void writeMeters(const Settings* this, FILE* fd, unsigned int column) { static void writeMeters(const Settings* this, FILE* fd, char separator, unsigned int column) {
const char* sep = ""; const char* sep = "";
for (uint8_t i = 0; i < this->hColumns[column].len; i++) { for (uint8_t i = 0; i < this->hColumns[column].len; i++) {
fprintf(fd, "%s%s", sep, this->hColumns[column].names[i]); fprintf(fd, "%s%s", sep, this->hColumns[column].names[i]);
sep = " "; sep = " ";
} }
fprintf(fd, "\n"); fputc(separator, fd);
} }
static void writeMeterModes(const Settings* this, FILE* fd, unsigned int column) { static void writeMeterModes(const Settings* this, FILE* fd, char separator, unsigned int column) {
const char* sep = ""; const char* sep = "";
for (uint8_t i = 0; i < this->hColumns[column].len; i++) { for (uint8_t i = 0; i < this->hColumns[column].len; i++) {
fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]); fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]);
sep = " "; sep = " ";
} }
fprintf(fd, "\n"); fputc(separator, fd);
} }
int Settings_write(const Settings* this, bool onCrash) { int Settings_write(const Settings* this, bool onCrash) {
FILE* fd; FILE* fd;
char separator;
if (onCrash) { if (onCrash) {
fd = stderr; fd = stderr;
separator = ';';
} else { } else {
fd = fopen(this->filename, "w"); fd = fopen(this->filename, "w");
if (fd == NULL) if (fd == NULL)
return -errno; return -errno;
separator = '\n';
} }
#define printSettingInteger(setting_, value_) \
fprintf(fd, setting_ "=%d%c", (int) value_, separator);
#define printSettingString(setting_, value_) \
fprintf(fd, setting_ "=%s%c", value_, separator);
if (!onCrash) { if (!onCrash) {
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n"); fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n"); fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
} }
fprintf(fd, "htop_version=%s\n", VERSION); printSettingString("htop_version", VERSION);
fprintf(fd, "config_reader_min_version=%d\n", CONFIG_READER_MIN_VERSION); printSettingInteger("config_reader_min_version", CONFIG_READER_MIN_VERSION);
writeFields(fd, this->fields, this->dynamicColumns, "fields"); writeFields(fd, this->fields, this->dynamicColumns, "fields", separator);
// This "-1" is for compatibility with the older enum format. // This "-1" is for compatibility with the older enum format.
fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1); printSettingInteger("sort_key", this->sortKey - 1);
fprintf(fd, "sort_direction=%d\n", (int) this->direction); printSettingInteger("sort_direction", this->direction);
fprintf(fd, "tree_sort_key=%d\n", (int) this->treeSortKey - 1); printSettingInteger("tree_sort_key", this->treeSortKey - 1);
fprintf(fd, "tree_sort_direction=%d\n", (int) this->treeDirection); printSettingInteger("tree_sort_direction", this->treeDirection);
fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads); printSettingInteger("hide_kernel_threads", this->hideKernelThreads);
fprintf(fd, "hide_userland_threads=%d\n", (int) this->hideUserlandThreads); printSettingInteger("hide_userland_threads", this->hideUserlandThreads);
fprintf(fd, "shadow_other_users=%d\n", (int) this->shadowOtherUsers); printSettingInteger("shadow_other_users", this->shadowOtherUsers);
fprintf(fd, "show_thread_names=%d\n", (int) this->showThreadNames); printSettingInteger("show_thread_names", this->showThreadNames);
fprintf(fd, "show_program_path=%d\n", (int) this->showProgramPath); printSettingInteger("show_program_path", this->showProgramPath);
fprintf(fd, "highlight_base_name=%d\n", (int) this->highlightBaseName); printSettingInteger("highlight_base_name", this->highlightBaseName);
fprintf(fd, "highlight_deleted_exe=%d\n", (int) this->highlightDeletedExe); printSettingInteger("highlight_deleted_exe", this->highlightDeletedExe);
fprintf(fd, "highlight_megabytes=%d\n", (int) this->highlightMegabytes); printSettingInteger("highlight_megabytes", this->highlightMegabytes);
fprintf(fd, "highlight_threads=%d\n", (int) this->highlightThreads); printSettingInteger("highlight_threads", this->highlightThreads);
fprintf(fd, "highlight_changes=%d\n", (int) this->highlightChanges); printSettingInteger("highlight_changes", this->highlightChanges);
fprintf(fd, "highlight_changes_delay_secs=%d\n", (int) this->highlightDelaySecs); printSettingInteger("highlight_changes_delay_secs", this->highlightDelaySecs);
fprintf(fd, "find_comm_in_cmdline=%d\n", (int) this->findCommInCmdline); printSettingInteger("find_comm_in_cmdline", this->findCommInCmdline);
fprintf(fd, "strip_exe_from_cmdline=%d\n", (int) this->stripExeFromCmdline); printSettingInteger("strip_exe_from_cmdline", this->stripExeFromCmdline);
fprintf(fd, "show_merged_command=%d\n", (int) this->showMergedCommand); printSettingInteger("show_merged_command", this->showMergedCommand);
fprintf(fd, "tree_view=%d\n", (int) this->treeView); printSettingInteger("tree_view", this->treeView);
fprintf(fd, "tree_view_always_by_pid=%d\n", (int) this->treeViewAlwaysByPID); printSettingInteger("tree_view_always_by_pid", this->treeViewAlwaysByPID);
fprintf(fd, "all_branches_collapsed=%d\n", (int) this->allBranchesCollapsed); printSettingInteger("all_branches_collapsed", this->allBranchesCollapsed);
fprintf(fd, "header_margin=%d\n", (int) this->headerMargin); printSettingInteger("header_margin", this->headerMargin);
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->detailedCPUTime); printSettingInteger("detailed_cpu_time", this->detailedCPUTime);
fprintf(fd, "cpu_count_from_one=%d\n", (int) this->countCPUsFromOne); printSettingInteger("cpu_count_from_one", this->countCPUsFromOne);
fprintf(fd, "show_cpu_usage=%d\n", (int) this->showCPUUsage); printSettingInteger("show_cpu_usage", this->showCPUUsage);
fprintf(fd, "show_cpu_frequency=%d\n", (int) this->showCPUFrequency); printSettingInteger("show_cpu_frequency", this->showCPUFrequency);
#ifdef BUILD_WITH_CPU_TEMP #ifdef BUILD_WITH_CPU_TEMP
fprintf(fd, "show_cpu_temperature=%d\n", (int) this->showCPUTemperature); printSettingInteger("show_cpu_temperature", this->showCPUTemperature);
fprintf(fd, "degree_fahrenheit=%d\n", (int) this->degreeFahrenheit); printSettingInteger("degree_fahrenheit", this->degreeFahrenheit);
#endif #endif
fprintf(fd, "update_process_names=%d\n", (int) this->updateProcessNames); printSettingInteger("update_process_names", this->updateProcessNames);
fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->accountGuestInCPUMeter); printSettingInteger("account_guest_in_cpu_meter", this->accountGuestInCPUMeter);
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme); printSettingInteger("color_scheme", this->colorScheme);
#ifdef HAVE_GETMOUSE #ifdef HAVE_GETMOUSE
fprintf(fd, "enable_mouse=%d\n", (int) this->enableMouse); printSettingInteger("enable_mouse", this->enableMouse);
#endif #endif
fprintf(fd, "delay=%d\n", (int) this->delay); printSettingInteger("delay", (int) this->delay);
fprintf(fd, "header_layout=%s\n", HeaderLayout_getName(this->hLayout)); printSettingInteger("hide_function_bar", (int) this->hideFunctionBar);
#ifdef HAVE_LIBHWLOC
printSettingInteger("topology_affinity", this->topologyAffinity);
#endif
printSettingString("header_layout", HeaderLayout_getName(this->hLayout));
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) { for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++) {
fprintf(fd, "column_meters_%u=", i); fprintf(fd, "column_meters_%u=", i);
writeMeters(this, fd, i); writeMeters(this, fd, separator, i);
fprintf(fd, "column_meter_modes_%u=", i); fprintf(fd, "column_meter_modes_%u=", i);
writeMeterModes(this, fd, i); writeMeterModes(this, fd, separator, i);
} }
fprintf(fd, "hide_function_bar=%d\n", (int) this->hideFunctionBar);
#ifdef HAVE_LIBHWLOC #undef printSettingString
fprintf(fd, "topology_affinity=%d\n", (int) this->topologyAffinity); #undef printSettingInteger
#endif
if (onCrash) if (onCrash)
return 0; return 0;