Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print $var by clicking identifiers in the source window #141

Open
MaskRay opened this issue Aug 16, 2017 · 3 comments
Open

print $var by clicking identifiers in the source window #141

MaskRay opened this issue Aug 16, 2017 · 3 comments

Comments

@MaskRay
Copy link

MaskRay commented Aug 16, 2017

If will be very convenient to execute print $identifier_under_cursor whenever an identifier (the icing on the cake is to recognize x->y or x.y member access operators) is clicked in the source window.

Enabling mouse clicks in ncurses can be achieved with the following snippet. There is also a standalone example at https://bbs.archlinux.org/viewtopic.php?id=199959 .

diff --git c/lib/util/sys_win.cpp i/lib/util/sys_win.cpp
index 0034d80..1c6a1da 100644
--- c/lib/util/sys_win.cpp
+++ i/lib/util/sys_win.cpp
@@ -53,13 +53,17 @@ bool swin_start()
 {
     bool success = swin_set_escdelay();
     if (success) {
-        success = swin_initscr() != NULL;
+        SWINDOW *win = swin_initscr();
+        success = win != NULL;
         if (success) {
             if (swin_has_colors()) {
                 swin_start_color();
                 swin_use_default_colors();
             }
 
+            swin_keypad(win, 1);
+            mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
+
             swin_refresh();
         }

See what escape sequences are generated for mouse tracking:

echo -e "\e[?1000h\e[?1001h\e[?1002h"; cat
# See also https://stackoverflow.com/questions/5966903/how-to-get-mousemove-and-mouseclick-in-bash
# Mouse moving report can be used to display arbitrary selected expression

To obtain the cursor position is tricky, because cgdb employs io.cpp:io_getchar which uses read() on terminals instead of ncurses' getch(). The terminal escape sequences are kind of tricky to parse, especially there are at least 4 different terminal modes for mouse support: 1000 (legacy), 1005, 1006 (the best), 1015 (urxvt) http://invisible-island.net/xterm/ctlseqs/ctlseqs.html . ncurses has its ncurses/base/lib_mouse.c (which supports 1000, 1005, 1006 I think) to translate the escape sequence to a terminal position.

Another improvement is to have a cgdb command to communicate with an external script. The filename and the line number are given to the external script and it should send some gdb commands back which print relevant expressions. Say the cursor is at core->a = core->b + core->c;, i would like the external script to send p core->a; core->b; p core->c back. The external script does not need to be full-fledged parser and it certainly cannot be. But with some regex matching, it could be very useful to give context in many cases.

@XVilka
Copy link

XVilka commented Aug 16, 2017

@brasko
Copy link
Contributor

brasko commented Oct 6, 2017

This is a pretty neat idea, I must admit. I'm not sure I personally have the time to work on
this at the moment. However, if you are interested, I could work out some ideas that we
find in common and could aid you along in adding this support.

@MaskRay
Copy link
Author

MaskRay commented Oct 26, 2017

LGTM! I'll delve into the source code for some days to understand how it works first...

MaskRay added a commit to MaskRay/cgdb that referenced this issue May 10, 2024
horizontal scrolling is supported but the cursor cannot move freely in the source window. A simple and dirty implementation of cgdb#141 is to add a key binding (say p) to print the identifier at the cursor.

However, the old max_width disallows horizontal scrolling when the longest line can be displayed in one screen. Loosen the restriction to make cursor being able to move to any identifier.

Eventually the free movement of cursor should be implemented.

Signed-off-by: Fangrui Song <i@maskray.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants