diff options
author | Luke <luke.wilde@live.co.uk> | 2020-08-25 04:33:07 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-25 09:46:06 +0200 |
commit | 694b86a4bf055ce80c2b234b33c73515426fff5e (patch) | |
tree | ccf7896ce5ef7327aa55f258d01e70c18804394d | |
parent | b58ca7cf3d73152e8e049df4ddd43912030ab4ea (diff) | |
download | serenity-694b86a4bf055ce80c2b234b33c73515426fff5e.zip |
LibDebug: Move everything into the "Debug" namespace
31 files changed, 115 insertions, 85 deletions
diff --git a/Applications/Debugger/main.cpp b/Applications/Debugger/main.cpp index 4829c52b0d..d88125cd47 100644 --- a/Applications/Debugger/main.cpp +++ b/Applications/Debugger/main.cpp @@ -46,7 +46,7 @@ RefPtr<Line::Editor> editor; -OwnPtr<DebugSession> g_debug_session; +OwnPtr<Debug::DebugSession> g_debug_session; static void handle_sigint(int) { @@ -186,7 +186,7 @@ int main(int argc, char** argv) "program", Core::ArgsParser::Required::Yes); args_parser.parse(argc, argv); - auto result = DebugSession::exec_and_attach(command); + auto result = Debug::DebugSession::exec_and_attach(command); if (!result) { fprintf(stderr, "Failed to start debugging session for: \"%s\"\n", command); exit(1); @@ -201,13 +201,13 @@ int main(int argc, char** argv) bool rc = g_debug_session->insert_breakpoint(g_debug_session->elf().entry().as_ptr()); ASSERT(rc); - DebugInfo::SourcePosition previous_source_position; + Debug::DebugInfo::SourcePosition previous_source_position; bool in_step_line = false; - g_debug_session->run([&](DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) { - if (reason == DebugSession::DebugBreakReason::Exited) { + g_debug_session->run([&](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) { + if (reason == Debug::DebugSession::DebugBreakReason::Exited) { printf("Program exited.\n"); - return DebugSession::DebugDecision::Detach; + return Debug::DebugSession::DebugDecision::Detach; } ASSERT(optional_regs.has_value()); @@ -223,7 +223,7 @@ int main(int argc, char** argv) printf("No source information for current instruction! stoppoing.\n"); in_step_line = false; } else { - return DebugSession::DebugDecision::SingleStep; + return Debug::DebugSession::DebugDecision::SingleStep; } } @@ -240,25 +240,25 @@ int main(int argc, char** argv) auto command_result = editor->get_line("(sdb) "); if (command_result.is_error()) - return DebugSession::DebugDecision::Detach; + return Debug::DebugSession::DebugDecision::Detach; auto& command = command_result.value(); bool success = false; - Optional<DebugSession::DebugDecision> decision; + Optional<Debug::DebugSession::DebugDecision> decision; if (command.is_empty() && !editor->history().is_empty()) { command = editor->history().last(); } if (command == "cont") { - decision = DebugSession::DebugDecision::Continue; + decision = Debug::DebugSession::DebugDecision::Continue; success = true; } else if (command == "si") { - decision = DebugSession::DebugDecision::SingleStep; + decision = Debug::DebugSession::DebugDecision::SingleStep; success = true; } else if (command == "sl") { if (source_position.has_value()) { - decision = DebugSession::DebugDecision::SingleStep; + decision = Debug::DebugSession::DebugDecision::SingleStep; in_step_line = true; success = true; } else { diff --git a/DevTools/HackStudio/Debugger/BacktraceModel.cpp b/DevTools/HackStudio/Debugger/BacktraceModel.cpp index 500b1a0747..afcf75ddbf 100644 --- a/DevTools/HackStudio/Debugger/BacktraceModel.cpp +++ b/DevTools/HackStudio/Debugger/BacktraceModel.cpp @@ -30,7 +30,7 @@ namespace HackStudio { -NonnullRefPtr<BacktraceModel> BacktraceModel::create(const DebugSession& debug_session, const PtraceRegisters& regs) +NonnullRefPtr<BacktraceModel> BacktraceModel::create(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) { return adopt(*new BacktraceModel(create_backtrace(debug_session, regs))); } @@ -51,7 +51,7 @@ GUI::ModelIndex BacktraceModel::index(int row, int column, const GUI::ModelIndex return create_index(row, column, &m_frames.at(row)); } -Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(const DebugSession& debug_session, const PtraceRegisters& regs) +Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) { u32 current_ebp = regs.ebp; u32 current_instruction = regs.eip; @@ -64,7 +64,7 @@ Vector<BacktraceModel::FrameInfo> BacktraceModel::create_backtrace(const DebugSe } frames.append({ name, current_instruction, current_ebp }); - auto frame_info = StackFrameUtils::get_info(*Debugger::the().session(), current_ebp); + auto frame_info = Debug::StackFrameUtils::get_info(*Debugger::the().session(), current_ebp); ASSERT(frame_info.has_value()); current_instruction = frame_info.value().return_address; current_ebp = frame_info.value().next_ebp; diff --git a/DevTools/HackStudio/Debugger/BacktraceModel.h b/DevTools/HackStudio/Debugger/BacktraceModel.h index ff974b57d4..06d697c388 100644 --- a/DevTools/HackStudio/Debugger/BacktraceModel.h +++ b/DevTools/HackStudio/Debugger/BacktraceModel.h @@ -31,13 +31,17 @@ #include <LibGUI/Model.h> #include <sys/arch/i386/regs.h> +namespace Debug { + class DebugSession; +} + namespace HackStudio { class BacktraceModel final : public GUI::Model { public: - static NonnullRefPtr<BacktraceModel> create(const DebugSession&, const PtraceRegisters& regs); + static NonnullRefPtr<BacktraceModel> create(const Debug::DebugSession&, const PtraceRegisters& regs); virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_frames.size(); } virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return 1; } @@ -66,7 +70,7 @@ private: { } - static Vector<FrameInfo> create_backtrace(const DebugSession&, const PtraceRegisters&); + static Vector<FrameInfo> create_backtrace(const Debug::DebugSession&, const PtraceRegisters&); Vector<FrameInfo> m_frames; }; diff --git a/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp b/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp index c3d7ebda5c..30fb546a74 100644 --- a/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp +++ b/DevTools/HackStudio/Debugger/DebugInfoWidget.cpp @@ -115,8 +115,8 @@ DebugInfoWidget::DebugInfoWidget() auto is_valid_index = [](auto& index) { if (!index.is_valid()) return false; - auto* variable = static_cast<const DebugInfo::VariableInfo*>(index.internal_data()); - if (variable->location_type != DebugInfo::VariableInfo::LocationType::Address) + auto* variable = static_cast<const Debug::DebugInfo::VariableInfo*>(index.internal_data()); + if (variable->location_type != Debug::DebugInfo::VariableInfo::LocationType::Address) return false; return variable->is_enum_type() || variable->type_name.is_one_of("int", "bool"); }; @@ -139,7 +139,7 @@ DebugInfoWidget::DebugInfoWidget() }; } -void DebugInfoWidget::update_state(const DebugSession& debug_session, const PtraceRegisters& regs) +void DebugInfoWidget::update_state(const Debug::DebugSession& debug_session, const PtraceRegisters& regs) { m_variables_view->set_model(VariablesModel::create(regs)); m_backtrace_view->set_model(BacktraceModel::create(debug_session, regs)); diff --git a/DevTools/HackStudio/Debugger/DebugInfoWidget.h b/DevTools/HackStudio/Debugger/DebugInfoWidget.h index 727c89f912..308ec6c02f 100644 --- a/DevTools/HackStudio/Debugger/DebugInfoWidget.h +++ b/DevTools/HackStudio/Debugger/DebugInfoWidget.h @@ -43,7 +43,7 @@ class DebugInfoWidget final : public GUI::Widget { public: virtual ~DebugInfoWidget() override {} - void update_state(const DebugSession&, const PtraceRegisters&); + void update_state(const Debug::DebugSession&, const PtraceRegisters&); void program_stopped(); void set_debug_actions_enabled(bool enabled); diff --git a/DevTools/HackStudio/Debugger/Debugger.cpp b/DevTools/HackStudio/Debugger/Debugger.cpp index 49280741cd..1938a77630 100644 --- a/DevTools/HackStudio/Debugger/Debugger.cpp +++ b/DevTools/HackStudio/Debugger/Debugger.cpp @@ -69,7 +69,7 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC if (change_type == BreakpointChange::Added) { Debugger::the().m_breakpoints.append(position); } else { - Debugger::the().m_breakpoints.remove_all_matching([&](DebugInfo::SourcePosition val) { return val == position; }); + Debugger::the().m_breakpoints.remove_all_matching([&](Debug::DebugInfo::SourcePosition val) { return val == position; }); } auto session = Debugger::the().session(); @@ -94,7 +94,7 @@ void Debugger::on_breakpoint_change(const String& file, size_t line, BreakpointC } } -DebugInfo::SourcePosition Debugger::create_source_position(const String& file, size_t line) +Debug::DebugInfo::SourcePosition Debugger::create_source_position(const String& file, size_t line) { if (!file.starts_with('/') && !file.starts_with("./")) return { String::format("./%s", file.characters()), line + 1 }; @@ -109,7 +109,7 @@ int Debugger::start_static() void Debugger::start() { - m_debug_session = DebugSession::exec_and_attach(m_executable_path); + m_debug_session = Debug::DebugSession::exec_and_attach(m_executable_path); ASSERT(!!m_debug_session); for (const auto& breakpoint : m_breakpoints) { @@ -130,11 +130,11 @@ int Debugger::debugger_loop() { ASSERT(m_debug_session); - m_debug_session->run([&](DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) { - if (reason == DebugSession::DebugBreakReason::Exited) { + m_debug_session->run([&](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> optional_regs) { + if (reason == Debug::DebugSession::DebugBreakReason::Exited) { dbg() << "Program exited"; m_on_exit_callback(); - return DebugSession::DebugDecision::Detach; + return Debug::DebugSession::DebugDecision::Detach; } remove_temporary_breakpoints(); ASSERT(optional_regs.has_value()); @@ -146,7 +146,7 @@ int Debugger::debugger_loop() if (m_state.should_stop_single_stepping(source_position.value())) { m_state.set_normal(); } else { - return DebugSession::DebugDecision::SingleStep; + return Debug::DebugSession::DebugDecision::SingleStep; } } @@ -165,18 +165,18 @@ int Debugger::debugger_loop() switch (m_continue_type) { case ContinueType::Continue: m_state.set_normal(); - return DebugSession::DebugDecision::Continue; + return Debug::DebugSession::DebugDecision::Continue; case ContinueType::SourceSingleStep: m_state.set_single_stepping(source_position.value()); - return DebugSession::DebugDecision::SingleStep; + return Debug::DebugSession::DebugDecision::SingleStep; case ContinueType::SourceStepOut: m_state.set_stepping_out(); do_step_out(regs); - return DebugSession::DebugDecision::Continue; + return Debug::DebugSession::DebugDecision::Continue; case ContinueType::SourceStepOver: m_state.set_stepping_over(); do_step_over(regs); - return DebugSession::DebugDecision::Continue; + return Debug::DebugSession::DebugDecision::Continue; } ASSERT_NOT_REACHED(); }); @@ -190,13 +190,13 @@ void Debugger::DebuggingState::set_normal() m_original_source_position.clear(); } -void Debugger::DebuggingState::set_single_stepping(DebugInfo::SourcePosition original_source_position) +void Debugger::DebuggingState::set_single_stepping(Debug::DebugInfo::SourcePosition original_source_position) { m_state = State::SingleStepping; m_original_source_position = original_source_position; } -bool Debugger::DebuggingState::should_stop_single_stepping(const DebugInfo::SourcePosition& current_source_position) const +bool Debugger::DebuggingState::should_stop_single_stepping(const Debug::DebugInfo::SourcePosition& current_source_position) const { ASSERT(m_state == State::SingleStepping); return m_original_source_position.value() != current_source_position; @@ -244,7 +244,7 @@ void Debugger::do_step_over(const PtraceRegisters& regs) void Debugger::insert_temporary_breakpoint_at_return_address(const PtraceRegisters& regs) { - auto frame_info = StackFrameUtils::get_info(*m_debug_session, regs.ebp); + auto frame_info = Debug::StackFrameUtils::get_info(*m_debug_session, regs.ebp); ASSERT(frame_info.has_value()); u32 return_address = frame_info.value().return_address; insert_temporary_breakpoint(return_address); diff --git a/DevTools/HackStudio/Debugger/Debugger.h b/DevTools/HackStudio/Debugger/Debugger.h index bcd496dda9..ec7dead40e 100644 --- a/DevTools/HackStudio/Debugger/Debugger.h +++ b/DevTools/HackStudio/Debugger/Debugger.h @@ -55,7 +55,7 @@ public: void set_executable_path(const String& path) { m_executable_path = path; } - DebugSession* session() { return m_debug_session.ptr(); } + Debug::DebugSession* session() { return m_debug_session.ptr(); } // Thread entry point static int start_static(); @@ -85,18 +85,18 @@ private: State get() const { return m_state; } void set_normal(); - void set_single_stepping(DebugInfo::SourcePosition original_source_position); + void set_single_stepping(Debug::DebugInfo::SourcePosition original_source_position); void set_stepping_out() { m_state = State::SteppingOut; } void set_stepping_over() { m_state = State::SteppingOver; } - bool should_stop_single_stepping(const DebugInfo::SourcePosition& current_source_position) const; + bool should_stop_single_stepping(const Debug::DebugInfo::SourcePosition& current_source_position) const; void clear_temporary_breakpoints(); void add_temporary_breakpoint(u32 address); const Vector<u32>& temporary_breakpoints() const { return m_addresses_of_temporary_breakpoints; } private: State m_state { Normal }; - Optional<DebugInfo::SourcePosition> m_original_source_position; // The source position at which we started the current single step + Optional<Debug::DebugInfo::SourcePosition> m_original_source_position; // The source position at which we started the current single step Vector<u32> m_addresses_of_temporary_breakpoints; }; @@ -105,7 +105,7 @@ private: Function<void()> on_continue_callback, Function<void()> on_exit_callback); - static DebugInfo::SourcePosition create_source_position(const String& file, size_t line); + static Debug::DebugInfo::SourcePosition create_source_position(const String& file, size_t line); void start(); int debugger_loop(); @@ -116,13 +116,13 @@ private: void insert_temporary_breakpoint(FlatPtr address); void insert_temporary_breakpoint_at_return_address(const PtraceRegisters&); - OwnPtr<DebugSession> m_debug_session; + OwnPtr<Debug::DebugSession> m_debug_session; DebuggingState m_state; pthread_mutex_t m_continue_mutex {}; pthread_cond_t m_continue_cond {}; - Vector<DebugInfo::SourcePosition> m_breakpoints; + Vector<Debug::DebugInfo::SourcePosition> m_breakpoints; String m_executable_path; diff --git a/DevTools/HackStudio/Debugger/VariablesModel.cpp b/DevTools/HackStudio/Debugger/VariablesModel.cpp index 8bc964fa40..6f958d12fd 100644 --- a/DevTools/HackStudio/Debugger/VariablesModel.cpp +++ b/DevTools/HackStudio/Debugger/VariablesModel.cpp @@ -34,7 +34,7 @@ GUI::ModelIndex VariablesModel::index(int row, int column, const GUI::ModelIndex { if (!parent_index.is_valid()) return create_index(row, column, &m_variables[row]); - auto* parent = static_cast<const DebugInfo::VariableInfo*>(parent_index.internal_data()); + auto* parent = static_cast<const Debug::DebugInfo::VariableInfo*>(parent_index.internal_data()); auto* child = &parent->members[row]; return create_index(row, column, child); } @@ -43,7 +43,7 @@ GUI::ModelIndex VariablesModel::parent_index(const GUI::ModelIndex& index) const { if (!index.is_valid()) return {}; - auto* child = static_cast<const DebugInfo::VariableInfo*>(index.internal_data()); + auto* child = static_cast<const Debug::DebugInfo::VariableInfo*>(index.internal_data()); auto* parent = child->parent; if (parent == nullptr) return {}; @@ -55,7 +55,7 @@ GUI::ModelIndex VariablesModel::parent_index(const GUI::ModelIndex& index) const ASSERT_NOT_REACHED(); } for (size_t row = 0; row < parent->parent->members.size(); row++) { - DebugInfo::VariableInfo* child_at_row = parent->parent->members.ptr_at(row).ptr(); + Debug::DebugInfo::VariableInfo* child_at_row = parent->parent->members.ptr_at(row).ptr(); if (child_at_row == parent) return create_index(row, 0, parent); } @@ -66,13 +66,13 @@ int VariablesModel::row_count(const GUI::ModelIndex& index) const { if (!index.is_valid()) return m_variables.size(); - auto* node = static_cast<const DebugInfo::VariableInfo*>(index.internal_data()); + auto* node = static_cast<const Debug::DebugInfo::VariableInfo*>(index.internal_data()); return node->members.size(); } -static String variable_value_as_string(const DebugInfo::VariableInfo& variable) +static String variable_value_as_string(const Debug::DebugInfo::VariableInfo& variable) { - if (variable.location_type != DebugInfo::VariableInfo::LocationType::Address) + if (variable.location_type != Debug::DebugInfo::VariableInfo::LocationType::Address) return "N/A"; auto variable_address = variable.location_data.address; @@ -108,7 +108,7 @@ static String variable_value_as_string(const DebugInfo::VariableInfo& variable) return String::format("type: %s @ %08x, ", variable.type_name.characters(), variable_address); } -static Optional<u32> string_to_variable_value(const StringView& string_value, const DebugInfo::VariableInfo& variable) +static Optional<u32> string_to_variable_value(const StringView& string_value, const Debug::DebugInfo::VariableInfo& variable) { if (variable.is_enum_type()) { auto prefix_string = String::format("%s::", variable.type_name.characters()); @@ -145,7 +145,7 @@ static Optional<u32> string_to_variable_value(const StringView& string_value, co void VariablesModel::set_variable_value(const GUI::ModelIndex& index, const StringView& string_value, GUI::Window* parent_window) { - auto variable = static_cast<const DebugInfo::VariableInfo*>(index.internal_data()); + auto variable = static_cast<const Debug::DebugInfo::VariableInfo*>(index.internal_data()); auto value = string_to_variable_value(string_value, *variable); @@ -163,7 +163,7 @@ void VariablesModel::set_variable_value(const GUI::ModelIndex& index, const Stri GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const { - auto* variable = static_cast<const DebugInfo::VariableInfo*>(index.internal_data()); + auto* variable = static_cast<const Debug::DebugInfo::VariableInfo*>(index.internal_data()); switch (role) { case GUI::ModelRole::Display: { auto value_as_string = variable_value_as_string(*variable); diff --git a/DevTools/HackStudio/Debugger/VariablesModel.h b/DevTools/HackStudio/Debugger/VariablesModel.h index bb0e3d5b2f..41ed5e3ec9 100644 --- a/DevTools/HackStudio/Debugger/VariablesModel.h +++ b/DevTools/HackStudio/Debugger/VariablesModel.h @@ -48,13 +48,13 @@ public: virtual GUI::ModelIndex index(int row, int column = 0, const GUI::ModelIndex& = GUI::ModelIndex()) const override; private: - explicit VariablesModel(NonnullOwnPtrVector<DebugInfo::VariableInfo>&& variables, const PtraceRegisters& regs) + explicit VariablesModel(NonnullOwnPtrVector<Debug::DebugInfo::VariableInfo>&& variables, const PtraceRegisters& regs) : m_variables(move(variables)) , m_regs(regs) { m_variable_icon.set_bitmap_for_size(16, Gfx::Bitmap::load_from_file("/res/icons/16x16/inspector-object.png")); } - NonnullOwnPtrVector<DebugInfo::VariableInfo> m_variables; + NonnullOwnPtrVector<Debug::DebugInfo::VariableInfo> m_variables; PtraceRegisters m_regs; GUI::Icon m_variable_icon; diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index 6f849a8f1d..d3dba62486 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -154,7 +154,7 @@ bool Emulator::load_elf() m_free_symbol_start = free_symbol.value().value(); m_free_symbol_end = m_free_symbol_start + free_symbol.value().size(); - m_debug_info = make<DebugInfo>(m_elf); + m_debug_info = make<Debug::DebugInfo>(m_elf); return true; } diff --git a/DevTools/UserspaceEmulator/Emulator.h b/DevTools/UserspaceEmulator/Emulator.h index 0709b93bd8..4b0ec9a94a 100644 --- a/DevTools/UserspaceEmulator/Emulator.h +++ b/DevTools/UserspaceEmulator/Emulator.h @@ -64,7 +64,7 @@ public: private: NonnullRefPtr<ELF::Loader> m_elf; - OwnPtr<DebugInfo> m_debug_info; + OwnPtr<Debug::DebugInfo> m_debug_info; SoftMMU m_mmu; SoftCPU m_cpu; diff --git a/Libraries/LibDebug/DebugInfo.cpp b/Libraries/LibDebug/DebugInfo.cpp index f8b13d25b5..0e29e7ca18 100644 --- a/Libraries/LibDebug/DebugInfo.cpp +++ b/Libraries/LibDebug/DebugInfo.cpp @@ -33,6 +33,8 @@ //#define DEBUG_SPAM +namespace Debug { + DebugInfo::DebugInfo(NonnullRefPtr<const ELF::Loader> elf) : m_elf(elf) , m_dwarf_info(Dwarf::DwarfInfo::create(m_elf)) @@ -107,9 +109,9 @@ void DebugInfo::prepare_lines() auto buffer = section.wrapping_byte_buffer(); InputMemoryStream stream { buffer }; - Vector<LineProgram::LineInfo> all_lines; + Vector<Dwarf::LineProgram::LineInfo> all_lines; while (!stream.eof()) { - LineProgram program(stream); + Dwarf::LineProgram program(stream); all_lines.append(program.lines()); } @@ -331,7 +333,9 @@ Vector<DebugInfo::SourcePosition> DebugInfo::source_lines_in_scope(const Variabl return source_lines; } -DebugInfo::SourcePosition DebugInfo::SourcePosition::from_line_info(const LineProgram::LineInfo& line) +DebugInfo::SourcePosition DebugInfo::SourcePosition::from_line_info(const Dwarf::LineProgram::LineInfo& line) { return { line.file, line.line, line.address }; } + +} diff --git a/Libraries/LibDebug/DebugInfo.h b/Libraries/LibDebug/DebugInfo.h index 9208dea102..3a02fa8003 100644 --- a/Libraries/LibDebug/DebugInfo.h +++ b/Libraries/LibDebug/DebugInfo.h @@ -36,6 +36,8 @@ #include <LibELF/Loader.h> #include <sys/arch/i386/regs.h> +namespace Debug { + class DebugInfo { public: explicit DebugInfo(NonnullRefPtr<const ELF::Loader> elf); @@ -48,7 +50,7 @@ public: bool operator==(const SourcePosition& other) const { return file_path == other.file_path && line_number == other.line_number; } bool operator!=(const SourcePosition& other) const { return !(*this == other); } - static SourcePosition from_line_info(const LineProgram::LineInfo&); + static SourcePosition from_line_info(const Dwarf::LineProgram::LineInfo&); }; struct VariableInfo { @@ -119,5 +121,7 @@ private: NonnullRefPtr<Dwarf::DwarfInfo> m_dwarf_info; Vector<VariablesScope> m_scopes; - Vector<LineProgram::LineInfo> m_sorted_lines; + Vector<Dwarf::LineProgram::LineInfo> m_sorted_lines; }; + +} diff --git a/Libraries/LibDebug/DebugSession.cpp b/Libraries/LibDebug/DebugSession.cpp index 2c6394de1e..2640817185 100644 --- a/Libraries/LibDebug/DebugSession.cpp +++ b/Libraries/LibDebug/DebugSession.cpp @@ -28,6 +28,8 @@ #include <AK/Optional.h> #include <stdlib.h> +namespace Debug { + DebugSession::DebugSession(int pid) : m_debugee_pid(pid) , m_executable(initialize_executable_mapped_file(pid)) @@ -263,3 +265,5 @@ void* DebugSession::single_step() set_registers(regs); return (void*)regs.eip; } + +} diff --git a/Libraries/LibDebug/DebugSession.h b/Libraries/LibDebug/DebugSession.h index e11f93c944..d3e212ff28 100644 --- a/Libraries/LibDebug/DebugSession.h +++ b/Libraries/LibDebug/DebugSession.h @@ -42,6 +42,8 @@ #include <sys/wait.h> #include <unistd.h> +namespace Debug { + class DebugSession { public: static OwnPtr<DebugSession> exec_and_attach(const String& command); @@ -243,3 +245,5 @@ void DebugSession::run(Callback callback) } } } + +} diff --git a/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp b/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp index 25e208b554..22c52f19d7 100644 --- a/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp +++ b/Libraries/LibDebug/Dwarf/AbbreviationsMap.cpp @@ -29,7 +29,7 @@ #include <AK/Stream.h> -namespace Dwarf { +namespace Debug::Dwarf { AbbreviationsMap::AbbreviationsMap(const DwarfInfo& dwarf_info, u32 offset) : m_dwarf_info(dwarf_info) diff --git a/Libraries/LibDebug/Dwarf/AbbreviationsMap.h b/Libraries/LibDebug/Dwarf/AbbreviationsMap.h index 2067e74495..ce5da7408a 100644 --- a/Libraries/LibDebug/Dwarf/AbbreviationsMap.h +++ b/Libraries/LibDebug/Dwarf/AbbreviationsMap.h @@ -31,7 +31,7 @@ #include <AK/Optional.h> #include <AK/Types.h> -namespace Dwarf { +namespace Debug::Dwarf { class DwarfInfo; diff --git a/Libraries/LibDebug/Dwarf/CompilationUnit.cpp b/Libraries/LibDebug/Dwarf/CompilationUnit.cpp index c22f3f34cd..664d68e957 100644 --- a/Libraries/LibDebug/Dwarf/CompilationUnit.cpp +++ b/Libraries/LibDebug/Dwarf/CompilationUnit.cpp @@ -26,7 +26,7 @@ #include "CompilationUnit.h" #include "DIE.h" -namespace Dwarf { +namespace Debug::Dwarf { CompilationUnit::CompilationUnit(const DwarfInfo& dwarf_info, u32 offset, const CompilationUnitHeader& header) : m_dwarf_info(dwarf_info) diff --git a/Libraries/LibDebug/Dwarf/CompilationUnit.h b/Libraries/LibDebug/Dwarf/CompilationUnit.h index 09f185c2d9..811ce3bc37 100644 --- a/Libraries/LibDebug/Dwarf/CompilationUnit.h +++ b/Libraries/LibDebug/Dwarf/CompilationUnit.h @@ -29,7 +29,7 @@ #include "AbbreviationsMap.h" #include <AK/Types.h> -namespace Dwarf { +namespace Debug::Dwarf { class DwarfInfo; class DIE; diff --git a/Libraries/LibDebug/Dwarf/DIE.cpp b/Libraries/LibDebug/Dwarf/DIE.cpp index 90dbe3d9b1..be3f669d55 100644 --- a/Libraries/LibDebug/Dwarf/DIE.cpp +++ b/Libraries/LibDebug/Dwarf/DIE.cpp @@ -30,7 +30,7 @@ #include <AK/ByteBuffer.h> #include <AK/Stream.h> -namespace Dwarf { +namespace Debug::Dwarf { DIE::DIE(const CompilationUnit& unit, u32 offset) : m_compilation_unit(unit) diff --git a/Libraries/LibDebug/Dwarf/DIE.h b/Libraries/LibDebug/Dwarf/DIE.h index 2d2da9ea4f..713609b772 100644 --- a/Libraries/LibDebug/Dwarf/DIE.h +++ b/Libraries/LibDebug/Dwarf/DIE.h @@ -33,7 +33,7 @@ #include <AK/Optional.h> #include <AK/Types.h> -namespace Dwarf { +namespace Debug::Dwarf { class CompilationUnit; diff --git a/Libraries/LibDebug/Dwarf/DwarfInfo.cpp b/Libraries/LibDebug/Dwarf/DwarfInfo.cpp index ccf5d26e0b..32ee6d1944 100644 --- a/Libraries/LibDebug/Dwarf/DwarfInfo.cpp +++ b/Libraries/LibDebug/Dwarf/DwarfInfo.cpp @@ -28,7 +28,7 @@ #include <AK/Stream.h> -namespace Dwarf { +namespace Debug::Dwarf { DwarfInfo::DwarfInfo(NonnullRefPtr<const ELF::Loader> elf) : m_elf(elf) diff --git a/Libraries/LibDebug/Dwarf/DwarfInfo.h b/Libraries/LibDebug/Dwarf/DwarfInfo.h index 24263cbc4f..96dcd2ad5a 100644 --- a/Libraries/LibDebug/Dwarf/DwarfInfo.h +++ b/Libraries/LibDebug/Dwarf/DwarfInfo.h @@ -34,7 +34,7 @@ #include <AK/String.h> #include <LibELF/Loader.h> -namespace Dwarf { +namespace Debug::Dwarf { class DwarfInfo : public RefCounted<DwarfInfo> { public: diff --git a/Libraries/LibDebug/Dwarf/DwarfTypes.h b/Libraries/LibDebug/Dwarf/DwarfTypes.h index 2db11bf5d4..86304b067a 100644 --- a/Libraries/LibDebug/Dwarf/DwarfTypes.h +++ b/Libraries/LibDebug/Dwarf/DwarfTypes.h @@ -28,7 +28,7 @@ #include <AK/Types.h> -namespace Dwarf { +namespace Debug::Dwarf { struct [[gnu::packed]] CompilationUnitHeader { diff --git a/Libraries/LibDebug/Dwarf/Expression.cpp b/Libraries/LibDebug/Dwarf/Expression.cpp index a38b0fd2bd..57c4ac2857 100644 --- a/Libraries/LibDebug/Dwarf/Expression.cpp +++ b/Libraries/LibDebug/Dwarf/Expression.cpp @@ -29,7 +29,7 @@ #include <sys/arch/i386/regs.h> -namespace Dwarf::Expression { +namespace Debug::Dwarf::Expression { Value evaluate(ReadonlyBytes bytes, const PtraceRegisters& regs) { diff --git a/Libraries/LibDebug/Dwarf/Expression.h b/Libraries/LibDebug/Dwarf/Expression.h index de9463901d..fedc636c83 100644 --- a/Libraries/LibDebug/Dwarf/Expression.h +++ b/Libraries/LibDebug/Dwarf/Expression.h @@ -31,7 +31,7 @@ class PtraceRegisters; -namespace Dwarf::Expression { +namespace Debug::Dwarf::Expression { enum class Type { None, diff --git a/Libraries/LibDebug/Dwarf/LineProgram.cpp b/Libraries/LibDebug/Dwarf/LineProgram.cpp index 99a5fb7136..a47b174a4b 100644 --- a/Libraries/LibDebug/Dwarf/LineProgram.cpp +++ b/Libraries/LibDebug/Dwarf/LineProgram.cpp @@ -30,6 +30,8 @@ //#define DWARF_DEBUG +namespace Debug::Dwarf { + LineProgram::LineProgram(InputMemoryStream& stream) : m_stream(stream) { @@ -252,3 +254,5 @@ void LineProgram::run_program() } } } + +} diff --git a/Libraries/LibDebug/Dwarf/LineProgram.h b/Libraries/LibDebug/Dwarf/LineProgram.h index 092b2deba8..7bb2fa3d78 100644 --- a/Libraries/LibDebug/Dwarf/LineProgram.h +++ b/Libraries/LibDebug/Dwarf/LineProgram.h @@ -30,6 +30,8 @@ #include <AK/String.h> #include <AK/Vector.h> +namespace Debug::Dwarf { + class LineProgram { public: explicit LineProgram(InputMemoryStream& stream); @@ -55,8 +57,7 @@ private: void handle_standard_opcode(u8 opcode); void handle_sepcial_opcode(u8 opcode); - struct [[gnu::packed]] UnitHeader32 - { + struct [[gnu::packed]] UnitHeader32 { u32 length; u16 version; u32 header_length; @@ -113,3 +114,5 @@ private: Vector<LineInfo> m_lines; }; + +} diff --git a/Libraries/LibDebug/StackFrameUtils.cpp b/Libraries/LibDebug/StackFrameUtils.cpp index e85fce6754..6b68237924 100644 --- a/Libraries/LibDebug/StackFrameUtils.cpp +++ b/Libraries/LibDebug/StackFrameUtils.cpp @@ -26,7 +26,8 @@ #include "StackFrameUtils.h" -namespace StackFrameUtils { +namespace Debug::StackFrameUtils { + Optional<StackFrameInfo> get_info(const DebugSession& session, FlatPtr current_ebp) { auto return_address = session.peek(reinterpret_cast<u32*>(current_ebp + sizeof(FlatPtr))); @@ -37,4 +38,5 @@ Optional<StackFrameInfo> get_info(const DebugSession& session, FlatPtr current_e StackFrameInfo info = { return_address.value(), next_ebp.value() }; return info; } + } diff --git a/Libraries/LibDebug/StackFrameUtils.h b/Libraries/LibDebug/StackFrameUtils.h index 9948ee04a7..557992d79e 100644 --- a/Libraries/LibDebug/StackFrameUtils.h +++ b/Libraries/LibDebug/StackFrameUtils.h @@ -31,7 +31,8 @@ #include "LibDebug/DebugSession.h" -namespace StackFrameUtils { +namespace Debug::StackFrameUtils { + struct StackFrameInfo { FlatPtr return_address; FlatPtr next_ebp; diff --git a/Userland/functrace.cpp b/Userland/functrace.cpp index 97406fb08e..ca90717ec9 100644 --- a/Userland/functrace.cpp +++ b/Userland/functrace.cpp @@ -47,7 +47,7 @@ #include <string.h> #include <unistd.h> -static OwnPtr<DebugSession> g_debug_session; +static OwnPtr<Debug::DebugSession> g_debug_session; static bool g_should_output_color = false; static void handle_sigint(int) @@ -126,7 +126,7 @@ int main(int argc, char** argv) "program", Core::ArgsParser::Required::Yes); args_parser.parse(argc, argv); - auto result = DebugSession::exec_and_attach(command); + auto result = Debug::DebugSession::exec_and_attach(command); if (!result) { fprintf(stderr, "Failed to start debugging session for: \"%s\"\n", command); exit(1); @@ -143,29 +143,29 @@ int main(int argc, char** argv) size_t depth = 0; bool new_function = true; - g_debug_session->run([&](DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> regs) { - if (reason == DebugSession::DebugBreakReason::Exited) { + g_debug_session->run([&](Debug::DebugSession::DebugBreakReason reason, Optional<PtraceRegisters> regs) { + if (reason == Debug::DebugSession::DebugBreakReason::Exited) { printf("Program exited.\n"); - return DebugSession::DebugDecision::Detach; + return Debug::DebugSession::DebugDecision::Detach; } - if (reason == DebugSession::DebugBreakReason::Syscall) { + if (reason == Debug::DebugSession::DebugBreakReason::Syscall) { print_syscall(regs.value(), depth + 1); - return DebugSession::DebugDecision::ContinueBreakAtSyscall; + return Debug::DebugSession::DebugDecision::ContinueBreakAtSyscall; } if (new_function) { auto function_name = g_debug_session->elf().symbolicate(regs.value().eip); print_function_call(function_name, depth); new_function = false; - return DebugSession::ContinueBreakAtSyscall; + return Debug::DebugSession::ContinueBreakAtSyscall; } auto instruction = instrumented->get((void*)regs.value().eip).value(); if (instruction.mnemonic() == "RET") { if (depth != 0) --depth; - return DebugSession::ContinueBreakAtSyscall; + return Debug::DebugSession::ContinueBreakAtSyscall; } // FIXME: we could miss some leaf functions that were called with a jump @@ -174,6 +174,6 @@ int main(int argc, char** argv) ++depth; new_function = true; - return DebugSession::DebugDecision::SingleStep; + return Debug::DebugSession::DebugDecision::SingleStep; }); } |