From: Alexander Monakov Date: Sun, 19 May 2013 08:10:40 +0000 (+0400) Subject: Cleanup backtrace setup code X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=4b48cfa5d5aa7ea7ecb522071526e8de4a6cd1b5;p=apitrace Cleanup backtrace setup code Obtain the list of functions to backtrace from the environment on Android as well. --- diff --git a/common/trace_backtrace.cpp b/common/trace_backtrace.cpp index 730cfef..93991a9 100644 --- a/common/trace_backtrace.cpp +++ b/common/trace_backtrace.cpp @@ -65,8 +65,6 @@ struct pstring { }; -#define PREFIX_BUF_SIZE (PREFIX_MAX_FUNC_NAME * MAX_BT_FUNC) - class StringPrefixes { private: std::set pset; @@ -82,15 +80,33 @@ private: } } public: - StringPrefixes(const char* source); + StringPrefixes(); bool contain(const char* s) { return pset.find(pstring(s, strlen(s) + 1)) != pset.end(); } }; +StringPrefixes::StringPrefixes() { + char *list = getenv("APITRACE_BACKTRACE"); + if (!list) + return; + for (char *t = strdup(list); ; t = NULL) { + char *tok = strtok(t, " \t\r\n"); + if (!tok) + break; + if (tok[0] == '#') + continue; + if (tok[strlen(tok) - 1] == '*') + addPrefix(tok, strlen(tok) - 1); + else + addPrefix(tok, strlen(tok) + 1); + } +} + + bool backtrace_is_needed(const char* fname) { - static StringPrefixes backtraceFunctionNamePrefixes(APITRACE_FNAMES_SOURCE); + static StringPrefixes backtraceFunctionNamePrefixes; return backtraceFunctionNamePrefixes.contain(fname); } @@ -104,37 +120,6 @@ bool backtrace_is_needed(const char* fname) { namespace trace { -StringPrefixes::StringPrefixes(const char* source) { - char* buf = (char*)malloc(sizeof(char) * PREFIX_BUF_SIZE); - char* startbuf = buf; - int n = 0; - FILE* f = fopen(source, "r"); - if (f == NULL) { - os::log("Cannot open " APITRACE_FNAMES_FILE); - } - while ((startbuf = fgets(startbuf, PREFIX_MAX_FUNC_NAME, f))) { - n = strlen(startbuf); - if (startbuf[n - 1] == '\n') { - n--; - } - if (n > 2 && startbuf[0] != '#') { - int psize; - if (startbuf[n - 1] != '*') { - startbuf[n] = '\0'; - psize = n + 1; - } - else { - psize = n - 1; - } - addPrefix(startbuf, psize); - startbuf += n + 1; - n = 0; - } - } - fclose(f); -} - - /* The following two declarations are copied from Android sources */ enum DebugTargetKind { @@ -297,38 +282,6 @@ std::vector get_backtrace() { namespace trace { -StringPrefixes::StringPrefixes(const char* source) { - char* buf = (char*)malloc(sizeof(char) * PREFIX_BUF_SIZE); - char* startbuf = buf; - int n = 0; - char* s = getenv(source); - char end = ';'; - if (s == NULL) { - return; - } - *buf = ';'; - strncpy(buf + 1, s, PREFIX_BUF_SIZE - 2); - while (end != '\0') { - startbuf++; - while (*(startbuf + n) != ';' && *(startbuf + n) != '\0') { - n++; - } - end = startbuf[n]; - if (n > 2 && startbuf[0] != '#') { - int psize; - if (startbuf[n - 1] != '*') { - startbuf[n] = '\0'; - psize = n + 1; - } - else { - psize = n - 1; - } - addPrefix(startbuf, psize); - startbuf += n; - n = 0; - } - } -} #define BT_DEPTH 10 diff --git a/common/trace_backtrace.hpp b/common/trace_backtrace.hpp index de6f415..a8210d5 100644 --- a/common/trace_backtrace.hpp +++ b/common/trace_backtrace.hpp @@ -13,23 +13,7 @@ namespace trace { std::vector get_backtrace(); bool backtrace_is_needed(const char* fname); -#if defined(ANDROID) - -#define MAX_BT_FUNC 20 -#define PREFIX_MAX_FUNC_NAME 100 -#define APITRACE_FNAMES_FILE "/data/apitrace.fnames" -#define APITRACE_FNAMES_SOURCE APITRACE_FNAMES_FILE - -#elif defined(__linux__) - -#define MAX_BT_FUNC 20 -#define PREFIX_MAX_FUNC_NAME 100 -#define APITRACE_FNAMES_ENV "APITRACE_BT_FUNCTIONS" -#define APITRACE_FNAMES_SOURCE APITRACE_FNAMES_ENV - -#endif - -#else /* !__linux__ && !ANDROID */ +#else static inline std::vector get_backtrace() { return std::vector();