|
|
baab13 |
From 56e7f58908997b6cfd52d44bca208ef50d1bdf61 Mon Sep 17 00:00:00 2001
|
|
|
baab13 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
baab13 |
Date: Thu, 13 Nov 2014 12:08:07 +0100
|
|
|
baab13 |
Subject: [ABRT PATCH 77/78] gdb: make gdb aware of the abrt's debuginfo dir
|
|
|
baab13 |
|
|
|
baab13 |
A debuginfo package might ship an auto-loaded gdb script. If abrt
|
|
|
baab13 |
unpacks that package into the abrt's debuginfo cache dir and points gdb
|
|
|
baab13 |
to that directory, gdb refuses to auto-loaded that gdb scripts and
|
|
|
baab13 |
produces a plenty of warning messages that abrt writes to 'backtrace'
|
|
|
baab13 |
file.
|
|
|
baab13 |
|
|
|
baab13 |
The previous solution of this issue was to turn auto-load off completely
|
|
|
baab13 |
but it turned the pretty printer off too.
|
|
|
baab13 |
|
|
|
baab13 |
The correct solution is to add the abrt's debuginfo cache directory to
|
|
|
baab13 |
auto-load safe-path and auto-load scripts-dir settings.
|
|
|
baab13 |
|
|
|
baab13 |
Thanks Jan Kratochvil <jkratoch@redhat.com>
|
|
|
baab13 |
|
|
|
baab13 |
Requires: rhbz#1163339
|
|
|
baab13 |
Resolves: rhbz#1128637
|
|
|
baab13 |
|
|
|
baab13 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
baab13 |
---
|
|
|
baab13 |
src/lib/hooklib.c | 83 ++++++++++++++++++++++++++++++++++++-------------------
|
|
|
baab13 |
1 file changed, 55 insertions(+), 28 deletions(-)
|
|
|
baab13 |
|
|
|
baab13 |
diff --git a/src/lib/hooklib.c b/src/lib/hooklib.c
|
|
|
baab13 |
index 4a50727..1d45cdd 100644
|
|
|
baab13 |
--- a/src/lib/hooklib.c
|
|
|
baab13 |
+++ b/src/lib/hooklib.c
|
|
|
baab13 |
@@ -252,11 +252,12 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
|
|
|
baab13 |
/* Let user know what's going on */
|
|
|
baab13 |
log(_("Generating backtrace"));
|
|
|
baab13 |
|
|
|
baab13 |
- char *args[21];
|
|
|
baab13 |
- args[0] = (char*)"gdb";
|
|
|
baab13 |
- args[1] = (char*)"-batch";
|
|
|
baab13 |
- args[2] = (char*)"-ex";
|
|
|
baab13 |
+ unsigned i = 0;
|
|
|
baab13 |
+ char *args[25];
|
|
|
baab13 |
+ args[i++] = (char*)"gdb";
|
|
|
baab13 |
+ args[i++] = (char*)"-batch";
|
|
|
baab13 |
struct strbuf *set_debug_file_directory = strbuf_new();
|
|
|
baab13 |
+ unsigned auto_load_base_index = 0;
|
|
|
baab13 |
if(debuginfo_dirs == NULL)
|
|
|
baab13 |
{
|
|
|
baab13 |
// set non-existent debug file directory to prevent resolving
|
|
|
baab13 |
@@ -266,6 +267,8 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
|
|
|
baab13 |
else
|
|
|
baab13 |
{
|
|
|
baab13 |
strbuf_append_str(set_debug_file_directory, "set debug-file-directory /usr/lib/debug");
|
|
|
baab13 |
+
|
|
|
baab13 |
+ struct strbuf *debug_directories = strbuf_new();
|
|
|
baab13 |
const char *p = debuginfo_dirs;
|
|
|
baab13 |
while (1)
|
|
|
baab13 |
{
|
|
|
baab13 |
@@ -274,11 +277,25 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
|
|
|
baab13 |
if (*p == '\0')
|
|
|
baab13 |
break;
|
|
|
baab13 |
const char *colon_or_nul = strchrnul(p, ':');
|
|
|
baab13 |
- strbuf_append_strf(set_debug_file_directory, ":%.*s/usr/lib/debug", (int)(colon_or_nul - p), p);
|
|
|
baab13 |
+ strbuf_append_strf(debug_directories, "%s%.*s/usr/lib/debug", (debug_directories->len == 0 ? "" : ":"),
|
|
|
baab13 |
+ (int)(colon_or_nul - p), p);
|
|
|
baab13 |
p = colon_or_nul;
|
|
|
baab13 |
}
|
|
|
baab13 |
+
|
|
|
baab13 |
+ strbuf_append_strf(set_debug_file_directory, ":%s", debug_directories->buf);
|
|
|
baab13 |
+
|
|
|
baab13 |
+ args[i++] = (char*)"-iex";
|
|
|
baab13 |
+ auto_load_base_index = i;
|
|
|
baab13 |
+ args[i++] = xasprintf("add-auto-load-safe-path %s", debug_directories->buf);
|
|
|
baab13 |
+ args[i++] = (char*)"-iex";
|
|
|
baab13 |
+ args[i++] = xasprintf("add-auto-load-scripts-directory %s", debug_directories->buf);
|
|
|
baab13 |
+
|
|
|
baab13 |
+ strbuf_free(debug_directories);
|
|
|
baab13 |
}
|
|
|
baab13 |
- args[3] = strbuf_free_nobuf(set_debug_file_directory);
|
|
|
baab13 |
+
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ const unsigned debug_dir_cmd_index = i++;
|
|
|
baab13 |
+ args[debug_dir_cmd_index] = strbuf_free_nobuf(set_debug_file_directory);
|
|
|
baab13 |
|
|
|
baab13 |
/* "file BINARY_FILE" is needed, without it gdb cannot properly
|
|
|
baab13 |
* unwind the stack. Currently the unwind information is located
|
|
|
baab13 |
@@ -300,27 +317,31 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
|
|
|
baab13 |
* TODO: check mtimes on COREFILE and BINARY_FILE and not supply
|
|
|
baab13 |
* BINARY_FILE if it is newer (to at least avoid gdb complaining).
|
|
|
baab13 |
*/
|
|
|
baab13 |
- args[4] = (char*)"-ex";
|
|
|
baab13 |
- args[5] = xasprintf("file %s", executable);
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ const unsigned file_cmd_index = i++;
|
|
|
baab13 |
+ args[file_cmd_index] = xasprintf("file %s", executable);
|
|
|
baab13 |
free(executable);
|
|
|
baab13 |
|
|
|
baab13 |
- args[6] = (char*)"-ex";
|
|
|
baab13 |
- args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, dump_dir_name);
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ const unsigned core_cmd_index = i++;
|
|
|
baab13 |
+ args[core_cmd_index] = xasprintf("core-file %s/"FILENAME_COREDUMP, dump_dir_name);
|
|
|
baab13 |
|
|
|
baab13 |
- args[8] = (char*)"-ex";
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ const unsigned bt_cmd_index = i++;
|
|
|
baab13 |
/*args[9] = ... see below */
|
|
|
baab13 |
- args[10] = (char*)"-ex";
|
|
|
baab13 |
- args[11] = (char*)"info sharedlib";
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ args[i++] = (char*)"info sharedlib";
|
|
|
baab13 |
/* glibc's abort() stores its message in __abort_msg variable */
|
|
|
baab13 |
- args[12] = (char*)"-ex";
|
|
|
baab13 |
- args[13] = (char*)"print (char*)__abort_msg";
|
|
|
baab13 |
- args[14] = (char*)"-ex";
|
|
|
baab13 |
- args[15] = (char*)"print (char*)__glib_assert_msg";
|
|
|
baab13 |
- args[16] = (char*)"-ex";
|
|
|
baab13 |
- args[17] = (char*)"info all-registers";
|
|
|
baab13 |
- args[18] = (char*)"-ex";
|
|
|
baab13 |
- args[19] = (char*)"disassemble";
|
|
|
baab13 |
- args[20] = NULL;
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ args[i++] = (char*)"print (char*)__abort_msg";
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ args[i++] = (char*)"print (char*)__glib_assert_msg";
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ args[i++] = (char*)"info all-registers";
|
|
|
baab13 |
+ args[i++] = (char*)"-ex";
|
|
|
baab13 |
+ const unsigned dis_cmd_index = i++;
|
|
|
baab13 |
+ args[dis_cmd_index] = (char*)"disassemble";
|
|
|
baab13 |
+ args[i++] = NULL;
|
|
|
baab13 |
|
|
|
baab13 |
/* Get the backtrace, but try to cap its size */
|
|
|
baab13 |
/* Limit bt depth. With no limit, gdb sometimes OOMs the machine */
|
|
|
baab13 |
@@ -330,9 +351,9 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
|
|
|
baab13 |
char *bt = NULL;
|
|
|
baab13 |
while (1)
|
|
|
baab13 |
{
|
|
|
baab13 |
- args[9] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full);
|
|
|
baab13 |
+ args[bt_cmd_index] = xasprintf("%s backtrace %u%s", thread_apply_all, bt_depth, full);
|
|
|
baab13 |
bt = exec_vp(args, /*redirect_stderr:*/ 1, timeout_sec, NULL);
|
|
|
baab13 |
- free(args[9]);
|
|
|
baab13 |
+ free(args[bt_cmd_index]);
|
|
|
baab13 |
if ((bt && strnlen(bt, 256*1024) < 256*1024) || bt_depth <= 32)
|
|
|
baab13 |
{
|
|
|
baab13 |
break;
|
|
|
baab13 |
@@ -357,7 +378,7 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
|
|
|
baab13 |
* End of assembler dump.
|
|
|
baab13 |
* (IOW: "empty" dump)
|
|
|
baab13 |
*/
|
|
|
baab13 |
- args[19] = (char*)"disassemble $pc-20, $pc+64";
|
|
|
baab13 |
+ args[dis_cmd_index] = (char*)"disassemble $pc-20, $pc+64";
|
|
|
baab13 |
|
|
|
baab13 |
if (bt_depth <= 64 && thread_apply_all[0] != '\0')
|
|
|
baab13 |
{
|
|
|
baab13 |
@@ -373,9 +394,15 @@ char *get_backtrace(const char *dump_dir_name, unsigned timeout_sec, const char
|
|
|
baab13 |
}
|
|
|
baab13 |
}
|
|
|
baab13 |
|
|
|
baab13 |
- free(args[3]);
|
|
|
baab13 |
- free(args[5]);
|
|
|
baab13 |
- free(args[7]);
|
|
|
baab13 |
+ if (auto_load_base_index > 0)
|
|
|
baab13 |
+ {
|
|
|
baab13 |
+ free(args[auto_load_base_index]);
|
|
|
baab13 |
+ free(args[auto_load_base_index + 2]);
|
|
|
baab13 |
+ }
|
|
|
baab13 |
+
|
|
|
baab13 |
+ free(args[debug_dir_cmd_index]);
|
|
|
baab13 |
+ free(args[file_cmd_index]);
|
|
|
baab13 |
+ free(args[core_cmd_index]);
|
|
|
baab13 |
return bt;
|
|
|
baab13 |
}
|
|
|
baab13 |
|
|
|
baab13 |
--
|
|
|
baab13 |
1.8.3.1
|
|
|
baab13 |
|