From a5bece25051e1d584b27b88d1d11d3c31dab8c32 Mon Sep 17 00:00:00 2001 From: dnovotny Date: Tue, 13 Oct 2009 05:13:40 -0400 Subject: added backtrace rating --- lib/Plugins/CCpp.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 0e0eb3b..88634dc 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...")); -- cgit From 828288e948ccc6c5c1525eaf44bc8cb83960e9f1 Mon Sep 17 00:00:00 2001 From: dnovotny Date: Tue, 13 Oct 2009 05:25:11 -0400 Subject: a little change --- lib/Plugins/CCpp.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 88634dc..f79877e 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -202,7 +202,6 @@ LineRating rate_line(std::string line) /* 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 = ""; -- cgit From c87548afdde1d0c4e8b2b70fb69327f62bcfd31d Mon Sep 17 00:00:00 2001 From: dnovotny Date: Tue, 13 Oct 2009 05:36:40 -0400 Subject: parameters passed as const string & --- lib/Plugins/CCpp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index f79877e..c1725fc 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -169,7 +169,7 @@ enum LineRating static const LineRating BestRating = Good; -LineRating rate_line(std::string line) +LineRating rate_line(const std::string & line) { bool function = false; bool library = false; @@ -200,7 +200,7 @@ LineRating rate_line(std::string line) } /* returns number of "stars" to show*/ -int rate_backtrace(std::string backtrace) +int rate_backtrace(const std::string & backtrace) { int l = backtrace.length(); int i; -- cgit From 6df7d19ab1b6681f89a0ba5bc2771acaa4db5454 Mon Sep 17 00:00:00 2001 From: dnovotny Date: Tue, 13 Oct 2009 06:46:26 -0400 Subject: backtrace rating saved with crash data --- lib/Plugins/CCpp.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index c1725fc..133811f 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -227,6 +227,8 @@ int rate_backtrace(const std::string & backtrace) } /*returning number of "stars" to show*/ + if (rating==0) + return 0; if (rating >= best_possible_rating*0.8) return 4; if (rating >= best_possible_rating*0.6) @@ -837,6 +839,8 @@ log("BACKTRACE:'%s'", (build_ids + backtrace).c_str()); { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); } + std::string rating = ssprintf("%d\n", rate_backtrace(backtrace)); + dd.SaveText(FILENAME_RATING, rating); } void CAnalyzerCCpp::Init() -- cgit From 4144647a53c8338da2d958b78fb4b2e6096a3ea2 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 23 Oct 2009 15:29:53 +0200 Subject: removing forgotted debugging printout Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 133811f..a2cb86e 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -834,7 +834,6 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) dd.Open(pDebugDumpDir); dd.SaveText(FILENAME_BACKTRACE, build_ids + backtrace); -log("BACKTRACE:'%s'", (build_ids + backtrace).c_str()); if (m_bMemoryMap) { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); -- cgit From b2ef9492881a0713cb8856b146570b261f57689e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 23 Oct 2009 15:40:00 +0200 Subject: updates to abrt-debuginfo-install (but it is still ifdef'ed out) Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index a2cb86e..7d6708f 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -265,7 +265,7 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra // when/if gdb supports it: // (https://bugzilla.redhat.com/show_bug.cgi?id=528668): //args[2] = (char*)"-ex"; - //args[3] = "set debug-file-directory /usr/lib/debug/.build-id:/var/cache/abrt-di/usr/lib/debug/.build-id"; + //args[3] = "set debug-file-directory /usr/lib/debug:/var/cache/abrt-di/usr/lib/debug"; /* * Unfortunately, "file BINARY_FILE" doesn't work well if BINARY_FILE * was deleted (as often happens during system updates): @@ -656,23 +656,22 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui { update_client(_("Searching for debug-info packages...")); - int pipein[2], pipeout[2]; //TODO: get rid of pipein. Can we use ExecVP? - xpipe(pipein); + int pipeout[2]; //TODO: can we use ExecVP? xpipe(pipeout); pid_t child = fork(); if (child < 0) { - /*close(pipein[0]); close(pipeout[0]); - why bother */ - /*close(pipein[1]); close(pipeout[1]); */ + /*close(pipeout[0]); - why bother */ + /*close(pipeout[1]); */ perror_msg_and_die("fork"); } if (child == 0) { - close(pipein[1]); close(pipeout[0]); - xmove_fd(pipein[0], STDIN_FILENO); xmove_fd(pipeout[1], STDOUT_FILENO); + close(STDIN_FILENO); + xopen("/dev/null", O_RDONLY); /* Not a good idea, we won't see any error messages */ /*close(STDERR_FILENO);*/ @@ -686,7 +685,6 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui exit(1); } - close(pipein[0]); close(pipeout[1]); update_client(_("Downloading and installing debug-info packages...")); -- cgit From 04edbf21f65285ae4c7494262fb4620a1549678f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 29 Oct 2009 17:32:37 +0100 Subject: Enable new debuginfo downloading code Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 96 ++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 52 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 7d6708f..cb45a0f 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -156,34 +156,23 @@ static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) return 0; } -enum LineRating +enum LineRating { - /* RATING -- EXAMPLE */ + // RATING EXAMPLE MissingEverything = 0, // #0 0x0000dead in ?? () - MissingFunction = 1, // #0 0x0000dead in ?? () from /usr/lib/libfoobar.so.4 - MissingLibrary = 2, // #0 0x0000dead in foobar() + 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) + Good = 4, // #0 0x0000dead in FooBar::crash (this=0x0) at /home/user/foobar.cpp:204 + BestRating = Good, }; -static const LineRating BestRating = Good; - -LineRating rate_line(const std::string & line) +static LineRating rate_line(const 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; + bool function = FOUND(" in ") && !FOUND(" in ??"); + bool library = FOUND(" from "); + bool source_file = FOUND(" at "); #undef FOUND /* see the "enum LineRating" comments for possible combinations */ @@ -199,43 +188,43 @@ LineRating rate_line(const std::string & line) return MissingEverything; } -/* returns number of "stars" to show*/ +/* returns number of "stars" to show */ int rate_backtrace(const std::string & backtrace) { int l = backtrace.length(); int i; - std::string s = ""; + 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--) + /* We look at the frames in reversed order, since + * - rate_line() looks at the first line of the frame + * - we increase weight (multiplier) for every frame, + * so that topmost frames end up most important. + */ + for (i = l-1; i >= 0; i--) { - if (backtrace[i] == '#') /*this divides frames from each other*/ + if (backtrace[i] == '#') /* this separates frames from each other */ { - multiplier++; + multiplier++; rating += rate_line(s) * multiplier; best_possible_rating += BestRating * multiplier; - - s = ""; /*starting new line*/ + s = ""; /* starting new line */ } else { - s=backtrace[i]+s; + s = backtrace[i] + s; } } - /*returning number of "stars" to show*/ - if (rating==0) - return 0; - if (rating >= best_possible_rating*0.8) + /* returning number of "stars" to show */ + if (rating*10 >= best_possible_rating*8) /* >= 0.8 */ return 4; - if (rating >= best_possible_rating*0.6) + if (rating*10 >= best_possible_rating*6) return 3; - if (rating >= best_possible_rating*0.4) + if (rating*10 >= best_possible_rating*4) return 2; - if (rating >= best_possible_rating*0.2) + if (rating*10 >= best_possible_rating*2) return 1; return 0; @@ -259,13 +248,13 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra unsetenv("TERM"); putenv((char*)"TERM=dumb"); - char* args[9]; + char* args[11]; args[0] = (char*)"gdb"; args[1] = (char*)"-batch"; // when/if gdb supports it: // (https://bugzilla.redhat.com/show_bug.cgi?id=528668): - //args[2] = (char*)"-ex"; - //args[3] = "set debug-file-directory /usr/lib/debug:/var/cache/abrt-di/usr/lib/debug"; + args[2] = (char*)"-ex"; + args[3] = "set debug-file-directory /usr/lib/debug:" LOCALSTATEDIR"/cache/abrt-di/usr/lib/debug"; /* * Unfortunately, "file BINARY_FILE" doesn't work well if BINARY_FILE * was deleted (as often happens during system updates): @@ -273,18 +262,18 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra * even if it is completely unrelated to the coredump * See https://bugzilla.redhat.com/show_bug.cgi?id=525721 */ - args[2] = (char*)"-ex"; - args[3] = xasprintf("file %s", executable.c_str()); args[4] = (char*)"-ex"; - args[5] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + args[5] = xasprintf("file %s", executable.c_str()); args[6] = (char*)"-ex"; - args[7] = (char*)"thread apply all backtrace full"; - args[8] = NULL; + args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + args[8] = (char*)"-ex"; + args[9] = (char*)"thread apply all backtrace full"; + args[10] = NULL; ExecVP(args, atoi(UID.c_str()), pBacktrace); - free(args[3]); free(args[5]); + free(args[7]); } static std::string GetIndependentBacktrace(const std::string& pBacktrace) @@ -461,6 +450,8 @@ static std::string run_unstrip_n(const std::string& pDebugDumpDir) return output; } +#if 0 +/* older code */ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) { log("Getting module names, file names, build IDs from core file"); @@ -650,8 +641,10 @@ Another application is holding the yum lock, cannot continue fclose(pipeout_fp); wait(NULL); } -#if 0 -/* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668 */ +#endif +/* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668 + * It is slated to be in F12/RHEL6. + */ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) { update_client(_("Searching for debug-info packages...")); @@ -680,8 +673,8 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); char *tempdir = xasprintf("/tmp/abrt-%u-%lu", (int)getpid(), (long)time(NULL)); /* log() goes to stderr/syslog, it's ok to use it here */ - VERB1 log("Executing: %s %s %s %s", "abrt-debuginfo-install", coredump, tempdir, "/var/cache/abrt-di"); - execlp("abrt-debuginfo-install", "abrt-debuginfo-install", coredump, tempdir, "/var/cache/abrt-di", NULL); + VERB1 log("Executing: %s %s %s %s", "abrt-debuginfo-install", coredump, tempdir, LOCALSTATEDIR"/cache/abrt-di"); + execlp("abrt-debuginfo-install", "abrt-debuginfo-install", coredump, tempdir, LOCALSTATEDIR"/cache/abrt-di", NULL); exit(1); } @@ -726,7 +719,6 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui fclose(pipeout_fp); wait(NULL); } -#endif std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) { -- cgit From 32036431d394cd8b1ff62046bd323ba794fb3cbe Mon Sep 17 00:00:00 2001 From: Jiri Moskovcak Date: Thu, 29 Oct 2009 22:12:58 +0100 Subject: CCpp: added missing Close() --- lib/Plugins/CCpp.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index cb45a0f..89e9c5c 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -830,6 +830,7 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) } std::string rating = ssprintf("%d\n", rate_backtrace(backtrace)); dd.SaveText(FILENAME_RATING, rating); + dd.Close(); } void CAnalyzerCCpp::Init() -- cgit From 995bb1352eb5a461047d0acfc5f9648270c9b446 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 13:22:56 +0100 Subject: Bugzilla: simplify; CCpp, DebugDump: don't add EOL to one-line data files Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 89e9c5c..4eacdd2 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -828,7 +828,7 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); } - std::string rating = ssprintf("%d\n", rate_backtrace(backtrace)); + std::string rating = ssprintf("%d", rate_backtrace(backtrace)); dd.SaveText(FILENAME_RATING, rating); dd.Close(); } -- cgit From 174bd9604471cc5b5ef940457b11fe0adcc39739 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 30 Oct 2009 14:41:34 +0100 Subject: lib/Plugins/CCpp: use /var/run instead of /tmp for tempdir Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 4eacdd2..23bd9db 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -671,7 +671,8 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui setsid(); char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); - char *tempdir = xasprintf("/tmp/abrt-%u-%lu", (int)getpid(), (long)time(NULL)); + /* SELinux guys are not happy with /tmp, using /var/run/abrt */ + char *tempdir = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%u-%lu", (int)getpid(), (long)time(NULL)); /* log() goes to stderr/syslog, it's ok to use it here */ VERB1 log("Executing: %s %s %s %s", "abrt-debuginfo-install", coredump, tempdir, LOCALSTATEDIR"/cache/abrt-di"); execlp("abrt-debuginfo-install", "abrt-debuginfo-install", coredump, tempdir, LOCALSTATEDIR"/cache/abrt-di", NULL); -- cgit From bc2da7891acc79a77de00e89f2fe39660dee228e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 31 Oct 2009 02:26:59 +0100 Subject: implement abrtd -t TIMEOUT_IN_SEC Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 23bd9db..849e169 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -44,17 +44,6 @@ CAnalyzerCCpp::CAnalyzerCCpp() : m_bMemoryMap(false), m_bInstallDebuginfo(true) {} -static bool is_hexstr(const char* str) -{ - while (*str) - { - if (!isxdigit(*str)) - return false; - str++; - } - return true; -} - static std::string CreateHash(const std::string& pInput) { std::string ret = ""; @@ -452,6 +441,16 @@ static std::string run_unstrip_n(const std::string& pDebugDumpDir) #if 0 /* older code */ +static bool is_hexstr(const char* str) +{ + while (*str) + { + if (!isxdigit(*str)) + return false; + str++; + } + return true; +} static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) { log("Getting module names, file names, build IDs from core file"); -- cgit From 7a354715cc5b0ef711003b7c9f3a6f806dcaa2f1 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 1 Nov 2009 22:58:22 +0100 Subject: CCpp.conf: add DebugInfoCacheMB option (ignored for now) Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 849e169..1d5b79d 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -41,7 +41,9 @@ #define FILENAME_MEMORYMAP "memorymap" CAnalyzerCCpp::CAnalyzerCCpp() : - m_bMemoryMap(false), m_bInstallDebuginfo(true) + m_bMemoryMap(false), + m_bInstallDebuginfo(true), + m_nDebugInfoCacheMB(4000) {} static std::string CreateHash(const std::string& pInput) @@ -243,7 +245,7 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra // when/if gdb supports it: // (https://bugzilla.redhat.com/show_bug.cgi?id=528668): args[2] = (char*)"-ex"; - args[3] = "set debug-file-directory /usr/lib/debug:" LOCALSTATEDIR"/cache/abrt-di/usr/lib/debug"; + args[3] = (char*)"set debug-file-directory /usr/lib/debug:" LOCALSTATEDIR"/cache/abrt-di/usr/lib/debug"; /* * Unfortunately, "file BINARY_FILE" doesn't work well if BINARY_FILE * was deleted (as often happens during system updates): @@ -720,6 +722,11 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui wait(NULL); } +static void trim_debuginfo_cache(unsigned max_mb) +{ + // TODO +} + std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) { log(_("Getting local universal unique identification...")); @@ -809,10 +816,9 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) dd.Close(); /* do not keep dir locked longer than needed */ std::string build_ids; - map_plugin_settings_t settings = GetSettings(); - if (settings["InstallDebuginfo"] == "yes" && - DebuginfoCheckPolkit(atoi(UID.c_str())) ) - { + if (m_bInstallDebuginfo && DebuginfoCheckPolkit(atoi(UID.c_str()))) { + if (m_nDebugInfoCacheMB > 0) + trim_debuginfo_cache(m_nDebugInfoCacheMB); InstallDebugInfos(pDebugDumpDir, build_ids); } else @@ -883,7 +889,8 @@ void CAnalyzerCCpp::DeInit() void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) { map_plugin_settings_t::const_iterator end = pSettings.end(); - map_plugin_settings_t::const_iterator it = pSettings.find("MemoryMap"); + map_plugin_settings_t::const_iterator it; + it = pSettings.find("MemoryMap"); if (it != end) { m_bMemoryMap = it->second == "yes"; @@ -893,6 +900,11 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) { m_sDebugInfo = it->second; } + it = pSettings.find("DebugInfoCacheMB"); + if (it != end) + { + m_nDebugInfoCacheMB = atoi(it->second.c_str()); + } it = pSettings.find("InstallDebuginfo"); if (it != end) { @@ -906,6 +918,7 @@ map_plugin_settings_t CAnalyzerCCpp::GetSettings() ret["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; ret["DebugInfo"] = m_sDebugInfo; + ret["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); ret["InstallDebuginfo"] = m_bInstallDebuginfo ? "yes" : "no"; return ret; -- cgit From 68e616def90ece3bdde925dc106e51e8560fa05d Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 2 Nov 2009 11:58:01 +0100 Subject: lib/Plugins/CCpp: respect DebugInfoCacheMB setting Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 11 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 1d5b79d..2fc8f0a 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -33,16 +33,18 @@ #include "CommLayerInner.h" #include "Polkit.h" -#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" -#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u" +#define CORE_PATTERN_IFACE "/proc/sys/kernel/core_pattern" +#define CORE_PATTERN "|"CCPP_HOOK_PATH" "DEBUG_DUMPS_DIR" %p %s %u" #define FILENAME_COREDUMP "coredump" #define FILENAME_BACKTRACE "backtrace" #define FILENAME_MEMORYMAP "memorymap" +#define DEBUGINFO_CACHE_DIR LOCALSTATEDIR"/cache/abrt-di" + CAnalyzerCCpp::CAnalyzerCCpp() : m_bMemoryMap(false), - m_bInstallDebuginfo(true), + m_bInstallDebugInfo(true), m_nDebugInfoCacheMB(4000) {} @@ -245,7 +247,7 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra // when/if gdb supports it: // (https://bugzilla.redhat.com/show_bug.cgi?id=528668): args[2] = (char*)"-ex"; - args[3] = (char*)"set debug-file-directory /usr/lib/debug:" LOCALSTATEDIR"/cache/abrt-di/usr/lib/debug"; + args[3] = (char*)"set debug-file-directory /usr/lib/debug:" DEBUGINFO_CACHE_DIR"/usr/lib/debug"; /* * Unfortunately, "file BINARY_FILE" doesn't work well if BINARY_FILE * was deleted (as often happens during system updates): @@ -675,8 +677,8 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui /* SELinux guys are not happy with /tmp, using /var/run/abrt */ char *tempdir = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%u-%lu", (int)getpid(), (long)time(NULL)); /* log() goes to stderr/syslog, it's ok to use it here */ - VERB1 log("Executing: %s %s %s %s", "abrt-debuginfo-install", coredump, tempdir, LOCALSTATEDIR"/cache/abrt-di"); - execlp("abrt-debuginfo-install", "abrt-debuginfo-install", coredump, tempdir, LOCALSTATEDIR"/cache/abrt-di", NULL); + VERB1 log("Executing: %s %s %s %s", "abrt-debuginfo-install", coredump, tempdir, DEBUGINFO_CACHE_DIR); + execlp("abrt-debuginfo-install", "abrt-debuginfo-install", coredump, tempdir, DEBUGINFO_CACHE_DIR, NULL); exit(1); } @@ -722,9 +724,67 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui wait(NULL); } +static double get_dir_size(const char *dirname, std::string *worst_file, double *maxsz) +{ + DIR *dp = opendir(dirname); + if (dp == NULL) + return 0; + + struct dirent *ep; + struct stat stats; + double size = 0; + while ((ep = readdir(dp)) != NULL) + { + if (dot_or_dotdot(ep->d_name)) + continue; + std::string dname = concat_path_file(dirname, ep->d_name); + if (lstat(dname.c_str(), &stats) != 0) + continue; + if (S_ISDIR(stats.st_mode)) + { + double sz = get_dir_size(dname.c_str(), worst_file, maxsz); + size += sz; + } + else if (S_ISREG(stats.st_mode)) + { + double sz = stats.st_size; + size += sz; + + if (worst_file) + { + /* Calculate "weighted" size and age + * w = sz_kbytes * age_mins */ + sz /= 1024; + long age = (time(NULL) - stats.st_mtime) / 60; + if (age > 0) + sz *= age; + + if (sz > *maxsz) + { + *maxsz = sz; + *worst_file = dname; + } + } + } + } + closedir(dp); + return size; +} + static void trim_debuginfo_cache(unsigned max_mb) { - // TODO + while (1) + { + std::string worst_file; + double maxsz = 0; + double cache_sz = get_dir_size(DEBUGINFO_CACHE_DIR, &worst_file, &maxsz); + if (cache_sz / (1024 * 1024) < max_mb) + break; + VERB1 log("%s is %.0f bytes (over %u MB), deleting '%s'", + DEBUGINFO_CACHE_DIR, cache_sz, max_mb, worst_file.c_str()); + if (unlink(worst_file.c_str()) != 0) + perror_msg("Can't unlink '%s'"); + } } std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) @@ -816,7 +876,7 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) dd.Close(); /* do not keep dir locked longer than needed */ std::string build_ids; - if (m_bInstallDebuginfo && DebuginfoCheckPolkit(atoi(UID.c_str()))) { + if (m_bInstallDebugInfo && DebuginfoCheckPolkit(atoi(UID.c_str()))) { if (m_nDebugInfoCacheMB > 0) trim_debuginfo_cache(m_nDebugInfoCacheMB); InstallDebugInfos(pDebugDumpDir, build_ids); @@ -905,10 +965,12 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) { m_nDebugInfoCacheMB = atoi(it->second.c_str()); } - it = pSettings.find("InstallDebuginfo"); + it = pSettings.find("InstallDebugInfo"); + if (it == end) //compat, remove after 0.0.11 + it = pSettings.find("InstallDebuginfo"); if (it != end) { - m_bInstallDebuginfo = it->second == "yes"; + m_bInstallDebugInfo = it->second == "yes"; } } @@ -919,7 +981,7 @@ map_plugin_settings_t CAnalyzerCCpp::GetSettings() ret["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; ret["DebugInfo"] = m_sDebugInfo; ret["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); - ret["InstallDebuginfo"] = m_bInstallDebuginfo ? "yes" : "no"; + ret["InstallDebugInfo"] = m_bInstallDebugInfo ? "yes" : "no"; return ret; } -- cgit From 131bb65c9de5543f6458ec7e5ab8af40466b2753 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 3 Nov 2009 18:06:59 +0100 Subject: lib/Plugins/CCpp.cpp: fix "too few arguments for format" Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 2fc8f0a..8362216 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -783,7 +783,7 @@ static void trim_debuginfo_cache(unsigned max_mb) VERB1 log("%s is %.0f bytes (over %u MB), deleting '%s'", DEBUGINFO_CACHE_DIR, cache_sz, max_mb, worst_file.c_str()); if (unlink(worst_file.c_str()) != 0) - perror_msg("Can't unlink '%s'"); + perror_msg("Can't unlink '%s'", worst_file.c_str()); } } -- cgit From 64c5d35aebc38f93ce5c086c15c15de5acb21b2f Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 5 Nov 2009 17:21:11 +0100 Subject: InformAllUsers support. enabled by default for Kerneloops. Tested wuth CCpp. Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 8362216..8a86e14 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -948,6 +948,8 @@ void CAnalyzerCCpp::DeInit() void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) { + m_pSettings = pSettings; + map_plugin_settings_t::const_iterator end = pSettings.end(); map_plugin_settings_t::const_iterator it; it = pSettings.find("MemoryMap"); @@ -976,7 +978,7 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) map_plugin_settings_t CAnalyzerCCpp::GetSettings() { - map_plugin_settings_t ret; + map_plugin_settings_t ret = m_pSettings; ret["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; ret["DebugInfo"] = m_sDebugInfo; -- cgit From c8e9e69f96c2bd0b9248d6dfab91e2d27ab8e608 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 12:41:24 +0100 Subject: mass replace of const string& params by const char* Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 8a86e14..3a3604b 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -223,7 +223,7 @@ int rate_backtrace(const std::string & backtrace) return 0; } -static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktrace) +static void GetBacktrace(const char *pDebugDumpDir, std::string& pBacktrace) { update_client(_("Getting backtrace...")); @@ -258,7 +258,7 @@ static void GetBacktrace(const std::string& pDebugDumpDir, std::string& pBacktra args[4] = (char*)"-ex"; args[5] = xasprintf("file %s", executable.c_str()); args[6] = (char*)"-ex"; - args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + args[7] = xasprintf("core-file %s/"FILENAME_COREDUMP, pDebugDumpDir); args[8] = (char*)"-ex"; args[9] = (char*)"thread apply all backtrace full"; args[10] = NULL; @@ -420,7 +420,7 @@ static void GetIndependentBuildIdPC(const std::string& pBuildIdPC, std::string& } } -static std::string run_unstrip_n(const std::string& pDebugDumpDir) +static std::string run_unstrip_n(const char *pDebugDumpDir) { std::string UID; { @@ -431,7 +431,7 @@ static std::string run_unstrip_n(const std::string& pDebugDumpDir) char* args[4]; args[0] = (char*)"eu-unstrip"; - args[1] = xasprintf("--core=%s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + args[1] = xasprintf("--core=%s/"FILENAME_COREDUMP, pDebugDumpDir); args[2] = (char*)"-n"; args[3] = NULL; @@ -455,7 +455,7 @@ static bool is_hexstr(const char* str) } return true; } -static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) +static void InstallDebugInfos(const char *pDebugDumpDir, std::string& build_ids) { log("Getting module names, file names, build IDs from core file"); std::string unstrip_list = run_unstrip_n(pDebugDumpDir); @@ -648,7 +648,7 @@ Another application is holding the yum lock, cannot continue /* Needs gdb feature from here: https://bugzilla.redhat.com/show_bug.cgi?id=528668 * It is slated to be in F12/RHEL6. */ -static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& build_ids) +static void InstallDebugInfos(const char *pDebugDumpDir, std::string& build_ids) { update_client(_("Searching for debug-info packages...")); @@ -673,7 +673,7 @@ static void InstallDebugInfos(const std::string& pDebugDumpDir, std::string& bui setsid(); - char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir.c_str()); + char *coredump = xasprintf("%s/"FILENAME_COREDUMP, pDebugDumpDir); /* SELinux guys are not happy with /tmp, using /var/run/abrt */ char *tempdir = xasprintf(LOCALSTATEDIR"/run/abrt/tmp-%u-%lu", (int)getpid(), (long)time(NULL)); /* log() goes to stderr/syslog, it's ok to use it here */ @@ -787,7 +787,7 @@ static void trim_debuginfo_cache(unsigned max_mb) } } -std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerCCpp::GetLocalUUID(const char *pDebugDumpDir) { log(_("Getting local universal unique identification...")); @@ -806,7 +806,7 @@ std::string CAnalyzerCCpp::GetLocalUUID(const std::string& pDebugDumpDir) return CreateHash(package + executable + independentBuildIdPC); } -std::string CAnalyzerCCpp::GetGlobalUUID(const std::string& pDebugDumpDir) +std::string CAnalyzerCCpp::GetGlobalUUID(const char *pDebugDumpDir) { log(_("Getting global universal unique identification...")); @@ -851,7 +851,7 @@ static bool DebuginfoCheckPolkit(int uid) return false; } -void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) +void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) { update_client(_("Starting report creation...")); @@ -889,13 +889,12 @@ void CAnalyzerCCpp::CreateReport(const std::string& pDebugDumpDir, int force) GetBacktrace(pDebugDumpDir, backtrace); dd.Open(pDebugDumpDir); - dd.SaveText(FILENAME_BACKTRACE, build_ids + backtrace); + dd.SaveText(FILENAME_BACKTRACE, (build_ids + backtrace).c_str()); if (m_bMemoryMap) { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); } - std::string rating = ssprintf("%d", rate_backtrace(backtrace)); - dd.SaveText(FILENAME_RATING, rating); + dd.SaveText(FILENAME_RATING, to_string(rate_backtrace(backtrace)).c_str()); dd.Close(); } -- cgit From 80975b02ec1a2e8dfc6f7ce21e47cf71b16b5a6e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 14:52:32 +0100 Subject: lib/Plugins/FileTransfer: massive surgery text data bss dec hex filename 50212 2144 16 52372 cc94 0/libTicketUploader.so 34693 1888 24 36605 8efd 1/libTicketUploader.so Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 3a3604b..a2d65f3 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -95,7 +95,6 @@ static std::string concat_str_vector(char **strings) static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) { int pipeout[2]; - char buff[1024]; pid_t child; struct passwd* pw = getpwuid(uid); @@ -137,6 +136,7 @@ static pid_t ExecVP(char** pArgs, uid_t uid, std::string& pOutput) close(pipeout[1]); /* write side of the pipe */ int r; + char buff[1024]; while ((r = read(pipeout[0], buff, sizeof(buff) - 1)) > 0) { buff[r] = '\0'; -- cgit From 1202706839ec42299e8794750cec66dfa7db0206 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 17:51:17 +0100 Subject: simplify logging a bit. warn_client() is gone, reuse error_msg() for it. Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index a2d65f3..b6a5db8 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -610,8 +610,8 @@ Another application is holding the yum lock, cannot continue if (last >= 0 && buff[last] == '\n') buff[last] = '\0'; - /* log(buff); - update_client logs it too */ - update_client(buff); /* maybe only if buff != ""? */ + log("%s", buff); + update_client("%s", buff); /* maybe only if buff != ""? */ #ifdef COMPLAIN_IF_NO_DEBUGINFO if (already_installed == false) @@ -715,8 +715,8 @@ static void InstallDebugInfos(const char *pDebugDumpDir, std::string& build_ids) } if (*p) { - /* log(buff); - update_client logs it too */ - update_client(buff); + log("%s", buff); + update_client("%s", buff); } } -- cgit From 57039b590e4411606795893c90f9871e0412ca31 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 6 Nov 2009 18:26:42 +0100 Subject: give Plugin class a map_plugin_settings_t member This simplifies and unifies get/set settings ops Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index b6a5db8..4b73938 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -975,16 +975,14 @@ void CAnalyzerCCpp::SetSettings(const map_plugin_settings_t& pSettings) } } -map_plugin_settings_t CAnalyzerCCpp::GetSettings() +const map_plugin_settings_t& CAnalyzerCCpp::GetSettings() { - map_plugin_settings_t ret = m_pSettings; + m_pSettings["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; + m_pSettings["DebugInfo"] = m_sDebugInfo; + m_pSettings["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); + m_pSettings["InstallDebugInfo"] = m_bInstallDebugInfo ? "yes" : "no"; - ret["MemoryMap"] = m_bMemoryMap ? "yes" : "no"; - ret["DebugInfo"] = m_sDebugInfo; - ret["DebugInfoCacheMB"] = to_string(m_nDebugInfoCacheMB); - ret["InstallDebugInfo"] = m_bInstallDebugInfo ? "yes" : "no"; - - return ret; + return m_pSettings; } PLUGIN_INFO(ANALYZER, -- cgit From b5cbb9b03aeab5fd452f0014474163864f2d0c10 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 9 Nov 2009 12:37:19 +0100 Subject: reinstate code which returns rating 0 on empty backtraces Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index 4b73938..bc10f11 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -210,7 +210,11 @@ int rate_backtrace(const std::string & backtrace) } } - /* returning number of "stars" to show */ + /* Bogus "backtrace" with zero frames? */ + if (best_possible_rating == 0) + return 0; + + /* Returning number of "stars" to show */ if (rating*10 >= best_possible_rating*8) /* >= 0.8 */ return 4; if (rating*10 >= best_possible_rating*6) -- cgit From ff0d8ed597eeaf8d80238ace1b26b65b43495e26 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 9 Nov 2009 13:05:02 +0100 Subject: lib/Plugins/CCpp: simpler rating code (do not painfully concatenate byte-by-byte) Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 55 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index bc10f11..e06d9bc 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -160,17 +160,25 @@ enum LineRating BestRating = Good, }; -static LineRating rate_line(const std::string & line) +static LineRating rate_line(const char *line) { -#define FOUND(x) (line.find(x) != std::string::npos) - bool function = FOUND(" in ") && !FOUND(" in ??"); - bool library = FOUND(" from "); - bool source_file = FOUND(" at "); -#undef FOUND - +#define FOUND(x) (strstr(line, x) != NULL) /* see the "enum LineRating" comments for possible combinations */ - if (function && source_file) - return Good; + const char *function = strstr(line, " in "); + if (function) + { + if (function[4] == '?') /* " in ??" does not count */ + { + function = NULL; + } + else + { + bool source_file = FOUND(" at "); + if (source_file) + return Good; + } + } + bool library = FOUND(" from "); if (function && library) return MissingSourceFile; if (function) @@ -179,34 +187,37 @@ static LineRating rate_line(const std::string & line) return MissingFunction; return MissingEverything; +#undef FOUND } /* returns number of "stars" to show */ -int rate_backtrace(const std::string & backtrace) +static int rate_backtrace(const char *backtrace) { - int l = backtrace.length(); - int i; - std::string s; + int i, len; int multiplier = 0; int rating = 0; int best_possible_rating = 0; - /* We look at the frames in reversed order, since - * - rate_line() looks at the first line of the frame + /* We look at the frames in reversed order, since: + * - rate_line() checks starting from the first line of the frame + * (note: it may need to look at more than one line!) * - we increase weight (multiplier) for every frame, - * so that topmost frames end up most important. + * so that topmost frames end up most important */ - for (i = l-1; i >= 0; i--) + len = 0; + for (i = strlen(backtrace) - 1; i >= 0; i--) { if (backtrace[i] == '#') /* this separates frames from each other */ { + std::string s(backtrace + 1, len); multiplier++; - rating += rate_line(s) * multiplier; + rating += rate_line(s.c_str()) * multiplier; best_possible_rating += BestRating * multiplier; - s = ""; /* starting new line */ - } else + len = 0; /* starting new line */ + } + else { - s = backtrace[i] + s; + len++; } } @@ -898,7 +909,7 @@ void CAnalyzerCCpp::CreateReport(const char *pDebugDumpDir, int force) { dd.SaveText(FILENAME_MEMORYMAP, "memory map of the crashed C/C++ application, not implemented yet"); } - dd.SaveText(FILENAME_RATING, to_string(rate_backtrace(backtrace)).c_str()); + dd.SaveText(FILENAME_RATING, to_string(rate_backtrace(backtrace.c_str())).c_str()); dd.Close(); } -- cgit From a5e45d3eea8a239c71da8ff871952d3e80030902 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 9 Nov 2009 13:42:44 +0100 Subject: fix my thinko in rate code. run tested Signed-off-by: Denys Vlasenko --- lib/Plugins/CCpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Plugins/CCpp.cpp') diff --git a/lib/Plugins/CCpp.cpp b/lib/Plugins/CCpp.cpp index e06d9bc..6d6edd5 100644 --- a/lib/Plugins/CCpp.cpp +++ b/lib/Plugins/CCpp.cpp @@ -209,7 +209,7 @@ static int rate_backtrace(const char *backtrace) { if (backtrace[i] == '#') /* this separates frames from each other */ { - std::string s(backtrace + 1, len); + std::string s(backtrace + i + 1, len); multiplier++; rating += rate_line(s.c_str()) * multiplier; best_possible_rating += BestRating * multiplier; -- cgit