0

A mysterious function Function '_ZNSsaSERKSs' appears in my gcov report which i have absolutely no idea what it is , can someone can explain to me what is happening

Thanks

Header file

#ifndef CASHIER_H #define CASHIER_H #include <string> using namespace std; class cashier { public: void setID(string); string getID(); void setPassword(string); string getPassword(); void settries(int); int gettries(); void increase_tries(); private: string ID; string Password; int tries; }; #endif /* CASHIER_H */ 

Implementation file

#include "cashier.h" void cashier::setID(string value) { this->ID = value; } void cashier::setPassword(string value) { this->Password = value; } string cashier::getID() { return this->ID; } string cashier::getPassword() { return this->Password; } void cashier::settries(int value) { this->tries=value; } int cashier::gettries() { return this->tries; } void cashier::increase_tries() { this->tries = this->tries + 1 ; } 

I type in the following command

gcov -f cashier.gnco 

I got the following results B

Function '_ZN7cashier8settriesEi' Lines executed:100.00% of 3 Function '_ZN7cashier8gettriesEv' Lines executed:100.00% of 2 Function '_ZN7cashier14increase_triesEv' Lines executed:100.00% of 3 Function '_ZN7cashier11getPasswordEv' Lines executed:100.00% of 2 Function '_ZN7cashier5getIDEv' Lines executed:100.00% of 2 Function '_ZNSsaSERKSs' //mysterious function Lines executed:0.00% of 2 Function '_ZN7cashier11setPasswordESs' Lines executed:100.00% of 3 Function '_ZN7cashier5setIDESs' Lines executed:100.00% of 3 File 'cashier.cpp' Lines executed:100.00% of 18 cashier.cpp:creating 'cashier.cpp.gcov' File '/usr/include/c++/4.4/bits/basic_string.h' Lines executed:0.00% of 2 /usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov' File '/usr/include/c++/4.4/bits/basic_string.h' Lines executed:0.00% of 2 No branches Calls executed:0.00% of 1 /usr/include/c++/4.4/bits/basic_string.h:creating 'basic_string.h.gcov 

EDIT

1
  • c++filt is your friend. You have it in your gcc toolset. There's one online. Commented Jan 20, 2014 at 3:58

2 Answers 2

3

Using c++filt to demangle the name gives

std::string::operator=(std::string const&) 

the copy-assignment operator for std::string.

Sign up to request clarification or add additional context in comments.

9 Comments

sorry i am very new to using gcov , how do i use c++filt to demangle the names given
@Computernerd: c++filt _ZNSsaSERKSs to demangle one symbol; or gcov -f cashier.gnco | c++filt to demangle the output of gcov; or man c++filt to learn all about it.
I have done as instructed and i get the following output: Function 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
@Computernerd: That's right. std::basic_string<char, std::char_traits<char>, std::allocator<char> > is the full name of std::string.
Why does the full name of std::string appear as a function in my report and why is 0 percent of the lines executed
|
1

As described by others, you need to use c++filt to translate the names from 'mangled' form into human-readable. c++filt takes standard input, detects mangled C++ strings and writes to output with the names corrected; so, e.g. gcov -f filename | c++filt

The source of your problem is taking std::string by value in a header file and putting the function body into an implementation, this prevents the compiler from doing clever optimizations and forces it to construct temporary std::strings.

void setID(string); void setPassword(string); 

These functions are trivial enough that you ought to put their implementations in the header file so that the compiler can inline them if need be. But ultimately, what you need to do is accept references.

void setID(const std::string& id) { this->m_id = id; } void setPassword(const std::string& password) { m_password = password; } 

(The 'm_' prefix for member variables is one of the more widely used methods for distinguishing member names from variable names).

This saves the compiler the need to create an intermediate temporary and copy the text from the source string. If your performance is still an issue, you may want to look at C++11s rvalues:

void setPassword(std::string&& password); 

2 Comments

what do you mean by taking std::string by value in header file and putting the usage into an implementation , which part of the code does that??
In the header file, you have "void setID(string);", that takes a std::string by value, by "usage" - a poor choice of words, edited - I meant the use of that copied value. What you've done forces the compiler to always construct a temporary, copy of the source std::string, which means allocating new memory for the text and memcpying the source string into it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.