aboutsummaryrefslogtreecommitdiff
path: root/tdbg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdbg.cpp')
-rw-r--r--tdbg.cpp56
1 files changed, 53 insertions, 3 deletions
diff --git a/tdbg.cpp b/tdbg.cpp
index 1ac21f7..08b47f4 100644
--- a/tdbg.cpp
+++ b/tdbg.cpp
@@ -33,7 +33,8 @@ enum InputMode {
33 INPUT_MODE_NORMAL, 33 INPUT_MODE_NORMAL,
34 INPUT_MODE_BREAKPOINT, 34 INPUT_MODE_BREAKPOINT,
35 INPUT_MODE_VARIABLE, 35 INPUT_MODE_VARIABLE,
36 INPUT_MODE_WATCH 36 INPUT_MODE_WATCH,
37 INPUT_MODE_HELP
37}; 38};
38 39
39struct LLDBGuard { 40struct LLDBGuard {
@@ -647,6 +648,47 @@ void draw_log_view(int x, int y, int w, int h, const std::vector<std::string>& l
647 } 648 }
648} 649}
649 650
651void draw_help_view(int width, int height) {
652 int w = 60;
653 int h = 18;
654 int x = (width - w) / 2;
655 int y = (height - h) / 2;
656
657 // Fill background
658 for (int i = 0; i < h; ++i) {
659 for (int j = 0; j < w; ++j) {
660 tb_set_cell(x + j, y + i, ' ', TB_DEFAULT, TB_DEFAULT);
661 }
662 }
663
664 draw_box(x, y, w, h, "Help / Keybinds");
665
666 int ty = y + 2;
667 int tx = x + 3;
668
669 auto d = [&](const std::string& key, const std::string& desc) {
670 draw_text(tx, ty, TB_YELLOW | TB_BOLD, TB_DEFAULT, key);
671 draw_text(tx + 13, ty, TB_DEFAULT, TB_DEFAULT, desc);
672 ty++;
673 };
674
675 d("r", "Run / Launch program");
676 d("b", "Add breakpoint (file:line or func)");
677 d("p", "Print variable / Evaluate expr");
678 d("w", "Add watch expression");
679 d("n", "Step Over (next line)");
680 d("s", "Step Into (into function)");
681 d("o", "Step Out (to caller)");
682 d("c", "Continue execution");
683 d("h", "Toggle help window");
684 d("q", "Quit debugger");
685 d("Esc", "Cancel input / Close help");
686 d("Ctrl+Arrows", "Resize layout");
687 d("Mouse Wheel", "Scroll active window");
688
689 draw_text(x + (w - 24) / 2, y + h - 2, TB_BLACK, TB_WHITE, " Press any key to close ");
690}
691
650void draw_status_bar(SBProcess &process, InputMode mode, int width, int height) { 692void draw_status_bar(SBProcess &process, InputMode mode, int width, int height) {
651 std::string state_str = "Status: "; 693 std::string state_str = "Status: ";
652 if (!process.IsValid()) { 694 if (!process.IsValid()) {
@@ -660,8 +702,8 @@ void draw_status_bar(SBProcess &process, InputMode mode, int width, int height)
660 } 702 }
661 703
662 state_str += (mode == INPUT_MODE_NORMAL) 704 state_str += (mode == INPUT_MODE_NORMAL)
663 ? " | r=Run, b=Add breakpoint, p=Print, w=Watch, n=Step Over, s=Step Into, o=Step Out, c=Continue, Ctrl+Arrows=Resize, q=Quit" 705 ? " | r=Run, b=Add bp, p=Print, w=Watch, n=Step, s=Step In, o=Step Out, c=Cont, h=Help, q=Quit"
664 : " | Enter=Confirm, Esc=Cancel"; 706 : (mode == INPUT_MODE_HELP ? " | Press any key to close help" : " | Enter=Confirm, Esc=Cancel");
665 707
666 for (int x = 0; x < width; ++x) { 708 for (int x = 0; x < width; ++x) {
667 tb_set_cell(x, height - 1, ' ', TB_BLACK, TB_WHITE); 709 tb_set_cell(x, height - 1, ' ', TB_BLACK, TB_WHITE);
@@ -793,6 +835,10 @@ int main(int argc, char** argv) {
793 draw_breakpoints_view(target, split_x, main_window_height, layout_config.sidebar_width, layout_config.log_height); 835 draw_breakpoints_view(target, split_x, main_window_height, layout_config.sidebar_width, layout_config.log_height);
794 draw_status_bar(process, mode, width, height); 836 draw_status_bar(process, mode, width, height);
795 837
838 if (mode == INPUT_MODE_HELP) {
839 draw_help_view(width, height);
840 }
841
796 tb_present(); 842 tb_present();
797 843
798 struct tb_event ev; 844 struct tb_event ev;
@@ -859,6 +905,8 @@ int main(int argc, char** argv) {
859 } else if (ev.ch == 'w') { 905 } else if (ev.ch == 'w') {
860 mode = INPUT_MODE_WATCH; 906 mode = INPUT_MODE_WATCH;
861 input_buffer.clear(); 907 input_buffer.clear();
908 } else if (ev.ch == 'h') {
909 mode = INPUT_MODE_HELP;
862 } else { 910 } else {
863 if (process.IsValid() && process.GetState() == eStateStopped) { 911 if (process.IsValid() && process.GetState() == eStateStopped) {
864 switch (ev.ch) { 912 switch (ev.ch) {
@@ -920,6 +968,8 @@ int main(int argc, char** argv) {
920 } else if (ev.ch != 0) { 968 } else if (ev.ch != 0) {
921 input_buffer += (char)ev.ch; 969 input_buffer += (char)ev.ch;
922 } 970 }
971 } else if (mode == INPUT_MODE_HELP) {
972 mode = INPUT_MODE_NORMAL;
923 } 973 }
924 } else if (ev.type == TB_EVENT_MOUSE) { 974 } else if (ev.type == TB_EVENT_MOUSE) {
925 int main_window_height = tb_height() - layout_config.log_height - layout_config.status_height; 975 int main_window_height = tb_height() - layout_config.log_height - layout_config.status_height;