vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.8k stars 2.16k forks source link

Hot reload not working on Windows with MSVC #6936

Open MangelMaxime opened 3 years ago

MangelMaxime commented 3 years ago

V version: V 0.1.29 9fbf38c OS: Windows 10

What did you do?

I run the following program with v -live run message.v

module main

import time

[live]
fn print_message() {
    println('Hello! Modify this message while the program is running.')
}

fn main() {
    for {
        print_message()
        time.sleep_ms(500)
    }
}

What did you expect to see?

Program should start with hot reload support.

What did you see instead?

$ ./message.exe 
>       compilation cmd: C:\Users\Maxime\Workspaces\Github\vlang\v\v.exe -cc msvc  -sharedlive -shared -o C:\\Users\\Maxime\\.cache/tmp.1.message message.v
compilation took: 855ms
> compile_and_reload_shared_lib compiled: C:\\Users\\Maxime\\.cache/tmp.1.message.dll
live mutex locking...
live mutex locked
> load_lib OK, new live_lib: 00007FFB6A340000
live mutex unlocking...
live mutex unlocked
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
Segmentation fault

There is another issue labeled "Hot reload on windows" https://github.com/vlang/v/issues/3548 but as I don't have the same error I created a new one.

JalonSolov commented 3 years ago

I get a different error with latest V:

PS D:\> v -live run foo.v
>       compilation cmd: D:\git\v\v.exe   -sharedlive -shared -o C:\\Users\\jalon\\.cache/tmp.1.foo foo.v
compilation took: 1534ms
new_lib_path: C:\\Users\\jalon\\.cache/tmp.1.foo.dll does not exist
errors while compiling foo.v
PS D:\>
larpon commented 3 years ago

Those paths look completely off

heronwr commented 3 years ago

The errors in Jalon's example seem to be caused by gcc/tcc building incorrect shared library on windows(.so instead of .dll), which have since been fixed, see https://github.com/vlang/v/issues/6940. I am not sure what caused the segfault though, could you verify on the latest build?

JalonSolov commented 3 years ago

Correct. It runs fine for me now, with latest V 0.1.29 e03ae19 using this gcc:

gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 10.2.0

MangelMaxime commented 3 years ago

Hello @heronwr , I just upgraded to the latest version of v using v up and I have the same result:

PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> v version
V 0.1.29 e03ae19
PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> v -live run .\message.v
>       compilation cmd: C:\Users\Maxime\Documents\Workspace\Github\vlang\v\v.exe -cc msvc  -sharedlive -shared -o C:\\Users\\Maxime\\.cache/tmp.1.message .\message.v
compilation took: 653ms
> compile_and_reload_shared_lib compiled: C:\\Users\\Maxime\\.cache/tmp.1.message.dll
live mutex locking...
live mutex locked
> load_lib OK, new live_lib: 00007FFE24990000
live mutex unlocking...
live mutex unlocked
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live>
MangelMaxime commented 3 years ago

I also tested -live using gcc

PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> gcc --version
gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 10.2.0

Live is working with -cc gcc with a a small bug, there is no newline added at the end of each messages:

PS C:\Users\Maxime\Documents\Workspace\Github\MangelMaxime\learning_v\test_live> v -live -cc gcc run .\message.v
>       compilation cmd: C:\Users\Maxime\Documents\Workspace\Github\vlang\v\v.exe   -sharedlive -shared -o C:\\Users\\Maxime\\.cache/tmp.1.message .\message.v
compilation took: 2099ms
> compile_and_reload_shared_lib compiled: C:\\Users\\Maxime\\.cache/tmp.1.message.dll
live mutex locking...
live mutex locked
> load_lib OK, new live_lib: 0000000068100000
live mutex unlocking...
live mutex unlocked
Hello! Modify this message while the program is running.Hello! Modify this message while the program is running.Hello! Modify this message while the program is running.^C

If I run the v -cc gcc run message.v it does add the new lines.

In summary:

danieldaeschle commented 3 years ago
➜  v git:(master) ✗ v -cc msvc -live run main.v
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
andorxornot commented 3 years ago

I confirm, the hot reload does not work

v from master:

  1. v -cc mscv -live run .\examples\hot_reload\message.v produce: Unhandled Exception 0xC0000005 / C.CaptureStackBackTrace returned less than 2 frames

  2. v -cc gcc -live run .\examples\hot_reload\message.v produce: TCC/BCHECK: Error: function '__bt_init()' not found in executable. (Need -bt or -b for linking the exe.)

andorxornot commented 2 years ago

still the same

felixf4xu commented 1 year ago

update in 2023: gcc works:

D:\github\v_test>v -g -cc gcc -live run src\main.v Please Modify this message while the program is running. Please Modify this message while the program is running. Please Modify this message while the program is running. Please Modify this message while the program is running.

msvc does not work:

D:\github\v_test>v -g -cc msvc -live run src\main.v Unhandled Exception 0xC0000005 C.CaptureStackBackTrace returned less than 2 frames signal 11: segmentation fault 6 : v_segmentation_fault_handler D:\github\v\vlib\builtin\builtin.c.v:26 5 : seh_filter_exe ?? : address = 0x21f44fbb350 4 : __scrt_common_main_seh'::1'::filt$0 D:\a_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304 3 : _C_specific_handler ?? : address = 0x21f44fbb620 2 : _chkstk ?? : address = 0x21f44fbbdf0 1 : RtlFindCharInUnicodeString ?? : address = 0x21f44fbaef0 0 : KiUserExceptionDispatcher ?? : address = 0x21f44fbb800

building v from git source

phcreery commented 1 year ago

I am seeing the same for msvc

> v -cg -cc msvc -live run .\src\main.v
Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
signal 11: segmentation fault
6 : v_segmentation_fault_handler  c:\users\phcre\appdata\local\temp\v_0\main.7911469902052297126.tmp.c:8056
5 : seh_filter_exe             ?? : address = 0x1e4d7f3cdc0
4 : `__scrt_common_main_seh'::`1'::filt$0  d:\agent\_work\2\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304
3 : _C_specific_handler        ?? : address = 0x1e4d7f3c410
2 : _chkstk                    ?? : address = 0x1e4d7f3c690
1 : RtlRaiseException          ?? : address = 0x1e4d7f3c550
0 : KiUserExceptionDispatcher  ?? : address = 0x1e4d7f3d130

gcc here doesn't work on Windows 10

> gcc --version
gcc.exe (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders) 13.1.0
> v -cg -cc gcc -live run .\src\main.v
...
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/phcre/AppData/Local/Temp/v_0/main.14353135948662305038.tmp.c:21248: undefined reference to `GC_init'
collect2.exe: error: ld returned 1 exit status
builder error:
==================
C error. This should never happen.
...

does -live not work with tcc?

andorxornot commented 8 months ago

confirm on latest master

command: v -cc msvc -live run .\examples\hot_reload\message.v

produce:

Unhandled Exception 0xC0000005
C.CaptureStackBackTrace returned less than 2 frames
signal 11: segmentation fault
6 : print_backtrace_skipping_top_frames  ?? : address = 0x2473a022140
5 : seh_filter_exe             ?? : address = 0x2473a0220f0
4 : `__scrt_common_main_seh'::`1'::filt$0  D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304
3 : _C_specific_handler        ?? : address = 0x2473a021ed0
2 : _chkstk                    ?? : address = 0x2473a021f20
1 : RtlRaiseException          ?? : address = 0x2473a022190
0 : KiUserExceptionDispatcher  ?? : address = 0x2473a021f30