title: gcc - gdb - pretty print stl
body: <p>I'm currently doing some research on the STL, especially for printing the STL content during debug. I know there are many different approaches.</p>
  
  <p>Like:</p>
  
  <ul>
  <li><a href="http://sourceware.org/gdb/wiki/STLSupport" rel="nofollow noreferrer">http://sourceware.org/gdb/wiki/STLSupport</a></li>
  <li>or using a shared library to print the content of a container</li>
  </ul>
  
  <p>What I'm currently looking for is, why g++ deletes functions, which are not used for example I have following code and use the compile setting <code>g++ -g main.cpp -o main.o</code>.</p>
  
  <pre><code>include &lt;vector&gt;
  include &lt;iostream&gt;
  using namespace std;
  int main() {
      std::vector&lt;int&gt; vec;
      vec.push_back(10);
      vec.push_back(20);
      vec.push_back(30);
  
      return;
  }
  </code></pre>
  
  <p>So when I debug this code I will see that I can't use <code>print vec.front()</code>. The message I receive is:</p>
  
  <pre><code>Cannot evaluate function -- may be inlined
  </code></pre>
  
  <p>Therefore I tried to use the setting <code>-fkeep-inline-functions</code>, but no changes.</p>
  
  <p>When i use <code>nm main.o | grep front</code> I see that there is no line entry for the method <code>.front()</code>. Doing the same again but, with an extra <code>vec.front()</code> entry within my code I can use <code>print vec.front()</code>, and using <code>nm main.o | grep front</code> where I see the entry </p>
  
  <pre><code>0000000000401834 W _ZNSt6vectorIiSaIiEE5frontEv
  </code></pre>
  
  <p>Can someone explain me how I can keep all functions within my code without loosing them. I think, that dead functions do not get deleted as long as I don't set optimize settings or do following.</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/668103/how-to-tell-compiler-to-not-optimize-certain-code-away">How to tell compiler to NOT optimize certain code away?</a></li>
  </ul>
  
  <p>Why I need it: Current Python implementations use the internal STL implementation to print the content of a container, but it would be much more interesting to use functions which are defined by ISO/IEC 14882. I know it's possible to write a shared library, which can be compiled to your actual code before you debug it, to maintain that you have all STL functions, but who wants to compile an extra lib to its code, before debugging. It would also be interesting to know if there are some advantages and disadvantages of this two approaches (Shared Lib. and Python)?</p>