diff --git a/.clang-format b/.clang-format index e7de6a6..af5dcc6 100644 --- a/.clang-format +++ b/.clang-format @@ -83,6 +83,4 @@ SpacesInSquareBrackets: 'false' Standard: Cpp11 TabWidth: '2' UseTab: ForIndentation -CommentPragmas: '^\\.+' - -... \ No newline at end of file +CommentPragmas: '^\\.+' \ No newline at end of file diff --git a/src/backend/lldb/lldb_backend.cpp b/src/backend/lldb/lldb_backend.cpp index a9be681..d672288 100644 --- a/src/backend/lldb/lldb_backend.cpp +++ b/src/backend/lldb/lldb_backend.cpp @@ -30,9 +30,10 @@ namespace LLDBBackend::~LLDBBackend() {} -LLDBBackend::LLDBBackend(std::string filename) +LLDBBackend::LLDBBackend(std::string filename, bool stop_at_entry) { - _filename = filename; + _filename = filename; + _stop_at_entry = stop_at_entry; char buf[256]; buf[0] = '\0'; pthread_getname_np(pthread_self(), buf, sizeof(buf)); @@ -60,11 +61,21 @@ void LLDBBackend::start() } _process = _target.Launch(listener, argv, nullptr, nullptr, nullptr, nullptr, cwd.c_str(), lldb::LaunchFlags::eLaunchFlagNone, - true, error); + _stop_at_entry, error); { pthread_setname_np(pthread_self(), buf); } + if (!_stop_at_entry) + { + // Create a breakpoint at main + auto bp = _target.BreakpointCreateByName("main"); + if (!bp.IsValid()) + { + spdlog::warn("Failed to create breakpoint for main"); + } + } + _msg_thread = std::thread{[this]() { auto ptr = this->shared_from_this(); static_cast(ptr.get())->run_msg_loop(); diff --git a/src/backend/lldb/lldb_backend.h b/src/backend/lldb/lldb_backend.h index bfd78d9..5401f46 100644 --- a/src/backend/lldb/lldb_backend.h +++ b/src/backend/lldb/lldb_backend.h @@ -90,7 +90,7 @@ namespace dbgui::backend }; // TODO: source_init_file: false - LLDBBackend(std::string filename); + LLDBBackend(std::string filename, bool stop_at_entry); virtual ~LLDBBackend(); void start() override; @@ -162,6 +162,7 @@ namespace dbgui::backend // process state bool _first_run = true; + bool _stop_at_entry = false; TargetState _state = TargetState::stopped; std::vector _reg_sets = {}; std::vector _threads = {}; diff --git a/src/frontend/frontend.cpp b/src/frontend/frontend.cpp index f0b119a..56353ae 100644 --- a/src/frontend/frontend.cpp +++ b/src/frontend/frontend.cpp @@ -9,12 +9,13 @@ using namespace dbgui; using namespace dbgui::frontend; -Target::Target(std::string filename) +Target::Target(std::string filename, bool stop_at_entry) { state = TargetState::startup; this->filename = filename; id = 0; - backend = std::make_shared(this->filename.c_str()); + backend = std::make_shared(this->filename.c_str(), + stop_at_entry); } Frontend::Frontend() @@ -43,6 +44,11 @@ void Frontend::run_frame() ImGui::ShowStackToolWindow(); } + if (_draw_demo_window) + { + ImGui::ShowDemoWindow(); + } + this->handle_msgs(); this->draw_open_popup(); this->draw_header(); @@ -154,6 +160,7 @@ void Frontend::draw_header() { ImGui::MenuItem("Metrics", nullptr, &_draw_metric_window); ImGui::MenuItem("Stack Tool", nullptr, &_draw_stack_tool); + ImGui::MenuItem("Demo Window", nullptr, &_draw_demo_window); ImGui::EndMenu(); } ImGui::EndMainMenuBar(); @@ -314,10 +321,13 @@ void Frontend::draw_open_popup() if (ImGui::Button("Start")) { - this->target = Target{_open_popup_name_buf.data()}; + this->target = + Target{_open_popup_name_buf.data(), _open_popup_stop_at_entry}; this->target->backend->start(); ImGui::CloseCurrentPopup(); } + + ImGui::Checkbox("Stop at _start", &_open_popup_stop_at_entry); ImGui::EndPopup(); } } diff --git a/src/frontend/frontend.h b/src/frontend/frontend.h index 64f4431..f339d79 100644 --- a/src/frontend/frontend.h +++ b/src/frontend/frontend.h @@ -44,10 +44,12 @@ namespace dbgui::frontend bool _draw_metric_window = false; bool _draw_stack_tool = false; + bool _draw_demo_window = false; bool _draw_open_popup = false; ImGuiID _open_popup_id = 0; std::vector _open_popup_name_buf = {}; + bool _open_popup_stop_at_entry = false; std::vector _windows = {}; }; diff --git a/src/frontend/target.h b/src/frontend/target.h index 790831d..5d39dd4 100644 --- a/src/frontend/target.h +++ b/src/frontend/target.h @@ -87,7 +87,7 @@ namespace dbgui::frontend bool is_cstr = false; }; - Target(std::string filename); + Target(std::string filename, bool stop_at_entry); std::optional data_idx_for_src_id(size_t id) { diff --git a/src/frontend/window.cpp b/src/frontend/window.cpp index 17fd2a7..7558ae4 100644 --- a/src/frontend/window.cpp +++ b/src/frontend/window.cpp @@ -908,6 +908,8 @@ bool SourceWindow::draw(Frontend &frontend) ImGui::GetWindowDrawList()->AddTriangleFilled( pos, p2, p3, IM_COL32(227, 197, 103, 255)); + ImGui::TableSetBgColor(ImGuiTableBgTarget_RowBg0, + ImGui::GetColorU32(ImVec4(1.f, 1.f, 1.f, 0.2f))); } // TODO: write custom code to catch mouse clicks in the whole cell, including padding @@ -1374,7 +1376,8 @@ void WatchWindow::draw_value(Frontend &frontend, } expr_path.push_back(ExprPathPart{ - .ident = std::string_view{name_begin, name_end - name_begin}, + .ident = std::string_view{name_begin, static_cast( + name_end - name_begin)}, .deref = false}); this->draw_value(frontend, member.type_id, member.name, node_idx, off + member.offset, expr_path); @@ -1390,7 +1393,8 @@ void WatchWindow::draw_value(Frontend &frontend, frontend.target->types[type_id.idx].byte_size / member_size; expr_path.push_back(ExprPathPart{ - .ident = std::string_view{name_begin, name_end - name_begin}, + .ident = std::string_view{name_begin, + static_cast(name_end - name_begin)}, .array = true}); char buf[32]; diff --git a/tmp/main b/tmp/main index b19ca1a..b08b16b 100755 Binary files a/tmp/main and b/tmp/main differ diff --git a/watchsyntax.txt b/watchsyntax.txt new file mode 100644 index 0000000..e69de29