2 * Copyright 2008, François Revol, revol@free.fr
3 * Distributed under the terms of the MIT License.
6 #include <arch/debug.h>
12 #include "disasm_arch.h"
16 disasm_command(int argc
, char **argv
)
22 if (argi
< argc
&& strcmp(argv
[argi
], "-b") == 0) {
24 print_debugger_command_usage(argv
[0]);
28 if (!evaluate_debug_expression(argv
[argi
++], &backCount
, false))
32 if (argi
+ 2 < argc
) {
33 print_debugger_command_usage(argv
[0]);
40 if (!evaluate_debug_expression(argv
[argi
++], &pc
, false))
43 pc
= (addr_t
)arch_debug_get_interrupt_pc(NULL
);
45 kprintf("Failed to get current PC!\n");
53 if (!evaluate_debug_expression(argv
[argi
++], &count
, false))
57 // TODO: autoincrement
59 // if back count is given, compute base address
60 addr_t baseAddress
= 0;
64 const char *imageName
;
67 if (IS_KERNEL_ADDRESS(pc
)) {
68 error
= elf_debug_lookup_symbol_address(pc
, &baseAddress
, &symbol
,
69 &imageName
, &exactMatch
);
71 error
= elf_debug_lookup_user_symbol_address(
72 debug_get_debugged_thread()->team
, pc
, &baseAddress
, &symbol
,
73 &imageName
, &exactMatch
);
82 disasm_arch_dump_insns((addr_t
)pc
, count
, baseAddress
, backCount
);
88 std_ops(int32 op
, ...)
90 if (op
== B_MODULE_INIT
) {
91 status_t err
= disasm_arch_init();
95 err
= add_debugger_command_etc("dis", disasm_command
,
96 "Print disassembly at address",
97 "[ -b <back count> ] [ <address> [ <count> ] ]\n"
98 "Prints disassembly at address.\n"
99 " <address> - Address at which to start disassembling\n"
100 " (defaults to current PC).\n"
101 " <count> - Number of instructions to disassemble\n"
102 " starting at <address>.\n"
103 " -b <back count> - Number of instruction to disassemble before\n"
108 } else if (op
== B_MODULE_UNINIT
) {
109 remove_debugger_command("dis", disasm_command
);
110 return disasm_arch_fini();
117 static struct debugger_module_info sModuleInfo
= {
119 "debugger/disasm/v1",
130 module_info
*modules
[] = {
131 (module_info
*)&sModuleInfo
,