Connect to luma3ds gdb stub with "GNU gdb local agent via GADP/TCP" #2721
Replies: 47 comments 312 replies
-
Can you connect to the stub via gdb? |
Beta Was this translation helpful? Give feedback.
-
Okay, this is where I am so far: |
Beta Was this translation helpful? Give feedback.
-
I keep forgetting you're on a Windows box....OK, right, so you're doing the right thing, but I probably haven't provided enough detail again. Either the "GNU gdb local agent over GADP/TCP" or the "IN-VM gdb local debugger" options should work as long as you specify the correct command in the "GDB launch command" parameter (in your case /path/to/arm-none-eabi-gdb.exe") . I would recommend the latter as it will give you more info if it dies and is easier to debug if we have to go that route. When you connect, the device may or may not be running. If it has broken, you'll be in the same state as you were with gdb.exe, and, when you select the process/inferior in the Objects Provider, the green resume/continue button should be enabled. If it's not (i.e. it's running), selecting the same object should enable the interrupt/pause button. If neither of those are true, you'll probably need to do something else in the Interpreter Console. The Interpreter Console is basically (more or less) the same environment as the gdb shell. If you are entering something like "target remote host:port" in gdb, you will have to do the same in the Interpreter. (If the Interpreter isn't visible, launch it from the Objects Provider.) You may also want to read a bit of the help - most of the windows don't display useful info until you are tracing the target. |
Beta Was this translation helpful? Give feedback.
-
I don't really get it. On my 2ds, I have Luma3ds and I turn on the debugger and |
Beta Was this translation helpful? Give feedback.
-
Yes, looks good -fire away! |
Beta Was this translation helpful? Give feedback.
-
(I say "immediate" although I realize you've been working at this for weeks!) |
Beta Was this translation helpful? Give feedback.
-
If it connected, it would be the little console-shaped icon in the Objects Provider at the far left of the toolbar |
Beta Was this translation helpful? Give feedback.
-
Sorry, I'm entering the conversation a little late. Several things to point out. First, as of now, the GDB connector (whether IN-VM or via GADP/TCP) is only supported on Linux. We use So, the simplest, though perhaps disappointing answer, is to just build and run Ghidra on Linux. Then you can use all the GDB stuff "out-of-the-box." If you insist on using Ghidra for Windows, and/or your like a good adventure, then proceed: You can use a Linux VM to host GDB, then connect to it from Ghidra on Windows. While I've not tested this myself, you might be able to forego the Linux VM for WSL. It'll probably work for WSL2, since that is essentially a Linux VM. I'm not as confident for WSL1, but it could. Note that the GADP connection over TCP cannot connect directly to a GDB stub. GADP is Ghidra's in-house protocol for communicating with its connectors. (GDB stubs use RSP, which we don't connect to directly.) We often run the actual connector in a separate "agent" process, because they are more prone to crash. Should they crash, we don't want it to take all of Ghidra with it. (the IN-VM variants loads the connector in Ghidra's process, the via GADP/TCP variants launch the agent and automatically connect via GADP). The "GADP connection over TCP" connector is used when you've already launched an agent, which is a less-common use case, but applies here. In a sense, the agent just wraps GDB as a means of translating GADP to RSP. Thus, you must build and launch the agent manually on Linux, and connect to it from your Windows Ghidra. In your ghidra repo (presumably on Windows), run:
This will generate
You will probably need the Now, from Ghidra on Windows, hit the connect button and select "GADP connection over TCP". Set the network address to your VM's virtual adapter's IP (again, localhost for WSL.) Set the port to 12345, and click connect. You should eventually receive the GDB prompt in Ghidra. You can then proceed as you normally would to connect GDB to your stub. |
Beta Was this translation helpful? Give feedback.
-
To emulate Linux, will I need Hyper-V? |
Beta Was this translation helpful? Give feedback.
-
Which version of Linux would Ghidra's debugger work well on? |
Beta Was this translation helpful? Give feedback.
-
Will the debugger ever work properly on windows? Or if it does now, to connect to 3ds-like devices? |
Beta Was this translation helpful? Give feedback.
-
@SirEnder125 yes, the post by @DrChat means there is hope - we're looking into to it! |
Beta Was this translation helpful? Give feedback.
-
Hey, sorry to bother you guys again, but do you think that |
Beta Was this translation helpful? Give feedback.
-
Hey, Going to weigh in here just to make sure we're all on the same page - if I say anything wrong, feel free to jump in because I'm not sure I have the complete picture myself. So, as I understand your scenario, you have Ghidra running on Windows (effectively the client) and the gdbstub on luma3ds (effectively the server). The gdbstub "speaks" the RSP protocol, so to communicate with it we need something that speaks RSP on the client side. Because we do not have an RSP client for, well, anything, we typically rely on a middleman. On Linux, this is gdb, which we wrap as a gdb agent. In that scenario, Ghidra launches gdb and speaks GADP to it. Gdb translates those requests to RSP and talks to the target (in your case luma3ds). On Linux, we can also create an SSH connection to GDB, issue the commands directly, and get the same result. For Windows, gdb running under Windows proper is basically a non-starter, so your options are either (a) gdb running on WSL, or (b) gdb running on a different machine. If luma3ds had an SSH server, you could talk directly to that, but I don't think it does. (Correct me if I'm wrong on this.) So, let's say we're going WSL. I know exactly nothing about WSL so again correct me if I say something stupid, but, in this case (or even in the second machine) case, you'll want to install the openssh server and gdb on the middleman. Sounds like you have already done this. When you launch the openssh server, you can, I believe, specify a host and a port for clients to talk to it. If you don't specify, the host is localhost and the port is 22. If the server is running under WSL, can the main windows account access it as localhost? I don't know the answer to this, actually. If it can, you'll want to (a) launch the openssh server, and (b) connect from Ghidra using "GDB over SSH" with the parameters set to /path/to/gdb, localhost, 22, and your username for WSL. On a good day, this will launch gdb in the WSL environment. From there, though, you'll still have to connect to the luma3ds. Probably, easiest to do this from the Interpreter using "target remote" etc. Yell if this is unclear (or, of course, incorrect) :/ |
Beta Was this translation helpful? Give feedback.
-
OK, so am guessing you've already done this, but the first thing I would try is opening a Windows cmd window and issuing the command "ssh user125@172.28.57.51:2222". There are two reasons for doing this: (1) ssh does some set-up on the very first connection that's hard to get right any other way, and (2) it might give you some insight if the ssh connection itself is failing. Assuming you've already done this, my guess is one of two things is going wrong - either gdb is not actually at /usr/bin/gdb ("which gdb" should tell you the actual path) or the path is a link. For reasons I don't quite understand, various tools are not happy with links. If so, "ls -l" the ostensible path, get the real path, and replace the first argument with that. |
Beta Was this translation helpful? Give feedback.
-
OK, hmmmm, well that's some progress. I think I need to think more about the Dynamic window issue. |
Beta Was this translation helpful? Give feedback.
-
I'm back at the "Record" window thing... again... |
Beta Was this translation helpful? Give feedback.
-
The objects list shows one thread while the Threads list shows 20. |
Beta Was this translation helpful? Give feedback.
-
I got a ton of error messages saying "Ignoring packet error, continuing..."
```
.
.
MI2: -interpreter-exec console "show version"
\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law."
.\n"
."
MI2: -interpreter-exec console "show architecture"
MI2: -interpreter-exec console "show os"
MI2: -interpreter-exec console "show endian"
MI2: -list-thread-groups
MI2: -list-thread-groups
MI2: -interpreter-exec console "source /mnt/c/Users/*/Downloads/ghidra-master/ghidra-master/Ghidra/Debug/Debugger/src/main/resources/define_info_proc_mappings"
MI2: -interpreter-exec console "set arch arm"
MI2: -interpreter-exec console "set endian little"
MI2: -interpreter-exec console "target remote 192.168.2.89:4000"
MI2: -interpreter-exec console "maintenance info sections ALLOBJ nosections"
MI2: -interpreter-exec console "show architecture"
MI2: -interpreter-exec console "show os"
MI2: -interpreter-exec console "show endian"
MI2: -list-thread-groups
MI2: -thread-info 1
MI2: -thread-info 2
MI2: -thread-info 3
MI2: -thread-info 4
MI2: -thread-info 5
MI2: -thread-info 6
>MI2: -thread-info 7
MI2: -thread-info 8
MI2: -thread-info 9
MI2: -thread-info 10
MI2: -thread-info 11
>MI2: -thread-info 12
MI2: -thread-info 13
>MI2: -thread-info 14
MI2: -thread-info 15
MI2: -thread-info 16
MI2: -thread-info 17
>MI2: -thread-info 18
MI2: -thread-info 19
>MI2: -thread-info 20
MI2: -thread-info 21
MI2: -thread-info 22
MI2: -thread-info 1
>MI2: -stack-list-frames --thread 1
MI2: -thread-info 2
MI2: -stack-list-frames --thread 2
MI2: -thread-info 3
MI2: -stack-list-frames --thread 3
>MI2: -thread-info 4
MI2: -thread-info 5
>MI2: -stack-list-frames --thread 4
MI2: -stack-list-frames --thread 5
MI2: -thread-info 6
MI2: -stack-list-frames --thread 6
>MI2: -thread-info 7
MI2: -stack-list-frames --thread 7
>MI2: -thread-info 8
MI2: -thread-info 9
>MI2: -stack-list-frames --thread 8
MI2: -stack-list-frames --thread 9
>MI2: -thread-info 10
MI2: -stack-list-frames --thread 10
>MI2: -thread-info 11
MI2: -stack-list-frames --thread 11
>MI2: -thread-info 12
MI2: -stack-list-frames --thread 12
MI2: -thread-info 13
MI2: -stack-list-frames --thread 13
>MI2: -thread-info 14
MI2: -stack-list-frames --thread 14
>MI2: -thread-info 15
MI2: -thread-info 16
>MI2: -stack-list-frames --thread 15
MI2: -stack-list-frames --thread 16
>MI2: -thread-info 17
MI2: -stack-list-frames --thread 17
>MI2: -thread-info 18
MI2: -stack-list-frames --thread 18
>MI2: -thread-info 19
MI2: -stack-list-frames --thread 19
MI2: -thread-info 20
MI2: -stack-list-frames --thread 20
MI2: -thread-info 21
MI2: -thread-info 22
>MI2: -stack-list-frames --thread 21
MI2: -stack-list-frames --thread 22
MI2: -interpreter-exec console "info proc mappings"
MI2: -list-thread-groups i1
MI2: -thread-select --thread 9 9
MI2: -list-thread-groups
MI2: -list-thread-groups
|
Beta Was this translation helpful? Give feedback.
-
I just came over here from #3102 that I opened about this issue. I have only skimmed through the the thread, so I am not 100% sure how you are connecting GDB to your device, but I know that WSL does not really work well with USB devices, so if you are using a USB debugger, that might be part of the problem. A possible alternative is to use a Raspberry Pi with the USB debugger plugged into it, and run the GDB server on the Raspberry Pi, then connect Ghidra to that. I'm going to be trying setting that up with a SEGGER J-Link in the next few days, and will add a comment here if that works. |
Beta Was this translation helpful? Give feedback.
-
@marsfan Sorry to be a pest, but my questions are relevant to the solution of your problem: do you have the Objects view visible and does that have anything in it? All of the other windows depend on the trace. If the trace isn't active, all of those will be blank. There are a number of reasons why this might be - many of the discussed above - but, if the Objects view is empty, it's a whole different set of problems. |
Beta Was this translation helpful? Give feedback.
-
In a pre-built distribution of Ghidra 10.0.1, how would I go about changing the |
Beta Was this translation helpful? Give feedback.
-
Any fixes lately to any problems that may have caused the issues with using Ghidra and ssh as debugger for the 3ds? This is a very old discussion, but I was wondering if it may not be too far gone? |
Beta Was this translation helpful? Give feedback.
-
Probably, although we definitely made some debugger-specific fixes in 10.0.3 |
Beta Was this translation helpful? Give feedback.
-
So I got some things working again. WSL finally booted up, after a PC reboot. And Ghidra connects successfully. The interpreter is filled with newline characters, and no threads are showing up. Clicking 'record' on the process opens this window: The "Debug Console" shows this:
|
Beta Was this translation helpful? Give feedback.
-
So, when you say "Ghidra connects successfully", what do you mean, i.e. what steps exactly did you take to launch the debugger and connect to the 3ds? The stack trace just says, basically, GDB failed, so I need more to go on. |
Beta Was this translation helpful? Give feedback.
-
@d-millar Hey! This is just me checking back foreverrrr later... I haven't been debugging 3ds for a long time, but I want to try maybe today, and I was wondering, do I still have to connect to WSL first? Or can I run gdb directly on windows yet? 🤔 |
Beta Was this translation helpful? Give feedback.
-
@SirEnder125 Long time! I think the issue may still be the version of gdb you need. In other words, if you need gdb-multiarch or something similar, I’m not sure Windows proper has an equivalent. That said, doesn’t hurt to try. I would use the “gdb over ssh” connector and see how you fare. |
Beta Was this translation helpful? Give feedback.
-
Ah, that's interesting - didn't realize Windows had a version of gdb-multiarch. Is that built to link against the WSL libraries or the native Windows API? In any case, I don't think that will work. We haven't implemented a version using ConPTY or any othe Windows Pseudo Console, primarily because the "GDB over SSH" option seems to fill that need. Are there shortcomings in the "GDB over SSH" solution that you feel merit time spent on a ConPTY solution? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hey. Someone recently told me:
I'm not sure if it is compatible. But Luma3ds does have a gdb stub. But the debugger gives me this error:
Beta Was this translation helpful? Give feedback.
All reactions