microsoft / microsoft/vscode-cpptools
"envFile" feature not working correctly with chained and quoted env var values
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Type: Debugger
The envFile parameter that can be used to set up the debugger environment with an .env file is handled by taking each line from the file, splitting the name and values and then stripping the value of any possible edge quotes (seen in this function). However, some environment files specify certain Linux env vars like PATH and LD_LIBRARY_PATH with multiple quoted paths separated by a colon (e.g. PATH="/home/user/video player/bin":"/home/opt/3rd party/bin"). This result in, for example, gdb receiving environment values such as /home/user/video player/bin":"/home/opt/3rd party/bin as input, which are invalid.
Describe the bug
- OS and Version: Ubuntu 18.04
- VS Code Version: 1.50.0
- C/C++ Extension Version: 1.0.1
- Other extensions you installed (and if the issue persists after disabling them): C++ TestMate, CMake, Docker etc.
To Reproduce
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "cppdbg",
"logging": {
"engineLogging": true
},
"request": "launch",
"name": "test",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/build/bin/main",
"envFile": "${workspaceFolder}/vars.env",
"stopAtEntry": false,
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(Test)
add_library(liba SHARED lib.cpp)
add_executable(main main.cpp)
target_link_libraries(main liba)
install(TARGETS liba main)
lib.hpp
void lib();
lib.cpp
#include "lib.hpp"
#include <iostream>
void lib()
{
std::cout << "hello" << std::endl;
}
main.cpp
#include "lib.hpp"
int main()
{
lib();
}
vars.env (assuming the test project is in /home/user/test)
LD_LIBRARY_PATH="/dummy/path":"/home/user/test/build/lib":"/dummy/path"
Steps to reproduce the behavior:
mkdir build && cd buildcmake .. -DCMAKE_INSTALL_PREFIX=.make install(to clear RPATHs)- Run the
testdebug task
My output:
/home/user/test/build/bin/main: error while loading shared libraries: libliba.so: cannot open shared object file: No such file or directory
Additional context
Debug tab output:
1: (347) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
1: (366) LaunchOptions ExePath='/home/user/test/build/bin/main'
1: (366) LaunchOptions WorkingDirectory='/home/user/test'
1: (366) LaunchOptions ExeArguments=''
1: (366) LaunchOptions MIMode='gdb'
1: (366) LaunchOptions MIDebuggerPath=''
1: (366) LaunchOptions WaitDynamicLibLoad='false'
1: (366) LaunchOptions>
1: (367) LaunchOptions <SetupCommands>
1: (367) LaunchOptions <Command IgnoreFailures='true' Description='Enable pretty-printing for gdb'>-enable-pretty-printing</Command>
1: (367) LaunchOptions </SetupCommands>
1: (367) LaunchOptions <Environment>
1: (367) LaunchOptions <EnvironmentEntry Name='LD_LIBRARY_PATH' Value='/dummy/path":"/home/user/test/build/lib":"/dummy/path' />
1: (367) LaunchOptions </Environment>
1: (367) LaunchOptions</LocalLaunchOptions>
1: (450) DbgCmd:echo $$ > /tmp/Microsoft-MIEngine-Pid-o3f7l5mq.jmh ; cd "/home/user/test/build/bin" ; DbgTerm=`tty` ; set -o monitor ; trap 'rm "/tmp/Microsoft-MIEngine-In-za9yinph.eoo" "/tmp/Microsoft-MIEngine-Out-ve7mvmdn.x7e" "/tmp/Microsoft-MIEngine-Pid-o3f7l5mq.jmh" "/tmp/Microsoft-MIEngine-Cmd-aa4tvvug.5u3"' EXIT ; "/usr/bin/gdb" --interpreter=mi --tty=$DbgTerm < "/tmp/Microsoft-MIEngine-In-za9yinph.eoo" > "/tmp/Microsoft-MIEngine-Out-ve7mvmdn.x7e" & clear; pid=$! ; echo $pid > "/tmp/Microsoft-MIEngine-Pid-o3f7l5mq.jmh" ; wait $pid;
1: (468) Wait for connection completion.
1: (921) ->=thread-group-added,id="i1"
1: (922) ->~"GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git\n"
1: (923) ->~"Copyright (C) 2018 Free Software Foundation, Inc.\n"
1: (923) ->~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law. Type \"show copying\"\nand \"show warranty\" for details.\n"
1: (923) ->~"This GDB was configured as \"x86_64-linux-gnu\".\nType \"show configuration\" for configuration details."
1: (923) ->~"\nFor bug reporting instructions, please see:\n"
1: (923) ->~"<http://www.gnu.org/software/gdb/bugs/>.\n"
1: (923) ->~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
1: (923) ->~"For help, type \"help\".\n"
1: (923) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (923) ->(gdb)
1: (927) <-1001-gdb-set target-async on
1: (927) ->1001^done
1: (927) ->(gdb)
1: (928) 1001: elapsed time 2
1: (935) <-1002-enable-pretty-printing
1: (936) ->1002^done
1: (936) ->(gdb)
1: (936) 1002: elapsed time 0
1: (936) <-1003-interpreter-exec console "set pagination off"
1: (936) ->=cmd-param-changed,param="pagination",value="off"
1: (936) ->1003^done
1: (936) ->(gdb)
1: (936) 1003: elapsed time 0
1: (936) <-1004-gdb-set auto-solib-add on
1: (937) ->1004^done
1: (937) ->(gdb)
1: (937) 1004: elapsed time 0
1: (937) <-1005-gdb-set solib-search-path /home/user/test/build/bin:
1: (937) ->1005^done
1: (937) ->(gdb)
1: (937) 1005: elapsed time 0
1: (937) <-1006-gdb-set stop-on-solib-events 1
1: (937) ->1006^done
1: (938) ->(gdb)
1: (938) 1006: elapsed time 0
1: (938) <-1007-environment-cd /home/user/test
1: (938) ->1007^done
1: (938) ->(gdb)
1: (938) 1007: elapsed time 0
1: (938) <-1008-file-exec-and-symbols /home/user/test/build/bin/main
1: (939) ->1008^done
1: (939) ->(gdb)
1: (939) 1008: elapsed time 0
1: (940) <-1009-interpreter-exec console "show architecture"
1: (940) ->~"The target architecture is set automatically (currently i386:x86-64)\n"
1: (941) ->1009^done
1: (941) ->(gdb)
1: (941) 1009: elapsed time 0
1: (942) <-1010-break-insert -f main
1: (942) ->1010^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000000000000073e",at="<main+4>",thread-groups=["i1"],times="0",original-location="main"}
1: (942) ->(gdb)
1: (945) 1010: elapsed time 3
1: (946) <-1011-interpreter-exec console "set env LD_LIBRARY_PATH /dummy/path\":\"/home/user/test/build/lib\":\"/dummy/path"
1: (946) ->1011^done
1: (946) ->(gdb)
1: (946) 1011: elapsed time 0
1: (951) Send Event AD7EngineCreateEvent
1: (953) Send Event AD7ProgramCreateEvent
1: (994) ShellPid=16135
1: (994) DebuggerPid=16137
1: (1395) Send Event AD7LoadCompleteEvent
=thread-group-added,id="i1"
GNU gdb (Ubuntu 8.1-0ubuntu3.2) 8.1.0.20180409-git
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
1: (1402) <-1012-exec-run
1: (1403) ->=thread-group-started,id="i1",pid="16142"
1: (1403) ->=thread-created,id="1",group-id="i1"
1: (1406) <-1013-thread-info 1
1: (1408) ->=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x000055555555473e",at="<main+4>",thread-groups=["i1"],times="0",original-location="main"}
1: (1408) ->=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1",ranges=[{from="0x00007ffff7dd5f10",to="0x00007ffff7df4b50"}]
1: (1420) ->1012^running
1: (1420) ->*running,thread-id="all"
1: (1420) ->(gdb)
1: (1420) 1012: elapsed time 17
1: (1420) ->1013^done,threads=[{id="1",target-id="process 16142",name="main",state="running",core="1"}]
1: (1420) ->(gdb)
1: (1421) 1013: elapsed time 14
1: (1422) ->~"Stopped due to shared library event (no libraries added or removed)\n"
1: (1423) ->*stopped,reason="solib-event",thread-id="1",stopped-threads="all",core="1"
1: (1423) Send Event AD7ProcessInfoUpdatedEvent
1: (1424) Send Event AD7ThreadCreateEvent
Stopped due to shared library event (no libraries added or removed)
1: (1433) <-1014-interpreter-exec console "shell echo -e \\\\033c 1>&2"
1: (1435) ->1014^done
1: (1435) ->(gdb)
1: (1435) 1014: elapsed time 2
1: (1436) <-1015-gdb-set stop-on-solib-events 0
1: (1436) ->1015^done
1: (1436) ->(gdb)
1: (1436) 1015: elapsed time 0
1: (1439) <-1016-interpreter-exec console "info sharedlibrary"
1: (1440) ->~"From To Syms Read Shared Object Library\n"
1: (1440) ->~"0x00007ffff7dd5f10 0x00007ffff7df4b50 Yes /lib64/ld-linux-x86-64.so.2\n"
1: (1440) ->1016^done
1: (1440) ->(gdb)
1: (1440) 1016: elapsed time 0
1: (1442) Send Event AD7ModuleLoadEvent
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
1: (1443) <--exec-continue
1: (1443) ->^running
1: (1443) ->*running,thread-id="all"
1: (1443) ->(gdb)
1: (1443) ->~"[Inferior 1 (process 16142) exited with code 0177]\n"
1: (1443) ->=thread-exited,id="1",group-id="i1"
1: (1443) ->=thread-group-exited,id="i1",exit-code="0177"
[Inferior 1 (process 16142) exited with code 0177]
1: (1443) ->*stopped,reason="exited",exit-code="0177"
1: (1444) Send Event AD7ThreadDestroyEvent
1: (1446) <--gdb-exit
1: (1446) ->^exit
1: (1451) Send Event AD7ProgramDestroyEvent
The program '/home/user/test/build/bin/main' has exited with code 177 (0x000000b1).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Extension/src/Debugger/ParsedEnvironmentFile.ts, especially the environment-file parsing function linked in the issue. Reproduce with the provided launch.json and vars.env using the CMake project, then verify that the LD_LIBRARY_PATH value passed to gdb preserves the quoted path segments and allows main to load libliba.so.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100