-
Notifications
You must be signed in to change notification settings - Fork 243
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 ability to change localhost when starting gdb #402
Comments
Yes, we’re aware of certain limitations in regards to usage with a WSL2 setup, because of the inability to access USB. At the current time we recommend using the |
It not really the GDB server that is the problem. It's the initialization of gdb. Specifically the call Edit: Just realized the titel was misleading. I had written gdb server by mistsake... I actually meant gdb. |
Yes - I understand where the issue is caused - and we are looking at adding some better support for running in a WSL2 setup (something I need to figure out how to setup so I have a testing environment) which would include determining the correct IP and stuff to connect on. I was trying to give you a work around for the time-being and that would be using something like the following:
and manually launch your GDB server. |
Ah sorry for being so slow... Now i get it. Thanks! I will try it out. It would be great if the |
The issue with it is that port and stuff are not necessarily consistent from run to run (it usually is - but isn't guaranteed to be) - so makes it hard to include. We are looking at adding support for the WSL2 environment where it would actually determine the appropriate IP/port and use that automatically - but need to do a bit more research into how to get that to work reliably. For now this is the work-around - not ideal as some features (like SWO) don't work and it doesn't manage launching the GDB server and stuff itself - but better than nothing. |
Thanks for clarification! Sure the IP adress would have to be fetched again for every run since it could be changed even if it's unlikely. And it would be nice not to have to configure it. I would gladly help out with testing when you come to that stage since I use this every day. |
In WSL2, can't you use a hostname instead of IPv4 address? |
Btw, if you use the "external" server method, you can launch the external server in persistent mode and just leave it running. |
Given the limitations of WSL2 specified above, is there anything wrong with the following patch? It allows for more control over the the gdb target. I've replicated the code across all of the debug interfaces, though only have only tested jlink at this time. Which port is inconsistent? The GDB server port? Is this for a specific debug interface that it changes?
|
The way code above works, we do a bunch of work to find available ports on the localhost and then we don't use them and use something else specified by The I agree, we need to find a better way for the WSL. I can't find a good solution right now. |
Could this be an option to find the IP to the Windows host? I tried it with the IP that the ${hostname}.local resolves to and it worked. Couldn't use ${hostname}.local directly in the obfuscated code though. Then it didn't resolve it so I'm guessing you need some more steps in the code. |
@lagerholm This sounds promising. Can you help me with the scene though? Following will give me a better problem statement and then may lead to solutions.
Note that every program I mentioned above expects localhost and 127.0.0.1 to be resolved properly. It might sound very simple (and frustrating to you all) but not from my perspective. I have seen users do all kinds of things. Like compiling in WSL but running the debugger in Windows and many combinations thereof and wonder why things don't work. If we can provide a flow that works for most people, then we made progress. I am thinking of not worrying about WSL1 at all. WSL2 and WSL1 are totally different beasts. I see people still using WSL1 and that baffles me. |
I'm going to try to describe how I think it works (in my setup) and answer your questions. (When I write WSL below i mean WSL2).
I'm not a JS developer so I don't know how to test that. If you could provide a method to test it then I could try that on my machine.
In my opinion this is the workflow that should be used today. It's the one that came easiest when I started using it. I haven't made any strange/hacky changes to the configuration (except modifying cortex-debug to connect to another IP for the gdb-server :) ). I can think that there where a lot of strange things going on before when WSL and VSC was more immature. Now they both seem pretty stable. I think it's wise to forget all about WSL1. It should be declared dead. I can't see any reason for anyone to use it. Except maybe if you are on a company PC with an old Windows version. Please let me know if there is anything else you need to know. |
Thanks, @lagerholm. I created a javascript (Node) script that you can run. I will do the same when my Windows machine is resuscitated. If others an also run this script and report back, that would be helpful Btw, You will need to install Node and have it in your path. Try Here is the script to run. Save it to a file const os = require('os');
console.log('Platform: ' + os.platform());
console.log('Type : ' + os.type());
console.log('Release : ' + os.release());
console.log('Hostname: ' + os.hostname());
// Older versions of Node does not have this
if (os.version) {
console.log('Version : ' + os.version());
} else {
console.log('Version : Unknown');
}
console.log('Network Interfaces:');
console.log(os.networkInterfaces()); |
|
Thanks. Is this right? So, the loopback/localhost addresses do not resolve to the WSL machine even though it is listed as such. It resolves to the host instead? That is crazy. In this case, '172.31.158.181' seems to be your local IP address and it was different before '172.31.191.195'. Was this the IP you wanted to set with |
MachineName was an edit as my machine name was a bit doxxable. Localhost is in the hosts file as 127.0.0.1 in the WSL instance, which will always resolve to the local instance of 127.0.0.1. What is necessary is being able to get to the Windows localhost, which Windows also knows as 127.0.01, because that's where JlinkGDBServer is hosting the GDB instance. In order to access the GDB server from WSL, I need to explicitly call out my Windows IP address, which is a 192.168.1.x. The 172.x.x.x is a WSL instantiated IP address. |
Okay, you can't run the JlinkGDBServer on your WSL side? SEGGER does offer Linux versions right? I USB/udev-rules a problem then? In this case, the GDB-server is truly external to the WSL (and VSCode and Cortex-Debug) |
Ah, you answered that question in your earlier comment. Sorry. |
I mentioned this previously, on a different issue thread, but if you're working with a j-link, you can:
Voila everything works from inside WSL. Tested and works for me. Edit: Edit 2: export WSL_HOST=$(tail -1 /etc/resolv.conf | cut -d' ' -f2) Credit: https://gist.github.com/ThYpHo0n/349f1f6473e207b866f65aca4728da3e#file-zshrc-L8 And setting the IP conf in |
Next thought: During normal processing, we do a port scan to see what ports are available. We need several and some consecutively. We keep searching until we find a set we can use. But this was done on the localhost. But suddenly we are connecting to another localhost where these same ports may not be free and will cause failures and collisions. A simple way to demonstrating this is to try to run two instances of Cortex-Debug. There are other ways this can fail. If we can do a port scan (by creating a server on it) on the Windows side, then we are golden. I see a security problem here where Windows Firewall may not allow us to do that. But there maybe other ways I have to try this for myself. |
Thanks, @RisinT96 Yup, I saw that documented on the SEGGER website a while ago as well. But, hopefully we can find a solution for all gdb servers and document a flow |
Yes, of course this is just j-link specific, and hopefully you can work out a solution that works for all gdb servers :) I think the fact that WSL allows running programs on the host from within WSL can be "abused" to do the port scan on windows. |
Yea @RisinT96 , I know, the thought of doing this makes me shudder. I feel bad about doing such a port-scan and MS may plug that hole anytime |
I am closing this as USB ports work better with WSL2 and for JLink, there are other options like using their server software |
Is there a way to change how to connect to the remote when starting gdb? To not always use localhost.
I can't find any setting for this. I thought that preLaunchCommands or overrideLaunchCommands would do it but it seems the three first commands are hardcoded. I found several references to
target-select extended-remote localhost
in debugadapter.js and extension.js. I tried changing these to the IP-adress I wanted and then I got it working as I wanted.Some background information:
I am using WSL2 on windows 10 as my primary development environment where i use a cross-compiler in a docker container. Since I'm doing this all the paths in the elf file will be relative to the linux system. Since WSL2 doesn't support USB forwarding i want to run the gdbserver in Windows and gdb in Linux. Therefore I want to change localhost:port since localhost in Linux won't point to the localhost in Windows that gdbserver is listening to. VS code is run as a remote in WSL2 with VS code Server making it think that it is running in Linux. Therefore I can't run both gdbserver and gdb in Windows since then gdb mi2 interpreter will spit out paths in the form of
//$wsl/some_path
which doesn't make sense under Linux.The text was updated successfully, but these errors were encountered: