From dd552a10c8f326284c2178bd36ce6bccc2f4486c Mon Sep 17 00:00:00 2001 From: Rafal Crypto Tigusoft Date: Wed, 28 Jun 2017 11:06:17 +0000 Subject: [PATCH 1/3] fix off-by-one when resolve goes up to ip==0 frame --- backward.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backward.hpp b/backward.hpp index 06fe157..e2cf7e7 100644 --- a/backward.hpp +++ b/backward.hpp @@ -752,7 +752,16 @@ public: while (*funcname && *funcname != '(') { funcname += 1; } - trace.object_filename.assign(filename, funcname++); + trace.object_filename.assign(filename, funcname); // it is ok if funcname is the ending \0, then we select string till end + + if ( ! (*funcname) ) { // we already hit end of string. This happens for the last address 0xffff for ip==0 + trace.object_function = "(none)"; + trace.source.function = "(none)"; + return trace; + } + + // else normal string, we are at the opening '(' now + funcname++; char* funcname_end = funcname; while (*funcname_end && *funcname_end != ')' && *funcname_end != '+') { funcname_end += 1; From e1bf45fd0c336e76b82aa5ae66881aab9fd18aa6 Mon Sep 17 00:00:00 2001 From: Rafal Crypto Tigusoft Date: Thu, 29 Jun 2017 10:21:02 +0000 Subject: [PATCH 2/3] After review pr#66 --- backward.hpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/backward.hpp b/backward.hpp index e2cf7e7..d847012 100644 --- a/backward.hpp +++ b/backward.hpp @@ -752,23 +752,17 @@ public: while (*funcname && *funcname != '(') { funcname += 1; } - trace.object_filename.assign(filename, funcname); // it is ok if funcname is the ending \0, then we select string till end + trace.object_filename.assign(filename, funcname); // ok even if funcname is the ending \0 (then we assign entire string) - if ( ! (*funcname) ) { // we already hit end of string. This happens for the last address 0xffff for ip==0 - trace.object_function = "(none)"; - trace.source.function = "(none)"; - return trace; + if (*funcname) { // if it's not end of string (e.g. from last frame ip==0) + char* funcname_end = funcname + 1; + while (*funcname_end && *funcname_end != ')' && *funcname_end != '+') { + funcname_end += 1; + } + *funcname_end = '\0'; + trace.object_function = this->demangle(funcname); + trace.source.function = trace.object_function; // we cannot do better. } - - // else normal string, we are at the opening '(' now - funcname++; - char* funcname_end = funcname; - while (*funcname_end && *funcname_end != ')' && *funcname_end != '+') { - funcname_end += 1; - } - *funcname_end = '\0'; - trace.object_function = this->demangle(funcname); - trace.source.function = trace.object_function; // we cannot do better. return trace; } From 89b77f96b92cb808a9a52afd9138afccf93898d4 Mon Sep 17 00:00:00 2001 From: Rafal Crypto Tigusoft Date: Thu, 29 Jun 2017 14:33:54 +0000 Subject: [PATCH 3/3] Fix the ip==0 workaround to skip opening-parentheses --- backward.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backward.hpp b/backward.hpp index d847012..687434d 100644 --- a/backward.hpp +++ b/backward.hpp @@ -755,7 +755,8 @@ public: trace.object_filename.assign(filename, funcname); // ok even if funcname is the ending \0 (then we assign entire string) if (*funcname) { // if it's not end of string (e.g. from last frame ip==0) - char* funcname_end = funcname + 1; + funcname += 1; + char* funcname_end = funcname; while (*funcname_end && *funcname_end != ')' && *funcname_end != '+') { funcname_end += 1; }