Skip to content
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

add support for envFile #358

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

add support for envFile #358

wants to merge 1 commit into from

Conversation

GitMensch
Copy link
Collaborator

fix #258

so far untested; it is likely possible to also add unit tests; so work in progress (@ any one, feel free to take over)

@GitMensch GitMensch marked this pull request as draft May 10, 2022 13:11
@GitMensch GitMensch added this to the v0.27.0 milestone May 11, 2022
@GitMensch GitMensch requested a review from brownts May 24, 2022 05:27
if (!(envFile || procEnv))
return;

// FIXME: if actuall debugged process is Win32, which we only know _after_ connect,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not really not know what type of process that will be debugged? The environment support is only applicable to the debugger running on the same machine as the debug adapter (not supported over SSH), so it should be able to determine the system it's running on via process.platform. Not sure I understand this issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't know. I'm regularly using gdb to attach to gdbserver on a different machine myself. Works fine as long as the gdb has support for the target's architecture.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But these environment variables are only being applied to the process where gdb is being run, not the process where gdbserver is run. I don't think I understand what the expectation of the environment variables would be in a remote scenario like that. Are they expected to be visible to the application being debugged?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are they expected to be visible to the application being debugged?

likely yes, as long as we use set environment (or its mi equivalent) this will work both for GDB and (at least on GNU/Linux environments) gdbserver (since GDB 8.1); for running processes wed need to call into putenv()`, but I think it is fine to say that this is only supported for new inferiors.

@@ -886,3 +889,32 @@ export class MI2 extends EventEmitter implements IBackend {
protected stream;
protected sshConn;
}
function readEnvFile(filename: string): { [key: string]: string } {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably recommend taking these functions, along with the functionality in the MI2 constructor above and moving it to its own class (e.g., "Environment"). This would encapsulate this functionality and make it easy to unit test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's a general issue with the existing code - the environment variables are expected to be found in the inferior (this "just happens" when GDB starts it locally). If we cannot make this happen all environment settings should be dropped from all remote scenarios.
I think this should be changed in general to use; and I even forgot if there's a better way than call setenv (name, value, 1) [which likely only work for C/C++ code, not everything GDB supports].

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There does appear to be commands in both gdb and lldb for setting environment variables, so using that approach, rather than attempting to set them at the process level might be the way to go. The environment variable setting commands could just be issued during the MI2::initCommands, similarly to how the path mappings are handled (i.e., extra commands). The GDB documentation even says these environment variable settings are sent to gdbserver, so should support remote debugging as well (see here). This should also work with SSH connections too, since the commands are issued to the debugger itself.

  • gdb Add/Remove Environment Variable:
(gdb) set environment FOO=BAR
(gdb) unset environment FOO
  • lldb Add/Remove Environment Variable:
(lldb) settings set target.env-vars FOO=BAR
(lldb) settings remove target.env-vars FOO

Copy link
Collaborator

@brownts brownts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the previous comments, adding some testing for this would be helpful. However, this approach looks reasonable to me.

@GitMensch
Copy link
Collaborator Author

I'm not (possibly anymore) familiar with the test setup - do we have a dev doc how to add tests and run them (outside of CI)?

@brownts
Copy link
Collaborator

brownts commented Feb 10, 2024

I'm not (possibly anymore) familiar with the test setup - do we have a dev doc how to add tests and run them (outside of CI)?

The HACKING document does provide a brief overview in the testing section. The Unit tests use Mocha and I recommended the Mocha Test Explorer extension as an easy way to run the unit tests interactively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for envFile
2 participants