dart-archive/ffi

How to debug .dylib library with attached process

shigomany opened this issue · 3 comments

Environment

  • OS and version: Mac OS Mneterey 12.0.1 (21A559)
  • VS Code: 1.70.1 (Universal)
  • C/C++ extension: v1.11.5

Bug Summary and Steps to Reproduce

Bug Summary:

How to debug .dylib library with attached process?

I created launch.json in this form:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Proccess C++",
            "request": "attach",
            "type": "cppdbg",
            "processId": "${command:pickProcess}",
            "program": "${workspaceRoot}/build/src/libNeoML.dylib",
            "showDisplayString": true,
            "logging": {
                "engineLogging": true,
                "trace": true,
                "traceResponse": true,
                "programOutput": true
            },
            "osx": {
                "MIMode": "lldb",
                "miDebuggerPath": "${extensionInstallFolder:ms-vscode.cpptools}/debugAdapters/lldb-mi/bin/lldb-mi",
            },
        }
    ]
}

Steps to reproduce:
I opened the CMake project in VSCode, built it. And I'm trying to join the dart process (with ffi).

Additional Information

I did the same thing on Windows and through Visual Studio I managed to attach the process. But for VSCode and mac os I don't get it.

I get information about such an error (with this launch.json):

image

If I specify the path to the dart process being started, I get a similar error.

I added this line:

{
   "program": "/Users/***/fvm/versions/stable/bin/cache/dart-sdk/bin/dart"
}

Dart proccess info:

cwd
/Users/***/Documents/workingprojects/dart-neoml
txt
/Users/***/fvm/versions/stable/bin/cache/dart-sdk/bin/dart
txt
/Library/Preferences/Logging/.plist-cache.I4U9d1iR
txt
/System/Library/CoreServices/Encodings/libCyrillicConverter.dylib
txt
/usr/lib/dyld
txt
/usr/share/icu/icudt68l.dat
txt
/private/var/db/timezone/tz/2022a.1.0/icutz/icutz44l.dat
txt
/Users/***/Documents/workingprojects/dart-neoml/assets/macOS/libNeoMathEngine.dylib
txt
/Users/***/Documents/workingprojects/dart-neoml/assets/macOS/libNeoML.dylib <--- LOADED
0
->0xd80a243142eea9a9
1
->0xd80a243142eeab39
2
->0xd80a243142eeacc9
3
->0x24ea0e11d814aa75
4
->0x7fd387dc7ca4a3ed
5
count=0, state=0xa
6
[ctl com.apple.netsrc id 6 unit 32]
7
localhost:50667
8
->0xd80a243142ee6809
9
10
->0xf73d07bf6fe61be6
11
->0xcc0999d3555a8d6f
13

I can't figure out how to set up launch.json so I can debug my .dylib library on macOS.

Indeed, one should launch the debugger on the Dart executable.

However, I use launch, rather than attach.

Here is my setup:

	"launch": {
		"version": "0.2.0",
		"configurations": [
			{
				"name": "ccpdbg dart",
				"type": "cppdbg",
				"request": "launch",
				"program": "path/to/bin/dart",
				"args": [
					"path/to/a/program.dart",
				],
				"stopAtEntry": false,
				"cwd": "${workspaceFolder}",
				"environment": [],
				"externalConsole": false,
				"MIMode": "gdb",
			},

(It's nested under "launch" because I keep my configurations in my workspace, rather than a separate launch.json file.)

And on MacOS:

	"launch": {
		"version": "0.2.0",
		"configurations": [
			{
				"name": "ccpdbg dart",
				"type": "cppdbg",
				"request": "launch",
				"program": "path/to/bin/dart",
				"args": [
					"path/to/a/program.dart",
				],
				"stopAtEntry": false,
				"cwd": "${workspaceFolder}",
				"environment": [],
				"externalConsole": false,
				"MIMode": "lldb",
			},

@dcharkes, thanks!

Okay, I'm closing the issue, if I find a solution (specifically by attaching the process), I'll just write here.