From: Ted Kremenek Date: Thu, 7 Jan 2010 23:13:53 +0000 (+0000) Subject: More crashtracer enhancements to CIndex. When "popping" a crashtracer string X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=254ba7cd3bc1b172c3f3c2b941aaae8335c25f85;p=clang More crashtracer enhancements to CIndex. When "popping" a crashtracer string restore to the one most recently created. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92959 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp index 1bda65f8e6..28a86e72be 100644 --- a/tools/CIndex/CIndex.cpp +++ b/tools/CIndex/CIndex.cpp @@ -38,19 +38,20 @@ using namespace idx; extern "C" const char *__crashreporter_info__; #define NUM_CRASH_STRINGS 16 static unsigned crashtracer_counter = 0; +static unsigned crashtracer_counter_id[NUM_CRASH_STRINGS] = { 0 }; static const char *crashtracer_strings[NUM_CRASH_STRINGS] = { 0 }; static const char *agg_crashtracer_strings[NUM_CRASH_STRINGS] = { 0 }; static unsigned SetCrashTracerInfo(const char *str, llvm::SmallString<1024> &AggStr) { - unsigned slot = crashtracer_counter; + unsigned slot = 0; while (crashtracer_strings[slot]) { if (++slot == NUM_CRASH_STRINGS) slot = 0; } crashtracer_strings[slot] = str; - crashtracer_counter = slot; + crashtracer_counter_id[slot] = ++crashtracer_counter; // We need to create an aggregate string because multiple threads // may be in this method at one time. The crash reporter string @@ -67,14 +68,19 @@ static unsigned SetCrashTracerInfo(const char *str, } static void ResetCrashTracerInfo(unsigned slot) { - agg_crashtracer_strings[slot] = crashtracer_strings[slot] = 0; - for (unsigned i = 0 ; i < NUM_CRASH_STRINGS; ++i) { - if (agg_crashtracer_strings[i]) { - __crashreporter_info__ = agg_crashtracer_strings[i]; - return; + unsigned max_slot = 0; + unsigned max_value = 0; + + crashtracer_strings[slot] = agg_crashtracer_strings[slot] = 0; + + for (unsigned i = 0 ; i < NUM_CRASH_STRINGS; ++i) + if (agg_crashtracer_strings[i] && + crashtracer_counter_id[i] > max_value) { + max_slot = i; + max_value = crashtracer_counter_id[i]; } - } - __crashreporter_info__ = 0; + + __crashreporter_info__ = agg_crashtracer_strings[max_slot]; } namespace {