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>
24 #include <grub/term.h>
25 #include <grub/backtrace.h>
27 GRUB_MOD_LICENSE ("GPLv3+");
30 grub_backtrace_print_address (void *addr
)
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
);
47 grub_printf ("%p", addr
);
51 grub_cmd_backtrace (grub_command_t cmd
__attribute__ ((unused
)),
52 int argc
__attribute__ ((unused
)),
53 char **args
__attribute__ ((unused
)))
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
);