mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 22:35:07 +00:00
Debugger: Use format instead of printf.
There was one bogus printf in a signal handler, I just left it there.
This commit is contained in:
parent
e1dfeef11f
commit
9efc69a6e2
1 changed files with 25 additions and 35 deletions
|
@ -50,7 +50,7 @@ OwnPtr<Debug::DebugSession> g_debug_session;
|
||||||
|
|
||||||
static void handle_sigint(int)
|
static void handle_sigint(int)
|
||||||
{
|
{
|
||||||
printf("Debugger: SIGINT\n");
|
outln("Debugger: SIGINT");
|
||||||
|
|
||||||
// The destructor of DebugSession takes care of detaching
|
// The destructor of DebugSession takes care of detaching
|
||||||
g_debug_session = nullptr;
|
g_debug_session = nullptr;
|
||||||
|
@ -58,21 +58,13 @@ static void handle_sigint(int)
|
||||||
|
|
||||||
static void handle_print_registers(const PtraceRegisters& regs)
|
static void handle_print_registers(const PtraceRegisters& regs)
|
||||||
{
|
{
|
||||||
printf("eax: 0x%x\n", regs.eax);
|
outln("eax={:08x} ebx={:08x} ecx={:08x} edx={:08x}", regs.eax, regs.ebx, regs.ecx, regs.edx);
|
||||||
printf("ecx: 0x%x\n", regs.ecx);
|
outln("esp={:08x} ebp={:08x} esi={:08x} edi={:08x}", regs.esp, regs.ebp, regs.esi, regs.edi);
|
||||||
printf("edx: 0x%x\n", regs.edx);
|
outln("eip={:08x} eflags={:08x}", regs.eip, regs.eflags);
|
||||||
printf("ebx: 0x%x\n", regs.ebx);
|
|
||||||
printf("esp: 0x%x\n", regs.esp);
|
|
||||||
printf("ebp: 0x%x\n", regs.ebp);
|
|
||||||
printf("esi: 0x%x\n", regs.esi);
|
|
||||||
printf("edi: 0x%x\n", regs.edi);
|
|
||||||
printf("eip: 0x%x\n", regs.eip);
|
|
||||||
printf("eflags: 0x%x\n", regs.eflags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool handle_disassemble_command(const String& command, void* first_instruction)
|
static bool handle_disassemble_command(const String& command, void* first_instruction)
|
||||||
{
|
{
|
||||||
(void)demangle("foo");
|
|
||||||
auto parts = command.split(' ');
|
auto parts = command.split(' ');
|
||||||
size_t number_of_instructions_to_disassemble = 5;
|
size_t number_of_instructions_to_disassemble = 5;
|
||||||
if (parts.size() == 2) {
|
if (parts.size() == 2) {
|
||||||
|
@ -102,9 +94,7 @@ static bool handle_disassemble_command(const String& command, void* first_instru
|
||||||
if (!insn.has_value())
|
if (!insn.has_value())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
printf(String::format(" %08x ", offset + reinterpret_cast<size_t>(first_instruction)).characters());
|
outln(" {:p} <+{}>:\t{}", offset + reinterpret_cast<size_t>(first_instruction), offset, insn.value().to_string(offset));
|
||||||
printf("<+%lu>:\t", reinterpret_cast<size_t>(offset));
|
|
||||||
printf("%s\n", insn.value().to_string(offset).characters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -131,10 +121,10 @@ static bool handle_breakpoint_command(const String& command)
|
||||||
return false;
|
return false;
|
||||||
auto file = source_arguments[0];
|
auto file = source_arguments[0];
|
||||||
if (!file.contains("/"))
|
if (!file.contains("/"))
|
||||||
file = String::format("./%s", file.characters());
|
file = String::formatted("./{}", file);
|
||||||
auto result = g_debug_session->debug_info().get_instruction_from_source(file, line.value());
|
auto result = g_debug_session->debug_info().get_instruction_from_source(file, line.value());
|
||||||
if (!result.has_value()) {
|
if (!result.has_value()) {
|
||||||
printf("No matching instruction found\n");
|
outln("No matching instruction found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
breakpoint_address = result.value();
|
breakpoint_address = result.value();
|
||||||
|
@ -143,7 +133,7 @@ static bool handle_breakpoint_command(const String& command)
|
||||||
} else {
|
} else {
|
||||||
auto symbol = g_debug_session->elf().find_demangled_function(argument);
|
auto symbol = g_debug_session->elf().find_demangled_function(argument);
|
||||||
if (!symbol.has_value()) {
|
if (!symbol.has_value()) {
|
||||||
printf("symbol %s not found\n", parts[1].characters());
|
outln("symbol {} not found", parts[1]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
breakpoint_address = reinterpret_cast<u32>(symbol.value().value());
|
breakpoint_address = reinterpret_cast<u32>(symbol.value().value());
|
||||||
|
@ -151,23 +141,23 @@ static bool handle_breakpoint_command(const String& command)
|
||||||
|
|
||||||
bool success = g_debug_session->insert_breakpoint(reinterpret_cast<void*>(breakpoint_address));
|
bool success = g_debug_session->insert_breakpoint(reinterpret_cast<void*>(breakpoint_address));
|
||||||
if (!success) {
|
if (!success) {
|
||||||
fprintf(stderr, "could not insert breakpoint at: %08x\n", breakpoint_address);
|
warnln("could not insert breakpoint at: {:p}", breakpoint_address);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
printf("breakpoint inserted at: %08x\n", breakpoint_address);
|
warnln("breakpoint inserted at: {:p}", breakpoint_address);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_help()
|
static void print_help()
|
||||||
{
|
{
|
||||||
printf("Options:\n"
|
new_out("Options:\n"
|
||||||
"cont - Continue execution\n"
|
"cont - Continue execution\n"
|
||||||
"si - step to the next instruction\n"
|
"si - step to the next instruction\n"
|
||||||
"sl - step to the next source line\n"
|
"sl - step to the next source line\n"
|
||||||
"line - show the position of the current instruction in the source code\n"
|
"line - show the position of the current instruction in the source code\n"
|
||||||
"regs - Print registers\n"
|
"regs - Print registers\n"
|
||||||
"dis [number of instructions] - Print disassembly\n"
|
"dis [number of instructions] - Print disassembly\n"
|
||||||
"bp <address/symbol/file:line> - Insert a breakpoint\n");
|
"bp <address/symbol/file:line> - Insert a breakpoint\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -188,7 +178,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto result = Debug::DebugSession::exec_and_attach(command);
|
auto result = Debug::DebugSession::exec_and_attach(command);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
fprintf(stderr, "Failed to start debugging session for: \"%s\"\n", command);
|
warnln("Failed to start debugging session for: \"{}\"", command);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
g_debug_session = result.release_nonnull();
|
g_debug_session = result.release_nonnull();
|
||||||
|
@ -206,7 +196,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
g_debug_session->run([&](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) {
|
g_debug_session->run([&](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) {
|
||||||
if (reason == Debug::DebugSession::DebugBreakReason::Exited) {
|
if (reason == Debug::DebugSession::DebugBreakReason::Exited) {
|
||||||
printf("Program exited.\n");
|
outln("Program exited.");
|
||||||
return Debug::DebugSession::DebugDecision::Detach;
|
return Debug::DebugSession::DebugDecision::Detach;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,20 +210,20 @@ int main(int argc, char** argv)
|
||||||
bool no_source_info = !source_position.has_value();
|
bool no_source_info = !source_position.has_value();
|
||||||
if (no_source_info || source_position.value() != previous_source_position) {
|
if (no_source_info || source_position.value() != previous_source_position) {
|
||||||
if (no_source_info)
|
if (no_source_info)
|
||||||
printf("No source information for current instruction! stoppoing.\n");
|
outln("No source information for current instruction! stoppoing.");
|
||||||
in_step_line = false;
|
in_step_line = false;
|
||||||
} else {
|
} else {
|
||||||
return Debug::DebugSession::DebugDecision::SingleStep;
|
return Debug::DebugSession::DebugDecision::SingleStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Program is stopped at: 0x%x (%s)\n", regs.eip, symbol_at_ip.characters());
|
outln("Program is stopped at: {:p} ({})", regs.eip, symbol_at_ip);
|
||||||
|
|
||||||
if (source_position.has_value()) {
|
if (source_position.has_value()) {
|
||||||
previous_source_position = source_position.value();
|
previous_source_position = source_position.value();
|
||||||
printf("Source location: %s:%lu\n", source_position.value().file_path.characters(), source_position.value().line_number);
|
outln("Source location: {}:{}", source_position.value().file_path, source_position.value().line_number);
|
||||||
} else {
|
} else {
|
||||||
printf("(No source location information for the current instruction)\n");
|
outln("(No source location information for the current instruction)");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -262,7 +252,7 @@ int main(int argc, char** argv)
|
||||||
in_step_line = true;
|
in_step_line = true;
|
||||||
success = true;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
printf("No source location information for the current instruction\n");
|
outln("No source location information for the current instruction");
|
||||||
}
|
}
|
||||||
} else if (command == "regs") {
|
} else if (command == "regs") {
|
||||||
handle_print_registers(regs);
|
handle_print_registers(regs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue