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

[lldb-dap] Added "port" property to vscode "attach" command. #91570

Merged
merged 44 commits into from
Jun 28, 2024

Conversation

santhoshe447
Copy link
Contributor

@santhoshe447 santhoshe447 commented May 9, 2024

Adding a "port" property to the VsCode "attach" command likely extends the functionality of the debugger configuration to allow attaching to a process using PID or PORT number.
Currently, the "Attach" configuration lets the user specify a pid. We tell the user to use the attachCommands property to run "gdb-remote ".
Followed the below conditions for "attach" command with "port" and "pid"
We should add a "port" property. If port is specified and pid is not, use that port to attach. If both port and pid are specified, return an error saying that the user can't specify both pid and port.

Ex - launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "lldb-dap Debug",
"type": "lldb-dap",
"request": "attach",
"gdb-remote-port":1234,
"program": "${workspaceFolder}/a.out",
"args": [],
"stopOnEntry": false,
"cwd": "${workspaceFolder}",
"env": [],

}

]
}

Santhosh Kumar Ellendula and others added 19 commits November 17, 2023 15:09
Adding a "port" property to the VsCode "attach" command likely extends the functionality of the debugger configuratiuon to allow attaching to a process using PID or PORT number.
Currently, the "Attach" configuration lets the user specify a pid. We tell the user to use the attachCommands property to run "gdb-remote <port>".
Followed the below conditions for "attach" command with "port" and "pid"
We should add a "port" property. If port is specified and pid is not, use that port to attach. If both port and pid are specified, return an error saying that the user can't specify both pid and port.

Ex - launch.json
{
	"version": "0.2.0",
    "configurations": [
        {
            "name": "lldb-dap Debug",
            "type": "lldb-dap",
            "request": "attach",
            "port":1234,
            "program": "${workspaceFolder}/a.out",
            "args": [],
            "stopOnEntry": false,
            "cwd": "${workspaceFolder}",
            "env": [],

        }
    ]
}
Adding a "port" property to the VsCode "attach" command likely extends the functionality of the debugger configuration to allow attaching to a process using PID or PORT number.
Currently, the "Attach" configuration lets the user specify a pid. We tell the user to use the attachCommands property to run "gdb-remote ".
Followed the below conditions for "attach" command with "port" and "pid"
We should add a "port" property. If port is specified and pid is not, use that port to attach. If both port and pid are specified, return an error saying that the user can't specify both pid and port.

Ex - launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "lldb-dap Debug",
"type": "lldb-dap",
"request": "attach",
"port":1234,
"program": "${workspaceFolder}/a.out",
"args": [],
"stopOnEntry": false,
"cwd": "${workspaceFolder}",
"env": [],

    }
]
}

In this patch we have resolved code formatting issues and fixed "test_by_name" failure.
@santhoshe447 santhoshe447 requested a review from JDevlieghere as a code owner May 9, 2024 08:22
Copy link

github-actions bot commented May 9, 2024

✅ With the latest revision this PR passed the Python code formatter.

@walter-erquinigo walter-erquinigo requested a review from clayborg May 14, 2024 21:36
@santhoshe447
Copy link
Contributor Author

