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

honor debugger args for connect + attach #316

Merged
merged 3 commits into from
Apr 5, 2022
Merged

Conversation

GitMensch
Copy link
Collaborator

@GitMensch GitMensch commented Mar 2, 2022

"should fix #206" - fair warning: untested

additional: fix extended-remote without executable
@WebFreak001
Copy link
Owner

hm this changes the order of arguments, the preargs are put before the executable now, I'm not sure if gdb arguments are fully unordered.

@GitMensch
Copy link
Collaborator Author

GitMensch commented Mar 5, 2022

gdb --help
This is the GNU debugger.  Usage:

    gdb [options] [executable-file [core-file or process-id]]
    gdb [options] --args executable-file [inferior-arguments ...]

The executable must be the last thing (if you don't use executable + pid, which we currently do via -p option; or use --args).

Copy link
Owner

@WebFreak001 WebFreak001 left a comment

Choose a reason for hiding this comment

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

though please test this before merging.

@brownts
Copy link
Collaborator

brownts commented Mar 12, 2022

I looked at this a little bit today and I believe the extraArgs are still missing from the SSH connections (MI2::ssh) as well as the LLDB attach (MI2_LLDB::attach).

@brownts
Copy link
Collaborator

brownts commented Apr 5, 2022

I was looking at this a bit more today to see how difficult it would be to fix the SSH scenario where the extraArgs are not being passed. I added the extraArgs with the preargs similar to how this is done in the non-SSH scenarios. The issue I ran into though is that the parameters are passed differently when running the command locally than they are when running over SSH. Running the command locally (via child_process.spawn) appears to call the process directly. Also, since the parameters are passed as an array, they appear to be passed directly to the process and there is no need to determine where one parameter ends and the next begins (i.e., spacing). However, when invoking the command via the ssh2.exec command, the command and all of the args are combined (and space separated) as a single string. This means that the command is parsed on the remote side and thus anything containing spaces, will need to be properly escaped. However, this behaves differently on Windows than it does on Linux. For example, I used the following debugger_args along with an autorun to print the result to verify behavior in the three different scenarios:

  • Local (Linux or Windows):
     debugger_args: ["-iex", "set $foo = \"bar\""],
     autorun: ["print $foo"]
    
  • SSH to Linux machine:
     debugger_args: ["-iex", "'set $foo = \"bar\"'"],
     autorun: ["print $foo"]
    
  • SSH to Windows machine:
    debugger_args: ["-iex", "\"set $foo = \\\"bar\\\"\""],
    autorun: ["print $foo"]
    

The escaping done for the "SSH to Linux machine" scenario didn't work for the "SSH to Windows machine" scenario and vice versa. Any ideas on how this can be properly escaped for both scenarios over SSH? It doesn't seem like there should be 3 different versions of debugger_args depending on whether you are running this locally or over SSH. Ideally, the escaping would be done behind the scenes, but I'm not sure there is a universal solution that will work.

@GitMensch
Copy link
Collaborator Author

Thank you for investigating again!

Ideally, the escaping would be done behind the scenes, but I'm not sure there is a universal solution that will work.

Yes, that would be ideal. As there are more users there with the same problem I'd suggest to drop the "how to escape arguments passed to commands" at https://github.com/mscdex/ssh2/issues.

For the "investigation issue part" - if I understand this correctly you've tested the changes and found it working everywhere this issue wants it to "connect + attach" with the exception of LMDB attach (where it should be easy to copy the changes from MI - but I can't test that it works there), correct?
Should this be merged to allow your work be based on it or do you want to tackle it (you're free to copy what you find useful) in which case I'd close the PR?

@brownts
Copy link
Collaborator

brownts commented Apr 5, 2022

For the "investigation issue part" - if I understand this correctly you've tested the changes and found it working everywhere this issue wants it to "connect + attach" with the exception of LMDB attach (where it should be easy to copy the changes from MI - but I can't test that it works there), correct?

Hi @GitMensch, I found that it also doesn't work for SSH connections. I'm not sure if that was considered to be part of this change or not. I had to add the extraArgs to the ssh command to get as far as I had in my previous response. So, the extraArgs are currently not applied on any SSH connection nor on the LLDB attach.

If you want to merge what you have, I can add support for those two remaining conditions in a separate PR (which is probably easier than me trying to apply changes to your current PR). With my proposed follow-on change, note that the extraArgs on the SSH connection may have to be escaped appropriately in order to work unless we can find a solution that would work there as well, but that could be yet another change, if a solution is found that will work.

@GitMensch GitMensch merged commit 5114701 into master Apr 5, 2022
@GitMensch
Copy link
Collaborator Author

Agreed. So looking forward for your SSH change (was not planned to be part) and LMDB fix (was an oversight).

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.

Why does "connect" ignore "extraargs"? 'debugger_args' not honored for 'attach' configuration in gdb
3 participants