summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordnovotny <danny@rawhide.localdomain>2009-10-13 05:13:40 -0400
committerdnovotny <danny@rawhide.localdomain>2009-10-13 05:13:40 -0400
commita5bece25051e1d584b27b88d1d11d3c31dab8c32 (patch)
treeeccf0afeead85c9ec6daceb9554be0a804b91195 /lib
parent98f5de8526c51d8ba8495351837b6ef5822860ad (diff)
downloadabrt-a5bece25051e1d584b27b88d1d11d3c31dab8c32.tar.gz
abrt-a5bece25051e1d584b27b88d1d11d3c31dab8c32.tar.xz
abrt-a5bece25051e1d584b27b88d1d11d3c31dab8c32.zip
added backtrace rating
Diffstat (limited to 'lib')
-rw-r--r--lib/Plugins/CCpp.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp
index 0e0eb3b3..88634dc8 100644
--- a/lib/Plugins/CCpp.cpp
+++ b/lib/Plugins/CCpp.cpp
@@ -156,6 +156,90 @@ static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput)
return 0;
}
+enum LineRating
+{
+ /* RATING -- EXAMPLE */
+ MissingEverything = 0, // #0 0x0000dead in ?? ()
+ MissingFunction = 1, // #0 0x0000dead in ?? () from /usr/lib/libfoobar.so.4
+ MissingLibrary = 2, // #0 0x0000dead in foobar()
+ MissingSourceFile = 3, // #0 0x0000dead in FooBar::FooBar () from /usr/lib/libfoobar.so.4
+ Good = 4, // #0 0x0000dead in FooBar::crash (this=0x0) at /home/user/foobar.cpp:204
+ InvalidRating = -1 // (dummy invalid value)
+};
+
+static const LineRating BestRating = Good;
+
+LineRating rate_line(std::string line)
+{
+ bool function = false;
+ bool library = false;
+ bool source_file = false;
+
+#define FOUND(x) (line.find(x) != std::string::npos)
+ if (FOUND(" in ") && !FOUND(" in ??"))
+ function = true;
+
+ if (FOUND(" from "))
+ library = true;
+
+ if(FOUND(" at "))
+ source_file = true;
+#undef FOUND
+
+ /* see the "enum LineRating" comments for possible combinations */
+ if (function && source_file)
+ return Good;
+ if (function && library)
+ return MissingSourceFile;
+ if (function)
+ return MissingLibrary;
+ if (library)
+ return MissingFunction;
+
+ return MissingEverything;
+}
+
+/* returns number of "stars" to show*/
+int rate_backtrace(std::string backtrace)
+{
+ backtrace="#"+backtrace; /*line termination condition*/
+ int l = backtrace.length();
+ int i;
+ std::string s = "";
+ int multiplier = 0;
+ int rating = 0;
+ int best_possible_rating = 0;
+
+ /*we get the lines from the end, b/c of the rating multiplier
+ which gives weight to the first lines*/
+ for (i=l-1; i>=0; i--)
+ {
+ if (backtrace[i] == '#') /*this divides frames from each other*/
+ {
+ multiplier++;
+ rating += rate_line(s) * multiplier;
+ best_possible_rating += BestRating * multiplier;
+
+ s = ""; /*starting new line*/
+ } else
+ {
+ s=backtrace[i]+s;
+ }
+ }
+
+ /*returning number of "stars" to show*/
+ if (rating >= best_possible_rating*0.8)
+ return 4;
+ if (rating >= best_possible_rating*0.6)
+ return 3;
+ if (rating >= best_possible_rating*0.4)
+ return 2;
+ if (rating >= best_possible_rating*0.2)
+ return 1;
+
+ return 0;
+}
+
static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace)
{
update_client(_("Getting backtrace..."));