Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / lib / backtrace.c
blob32945d9f8fde24583e38ac476393427d34cd686c
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/misc.h>
20 #include <grub/command.h>
21 #include <grub/err.h>
22 #include <grub/dl.h>
23 #include <grub/mm.h>
24 #include <grub/term.h>
25 #include <grub/backtrace.h>
27 GRUB_MOD_LICENSE ("GPLv3+");
29 void
30 grub_backtrace_print_address (void *addr)
32 grub_dl_t mod;
34 FOR_DL_MODULES (mod)
36 grub_dl_segment_t segment;
37 for (segment = mod->segment; segment; segment = segment->next)
38 if (segment->addr <= addr && (grub_uint8_t *) segment->addr
39 + segment->size > (grub_uint8_t *) addr)
41 grub_printf ("%s.%x+%" PRIxGRUB_SIZE, mod->name, segment->section,
42 (grub_uint8_t *) addr - (grub_uint8_t *) segment->addr);
43 return;
47 grub_printf ("%p", addr);
50 static grub_err_t
51 grub_cmd_backtrace (grub_command_t cmd __attribute__ ((unused)),
52 int argc __attribute__ ((unused)),
53 char **args __attribute__ ((unused)))
55 grub_backtrace ();
56 return 0;
59 static grub_command_t cmd;
61 GRUB_MOD_INIT(backtrace)
63 cmd = grub_register_command ("backtrace", grub_cmd_backtrace,
64 0, N_("Print backtrace."));
67 GRUB_MOD_FINI(backtrace)
69 grub_unregister_command (cmd);