FWIW, I think this feature would be more useful and easier to implement if there was just a single setting called "connection url" or something, which accepted all of the usual lldb connection urls (unix-abstract-connect://, listen://, ...).

Since a simple tcp port connection is definitely going to be the most commonly used connection, you can, if you want, treat a simple number (or :number) as an alias to connect://localhost:number. lldb-server does something similar.

PS: I'm clicking request changes because I don't believe the test for the feature can go in in this form. I don't consider myself an owner for the rest, so you can consider my comments as suggestions.

I apologize for missing your earlier comment. To clarify.
Using the URL "connect://localhost:12345" or "connect://:12345" with the "connect" scheme helps invoke the appropriate function to establish a connection.
Pls ref: https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp#L148
$gdb-remote number - would work from the command-line, because lldb is taking care of adding "connect://".

Please let me know if my understating is incorrect.

@labath
Copy link
Collaborator

labath commented Jun 5, 2024

FWIW, I think this feature would be more useful and easier to implement if there was just a single setting called "connection url" or something, which accepted all of the usual lldb connection urls (unix-abstract-connect://, listen://, ...).
Since a simple tcp port connection is definitely going to be the most commonly used connection, you can, if you want, treat a simple number (or :number) as an alias to connect://localhost:number. lldb-server does something similar.
PS: I'm clicking request changes because I don't believe the test for the feature can go in in this form. I don't consider myself an owner for the rest, so you can consider my comments as suggestions.

I apologize for missing your earlier comment. To clarify. Using the URL "connect://localhost:12345" or "connect://:12345" with the "connect" scheme helps invoke the appropriate function to establish a connection. Pls ref: https://github.com/llvm/llvm-project/blob/main/lldb/source/Host/posix/ConnectionFileDescriptorPosix.cpp#L148 $gdb-remote number - would work from the command-line, because lldb is taking care of adding "connect://".

Please let me know if my understating is incorrect.

Your understanding of the code is correct. What I am suggesting is basically to emulate this command line behavior in vscode.

Basically, instead of two host+port settings, you could have one setting with a sufficiently vague name ("connection url", "remote address", ...) to cover the expanded scope. Then, you implementation could take the user-provided string and fill in the blanks:

  • if the user types "1234", you'd convert it to connect://localhost:1234
  • if the user types "my-host:1234", you'd convert it to connect://localhost:1234
  • if the user types "unix-abstract-connect://..." (or any other scheme supported by lldb), you'd pass the value unmodified

The advantage of this is that you'd automatically support every connection protocol that lldb understands with almost no effort. If we stick to the current implementation, then if someone later needs to connect through unix sockets (or whatever), he would have to go back and add another setting to support connecting through that.

Now, I do see the appeal of having an explicit host/port fields (they're much easier to understand for the average user), which is why I'm not insisting on this approach. Nonetheless, I think this is an option worth considering, and I think we could avoid most of the confusion by carefully crafting the description of this field to guide the user to the most common scenarios.

Copy link
Collaborator

@clayborg clayborg left a comment

Choose a reason for hiding this comment

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

The code looks good, a few nits in comments.

@labath: did we resolve the port race condition testing issue? We really don't want this to be a flaky test on overloaded systems. It would be nice to make sure this is solid before getting this in.

const auto gdb_remote_port =
GetUnsigned(arguments, "gdb-remote-port", invalid_port);
llvm::StringRef gdb_remote_hostname =
GetString(arguments, "gdb-remote-hostname", "localhost");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know in the past we have used 127.0.0.1 instead of localhost. The reason is people can modify their config files in their environment and localhost can be aliased to something else. Not sure if this is an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using 127.0.0.1 can provide slight advantage in terms of consistency and compatibility in specific scenarios.
Any suggestions from others?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are environments (Google's (default) test environment is like that) that don't have an IPv4 stack configured (just v6), so localhost would be an advantage there. That said, this definitely wouldn't be the first instance of `127.0.0.1 in lldb.

FWIW, I'm of the opinion that anyone who configures localhost to point to something other than their local host deserves whatever is coming their way,

lldb/tools/lldb-dap/lldb-dap.cpp Outdated Show resolved Hide resolved
@santhoshe447 santhoshe447 requested a review from labath June 7, 2024 21:29
@labath
Copy link
Collaborator

labath commented Jun 10, 2024

The code looks good, a few nits in comments.

@labath: did we resolve the port race condition testing issue? We really don't want this to be a flaky test on overloaded systems. It would be nice to make sure this is solid before getting this in.

The current version of the code should be fine. We just need to sort out the code placement issue.

santhoshe447 and others added 4 commits June 10, 2024 14:55
I have shifted "Pipe" class to common location "lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py"
@labath labath removed their request for review June 11, 2024 08:20
Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

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

My concerns have been addressed (*), so I'm removing my request for changes. It looks like the only way to do that is to Approve the PR, but I'd suggest getting another approval from a lldb-dap owner as well.

(*) There is still the question of the single "url" setting (to rule them all), but I don't consider myself an authority there.

const auto gdb_remote_port =
GetUnsigned(arguments, "gdb-remote-port", invalid_port);
llvm::StringRef gdb_remote_hostname =
GetString(arguments, "gdb-remote-hostname", "localhost");
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are environments (Google's (default) test environment is like that) that don't have an IPv4 stack configured (just v6), so localhost would be an advantage there. That said, this definitely wouldn't be the first instance of `127.0.0.1 in lldb.

FWIW, I'm of the opinion that anyone who configures localhost to point to something other than their local host deserves whatever is coming their way,

@walter-erquinigo
Copy link
Member

I'll review this today or tomorrow. Thanks for all the activity!

Copy link
Member

@walter-erquinigo walter-erquinigo left a comment

Choose a reason for hiding this comment

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

This LGTM

@tedwoodward tedwoodward merged commit a52be0c into llvm:main Jun 28, 2024
6 checks passed
@omjavaid
Copy link
Contributor

This breaks lldb-api :: tools/lldb-server/commandline/TestGdbRemoteConnection.py on lldb-aarch64-windows bot.

https://lab.llvm.org/buildbot/#/builders/141/builds/376

@tedwoodward
Copy link

This breaks lldb-api :: tools/lldb-server/commandline/TestGdbRemoteConnection.py on lldb-aarch64-windows bot.

https://lab.llvm.org/buildbot/#/builders/141/builds/376

File "C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\tools\lldb-server\lldbgdbserverutils.py", line 1045, in init
self.name = "lldb-" + str(random.randrange(1e10))
^^^^^^
NameError: name 'random' is not defined

Looks like "import random" should have been added to lldbgdbserverutils.py when the pipe class was moved from TestGDBRemoteConnection.py.

omjavaid added a commit that referenced this pull request Jul 1, 2024
This fixes TestGdbRemoteConnection.py failing after PR #91570 on
AArch64 Windows LLDB buildbot.

https://lab.llvm.org/buildbot/#/builders/141/builds/376
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
)

Adding a "port" property to the VsCode "attach" command likely extends
the functionality of the debugger configuration to allow attaching to a
process using PID or PORT number.
Currently, the "Attach" configuration lets the user specify a pid. We
tell the user to use the attachCommands property to run "gdb-remote ".
Followed the below conditions for "attach" command with "port" and "pid"
We should add a "port" property. If port is specified and pid is not,
use that port to attach. If both port and pid are specified, return an
error saying that the user can't specify both pid and port.

Ex - launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "lldb-dap Debug",
"type": "lldb-dap",
"request": "attach",
"gdb-remote-port":1234,
"program": "${workspaceFolder}/a.out",
"args": [],
"stopOnEntry": false,
"cwd": "${workspaceFolder}",
"env": [],

    }
]
}

---------

Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-hyd.qualcomm.com>
Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-lv.qualcomm.com>
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
This fixes TestGdbRemoteConnection.py failing after PR llvm#91570 on
AArch64 Windows LLDB buildbot.

https://lab.llvm.org/buildbot/#/builders/141/builds/376
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
This fixes TestGdbRemoteConnection.py failing after PR llvm#91570 on
AArch64 Windows LLDB buildbot.

https://lab.llvm.org/buildbot/#/builders/141/builds/376
santhoshe447 pushed a commit to santhoshe447/llvm-project that referenced this pull request Jul 22, 2024
Added "gdb-remote-port" and "gdb-remote-hostname" attach properties usage in
README.md.

This was missed in PR llvm#91570
tedwoodward pushed a commit that referenced this pull request Jul 26, 2024
Added "gdb-remote-port" and "gdb-remote-hostname" attach properties
usage in
README.md and updated package.json version to 0.2.3
    
This was missed in PR #91570

---------

Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-hyd.qualcomm.com>
Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-lv.qualcomm.com>
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Oct 16, 2024
…#99926)

Added "gdb-remote-port" and "gdb-remote-hostname" attach properties
usage in
README.md and updated package.json version to 0.2.3

This was missed in PR llvm#91570

---------

Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-hyd.qualcomm.com>
Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-lv.qualcomm.com>
(cherry picked from commit 7345025)
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.

6 participants