diff --git a/src/backend/lldb/lldb_backend.cpp b/src/backend/lldb/lldb_backend.cpp index 6292d48..a6feed4 100644 --- a/src/backend/lldb/lldb_backend.cpp +++ b/src/backend/lldb/lldb_backend.cpp @@ -123,6 +123,8 @@ void LLDBBackend::handle_state_change(lldb::StateType state) } } + this->dump_threads(); + switch (state) { case eStateStopped: @@ -280,6 +282,63 @@ void LLDBBackend::dump_threads() if (sel.IsValid()) { printf("Selected Thread: %lu\n", sel.GetThreadID()); + + auto frame = sel.GetFrameAtIndex(0); + auto symctx = frame.GetSymbolContext(eSymbolContextEverything); + auto stream = SBStream{}; + symctx.GetDescription(stream); + + printf("Symctx: %.*s\n", static_cast(stream.GetSize()), + stream.GetData()); + + auto list = _target.FindTypes("test::MyType"); + printf("List len: %lu\n", list.GetSize()); + auto len = list.GetSize(); + for (uint32_t i = 0; i < len; ++i) + { + auto typ = list.GetTypeAtIndex(i); + stream.Clear(); + typ.GetDescription(stream, eDescriptionLevelFull); + + printf("Type %u: %.*s\n", i, static_cast(stream.GetSize()), + stream.GetData()); + } + + stream.Clear(); + auto sc = + frame.GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol); + + uint64_t start, end; + if (sc.GetFunction().IsValid()) + { + auto fn = sc.GetFunction(); + start = fn.GetStartAddress().GetLoadAddress(_target); + end = fn.GetEndAddress().GetLoadAddress(_target); + } else if (sc.GetSymbol().IsValid() + && sc.GetSymbol().GetStartAddress().IsValid()) + { + auto sym = sc.GetSymbol(); + start = sym.GetStartAddress().GetLoadAddress(_target); + end = sym.GetEndAddress().GetLoadAddress(_target); + } else + { + start = frame.GetPC(); + end = start + 0x100; + } + + auto buf = std::vector{}; + buf.resize(end - start); + auto err = SBError{}; + _target.ReadMemory(SBAddress{start, _target}, buf.data(), buf.size(), err); + + auto inst_list = + _target.GetInstructionsWithFlavor(start, "intel", buf.data(), buf.size()); + stream.Clear(); + inst_list.GetDescription(stream); + printf("InstList: %.*s\n", static_cast(stream.GetSize()), + stream.GetData()); + + //printf("Disasm: %s\n", frame.Disassemble()); } else { printf("Selected thread not valid\n"); diff --git a/src/data.h b/src/data.h new file mode 100644 index 0000000..0dd52dd --- /dev/null +++ b/src/data.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include + +namespace dbgui::data +{ + struct DataSource + { + enum class Type : uint8_t + { + reg, + // TODO: special IP/SP source? so that scope selection can apply to that? + // variable, + // const, + }; + + struct Reg + { + // TODO: identify through names? + uint16_t set; + uint16_t idx; + }; + + Type type; + std::variant data; + }; + + struct DataNode + { + size_t id; + }; + + struct DataResult + { + // TODO: needs indicator that data was failed to be retrieved + size_t id; + std::vector data; + }; + +} // namespace dbgui::data \ No newline at end of file diff --git a/src/frontend/frontend.cpp b/src/frontend/frontend.cpp index 719d46a..31ca95b 100644 --- a/src/frontend/frontend.cpp +++ b/src/frontend/frontend.cpp @@ -27,6 +27,16 @@ Frontend::Frontend() void Frontend::run_frame() { + if (_draw_metric_window) + { + ImGui::ShowMetricsWindow(); + } + + if (_draw_stack_tool) + { + ImGui::ShowStackToolWindow(); + } + this->handle_msgs(); this->draw_open_popup(); this->draw_header(); @@ -98,6 +108,13 @@ void Frontend::draw_header() } ImGui::EndMenu(); } + + if (ImGui::BeginMenu("Debug")) + { + ImGui::MenuItem("Metrics", nullptr, &_draw_metric_window); + ImGui::MenuItem("Stack Tool", nullptr, &_draw_stack_tool); + ImGui::EndMenu(); + } ImGui::EndMainMenuBar(); } diff --git a/src/frontend/frontend.h b/src/frontend/frontend.h index e1fe92f..7ada723 100644 --- a/src/frontend/frontend.h +++ b/src/frontend/frontend.h @@ -41,6 +41,9 @@ namespace dbgui::frontend bool _draw_second = false; + bool _draw_metric_window = false; + bool _draw_stack_tool = false; + bool _draw_open_popup = false; ImGuiID _open_popup_id = 0; std::vector _open_popup_name_buf = {}; diff --git a/src/frontend/window.cpp b/src/frontend/window.cpp index 3381bf5..3b9b5fd 100644 --- a/src/frontend/window.cpp +++ b/src/frontend/window.cpp @@ -88,6 +88,7 @@ void RegWindow::draw(const Frontend &frontend) continue; } + // TODO: formatting options switch (reg.bytes.size()) { case 1: std::snprintf(buf, sizeof(buf), "%X", reg.bytes[0]); break; @@ -109,7 +110,24 @@ void RegWindow::draw(const Frontend &frontend) default: std::snprintf(buf, sizeof(buf), ""); break; } + ImGui::PushID(set_idx * 1000 + i); ImGui::Text(buf); + if (ImGui::IsItemHovered() + && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) + { + ImGui::OpenPopup("Context"); + } + + if (ImGui::BeginPopup("Context")) + { + if (ImGui::Selectable("Copy")) + { + ImGui::SetClipboardText(buf); + } + ImGui::EndPopup(); + } + + ImGui::PopID(); } ImGui::EndTable(); } diff --git a/tmp/main b/tmp/main index b2fdb7c..d87e847 100755 Binary files a/tmp/main and b/tmp/main differ diff --git a/tmp/main.c b/tmp/main.c deleted file mode 100644 index 46d7524..0000000 --- a/tmp/main.c +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int main(int argc, char* argv[]) { - int tmp = 10; - while (tmp != 0) { - sleep(1); - tmp--; - } - return 0; -} diff --git a/tmp/main.cpp b/tmp/main.cpp new file mode 100644 index 0000000..d26ebb2 --- /dev/null +++ b/tmp/main.cpp @@ -0,0 +1,19 @@ +#include +#include + +namespace { + struct MyType { + int data; + }; +} + +void helper_fn(); + +int main(int argc, char* argv[]) { + MyType tmp = MyType{10}; + while (tmp.data != 0) { + helper_fn(); + tmp.data--; + } + return 0; +} diff --git a/tmp/sec.cpp b/tmp/sec.cpp new file mode 100644 index 0000000..44c18c5 --- /dev/null +++ b/tmp/sec.cpp @@ -0,0 +1,13 @@ +#include +#include + +namespace test { + struct MyType { + int data; + }; +} + +void helper_fn() { + test::MyType tmp = test::MyType{1}; + sleep(tmp.data); +}