Blame SOURCES/0005-Unify-reason-message-format.patch

d7180c
From 9eaeea7851ff8682b7b6289dd9bded87d29c6fdd Mon Sep 17 00:00:00 2001
d7180c
From: Jakub Filak <jfilak@redhat.com>
d7180c
Date: Fri, 25 Oct 2013 15:46:43 +0200
d7180c
Subject: [PATCH 05/39] Unify reason message format
d7180c
d7180c
Use the same message for abrt and log:
d7180c
d7180c
(Caught|Uncaght) exception $FQDN_TYPE in method $FQDN_METHOD
d7180c
d7180c
The new format misses thread name and method signature. Thread's name is
d7180c
available in stack trace and method's signature is useful only for
d7180c
debugging.
d7180c
d7180c
Length of the reason message is limited to 255 characters. If the
d7180c
message exceeds that limit, algorithm tries to generate the message
d7180c
according to the following formats:
d7180c
d7180c
(Caught|Uncaght) exception $FQDN_TYPE in method $CLASS_NAME_METHOD
d7180c
(Caught|Uncaght) exception $EXCEPTION_CLASS in method $CLASS_NAME_METHOD
d7180c
(Caught|Uncaght) exception $EXCEPTION_CLASS in method $METHOD
d7180c
d7180c
The first suitable message is used. If none of these formats generate an
d7180c
acceptable message, the last format is used and the message is truncated.
d7180c
d7180c
Related to rhbz#1023081
d7180c
Related to rhbz#1055581
d7180c
d7180c
Signed-off-by: Jakub Filak <jfilak@redhat.com>
d7180c
---
d7180c
 src/abrt-checker.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++--------
d7180c
 1 file changed, 85 insertions(+), 14 deletions(-)
d7180c
d7180c
diff --git a/src/abrt-checker.c b/src/abrt-checker.c
d7180c
index 22f772e..23e76b0 100644
d7180c
--- a/src/abrt-checker.c
d7180c
+++ b/src/abrt-checker.c
d7180c
@@ -87,6 +87,9 @@
d7180c
 /* Don't need to be changed */
d7180c
 #define MAX_THREAD_NAME_LENGTH 40
d7180c
 
d7180c
+/* Max. length of reason message */
d7180c
+#define MAX_REASON_MESSAGE_STRING_LENGTH 255
d7180c
+
d7180c
 /* Max. length of stack trace */
d7180c
 #define MAX_STACK_TRACE_STRING_LENGTH 10000
d7180c
 
d7180c
@@ -402,7 +405,7 @@ static void add_process_properties_data(problem_data_t *pd)
d7180c
  * Register new ABRT event using given message and a method name.
d7180c
  * If reportErrosTo global flags doesn't contain ED_ABRT, this function does nothing.
d7180c
  */
