www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't get into debugger in vscode on macOS

reply Daniel Zuncke <daniel.zuncke gmail.com> writes:
Hello, I need some help getting into the debugger in vscode on 
macOS. It did work some months ago but that was finicky to set 
up. Maybe I am forgetting something now?

I am compiling the project with `dub build --build debug 
--compiler ldc2 --force` (the `-ld_classic` flag to fix the new 
Xcode linker is set in dub.json).

Debugging in the terminal with lldb works as expected `lldb 
bin/dfmt -- --help`.

In vscode I the debug process immediately exits with error (as 
far as I can tell, don't know how to get more output).
All required extensions should be installed since it worked some 
time ago (mainly CodeLLDB, code-d and C++ from what I remember).

I have tried 2 launch configs (launch.json):
```json
{
     "version": "0.2.0",
     "configurations": [
         {
             "type": "lldb",
             "request": "launch",
             "name": "debug lldb",
             "cwd": "${workspaceFolder}",
             "program": "./bin/dfmt",
             "args": ["--help"],
         },
         {
             "type": "code-d",
             "request": "launch",
             "name": "debug code-d",
             "cwd": "${workspaceFolder}",
             "program": "./bin/dfmt",
             "args": ["--help"],
         },
     ]
}
```
And both fail the same way (vscode Debug Console output):
```
Launching: /Users/dz/dev/dfmt/issue578/bin/dfmt --help
Launched process 24999
Process exited with code -1.
```
Any ideas what the problem could be? Can I get more verbose 
output what the problem is after launching the process?
Oct 18 2023
next sibling parent reply evilrat <evilrat666 gmail.com> writes:
On Thursday, 19 October 2023 at 06:03:06 UTC, Daniel Zuncke wrote:
 Hello, I need some help getting into the debugger in vscode on 
 macOS. It did work some months ago but that was finicky to set 
 up. Maybe I am forgetting something now?

 I am compiling the project with `dub build --build debug 
 --compiler ldc2 --force` (the `-ld_classic` flag to fix the new 
 Xcode linker is set in dub.json).

 Debugging in the terminal with lldb works as expected `lldb 
 bin/dfmt -- --help`.

 In vscode I the debug process immediately exits with error (as 
 far as I can tell, don't know how to get more output).
 All required extensions should be installed since it worked 
 some time ago (mainly CodeLLDB, code-d and C++ from what I 
 remember).

 I have tried 2 launch configs (launch.json):
 ```json
 {
     "version": "0.2.0",
     "configurations": [
         {
             "type": "lldb",
             "request": "launch",
             "name": "debug lldb",
             "cwd": "${workspaceFolder}",
             "program": "./bin/dfmt",
             "args": ["--help"],
         },
         {
             "type": "code-d",
             "request": "launch",
             "name": "debug code-d",
             "cwd": "${workspaceFolder}",
             "program": "./bin/dfmt",
             "args": ["--help"],
         },
     ]
 }
 ```
 And both fail the same way (vscode Debug Console output):
 ```
 Launching: /Users/dz/dev/dfmt/issue578/bin/dfmt --help
 Launched process 24999
 Process exited with code -1.
 ```
 Any ideas what the problem could be? Can I get more verbose 
 output what the problem is after launching the process?
Could it be is that it instantly crashes? In that case you need to set the breakpoints, it works by default in Windows, but not in Linux and probably MacOS too. You need to set breakpoints for these functions _d_throw, _d_throwdwarf (dmd), _d_throw_exception (ldc, i think?). I'm not exactly sure what is the relevant name for LDC and i'm on windows machine so i can't check my debugger config. With this it will break on throw and you should be able to inspect it in debugger.
Oct 19 2023
parent Daniel Zuncke <daniel.zuncke gmail.com> writes:
On Thursday, 19 October 2023 at 14:30:06 UTC, evilrat wrote:
 Could it be is that it instantly crashes?
Thanks, but I have found it doesn't get that far* while debugging in vscode, it seems to be a linker error. \* If I randomly change program arguments (`--help`, `./tests/issue0578.d` or none) and recompile (same `dub build --build debug --compiler ldc2 --force`) it works maybe once in 20 tries and I get into vs-code debugger, from then on it the program executes without error. Changing nothing and hitting debug after that gives an error again.
Oct 19 2023
prev sibling next sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
On Thursday, 19 October 2023 at 06:03:06 UTC, Daniel Zuncke wrote:
 Hello, I need some help getting into the debugger in vscode on 
 macOS. It did work some months ago but that was finicky to set 
 up. Maybe I am forgetting something now?

 I am compiling the project with `dub build --build debug 
 --compiler ldc2 --force` (the `-ld_classic` flag to fix the new 
 Xcode linker is set in dub.json).

 Debugging in the terminal with lldb works as expected `lldb 
 bin/dfmt -- --help`.

 In vscode I the debug process immediately exits with error (as 
 far as I can tell, don't know how to get more output).
 All required extensions should be installed since it worked 
 some time ago (mainly CodeLLDB, code-d and C++ from what I 
 remember).

 I have tried 2 launch configs (launch.json):
 ```json
 {
     "version": "0.2.0",
     "configurations": [
         {
             "type": "lldb",
             "request": "launch",
             "name": "debug lldb",
             "cwd": "${workspaceFolder}",
             "program": "./bin/dfmt",
             "args": ["--help"],
         },
         {
             "type": "code-d",
             "request": "launch",
             "name": "debug code-d",
             "cwd": "${workspaceFolder}",
             "program": "./bin/dfmt",
             "args": ["--help"],
         },
     ]
 }
 ```
 And both fail the same way (vscode Debug Console output):
 ```
 Launching: /Users/dz/dev/dfmt/issue578/bin/dfmt --help
 Launched process 24999
 Process exited with code -1.
 ```
 Any ideas what the problem could be? Can I get more verbose 
 output what the problem is after launching the process?
I looked at the doc, and looks like you can put a breakpoint on reaching entry point, maybe that'll help diagnose better the issue by stepping in ``` "stopOnEntry": true, ```
Oct 19 2023
parent Daniel Zuncke <daniel.zuncke gmail.com> writes:
On Thursday, 19 October 2023 at 15:25:36 UTC, ryuukk_ wrote:
 ```
         "stopOnEntry": true,
 ```
Thanks, my bad I missed that. The entry point I get is a dynamic link error and the program exits after trying to do a single step (I've put the asm below). Since calling `./bin/dfmt` works in the terminal and from lldb in the terminal I don't see how any linker error makes sense or why calling it from code lldb should be different. The only maybe related thing I can think of is that dmd produces linker error too (below). I have both ldc2 and dmd installed but dmd doesn't work for me (dmd neither functions if installed with brew or the install.sh). I had problems with the debugger already when dmd wasn't installed but RemedyBG debugger has problems with debugging llvm executables and dmd works so I wanted to try both here. I have found that the cpp debugger works to step around which might be enough for now so I am not wasting more time here if I don't have to. Thanks for the suggestions though. If you want me to try something I can do that. `stopOnEntry` brings me here: ```asm ; Symbol: _dyld_start ; Source: unknown 1006BD040: 48 89 E7 movq %rsp, %rdi 1006BD043: 48 83 E4 F0 andq $-0x10, %rsp 1006BD047: 48 C7 C5 00 00 00 00 movq $0x0, %rbp 1006BD04E: 6A 00 pushq $0x0 1006BD050: E9 BB 0B 00 00 jmp 0x1006bdc10 ; start ``` dmd linker error running `dub build --build debug --compiler dmd`; dub.json has `"lflags": ["-ld_classic", "-v"]` specified so I don't know why clang suggests to specify `-v`. ``` BUILD 18:48:43 Aug 22 2023 configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29) TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3) Library search paths: /usr/local/opt/dmd/lib /usr/local/lib Framework search paths: ld: multiple errors: symbol count from symbol table and dynamic symbol table differ in '/Users/dz/.dub/cache/dfmt/~master/build/application-debug-tVygsEVCB8 zk4_L3pjNiA/dfmt.o' in '/Users/dz/.dub/cache/dfmt/~master/build/application-debug-tVygsEVCB8P k4_L3pjNiA/dfmt.o'; address=0x0 points to section(2) with no content in '/usr/local/opt/dmd/lib/libphobos2.a[3177](config_a68_4c3.o)' clang: error: linker command failed with exit code 1 (use -v to see invocation) Error: linker exited with status 1 Error dmd failed with exit code 1. ```
Oct 19 2023
prev sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Thursday, 19 October 2023 at 06:03:06 UTC, Daniel Zuncke wrote:
 Hello, I need some help getting into the debugger in vscode on 
 macOS. It did work some months ago but that was finicky to set 
 up. Maybe I am forgetting something now?

 [...]
This can also happen if there's not a correct program database file or it can't find it.
Oct 20 2023