]> granicus.if.org Git - neomutt/blob - backtrace.c
Fix mutt_write_mime_body() application/pgp-encrypted handling
[neomutt] / backtrace.c
1 /**
2  * @file
3  * Code backtrace
4  *
5  * @authors
6  * Copyright (C) 2018-2019 Richard Russon <rich@flatcap.org>
7  *
8  * @copyright
9  * This program is free software: you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License as published by the Free Software
11  * Foundation, either version 2 of the License, or (at your option) any later
12  * version.
13  *
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  * details.
18  *
19  * You should have received a copy of the GNU General Public License along with
20  * this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22
23 /**
24  * @page backtrace Code backtrace
25  *
26  * Code backtrace
27  */
28
29 #include "config.h"
30 #include <libunwind.h>
31 #include <stdio.h>
32 #include "mutt/mutt.h"
33
34 /**
35  * show_backtrace - Log the program's call stack
36  */
37 void show_backtrace(void)
38 {
39   unw_cursor_t cursor;
40   unw_context_t uc;
41   unw_word_t ip, sp;
42   char buf[256];
43
44   printf("\nBacktrace\n");
45   mutt_debug(LL_DEBUG1, "\nBacktrace\n");
46   unw_getcontext(&uc);
47   unw_init_local(&cursor, &uc);
48   while (unw_step(&cursor) > 0)
49   {
50     unw_get_reg(&cursor, UNW_REG_IP, &ip);
51     unw_get_reg(&cursor, UNW_REG_SP, &sp);
52     unw_get_proc_name(&cursor, buf, sizeof(buf), &ip);
53     if (buf[0] == '_')
54       break;
55     printf("\t%s() ip = %lx, sp = %lx\n", buf, (long) ip, (long) sp);
56     mutt_debug(LL_DEBUG1, "\t%s() ip = %lx, sp = %lx\n", buf, (long) ip, (long) sp);
57   }
58   printf("\n");
59 }