d7180c
-static void register_abrt_event(char * executable, char * message, unsigned char * method, char * backtrace)
d7180c
+static void register_abrt_event(char * executable, char * message, char * backtrace)
d7180c
 {
d7180c
     if ((reportErrosTo & ED_ABRT) == 0)
d7180c
     {
d7180c
@@ -410,7 +413,6 @@ static void register_abrt_event(char * executable, char * message, unsigned char
d7180c
         return;
d7180c
     }
d7180c
 
d7180c
-    char abrt_message[1000];
d7180c
     char s[11];
d7180c
     problem_data_t *pd = problem_data_new();
d7180c
 
d7180c
@@ -421,14 +423,12 @@ static void register_abrt_event(char * executable, char * message, unsigned char
d7180c
     get_uid_as_string(s);
d7180c
     problem_data_add_text_editable(pd, FILENAME_UID, s);
d7180c
 
d7180c
-    sprintf(abrt_message, "%s in method %s", message, method);
d7180c
-
d7180c
     /* executable must belong to some package otherwise ABRT refuse it */
d7180c
     problem_data_add_text_editable(pd, FILENAME_EXECUTABLE, executable);
d7180c
     problem_data_add_text_editable(pd, FILENAME_BACKTRACE, backtrace);
d7180c
 
d7180c
     /* type and analyzer are the same for abrt, we keep both just for sake of comaptibility */
d7180c
-    problem_data_add_text_editable(pd, FILENAME_REASON, abrt_message);
d7180c
+    problem_data_add_text_editable(pd, FILENAME_REASON, message);
d7180c
     /* end of required fields */
d7180c
 
d7180c
     /* add optional fields */
d7180c
@@ -489,6 +489,66 @@ static int get_tid(
d7180c
 
d7180c
 
d7180c
 
d7180c
+static char *format_exception_reason_message(
d7180c
+        int caught,
d7180c
+        const char *exception_fqdn,
d7180c
+        const char *class_fqdn,
d7180c
+        const char *method)
d7180c
+{
d7180c
+    const char *exception_name = exception_fqdn;
d7180c
+    const char *class_name = class_fqdn;
d7180c
+    const char *prefix = caught ? "Caught" : "Uncaught";
d7180c
+
d7180c
+    char *message = (char*)calloc(MAX_REASON_MESSAGE_STRING_LENGTH + 1, sizeof(char));
d7180c
+    if (message == NULL)
d7180c
+    {
d7180c
+        fprintf(stderr, __FILE__ ":" STRINGIZE(__LINE__) ": calloc(): out of memory");
d7180c
+        return NULL;
d7180c
+    }
d7180c
+
d7180c
+    while (1)
d7180c
+    {
d7180c
+        const int message_len = snprintf(message, MAX_REASON_MESSAGE_STRING_LENGTH,
d7180c
+                "%s exception %s in method %s%s%s()", prefix,
d7180c
+                exception_name, class_name, ('\0' != class_name[0] ? "." : ""),
d7180c
+                method);
d7180c
+
d7180c
+        if (message_len <= 0)
d7180c
+        {
d7180c
+            fprintf(stderr, __FILE__ ":" STRINGIZE(__LINE__) ": snprintf(): can't print reason message to memory on stack\n");
d7180c
+            free(message);
d7180c
+            return NULL;
d7180c
+        }
d7180c
+        else if (message_len >= MAX_REASON_MESSAGE_STRING_LENGTH)
d7180c
+        {
d7180c
+            const char *ptr = NULL;
d7180c
+            if (NULL != (ptr = strrchr(class_name, '.')))
d7180c
+            {
d7180c
+                /* Drop name space from method signature */
d7180c
+                class_name = ptr + 1;
d7180c
+                continue;
d7180c
+            }
d7180c
+            else if(NULL != (ptr = strrchr(exception_name, '.')))
d7180c
+            {
d7180c
+                /* Drop name space from exception class signature */
d7180c
+                exception_name = ptr + 1;
d7180c
+                continue;
d7180c
+            }
d7180c
+            else if (class_name[0] != '\0')
d7180c
+            {
d7180c
+                /* Drop class name from method signature */
d7180c
+                class_name += strlen(class_name);
d7180c
+                continue;
d7180c
+            }
d7180c
+            /* No more place for shortening. The message will remain truncated. */
d7180c
+        }
d7180c
+
d7180c
+        return message;
d7180c
+    }
d7180c
+}
d7180c
+
d7180c
+
d7180c
+
d7180c
 /*
d7180c
  * Format class signature into a printable form.
d7180c
  * Class names have form "Ljava/lang/String;"
d7180c
@@ -1892,19 +1952,30 @@ static void JNICALL callback_on_exception(
d7180c
                 jthrowable_circular_buf_push(threads_exc_buf, exception_object);
d7180c
             }
d7180c
 
d7180c
-            log_print("%s %s exception in thread \"%s\" ", (catch_method == NULL ? "Uncaught" : "Caught"), updated_exception_name_ptr, tname);
d7180c
-            log_print("in a method %s%s() with signature %s\n", class_name_ptr, method_name_ptr, method_signature_ptr);
d7180c
+            /* Remove trailing '.' */
d7180c
+            const ssize_t class_name_len = strlen(class_name_ptr);
d7180c
+            if (class_name_len > 0)
d7180c
+                class_name_ptr[class_name_len - 1] = '\0';
d7180c
+
d7180c
+            char *message = format_exception_reason_message(/*caught?*/NULL != catch_method,
d7180c
+                    updated_exception_name_ptr, class_name_ptr, method_name_ptr);
d7180c
 
d7180c
-            //char *stack_trace_str = generate_stack_trace(jvmti_env, jni_env, thr, tname, updated_exception_name_ptr);
d7180c
-            char *stack_trace_str = generate_thread_stack_trace(jvmti_env, jni_env, tname, exception_object);
d7180c
-            if (NULL != stack_trace_str)
d7180c
+            if (NULL != message)
d7180c
             {
d7180c
-                log_print("%s", stack_trace_str);
d7180c
-                if (NULL != threads_exc_buf)
d7180c
+                log_print("%s\n", message);
d7180c
+
d7180c
+                //char *stack_trace_str = generate_stack_trace(jvmti_env, jni_env, thr, tname, updated_exception_name_ptr);
d7180c
+                char *stack_trace_str = generate_thread_stack_trace(jvmti_env, jni_env, tname, exception_object);
d7180c
+                if (NULL != stack_trace_str)
d7180c
                 {
d7180c
-                    register_abrt_event(processProperties.main_class, (catch_method == NULL ? "Uncaught exception" : "Caught exception"), (unsigned char *)method_name_ptr, stack_trace_str);
d7180c
+                    log_print("%s", stack_trace_str);
d7180c
+                    if (NULL != threads_exc_buf)
d7180c
+                    {
d7180c
+                        register_abrt_event(processProperties.main_class, message, stack_trace_str);
d7180c
+                    }
d7180c
+                    free(stack_trace_str);
d7180c
                 }
d7180c
-                free(stack_trace_str);
d7180c
+                free(message);
d7180c
             }
d7180c
         }
d7180c
         else
d7180c
-- 
d7180c
1.8.3.1
d7180c