Blame SOURCES/0077-gdb-make-gdb-aware-of-the-abrt-s-debuginfo-dir.patch

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