puremourning / vimspector

vimspector - A multi-language debugging system for Vim
http://puremourning.github.io/vimspector-web
Apache License 2.0
4.08k stars 171 forks source link

Incorrect Thread status in multithread debug #865

Closed gagara closed 3 months ago

gagara commented 3 months ago

Description

When we have breakpoints in different threads (which leads to 2 Threads to be paused) after stepping in one thread, the status of second is "lost", i.e. it became (running) and no stack trace is available for it.

Is it reproducible in vim?

Reproducible in Vim

Works with clean config?

No

Sample project works?

Not reproducible with sample project

Minimal Reproduction

Sample java code to reproduce:

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DebugTest {

    private static ExecutorService es = Executors.newFixedThreadPool(1);

    public static void main(String[] args) {
        System.out.println("Hello world"); // << breakpoint 1
        es.submit(() -> {
            System.out.println("task1"); // << breakpoint 2
        });
        System.out.println("Bye world");
    }
}

Two breakpoints are set.

From the start debugger will stop at "breakpoint 1". This will show as "Thread 1 (paused)" -- Correct After StepOver we stop at "breakpoint 2". This will be new "Thread 11 (paused)" -- Correct After several StepOver-s in Thread 11 it is finished, the output of program:

Hello world
task1

all threads (including Thread 1) are in running state. no stack trace for Thread 1 is available. Executing StepOver, Coninue does nothing. In fact program is paused in last line.

If we explicitly focus Thread 1 (<leader><CR>) then we can continue stepping in Thread 1 correctly.

Expected Behaviour

Thread 1 should have (paused) status with respective stack trace after returning from another Thread 11.

Actual Behaviour

Status of Thread 1 is (running), no stack trace is available for it. It is not possible to continue program debug with "Continue", "StepOver", etc

Additional information

No response

Installation Type

Plugin Manager (git clone)

Vimspector version

c37d50fc463013bdad2ba044615b0bc2ce163681

Debug Info

Vimspector Debug Info
--------------------------------------------------------------------------------
ConnectionType: channel
Adapter: 
--------------------------------------------------------------------------------
{
  "configuration": {
    "cwd": "/home/slg"
  },
  "custom_handler": "vimspector.custom.java.JavaDebugAdapter",
  "name": "vscode-java",
  "port": "34947",
  "env": {},
  "cwd": "/home/slg"
}
--------------------------------------------------------------------------------
Configuration: 
--------------------------------------------------------------------------------
{
  "breakpoints": {
    "exception": {
      "uncaught": "N",
      "caught": "N"
    }
  },
  "configuration": {
    "projectName": "",
    "vmArgs": " --enable-preview -XX:+ShowCodeDetailsInExceptionMessages",
    "classPathString": "/home/slg/.config/coc/extensions/coc-java-data/jdt_ws_6f3da6e7a4a533c373f1e7258de46d7d/jdt.ls-java-project/bin",
    "console": "externalTerminal",
    "shortenCommandLine": "none",
    "name": "CodeLens (Launch) - DebugTest",
    "modulePaths": [],
    "type": "java",
    "mainClass": "DebugTest",
    "request": "launch",
    "classPaths": [
      "/home/slg/.config/coc/extensions/coc-java-data/jdt_ws_6f3da6e7a4a533c373f1e7258de46d7d/jdt.ls-java-project/bin"
    ],
    "javaExec": "/opt/openjdk-bin-21/bin/java"
  },
  "adapter": "vscode-java"
}
--------------------------------------------------------------------------------
API Prefix: 
Launch/Init: True / True
Workspace Root: /home/slg
Launch Config: 
--------------------------------------------------------------------------------
{
  "cwd": "/home/slg",
  "projectName": "",
  "vmArgs": " --enable-preview -XX:+ShowCodeDetailsInExceptionMessages",
  "classPathString": "/home/slg/.config/coc/extensions/coc-java-data/jdt_ws_6f3da6e7a4a533c373f1e7258de46d7d/jdt.ls-java-project/bin",
  "console": "externalTerminal",
  "shortenCommandLine": "none",
  "name": "CodeLens (Launch) - DebugTest",
  "modulePaths": [],
  "type": "java",
  "mainClass": "DebugTest",
  "request": "launch",
  "classPaths": [
    "/home/slg/.config/coc/extensions/coc-java-data/jdt_ws_6f3da6e7a4a533c373f1e7258de46d7d/jdt.ls-java-project/bin"
  ],
  "javaExec": "/opt/openjdk-bin-21/bin/java"
}
--------------------------------------------------------------------------------
Server Capabilities: 
--------------------------------------------------------------------------------
{
  "supportsConfigurationDoneRequest": true,
  "supportsHitConditionalBreakpoints": true,
  "supportsConditionalBreakpoints": true,
  "supportsEvaluateForHovers": true,
  "supportsCompletionsRequest": true,
  "supportsRestartFrame": true,
  "supportsSetVariable": true,
  "supportsRestartRequest": false,
  "supportTerminateDebuggee": true,
  "supportsDelayedStackTraceLoading": false,
  "supportsLogPoints": true,
  "supportsExceptionInfoRequest": true,
  "exceptionBreakpointFilters": [
    {
      "label": "Uncaught Exceptions",
      "filter": "uncaught"
    },
    {
      "label": "Caught Exceptions",
      "filter": "caught"
    }
  ],
  "supportsDataBreakpoints": true,
  "supportsClipboardContext": true
}
--------------------------------------------------------------------------------
Line Breakpoints: 
--------------------------------------------------------------------------------
{
  "/home/slg/DebugTest.java": [
    {
      "state": "ENABLED",
      "line": 9,
      "options": {},
      "is_instruction_breakpoint": null,
      "sign_id": 1,
      "server_bp": {
        "0": {
          "id": 1,
          "verified": true,
          "line": 9,
          "message": ""
        }
      }
    },
    {
      "state": "ENABLED",
      "line": 11,
      "options": {},
      "is_instruction_breakpoint": null,
      "sign_id": 2,
      "server_bp": {
        "0": {
          "id": 2,
          "verified": true,
          "line": 11,
          "message": ""
        }
      }
    }
  ]
}
--------------------------------------------------------------------------------
Func Breakpoints: 
--------------------------------------------------------------------------------
[]
--------------------------------------------------------------------------------
Ex Breakpoints: 
--------------------------------------------------------------------------------
{
  "filters": []
}
--------------------------------------------------------------------------------

