6 * Copyright (C) 2018-2019 Richard Russon <rich@flatcap.org>
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
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
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/>.
24 * @page backtrace Code backtrace
30 #include <libunwind.h>
32 #include "mutt/mutt.h"
35 * show_backtrace - Log the program's call stack
37 void show_backtrace(void)
44 printf("\nBacktrace\n");
45 mutt_debug(LL_DEBUG1, "\nBacktrace\n");
47 unw_init_local(&cursor, &uc);
48 while (unw_step(&cursor) > 0)
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);
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);