vscode-cmake-tools icon indicating copy to clipboard operation
vscode-cmake-tools copied to clipboard

Doesn't pass environment variables

Open magpier84 opened this issue 10 years ago • 16 comments

Function getenv("HOME") returns empty string when application is launched via target debugging.

CMakeTools 0.7.4 (it worked on 0.7.3) VSCode 1.7.1

magpier84 avatar Nov 10 '16 18:11 magpier84

I'm not able to reproduce the issue. Do you have anything in your debugConfig?

vector-of-bool avatar Nov 11 '16 03:11 vector-of-bool

Platform: OSX, llvm 3.9.0 I have a such settings only: { "cmake.buildDirectory": "${workspaceRoot}/../build", "cmake.experimental.enableTargetDebugging": true }

magpier84 avatar Nov 11 '16 06:11 magpier84

So, this is what I have investigated at the moment.

  1. Running the target without "debugConfig" generates default launch configuration. This configuration is launched with empty environment. May be, because of absence of "environment" variable, needed for "cppdbg". But I am using other debugger.
  2. But the main problem for me is not well formed (for 0.7.4) debugConfig string

Instead of:

"cmake.debugConfig": { "all": { "request": "launch", "type": "lldb", "env": {"QT_PLUGIN_PATH": "/Users/admin/Qt/5.5/clang_64/plugins"} } }

I should use:

"cmake.debugConfig": { "request": "launch", "type": "lldb", "env": {"DYLD_IMAGE_SUFFIX": "_debug"} }

magpier84 avatar Nov 11 '16 18:11 magpier84

At the moment, I've only got in support for the cpptools debugging engine from Microsoft, which wants environment variables in environment rather than env, and they are passed in a different format (a list of objects rather than a single object of key-value paris). Are you trying to use a different debugger?

Also, yes. I did change the format of the debugConfig.

vector-of-bool avatar Nov 11 '16 19:11 vector-of-bool

Yes, I am using "LLDB Debugger" extension. It works for me after fixing my debugConfig. But default debug configuration (cppdbg) is still launched with missing environment variables.

magpier84 avatar Nov 11 '16 19:11 magpier84

I should probably make it clearer that target debugging is specifically written against cpptools. So, if you fix up the debugConfig, is it all working well?

vector-of-bool avatar Nov 11 '16 19:11 vector-of-bool

It doesn't work correctly for cppdbg (lose system environment variables) and works for lldb. Note, that lldb - is debugger extension for cpptools.

magpier84 avatar Nov 11 '16 20:11 magpier84

FWIW I have this exact same issue on macOS (but it works fine in Linux).

I was able to work around it by setting "externalConsole": true in my "cmake.debugConfig": { } settings section. Not ideal, maybe, but it did fix the problem for me.

clangen avatar May 29 '17 23:05 clangen

It's been a while, but has anyone tried using the ${command:cmake.debugTargetProgramPath} substitution in their launch.json?

vector-of-bool avatar Jun 04 '17 23:06 vector-of-bool

@vector-of-bool are there instructions for doing this? I don't quite understand what this means, but can give it a shot next time I'm debugging on my mac if there are more setup details.

clangen avatar Jun 05 '17 01:06 clangen

Not quite. The substitution behavior is documented, but not often used.

Basically, for any value in launch.json, you can put ${command:<some-command>} and VSCode will call <some-command> to replace the value. This means that you can put ${command:cmake.debugTargetProgramPath} in place of the path to the executable, and VSCode will use that command to ask CMake Tools for the path to the executable.

vector-of-bool avatar Jun 05 '17 01:06 vector-of-bool

@clangen Please find sample launch.json in the PR above, if you're still interested.

ytimenkov avatar Jun 13 '17 13:06 ytimenkov

@ytimenkov thanks for the updated documentation. Unfortunately the suggestion to use a custom launch.json did not solve my particular issue -- I'm still unable to resolve environment variables (e.g. $HOME) unless I force the app to run in an external console.

clangen avatar Jun 13 '17 19:06 clangen

Maybe issue is in cpp extension or VS code itself, or specific to Mac. Works on my Windows machine. It might help if you provide VS version info (Click on smiley in the bottom-right corner of VS Code, then "Submit bug" and copy/paste here).

ytimenkov avatar Jun 13 '17 20:06 ytimenkov

Sure. Everything should be up to date, and I have very few extensions installed:

  • VSCode Version: Code 1.13.0 (376c52b955428d205459bea6619fc161fc8faacf, 2017-06-08T16:34:53.678Z)
  • OS Version: Darwin x64 16.6.0
  • Extensions:
Extension Author Version
autotrim NathanRidley 1.0.6
cpptools ms-vscode 0.11.4
cmake twxs 0.0.17
cmake-tools vector-of-bool 0.9.7

clangen avatar Jun 13 '17 20:06 clangen

Closed. If this issues still persists in the current 0.11.0-beta4, feel free to reopen this one or create a new one.

no-realm avatar Mar 01 '18 13:03 no-realm