Log file

No response

Vim version

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Apr 10 2024 13:40:49)
Included patches: 1-2167
Modified by Gentoo-9.0.2167 (RIP Bram)
Compiled by slg@localhost
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        -terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3           +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
-cscope            +localmap          -ruby              +wildignore
+cursorbind        -lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            +X11
+digraphs          +mouse             +sound             +xattr
-dnd               -mouseshape        +spell             +xfontset
-ebcdic            +mouse_dec         +startuptime       -xim
+emacs_tags        +mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      +xsmp_interact
+ex_extra          +mouse_netterm     +syntax            +xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static    
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: x86_64-pc-linux-gnu-gcc -c -I. -Iproto -DHAVE_CONFIG_H -march=native -O2 -pipe -fomit-frame-pointer -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
Linking: x86_64-pc-linux-gnu-gcc -Wl,--as-needed -L/usr/local/lib -o vim -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lelf -lcanberra -lsodium -lacl -lattr -lgpm -lpython3.11 -ldl -lm

Python version

No response

Neovim diagnostics

No response

Operating System

Linux desna 6.8.4-gentoo-x86_64 #1 SMP PREEMPT_DYNAMIC Mon Apr 8 18:28:35 EEST 2024 x86_64 Intel(R) Core(TM) i5-4210M CPU @ 2.60GHz GenuineIntel GNU/Linux

Declaration

gagara commented 3 months ago

Log file .vimspector.log

puremourning commented 3 months ago

There is some quirk with multi-thread debugging. DAP has this notion of "all threads stopped" and some adapters continue all threads on step, some only the focussed thread. I vaguely recall that I put something in for single stepping within a thread, but I don't quite remember. I'll have to take a look..

Thanks for the repro case, I'll see if I can repro.

sorry for the delay.

puremourning commented 3 months ago

Thanks I can repro. Not totally sure if this is a vimspector bug or a java debug adapter bug, but I can certainly repro weirdness.

puremourning commented 3 months ago

Hey @gagara can you test patch https://github.com/puremourning/vimspector/pull/867 ?

gagara commented 3 months ago

Works as expected. Many thanks!