mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain
Other
1.85k stars 180 forks source link

Tab completion in LLDB command line #286

Open alvinhochun opened 2 years ago

alvinhochun commented 2 years ago

It seems LLDB needs libedit for tab completion, which in turn also depends on curses. This is probably hard to integrate on Windows. Had anyone tried? Would it be easier now that Windows have opt-in support for VT sequences?

longnguyen2004 commented 2 years ago

Maybe we can bring in PDCursesMod, which has a Win32 API and VT implementation, and doesn't have any dependencies.

longnguyen2004 commented 2 years ago

For a no extra dependencies options: wineditline

SquallATF commented 2 years ago

For a no extra dependencies options: wineditline

winditline is not compatible with libedit's api https://github.com/llvm/llvm-project/blob/7207373e1eb0dd419b4e13a5e2d0ca146ef9544e/lldb/source/Host/common/Editline.cpp#L83-L91 PDCursesMod not support define_key which lldb needed. https://github.com/llvm/llvm-project/issues/51296 gui may be work with ncurses

longnguyen2004 commented 2 years ago

ncurses seems pretty heavyweight, so I'm not sure if @mstorsjo would be ok with that.

SquallATF commented 2 years ago

I tried to compile the gui interface using the PDCursesMod library via https://github.com/Bill-Gray/PDCursesMod/issues/214#issuecomment-926634755 . The interface looks ok but the Alt+Enter shortcut does not work, that shortcut key is used to switch full screen under windows. PDC_WIDE and PDC_FORCE_UTF8 is my custom curses build configure.I think lldb-vscode is better than gui. image

diff --git a/lldb/source/Core/IOHandlerCursesGUI.cpp b/lldb/source/Core/IOHandlerCursesGUI.cpp
index 0151255631bf..44d9a78d3923 100644
--- a/lldb/source/Core/IOHandlerCursesGUI.cpp
+++ b/lldb/source/Core/IOHandlerCursesGUI.cpp
@@ -14,6 +14,8 @@
 #include <ncurses/curses.h>
 #include <ncurses/panel.h>
 #else
+#define PDC_WIDE 1
+#define PDC_FORCE_UTF8 1
 #include <curses.h>
 #include <panel.h>
 #endif
@@ -91,8 +93,13 @@ using llvm::StringRef;
 #define KEY_ESCAPE 27
 #define KEY_DELETE 127

+#ifdef __PDCURSES__
+#define KEY_SHIFT_TAB KEY_BTAB
+#define KEY_ALT_ENTER ALT_ENTER
+#else /* for ncurses */
 #define KEY_SHIFT_TAB (KEY_MAX + 1)
 #define KEY_ALT_ENTER (KEY_MAX + 2)
+#endif

 namespace curses {
 class Menu;
@@ -7699,8 +7706,10 @@ void IOHandlerCursesGUI::Activate() {
     init_pair(18, COLOR_MAGENTA, COLOR_WHITE);
     static_assert(LastColorPairIndex == 18, "Color indexes do not match.");

+#ifndef __PDCURSES__
     define_key("\033[Z", KEY_SHIFT_TAB);
     define_key("\033\015", KEY_ALT_ENTER);
+#endif
   }
 }
cristianadam commented 2 years ago

Just as a side note: CMake is using now https://gitlab.kitware.com/cmake/cmake/-/tree/master/Utilities/cmpdcurses for ccmake on Windows.

SquallATF commented 2 years ago

windows terminal can config { "command": "null", "keys": "alt+enter" } to avoid Alt+Enter conflicting. It looks like all functions are working fine now.

longnguyen2004 commented 2 years ago

Just a heads up: This went from getting tab completion to work (which requires libedit + a curses implementation) to getting LLDB TUI mode to work 😅 But since @SquallATF already got that working, can you also test out libedit?

SquallATF commented 2 years ago

found some problems, form from Target and Process submenu not work will. image lldb on linux image Then I tested PDCurses and ncurses, the results of PDCurses and PDCursesMod are the same, and ncurses can display the form normally, but Shift+Tab and Alt+Enter shortcuts and backspace does not work image