summaryrefslogtreecommitdiff
path: root/Applications/Debugger
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2020-04-13 19:23:19 +0300
committerAndreas Kling <kling@serenityos.org>2020-04-13 23:20:59 +0200
commite207de84492a4a12bde4714f64263e2ed3a9db43 (patch)
tree6a6d9e1dcc538f230e6fc1bac2c9ab4da52f070c /Applications/Debugger
parent34f0d98e67d4994c1c712b61d73384189c78b00a (diff)
downloadserenity-e207de84492a4a12bde4714f64263e2ed3a9db43.zip
LibELF: Add find_demangled_function
Also, added AK::String::index_of and fixed a bug in ELF::Loader::symbol_ptr
Diffstat (limited to 'Applications/Debugger')
-rw-r--r--Applications/Debugger/DebugSession.cpp9
-rw-r--r--Applications/Debugger/DebugSession.h9
-rw-r--r--Applications/Debugger/main.cpp27
3 files changed, 28 insertions, 17 deletions
diff --git a/Applications/Debugger/DebugSession.cpp b/Applications/Debugger/DebugSession.cpp
index 86c59e8196..14e673cc5e 100644
--- a/Applications/Debugger/DebugSession.cpp
+++ b/Applications/Debugger/DebugSession.cpp
@@ -30,8 +30,8 @@
DebugSession::DebugSession(int pid)
: m_debugee_pid(pid)
- , m_executable(make<MappedFile>(String::format("/proc/%d/exe", pid)))
- , m_elf_image(make<ELF::Image>(reinterpret_cast<u8*>(m_executable->data()), m_executable->size()))
+ , m_executable(String::format("/proc/%d/exe", pid))
+ , m_elf(reinterpret_cast<u8*>(m_executable.data()), m_executable.size())
{
}
@@ -176,8 +176,3 @@ void DebugSession::continue_debugee()
ASSERT_NOT_REACHED();
}
}
-
-VirtualAddress DebugSession::get_entry_point() const
-{
- return m_elf_image->entry();
-}
diff --git a/Applications/Debugger/DebugSession.h b/Applications/Debugger/DebugSession.h
index 9ac7774f20..2b683c6ecd 100644
--- a/Applications/Debugger/DebugSession.h
+++ b/Applications/Debugger/DebugSession.h
@@ -26,13 +26,14 @@
#pragma once
+#include <AK/Demangle.h>
#include <AK/HashMap.h>
#include <AK/MappedFile.h>
#include <AK/Optional.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>
#include <LibC/sys/arch/i386/regs.h>
-#include <LibELF/Image.h>
+#include <LibELF/Loader.h>
#include <signal.h>
#include <stdio.h>
#include <sys/ptrace.h>
@@ -69,7 +70,7 @@ public:
template<typename Callback>
void run(Callback callback);
- VirtualAddress get_entry_point() const;
+ const ELF::Loader& elf() const { return m_elf; }
enum DebugDecision {
Continue,
@@ -90,8 +91,8 @@ private:
int m_debugee_pid { -1 };
bool m_is_debugee_dead { false };
- NonnullOwnPtr<MappedFile> m_executable;
- NonnullOwnPtr<ELF::Image> m_elf_image;
+ MappedFile m_executable;
+ ELF::Loader m_elf;
HashMap<void*, BreakPoint> m_breakpoints;
};
diff --git a/Applications/Debugger/main.cpp b/Applications/Debugger/main.cpp
index 94fbe0ffcb..eeb09ffa99 100644
--- a/Applications/Debugger/main.cpp
+++ b/Applications/Debugger/main.cpp
@@ -27,6 +27,7 @@
#include "DebugSession.h"
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
+#include <AK/Demangle.h>
#include <AK/LogStream.h>
#include <AK/StringBuilder.h>
#include <AK/kmalloc.h>
@@ -137,14 +138,28 @@ bool handle_breakpoint_command(const String& command)
if (parts.size() != 2)
return false;
- u32 breakpoint_address = strtoul(parts[1].characters(), nullptr, 16);
- if (errno != 0)
+ auto argument = parts[1];
+ if (argument.is_empty())
return false;
+
+ u32 breakpoint_address = 0;
+
+ if ((argument[0] >= '0' && argument[0] <= '9')) {
+ breakpoint_address = strtoul(argument.characters(), nullptr, 16);
+ } else {
+ auto symbol = g_debug_session->elf().find_demangled_function(argument);
+ if (!symbol.has_value()) {
+ printf("symbol %s not found\n", parts[1].characters());
+ return false;
+ }
+ breakpoint_address = reinterpret_cast<u32>(symbol.value().value());
+ }
bool success = g_debug_session->insert_breakpoint(reinterpret_cast<void*>(breakpoint_address));
if (!success) {
- fprintf(stderr, "coult not insert breakpoint at: 0x%x\n", breakpoint_address);
+ fprintf(stderr, "coult not insert breakpoint at: %08x\n", breakpoint_address);
return false;
}
+ printf("breakpoint insterted at: %08x\n", breakpoint_address);
return true;
}
@@ -153,8 +168,8 @@ void print_help()
printf("Options:\n"
"cont - Continue execution\n"
"regs - Print registers\n"
- "dis <number of instructions> - Print disassembly\n"
- "bp <address> - Insert a breakpoint\n");
+ "dis [number of instructions] - Print disassembly\n"
+ "bp <address/symbol> - Insert a breakpoint\n");
}
int main(int argc, char** argv)
@@ -185,7 +200,7 @@ int main(int argc, char** argv)
sa.sa_handler = handle_sigint;
sigaction(SIGINT, &sa, nullptr);
- bool rc = g_debug_session->insert_breakpoint(g_debug_session->get_entry_point().as_ptr());
+ bool rc = g_debug_session->insert_breakpoint(g_debug_session->elf().entry().as_ptr());
ASSERT(rc);
g_debug_session->run([&](DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) {