{"id":3072,"date":"2015-02-13T13:58:31","date_gmt":"2015-02-13T02:58:31","guid":{"rendered":"http:\/\/blog.mozilla.org\/nnethercote\/?p=3072"},"modified":"2015-02-13T13:58:31","modified_gmt":"2015-02-13T02:58:31","slug":"using-gdb-to-get-stack-traces-at-particular-program-points","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/nnethercote\/2015\/02\/13\/using-gdb-to-get-stack-traces-at-particular-program-points\/","title":{"rendered":"Using GDB to get stack traces at particular program points"},"content":{"rendered":"<p>A while back I wrote how I sometimes <a href=\"https:\/\/blog.mozilla.org\/nnethercote\/2011\/01\/11\/using-valgrind-to-get-stack-traces\/\">use Valgrind to print a stack trace every time a particular program point is reached<\/a>. I just learned how to do likewise with GDB. Here&#8217;s an example session that illustrates what to do.<\/p>\n<pre>(gdb) break je_chunk_alloc_mmap     # set a breakpoint\r\nBreakpoint 1 at 0x1aa32c0\r\n(gdb) commands                      # enter breakpoint command sequence\r\nType commands for breakpoint(s) 1, one per line.\r\nEnd with a line saying just \"end\".\r\n&gt;bt                                 # print stack trace\r\n&gt;c                                  # continue execution\r\n&gt;end                                # end command sequence\r\n(gdb) set pagination off            # don't pause when the screen fills up\r\n(gdb) set logging on                # copy output to a file\r\nCopying output to gdb.txt.<\/pre>\n<p>This is better than the Valgrind technique because (a) it doesn&#8217;t require modifying the source code, and (b) programs tend to run faster under GDB than they do under Valgrind.<\/p>\n<p>Thanks to Mike Hommey for helping with this.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while back I wrote how I sometimes use Valgrind to print a stack trace every time a particular program point is reached. I just learned how to do likewise with GDB. Here&#8217;s an example session that illustrates what to do. (gdb) break je_chunk_alloc_mmap # set a breakpoint Breakpoint 1 at 0x1aa32c0 (gdb) commands # [&hellip;]<\/p>\n","protected":false},"author":139,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4141,617],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/3072"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/comments?post=3072"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/posts\/3072\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/media?parent=3072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/categories?post=3072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/nnethercote\/wp-json\/wp\/v2\/tags?post=3072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}