-
-
Notifications
You must be signed in to change notification settings - Fork 26
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 GDB support #618
Comments
Totally, yes, I've used gdb to test the emulators api. |
Wouldn't it be easier to start out by creating a facade that mimics FS/WinUAE? I.e. at first provide hacky implementations of e..g. Getting familiar with the protocol is a good idea, but you can probably get something working a lot quicker by leaning more on the previous implementations. Should also make integrating changes easier. Just my 2 cents. |
I think mimicking fsuae or winuae, is too much work for a temporary solution. |
Example of exchange between the extension and WinUAEStart of a debugging session and breakpoint hit. To have these traces in the debug console add the trace:"true" option in the launch parameters. Remote protocol documentation https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.html
Debugger stopped and waiting for user input. |
@prb28: Thanks a lot for the example log which is an excellent starting point. Right now, I am playing around with a small example program that opens a socket, talks to gdb, computes checksums etc. Once I feel confident in what I am doing, I'll start on implementing the necessary commands to get the above example conversation working. |
My first milestone was to open up a socket connection which has been achieved. My second milestone was to set a breakpoint in vAmiga via GDB which has been achieved partly. To allow GDB to connect, vAmiga's gdbserver needs to be started. Currently, this is done via a shell command: The small bug icon in the status bar indicates that the server is running. Now, GDB can be connected:
GDB and vAmiga are exchanging some information at this point: Some replies are "fake replies" at the moment to get the conversation going. Now, a breakpoint can be set in GDB:
vAmiga continues emulation and stops at the specified location: It would be nice if I could see the breakpoint in the inspector. Unfortunately, GDB does not set them immediately when the There is various internal stuff that needs to be cleaned up before I continue with the next milestone. What I haven't looked at yet is the way how executables have to be loaded into vAmiga to make them debuggable in VSC later. E.g., by looking at the protocol snippet posted above, I see that a relocation address has to be transmitted to GDB. |
Great progress! |
OK, I see. This is done in So my next milestone will be to add functionality similar to |
Brief update: vAmiga will get a new component called OSDebugger which allows the user to retrieve AmigaOS related information in RetroShell. Eventually, this component will deliver the relocation offsets that we need. At the moment, OSDebugger is able to print some information about tasks, similar to the ’T’ command in UAE: In the next step, I want to extend the functionality to processes. I understand that the Process struct has a field called
I’ve found the following description which is not 100% clear to me:
My current understanding is as follows: U32: Number of items Here is what I am unsure about: There is no structure called
This struct can be chained, so I guess this structure is meant with |
It's a linked linked (0 terminated) of BPTR's (i.e. you must multiply the value with 4 to get the real address), the ULONG just before holds the size of the segment and the actual segment follows. You can see how AROS chains the loaded segments together here. (I recently coded up some hacky stuff to scan the system structures as well, which is why I looked into it link) BTW: At some point you may want to add some more sanity checks to your code (e..g. that the SysBase structure is valid and that you're not traversing corrupted, circular lists). |
Great! I think these two functions tell me exactly what I need to know. |
By reviewing the code from @mras0, I've got the following understanding about the segment list structure. Did I get it right? |
Yes, but to be clear what you've labelled "start" is literally the start of the segment (not a pointer). I can see the segment list is processed similarly here in the WinUAE gdb stub. Looks like the fs-uae stub calls LoadSeg directly instead of trawling through exec/dos data structures. BTW I found a bit more info on the other entries: AmigaDOS Technical Reference Manual page 3-2 says the first two entries point to resident code and the third being the SegList passed in as an argument (most of the time from LoadSeg). This matches what the WinUAE gdb stub does (only looking at the third entry, in the case of a normal task). |
@prb28 I have a couple of questions about the way the VSC plugin will launch vAmiga.
|
I don't know how OS tasks are supposed to look, but the lists look suspicious. For the interesting case (a user provided executable loaded from disk) the output is wrong. If I add the following to the start of
|
The run command is different for each UAE.
Yes, no problem. I think the script should be set as an example and we may let the user edit it if he wants. Or/And it can be generated by vscode with parameters set in the launch command.
It's on the launch arguments of the UAEs. These arguments are set in the .vscode/launch.json file
No I let the user set it in the launch parameters of the debugger.
Yes we can do both. Can vAmiga mount a disk linked to a local directory ? Can I run vAmiga on a simple window for all the os ? Do I need to make a custom build with a window library as wx-windows or others ? |
OK, sounds good to me. I think this is better than letting VSC create the script based on some other description. It would add another layer of indirection.
Ok, good. So the user would add the path the Kickstart to the script file.
vAmiga doesn't support hard drives. We would have to load the program into the emulator in form of a bootable ADF (an EXE file is fine, too, because vAmiga can convert those to bootable ADFs on-the-fly. However, if ADFs are already there or if they are easy to create on the VSC side, I would prefer ADFs to EXE files.
No, vAmiga doesn't know where the disks are coming from. When a disk is inserted into a drive, the MFM encoder is utilised to translate the ADF into a MFM stream. From that moment on, vAmiga only works on the bit stream (i.e., no changes are written back to the original ADF). If the user wants to persist his work, he has to export the disk explicitly, e.g., in form of another ADF.
The original vAmiga app runs on macOS, only. Then there is the outdated vAmigaBM Linux port. I could resurrect this project, but I would rather prefer to let it die. @mras0 has successfully compiled vAmiga on Windows with some GUI code attached (based on SDL). Maybe this project is the most promising at the moment to get vAmiga work on Windows, at least to the point that it can connect to VSC via the GDB remote protocol. At the moment, the GDB server wouldn't compile on Windows because of the Socket code, but this shouldn't be too hard to fix. I also want to mention the two great web ports of vAmiga based on WASM, but they don't help us in this special scenario. |
I'll gladly share the latest version of my "frontend" (which seems to work OK under both windows and Linux (WSL2)), but it's not really user friendly to put it mildly. The big issue is the user interface, which I don't want to be responsible for :). I just handle everything with command line arguments (and the retroshell, which I've made accessible with a hacky overlay). For just this purpose: Starting an executable from VS code and running it vAmiga on most platforms, it'll work fine, but as soon as people want to do anything more it'll be lacking (especially if they expect to access the same tools/debugging capabilities that are available in the MacOS version). I see multiple issues here that you probably want to track differently:
The last one could be hacked by creating a disk image of the directory, but currently I think that'll be limited to a HD floppy size (which is probably OK for now). Doing it properly is a bit more involved (it's on the TODO list for my own for-fun emulator). Getting some (hacky) harddisk support isn't too difficult (I've already managed that), but mounting a directory isn't as easy. |
If you agree I'll would like to try building running it. I would be interested in testing the script feature.
The first need, as you mention, is simple for the Gui. The fancy options for debugging should be integrated in the IDE so we don't need a complex GUI (thinking of a step back option ;-)).
Totally agree with your view.
I don't have a clear idea if this option is mandatory for users. It can be useful to be able to inspect the files written during the process. I think being able to bring them out of the emulator at least at the end of the run maybe important. A script command may do the trick. The WASM build could be an interesting option for an integrated emulator, but it way be difficult and too heavy to have it in vscode. |
Brief update: Today, I'm working on
Once this is done, I'll create a new branch which will make experimental modifications easier. |
Update:
Here is an example script that configures and launches vAmiga:
|
@prb28 interesting idea ... could possibly be done if vsc Amiga Assembly would act as a simple webserver one way to make that work from vsc amiga assembly would probably be to
|
Well vscode is made with chromium. And it can load wasm in a webview. |
Ah well I see that would be then "really" integrated 😎 and therefore much more simple and robust ... no need for any additionally socket communication ... only pure javascript ... everything inside vsc ... 🤤 lets definitely schedule this as an experimental goal for a phase 2 ... we are still at phase 1 when phase1 is done we try to integrate a wasm build into the amiga assembly plugin. Maybe we can just move basic parts of the code from one of our current web ports which is hosted at https://github.com/vAmigaWeb/vAmigaWeb over into yours repo and as a result make a special version for amiga assembly... does that make sense ? |
Yes totally. |
Vscode will wait for the answer, you can hold and send the response when it's ready. |
This means that VSC will periodically send a |
I just did one call, but; if needed I can change it.
|
The second approach sound most promising to me. A general issue is how to detect when the program has been loaded. Is it sufficient to wait until a process has been created? In other words: Is the first created process the process we are looking for? How do the other emulators deal with this issue? |
WinUAE uses a parameter telling what is the program name that triggers the debug session. |
Did you close the socket ? |
No. The socket connection is still open (otherwise I wouldn't have received the More questions:
|
I've been running into more issues. I've tried to connect vAmiga to
Maybe I am doing something fundamentally wrong (maybe in my socket code) or the currently existing Amiga toolchains have issues. |
You should be able to test on ubuntu with "my" frontend (just change the submodule to point at your preferred vAmiga version). Is your dev branch up to date with what you're trying with? The change to I can do some testing tomorrow after work if you'd like. |
The parse in winuae : https://github.com/prb28/WinUAE/blob/fee2f4ce524994c29ede9bce45bdad0a315bb5a1/od-win32/barto_gdbserver.cpp#L1155 You can respond "ok" and skip this message for now. |
Looks like a acknowledgment: https://sourceware.org/gdb/onlinedocs/gdb/Packet-Acknowledgment.html#Packet-Acknowledgment |
I've tried it and, Yes the Z1 command arrives at the before the end of the qOffsets. |
I can confirm, my mutex doesn't seem to work. I'll try to fix it tomorrow. |
You got it! This change is the major cause of all the trouble. Originally, the code looked like this (with an additional
I removed the |
@dirkwhoffmann The problem was the timeout of the mutex that was too short. |
Thanks! Now, it works until I receive the
|
You can run the bebbo's gdbserver in your emulator and print the protocol dialog (skipping your implementation). |
I had this idea, too. But there doesn't seem to be a gdbserver in |
I want to thank everyone who has supported me in trying to make vAmiga VSC/GDB compatible. I wouldn't have found much of the needed information on my own. Nevertheless, I have decided to personally withdraw from this project. This may come as a surprise, but every project reaches the point where progress has to be weighed against invested time. Based on my experience so far, I expect it would take me a long time to reach a usable result. This in turn means that I couldn’t work on other projects during this time. There are still quite a few open issues in the bug database concerning the compatibility of the emulator and I don't want to leave these issues unprocessed for a long period of time. If someone else wants to continue working on the debug functionality, feel free. I think the VSC/GDB integration is a worthwhile goal and it would be nice if it can be achieved sometime. |
Thank you for starting it! |
Somehow unexpectedly, I’ve been successful in connecting @bebbo's Details are documented in this wiki article, in case anyone is still interested: |
The experimental GDB server (as described in the Wiki article) is part of v1.1b7. |
Impressive. Great to see this going forward. |
This is a follow-up to discussion #525.
To get an idea about what has to be done, I had a brief look at the links @prb28 provided.
https://github.com/prb28/WinUAE/blob/master/od-win32/barto_gdbserver.cpp
https://github.com/prb28/fs-uae/tree/master/src/remote_debug
What I understand from the source code is that vAmiga needs to implement (part of) the GDB Remote Serial Protocol (RSP). Communication will be performed via sockets.
To make myself familiar with GDB and the socket API, I’ve written a small test program that opens a socket (port 8080) and waits for another application to connect. When this happens, it sends back a
-
which is interpreted by GDB as an unsuccessful transmission.To test the code, I’ve connected to my app in GDB as follows:
As response to the payload (
-
) GDB sent me this:+$qSupported:multiprocess+;swbreak+;hwbreak+;qRelocInsn+;fork-events+;vfork-events+;exec-events+;vContSupported+;QThreadEvents+;no-resumed+;memory-tagging+;xmlRegisters=i386#77
The contents doesn't matter, because it's all about establishing communication yet. The output shows that some communication is taking place in both directions.
What I would do as a starting point is to add the ability to vAmiga to communicate with GDB this way. Once this works, I would start implementing parts of the protocol. Does this make sense or am I heading in the wrong direction?
The text was updated successfully, but these errors were encountered: