Skip to content
Snippets Groups Projects
Commit 9d5f962e authored by Pietro Incardona's avatar Pietro Incardona
Browse files

Adding print stack trace

parent b96708b8
No related branches found
No related tags found
No related merge requests found
...@@ -23,7 +23,7 @@ libofpmmemory_se2_a_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/i ...@@ -23,7 +23,7 @@ libofpmmemory_se2_a_CXXFLAGS = $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/i
libofpmmemory_se2_a_CFLAGS = libofpmmemory_se2_a_CFLAGS =
nobase_include_HEADERS = memory/ExtPreAlloc.hpp memory/BHeapMemory.hpp memory/HeapMemory.hpp memory/memory.hpp memory/PtrMemory.hpp \ nobase_include_HEADERS = memory/ExtPreAlloc.hpp memory/BHeapMemory.hpp memory/HeapMemory.hpp memory/memory.hpp memory/PtrMemory.hpp \
Memleak_check.hpp ptr_info.hpp \ Memleak_check.hpp util/print_stack.hpp ptr_info.hpp \
util/se_util.hpp util/se_util.hpp
.cu.o : .cu.o :
......
...@@ -61,15 +61,60 @@ static inline void print_stack() ...@@ -61,15 +61,60 @@ static inline void print_stack()
"in your code, follow from top to bottom the list of calls until you find " << "in your code, follow from top to bottom the list of calls until you find " <<
"a source code familiar to you.\033[0m" << std::endl; "a source code familiar to you.\033[0m" << std::endl;
for (int i = 0 ; i < ncall ; i++) std::string translators[]={"eu-addr2line","addr2line"};
{ std::string translator;
str << "STACK TRACE Address: " << trace[i] << " " << messages[i] << " source:";
for (size_t i = 0 ; i < sizeof(translators)/sizeof(std::string) ; i++)
{
// for for the best address to source code translator
char syscom[256]; char syscom[256];
sprintf(syscom,"addr2line %p -e %s", trace[i],program_name.c_str()); //last parameter is the name of this app sprintf(syscom,"%s --version",translators[i].c_str());
std::string ss = exec(syscom); std::string ss = exec(syscom);
str << std::endl << "\033[1;31m" << ss << "\033[0m"; size_t found = ss.find("command not found");
if (found == std::string::npos)
{
// command exist
translator = translators[i];
str << "Using translator: " << translator << std::endl;
break;
}
}
if (translator.size() == 0)
{
str << "In order to have a more detailed stack-trace with function name and precise location in the source code" <<
"Please install one of the following utils: ";
str << translators[0];
for (size_t i = 1 ; i < sizeof(translators)/sizeof(std::string) ; i++)
str << "," << translators[i];
}
for (int i = 0 ; i < ncall ; i++)
{
str << "\033[1m" << "CALL(" << i << ")" << "\033[0m" << " Address: " << trace[i] << " " << messages[i] << " ";
if (translator.size() != 0)
{
char syscom[256];
sprintf(syscom,"%s %p -f --demangle -e %s",translator.c_str(), trace[i],program_name.c_str()); //last parameter is the name of this app
std::string ss = exec(syscom);
std::stringstream sss(ss);
std::string sfunc;
std::string sloc;
std::getline(sss,sfunc,'\n');
std::getline(sss,sloc,'\n');
str << std::endl;
str << "\033[35m" << "Function:" << std::endl << sfunc << "\033[0m" << std::endl;
str << "\033[1;31m" << "Location:" << std::endl << sloc << "\033[0m" << std::endl;
}
else
{
str << std::endl;
}
} }
std::cerr << str.str() << std::endl; std::cerr << str.str() << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment