title: Why can `gdb` not see a global variable?
body: <p>Please see how <code>gdb</code> fails to print the global variable <code>dictionary</code> in the code below:</p>
  
  <pre><code>m@m-X555LJ ~ $ cat 148.cc
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;array&gt;
  #include &lt;utility&gt;
  #include &lt;algorithm&gt;
  #include &lt;sstream&gt;
  using namespace std;
  
  using letters = array&lt;int, 26&gt;;
  letters emptylet = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  vector&lt;pair&lt;string, letters&gt;&gt; dictionary;
  
  void backtrace(string &amp;orig, vector&lt;string&gt; &amp;phrase, vector&lt;string&gt; &amp;acc, letters &amp;curr, letters &amp;goal, decltype(dictionary)::iterator it) {
    if(it == dictionary.end())
      return;
    for(int i = 0; i &lt; it-&gt;second.size(); i++)
      curr[i] += it-&gt;second[i];
    acc.push_back(it-&gt;first);
    bool all_same = true;
    for(int i = 0; i &lt; curr.size(); i++)
      if(curr[i] &gt; goal[i])
        goto clean;
      else if(curr[i] != goal[i])
        all_same = false;
    if(all_same) {
      if(acc != phrase) {
        cout &lt;&lt; orig &lt;&lt; " =";
        for(string word: acc)
          cout &lt;&lt; ' ' &lt;&lt; word;
        cout &lt;&lt; '\n';
      }
    } else
      backtrace(orig, phrase, acc, curr, goal, it+1);
  clean:
    acc.pop_back();
    for(int i = 0; i &lt; it-&gt;second.size(); i++)
      curr[i] -= it-&gt;second[i];
    backtrace(orig, phrase, acc, curr, goal, it+1);
  }
  
  int main()
  {
    while((cin&gt;&gt;ws).peek()!='#') {
      string word;
      cin &gt;&gt; word;
      letters let = emptylet;
      for(char c: word)
        let[c-'A']++;
      dictionary.push_back(make_pair(word, let));
    }
    while((cin&gt;&gt;ws).peek()!='#') {
      string s;
      getline(cin, s);
      string orig = s;
      stringstream ss(s+'\n');
      vector&lt;string&gt; phrase;
      while(cin&gt;&gt;s){
        phrase.push_back(s);
      }
      sort(phrase.begin(), phrase.end());
      letters let = emptylet;
      for(string wrd: phrase)
        for(char c: wrd)
          let[c-'A']++;
      vector&lt;string&gt; empt;
      backtrace(orig, phrase, empt, emptylet, let, dictionary.begin());
    }
  }
  m@m-X555LJ ~ $ g++ -g -std=c++11 -o 148 148.cc
  m@m-X555LJ ~ $ cat 148.in
  ABC
  AND
  DEF
  DXZ
  K
  KX
  LJSRT
  LT
  PT
  PTYYWQ
  Y
  YWJSRQ
  ZD
  ZZXY
  #
  ZZXY ABC DEF
  SXZYTWQP KLJ YRTD
  ZZXY YWJSRQ PTYYWQ ZZXY
  #
  m@m-X555LJ ~ $ gdb ./148
  GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
  Copyright (C) 2016 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later &lt;http://gnu.org/licenses/gpl.html&gt;
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  and "show warranty" for details.
  This GDB was configured as "x86_64-linux-gnu".
  Type "show configuration" for configuration details.
  For bug reporting instructions, please see:
  &lt;http://www.gnu.org/software/gdb/bugs/&gt;.
  Find the GDB manual and other documentation resources online at:
  &lt;http://www.gnu.org/software/gdb/documentation/&gt;.
  For help, type "help".
  Type "apropos word" to search for commands related to "word"...
  Reading symbols from ./148...done.
  (gdb) break 52
  Breakpoint 1 at 0x401d0f: file 148.cc, line 52.
  (gdb) r &lt; 148.in
  Starting program: /home/m/148 &lt; 148.in
  
  Breakpoint 1, main () at 148.cc:52
  52    while((cin&gt;&gt;ws).peek()!='#') {
  (gdb) p dictionary
  No symbol "dictionary" in current context.
  (gdb) p di
  dictionary[abi:cxx11]    dir_data                 dirfd                    dirstream.h              div                      divmod_1.c
  difftime                 dirent                   dirfd.c                  disallow_malloc_check    div.c                    divrem.c
  difftime.c               dirent.h                 dirname                  distinguish_extX         div_t                    
  digits_dots.c            dirent64                 dirname.c                distinguish_extX.isra.0  divide                   
  (gdb) p dictionary[abi:cxx11] 
  No symbol "dictionary" in current context.
  (gdb) quit
  A debugging session is active.
  
      Inferior 1 [process 3815] will be killed.
  
  Quit anyway? (y or n) y
  m@m-X555LJ ~ $ g++ --version
  g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  Copyright (C) 2015 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  
  m@m-X555LJ ~ $ 
  </code></pre>
  
  <p>I do not understand this. Why is this the case? Is there something obvious about <code>gdb</code> I do not know?</p>
  
  <p>To my best understanding, <code>p dictionary</code> should print the contents of the <code>std::vector</code> global variable called <code>dictionary</code>.</p>
  
  <p>And this is not the first time something like that happens to me. I remember <code>gdb</code> not seeing functions, variables, etc. This time I decided to record the case.</p>