-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Injecting Environment Variables to GDB and GDBSERVER processes #303
Injecting Environment Variables to GDB and GDBSERVER processes #303
Conversation
Some additional update notes:
|
For windows tests are broken, see #299 For tests I think we can use getenv C function in a new test class to see what environment ends up in the inferior. See https://www.tutorialspoint.com/c_standard_library/c_function_getenv.htm The other thing you can do is use I'll do a review of the code itself soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried adding ${env:PATH}
to my launch.json and it was expanded as I expected with no special handling. Can you look again at that? I would prefer just to have ${env:XXXX}
from VSCode and do no special handling.
src/util.ts
Outdated
data: any, | ||
...keyRegexs: RegExp[] | ||
): string { | ||
const _resolveFromSourceHandler = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expected _
to be unreferenced variables:
Lines 16 to 22 in 33b2f35
'@typescript-eslint/no-unused-vars': [ | |
'warn', | |
{ | |
argsIgnorePattern: '^_', | |
varsIgnorePattern: '^_', | |
caughtErrorsIgnorePattern: '^_', | |
}, |
Is this a different style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this implementation, setting the variable to null is unsetting the environment variable. I add it to the tests, but I see that I missed in documentation.
My personal view is since _
is also a string I will vote for keep using null
to unset the variables and update the documentation, how this sounds to you?
By the way, buildString
is only used for merging the key/values into a given string (some kind of string interpolation). The variables handled in createEnvValues
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are talking cross purposes.
My comment was the minor issue of _resolveFromSourceHandler
starting with a _
because of the quoted rules in eslint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is no longer exists in the update.
src/integration-tests/util.spec.ts
Outdated
const initialENV = { | ||
VAR1: 'TEST1', | ||
VAR2: 'TEST2', | ||
var3: 'TEST3', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see use of lowercase here, but afaict there is no test for either of these cases:
- Linux/osx: case sensitive variables, i.e.
var
!=VAR
- Windows: case insensitive variables, i.e.
var
==VAR
In particular, PATH
on Windows is typically written Path
, but can be any capitalization of path
.
So a valuesToInject
of {Path: 'C:\\mytools\\bin;%Path%'}
should update if the initialENV
has PATH:
or Path:
properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functinality removed and no longer exists in the update.
src/integration-tests/util.spec.ts
Outdated
}); | ||
it('should injection formats', () => { | ||
const valuesToInject = { | ||
VARFORMATTEST1: '$VAR1', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a test where there is more than one environment variable in the valuesToInject
, e.g: valuesToInject = { NEWTEST1: '$VAR1$VAR1', NEWTEST2: '$VAR1VAR2' }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functinality removed and no longer exists in the update.
I experimented with case sensitivity and multiple vars in a single expansion and it all worked as I would expect according to https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, let me check on them.
src/util.ts
Outdated
data: any, | ||
...keyRegexs: RegExp[] | ||
): string { | ||
const _resolveFromSourceHandler = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this implementation, setting the variable to null is unsetting the environment variable. I add it to the tests, but I see that I missed in documentation.
My personal view is since _
is also a string I will vote for keep using null
to unset the variables and update the documentation, how this sounds to you?
By the way, buildString
is only used for merging the key/values into a given string (some kind of string interpolation). The variables handled in createEnvValues
function.
@asimgunes please let me know when you are ready for me to re-review this, with a comment on pressing the "re-request review" button. |
Adding tests to cover environment variable controls
Hi @jonahgraham, I think this pull request is ready to re-check right now. To summarize, following changes performed:
Note: Both commands tried: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, some small issues with the tests to look at and it should be ready to go.
fillDefaults(test, { | ||
program: path.join( | ||
testProgramsDir, | ||
platform() === 'win32' ? 'vars_env.exe' : 'vars_env' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't matter much, but do you know why this code needs the .exe
where the rest of the tests don't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this issue and remoed the platform() condition.
}); | ||
|
||
it('sets environment variables passed to the process', async function () { | ||
if (hardwareBreakpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why skip on hardwareBreakpoint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting error in hardwareBreakpoint condition:
"No hardware breakpoint support in the target."
I skipped the test since the target of the test is not related to the hardwareBreakpoint condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason you were getting those errors is you were using debugAdapter.js
when --test-remote
was in use. The reason it fails is that hardware breakpoints can only be used in remote (target) debugging. See my commit where I fix this up consistent with how other tests force using the target adapter.
}); | ||
|
||
it('check setting null will delete the variable', async function () { | ||
if (platform() === 'win32' || hardwareBreakpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why skipped on win32? Can we not delete on win32?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Win32 test environment is injecting another folder into the path so it never became null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned, the problem is related to the test environment, I added an arbitrary environment variable named "ENV_TEST_VAR" to control the deleting variable functionality and updated this code to also check it in Windows.
}); | ||
|
||
it('checks setting environment variables with debugAdapter', async function () { | ||
if (hardwareBreakpoint || (platform() === 'win32' && !isRemoteTest)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this skip condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the skip condition for hardwareBreakpoint only. I realise that win32 is failing because of the recent test problem in Windows tests.
src/integration-tests/utils.ts
Outdated
if (variable.value === '0x0') { | ||
return null; | ||
} | ||
// IMPORTANT: When value of the string is long, it returns dots `...` at the end, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like this :-(
Instead I recommend sending a command to gdb to disable this behaviour for the test with set print elements 0
- see https://sourceware.org/gdb/onlinedocs/gdb/Print-Settings.html#index-number-of-array-elements-to-print
Alternatively use printf "%s", name
as the gdb command to get the value with the custom command.
The printf option has the advantage that you don't need to do regex to get the string out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With print I got other complications in NULL checks (throwing error). I used set print addr off
option and continue with that. Could you please check the current implementation?
Hi @jonahgraham, I made some updates about your comments, Could you please re-check the updates when you are available? Kind regards. |
}); | ||
|
||
it('sets environment variables passed to the process', async function () { | ||
if (hardwareBreakpoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason you were getting those errors is you were using debugAdapter.js
when --test-remote
was in use. The reason it fails is that hardware breakpoints can only be used in remote (target) debugging. See my commit where I fix this up consistent with how other tests force using the target adapter.
breakpoints: [ | ||
{ | ||
column: 1, | ||
line: 22, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets remove hardcoded line numbers, at least from new tests. Some old tests still use them. See latest commit.
@asimgunes I made some changes to the code in line with my review comments. Please have a review of that and let me know if it looks good to you |
I have now fixed the Windows issue, rebasing this on main will pull in the fix for #299 |
Hi @jonahgraham, Thanks for the updates, they all seem fine and I like the idea of lineTags. I also rebased the current request and all tests seem to be passed. From my point of view, update seem fine. |
@asimgunes this is now merged - are there other changes incoming, or should I do a publish to npm and version bump? Will you provide the corresponding change to cdt-gdb-vscode? |
Hi @jonahgraham, Thanks for the merge, there is no upcoming change from my side, and sure I can provide an update about related changes to the cdt-gdb-vscode, once you publish the recent cdt-gdb-adapter to npm. |
@asimgunes - I have published new version - https://www.npmjs.com/package/cdt-gdb-adapter/v/0.0.29 - can you consume that update when you make the cdt-gdb-vscode changes? |
I am making the change to cdt-gdb-vscode now to pull in the fix in #306 |
Adds support for these features in the adapter: - setting cwd for gdb - eclipse-cdt-cloud/cdt-gdb-adapter#306 - better handling of complex variables: - eclipse-cdt-cloud/cdt-gdb-adapter#304 - environment variables - eclipse-cdt-cloud/cdt-gdb-adapter#303 And the new launch.json settings needed to enable the above. Along with a variety of bug fixes in the adapter.
Adds support for these features in the adapter: - setting cwd for gdb - eclipse-cdt-cloud/cdt-gdb-adapter#306 - better handling of complex variables: - eclipse-cdt-cloud/cdt-gdb-adapter#304 - environment variables - eclipse-cdt-cloud/cdt-gdb-adapter#303 And the new launch.json settings needed to enable the above. Along with a variety of bug fixes in the adapter.
Adds support for these features in the adapter: - setting cwd for gdb - eclipse-cdt-cloud/cdt-gdb-adapter#306 - better handling of complex variables: - eclipse-cdt-cloud/cdt-gdb-adapter#304 - environment variables - eclipse-cdt-cloud/cdt-gdb-adapter#303 And the new launch.json settings needed to enable the above. Along with a variety of bug fixes in the adapter.
Hi,
I like to propose a new feature for cdt-gdb-adapter which enables injecting environment variables to gdb and gdbserver processes.
The new variables are located as
environment
andtarget.environment
. The rootenvironment
injects environment variables togdb
process, wheretarget.environment
injects environment variables to gdbserver process.Similar to
cwd
andtarget.cwd
behaviour, gdbserver process also includesenvironment
definition. (Which means gdbserver is injecting both environment and target.environment).In this implementation, we also support construction of new values with using the old values. This is a common scenario for PATH environment variable in most cases. The following configuration will append a new path to the PATH variable:
PATH: '%PATH%;C:\some\new\path'
or
PATH: '$PATH:/some/new/path'
New value construction is not limited to the PATH variable, the logic could be used in any
variable and the following formats are supported:
%VAR_NAME% format:
TEST_VAR: "%TEST_VAR%;Some other text"
$VAR_NAME format:
TEST_VAR: "$TEST_VAR;Some other text"
${env.VAR_NAME} format:
TEST_VAR: "${env.TEST_VAR};Some other text"
I believe this could be a useful scenario in some cases where developers need to inject some environment variables seamlessly and improve the user experience.
To sum up, I would be happy if you can review this request, and happy to hear any feedback.
Kind regards.
Asim Gunes