fix compile, fix clang-format, add demo window debug setting, add setting to stop at entry or go to main directly

This commit is contained in:
T0b1
2024-05-03 02:19:47 +02:00
parent d4e4fc8c5a
commit 608cec26b1
9 changed files with 39 additions and 13 deletions

View File

@@ -83,6 +83,4 @@ SpacesInSquareBrackets: 'false'
Standard: Cpp11 Standard: Cpp11
TabWidth: '2' TabWidth: '2'
UseTab: ForIndentation UseTab: ForIndentation
CommentPragmas: '^\\.+' CommentPragmas: '^\\.+'
...

View File

@@ -30,9 +30,10 @@ namespace
LLDBBackend::~LLDBBackend() {} 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]; char buf[256];
buf[0] = '\0'; buf[0] = '\0';
pthread_getname_np(pthread_self(), buf, sizeof(buf)); pthread_getname_np(pthread_self(), buf, sizeof(buf));
@@ -60,11 +61,21 @@ void LLDBBackend::start()
} }
_process = _target.Launch(listener, argv, nullptr, nullptr, nullptr, nullptr, _process = _target.Launch(listener, argv, nullptr, nullptr, nullptr, nullptr,
cwd.c_str(), lldb::LaunchFlags::eLaunchFlagNone, cwd.c_str(), lldb::LaunchFlags::eLaunchFlagNone,
true, error); _stop_at_entry, error);
{ {
pthread_setname_np(pthread_self(), buf); 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]() { _msg_thread = std::thread{[this]() {
auto ptr = this->shared_from_this(); auto ptr = this->shared_from_this();
static_cast<LLDBBackend *>(ptr.get())->run_msg_loop(); static_cast<LLDBBackend *>(ptr.get())->run_msg_loop();

View File

@@ -90,7 +90,7 @@ namespace dbgui::backend
}; };
// TODO: source_init_file: false // TODO: source_init_file: false
LLDBBackend(std::string filename); LLDBBackend(std::string filename, bool stop_at_entry);
virtual ~LLDBBackend(); virtual ~LLDBBackend();
void start() override; void start() override;
@@ -162,6 +162,7 @@ namespace dbgui::backend
// process state // process state
bool _first_run = true; bool _first_run = true;
bool _stop_at_entry = false;
TargetState _state = TargetState::stopped; TargetState _state = TargetState::stopped;
std::vector<RegSet> _reg_sets = {}; std::vector<RegSet> _reg_sets = {};
std::vector<Thread> _threads = {}; std::vector<Thread> _threads = {};

View File

@@ -9,12 +9,13 @@
using namespace dbgui; using namespace dbgui;
using namespace dbgui::frontend; using namespace dbgui::frontend;
Target::Target(std::string filename) Target::Target(std::string filename, bool stop_at_entry)
{ {
state = TargetState::startup; state = TargetState::startup;
this->filename = filename; this->filename = filename;
id = 0; id = 0;
backend = std::make_shared<backend::LLDBBackend>(this->filename.c_str()); backend = std::make_shared<backend::LLDBBackend>(this->filename.c_str(),
stop_at_entry);
} }
Frontend::Frontend() Frontend::Frontend()
@@ -43,6 +44,11 @@ void Frontend::run_frame()
ImGui::ShowStackToolWindow(); ImGui::ShowStackToolWindow();
} }
if (_draw_demo_window)
{
ImGui::ShowDemoWindow();
}
this->handle_msgs(); this->handle_msgs();
this->draw_open_popup(); this->draw_open_popup();
this->draw_header(); this->draw_header();
@@ -154,6 +160,7 @@ void Frontend::draw_header()
{ {
ImGui::MenuItem("Metrics", nullptr, &_draw_metric_window); ImGui::MenuItem("Metrics", nullptr, &_draw_metric_window);
ImGui::MenuItem("Stack Tool", nullptr, &_draw_stack_tool); ImGui::MenuItem("Stack Tool", nullptr, &_draw_stack_tool);
ImGui::MenuItem("Demo Window", nullptr, &_draw_demo_window);
ImGui::EndMenu(); ImGui::EndMenu();
} }
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
@@ -314,10 +321,13 @@ void Frontend::draw_open_popup()
if (ImGui::Button("Start")) 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(); this->target->backend->start();
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::Checkbox("Stop at _start", &_open_popup_stop_at_entry);
ImGui::EndPopup(); ImGui::EndPopup();
} }
} }

View File

@@ -44,10 +44,12 @@ namespace dbgui::frontend
bool _draw_metric_window = false; bool _draw_metric_window = false;
bool _draw_stack_tool = false; bool _draw_stack_tool = false;
bool _draw_demo_window = false;
bool _draw_open_popup = false; bool _draw_open_popup = false;
ImGuiID _open_popup_id = 0; ImGuiID _open_popup_id = 0;
std::vector<char> _open_popup_name_buf = {}; std::vector<char> _open_popup_name_buf = {};
bool _open_popup_stop_at_entry = false;
std::vector<Window> _windows = {}; std::vector<Window> _windows = {};
}; };

View File

@@ -87,7 +87,7 @@ namespace dbgui::frontend
bool is_cstr = false; bool is_cstr = false;
}; };
Target(std::string filename); Target(std::string filename, bool stop_at_entry);
std::optional<uint16_t> data_idx_for_src_id(size_t id) std::optional<uint16_t> data_idx_for_src_id(size_t id)
{ {

View File

@@ -908,6 +908,8 @@ bool SourceWindow::draw(Frontend &frontend)
ImGui::GetWindowDrawList()->AddTriangleFilled( ImGui::GetWindowDrawList()->AddTriangleFilled(
pos, p2, p3, IM_COL32(227, 197, 103, 255)); 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 // 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{ expr_path.push_back(ExprPathPart{
.ident = std::string_view{name_begin, name_end - name_begin}, .ident = std::string_view{name_begin, static_cast<size_t>(
name_end - name_begin)},
.deref = false}); .deref = false});
this->draw_value(frontend, member.type_id, member.name, node_idx, this->draw_value(frontend, member.type_id, member.name, node_idx,
off + member.offset, expr_path); 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; frontend.target->types[type_id.idx].byte_size / member_size;
expr_path.push_back(ExprPathPart{ expr_path.push_back(ExprPathPart{
.ident = std::string_view{name_begin, name_end - name_begin}, .ident = std::string_view{name_begin,
static_cast<size_t>(name_end - name_begin)},
.array = true}); .array = true});
char buf[32]; char buf[32];

BIN
tmp/main

Binary file not shown.

0
watchsyntax.txt Normal file
View File