title: Stepping over a function with a throw statement inside in gdb doesn't take me to catch statement
body: <p>I'm trying to step through a C++ program. It throws an exception in a lower layer, but I'm unable to have the gdb debugger take me to the catch statement. One workaround is to register catch-points with <code>(gdb) catch catch</code> but it feels clunky to have to remember to always do that, and it will cause the program to halt at each chain of catch-statements in the lower layers.</p>
  <p>Here's a repro to illustrate my point. For this program compiled with <code>g++ foo.cpp -g -o foo</code>..</p>
  <pre><code>#include &lt;cstdio&gt;
  
  void f() {
      throw 42;
  }
  int main(int argc, char *argv[])
  {
      try {
          throw 42;
          //f();
          printf(&quot;after throw\n&quot;);
      } catch (...) {
          printf(&quot;in catch stmt\n&quot;);
      }
      printf(&quot;after try-catch stmt\n&quot;);
  }
  </code></pre>
  <p>.. Gdb works as I expect: When I step over the throw statement, the next statement is the catch.</p>
  <pre><code>$ gdb -q foo
  Reading symbols from foo...done.
  (gdb) start
  Temporary breakpoint 1 at 0x912: file foo.cpp, line 9.
  Starting program: /home/dannas/foo
  Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdd88) at foo.cpp:9
  9               throw 42;
  (gdb) next
  12          } catch (...) {
  (gdb)
  13              printf(&quot;in catch stmt\n&quot;);
  (gdb)
  in catch stmt
  12          } catch (...) {
  </code></pre>
  <p>But if I replace the <code>throw 42</code> statement in <code>main</code> with <code>f()</code>, then the program will end if I step over <code>f()</code>.</p>
  <pre><code>$ gdb -q foo
  Reading symbols from foo...done.
  (gdb) start
  Temporary breakpoint 1 at 0x912: file foo.cpp, line 10.
  Starting program: /home/dannas/foo
  
  Temporary breakpoint 1, main (argc=1, argv=0x7fffffffdd78) at foo.cpp:10
  10              f();
  (gdb) n
  in catch stmt
  after try-catch stmt
  [Inferior 1 (process 32522) exited normally]
  </code></pre>
  <p>Versions:</p>
  <pre><code> $ gdb --version
   GNU gdb (Ubuntu 8.1-0ubuntu3) 8.1.0.20180409-git
   $ gcc --version
   gcc (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0
  </code></pre>
  <p>Tom Troey says in <a href="https://stackoverflow.com/a/34601424/582010">https://stackoverflow.com/a/34601424/582010</a>:</p>
  <blockquote>
  <p>[...] there is a special debugging marker (either a function or an &quot;SDT
  probe&quot;, depending on how things were built) in the low-level unwinding
  code that is used when an exception is thrown. gdb puts a breakpoint
  at this spot. When this breakpoint is hit, gdb examines the target
  stack frame of the throw and, if it is above the nexting frame, puts a
  temporary breakpoint at the target of the throw.</p>
  </blockquote>
  <h1>Question</h1>
  <p>Is gdb unable to know which line it will execute next? The quote above seems to suggest that gdb makes an effort to figure out which is the next statement based on available catch handlers? Is there a way to make the debugger behave as I expect: &quot;gdb stops at the next executed statement in a function when stepping&quot;?</p>