Replies: 76 comments 54 replies
-
@yattr Hey and sorry you're getting stuck! I think you're probably getting confused by the convenience methods on main Toolbar, which are not, I think, exactly what you want for your scenario. By way of example, let's say you have xclock loaded in the static listing. Hitting "Debug xclock in GDB via ssh:user@localhost is going to attempt to run /usr/bin/gdb on the local box, assuming there's an account name "user" which you can authenticate to, and then launch xclock in that gdb session. All of the specfics here are determined by the last execution. Instead of that, go to the Objects window and hit the "Create a new connection..." button. In the dialog that comes up, use the pull-down to select "gdb", make sure the path to a local version of gdb is correct, and hit connect. This should bring up a new gdb session without a target and a new Interpreter window. In the Interpreter window, enter "target remote 127.0.01:2331" as you might normally for a gdb/gdbserver configuration. Ghidra should then connect to the JLink GDB Server. For completeness, I should mention how "gdb via SSH" is intended to work, although the use case doesn't match yours. Had you opened the Objects window and selected "gdb via SSH", the resulting dialog would allow you to specify the path to gdb (on a potentially remote machine), the username and credentials for that machine, its IP and port, and some platform-dependent configuration options. Those parameters would be used to launch gdb over an ssh tunnel. Any subsequent launches made either from that dialog box or the main toolbar would use the same parameters. A bit confusing I'll concede - let us know if this doesn't get you to where you want. |
Beta Was this translation helpful? Give feedback.
-
All of this is a bit over my head but I am pushing forward trying to get something to work. 1 - I am using an Apple M1 based Mac. There is no GDB for this architecture at this time from what I can tell. 2 - I pursued both the Frida and LLDB approaches I found on the web for M1x based Macs but neither completed without issues. 3 - I will attempt with LLDB yet again and reply with the issues. I will be using the instructions from Ghidra GIT... Lastly, in the Ghidra Debugger the connection options are in the Debugger Targets window. Thank you for the detailed and timely response... |
Beta Was this translation helpful? Give feedback.
-
@yattr Understood - and, yes, setting up LLDB for use with Ghidra is considerably more complicated. The instructions are in Ghidra/Debug/Debugger-swig-lldb/InstructionsForBuildingLLDBInterface.txt. Before you do that, I would just make sure LLDB can attach to the JLink. The LLDB equivalent to GDB's "target remote host:port" is "gdb-remote host:port". If that works, let me know, and I can walk you through the setup instructions if they aren't clear. Apologies re "Objects" vs "Debugger Targets" - wasn't thinking. |
Beta Was this translation helpful? Give feedback.
-
I found this on Segger's web which is what I have been using but will try again with your settings LLDB support J-Link can be used with LLDB. Originally, GNU toolchains provided GCC as a compiler and GDB as a debugger. Since Clang’s introduction as a compiler, LLDB was introduced (which was essentially a GDB successor). In terms of protocol, it is backward compatible to GDB whilst the API for the IDE is slightly different. The J-Link Software and Documentation Package comes with the J-Link GDBServer. This permits the use of J-Link in LLDB-based setups. |
Beta Was this translation helpful? Give feedback.
-
Connecting lldb failed (lldb) gdb-remote host:2331 (lldb) version |
Beta Was this translation helpful? Give feedback.
-
"host" should be either "localhost" or "127.0.0.1" or the IP of whatever machine you're running JLink on (if remote) |
Beta Was this translation helpful? Give feedback.
-
Tried it both ways with the following results (lldb) gdb-remote localhost:2331
(lldb) gdb-remote 127.0.0.1:2331
From the Jlink server log Connected to target |
Beta Was this translation helpful? Give feedback.
-
Both of those look OK to me - not surprised by the warnings, essentially the JLink device is only supporting a subset of the Remote Serial Protocol commands. |
Beta Was this translation helpful? Give feedback.
-
Somehow you have an extra "gradle" in there - should be "gradle generateSwig" |
Beta Was this translation helpful? Give feedback.
-
MacBook-Pro Debugger-swig-lldb % echo $LLVM_HOME /path/to/llvm MacBook-Pro Debugger-swig-lldb % gradle generateSwig
FAILURE: Build failed with an exception.
BUILD FAILED in 2s |
Beta Was this translation helpful? Give feedback.
-
Ah, yes, you will need to install swig. |
Beta Was this translation helpful? Give feedback.
-
" yes, setting up LLDB for use with Ghidra is considerably more complicated" Living up to the stated expectations...about to continue...... |
Beta Was this translation helpful? Give feedback.
-
I hear ya - if it's any consolation, we're moving to a Python-based set of debuggers (hopefully, 11.1) which should remove some of these difficulties. |
Beta Was this translation helpful? Give feedback.
-
Good to know - thanks...just might wait! I have been using Ghidra for an nRF51x based device and found that I need to interact with the running code (stepping through it) to get all the branching to worked out in Ghidra. Segger has a Ozone which is nice but it operates independent of Ghidra. As I fumble my way through understand all the great features of Ghidra, I decided to go down the path of its debugger. I am learning a lot but not making any progress... I thought having Jlink and Ghidra coupled would help get the branches sorted out. I have yet to figure out how to get a branch, bx, from a register, r3, to flow to the branch address contained in r3... |
Beta Was this translation helpful? Give feedback.
-
Will have to concede, am kind of a x64 guy, so may not be helpful on that front. That said, the big issues using Ghidra's debugger center on getting the mapping from the static images to the dynamic images. For this to work, you have to have or be able to fake the commands that report the target's memory regions and the loaded modules. For embedded devices, that usually means telling Regions to map in the entire address space and telling Modules to map your current static image to the existing dynamic space. The Debugger Help is one place to start, but the Debugger Course include with the distro is probably your best bet. |
Beta Was this translation helpful? Give feedback.
-
I have been trying a few things... The only path to an Interpreter is via Target LLDB then Object Connector Context to server. With the above lldb appears. Entering gdb-remote 2331 results in (lldb)gdb-remote 2331 and (lldb)gdb-remote 127.0.0.1:2331 I can not identify a process with the number. Any ideas? |
Beta Was this translation helpful? Give feedback.
-
Are you testing from Ghidra or from lldb proper? And what do you get if you type "process status" in the command line? |
Beta Was this translation helpful? Give feedback.
-
lldb within ghidra... (lldb)process status
if I tyoe "contimue" then "process status" (lldb)continue nothing from process status Note no executable module.... |
Beta Was this translation helpful? Give feedback.
-
Oh, ok - well, that’s reasonably encouraging! Once the target is running, it’s unlikely any commands will receive a response. The next things I would try are: (1) hitting the pause button on the Interpreter and/or in Objects after you’ve said “continue” to see whether you can stop the target again. (Note: I would close the connection from Targets between experiments.) |
Beta Was this translation helpful? Give feedback.
-
OK, so a couple of things to explain and a couple of things to try.... Probably, more than you want to know but...in the Debugger, the only Windows that communicate directly with the target are Targets, Objects, and the Interpreter. Everything else is mediated by a thing we call the trace, which records everything you do and the state of your targets every time you are stopped. This allows us to do some interesting things, but also means, if the trace setup fails, all of the other windows are blank - which obviously is where we're at right now. There are a couple of bits of your situation that are unsurprising and a couple more that strike me as odd. The fact that the only thread has tid 0xdead is definitely among the latter - not an artifact we're adding as far as I know. I'd be interested in whether you get the same values from lldb w/o ghidra. If you're up for an experiment, start lldb and then enter: (1) gdb-remote 127.0.0.1:2331 (or maybe localhost:2332 or 0.0.0.0:2331) Am wondering if the tid is still 0xdead. The register command, I think, failed because I mis-typed it - should be "registers read". FYI, in the Interpreter or lldb command line, "help" will get you the list of commands, "help threads" those pertaining to threads, etc. Two other commands I'd be interested in "target module list" and "target module dump". If either of those fail (or have output different than what we expect), the trace startup will fail. Another thing to try in Ghidra: while stopped, from the Regions window, use the top right pull-down to "Force Full View". Also, if that works, from the Modules window use the double-headed arrow to "Map the current trace to the current program". This may not work if the Regions thing didn't get you a trace, but.... |
Beta Was this translation helpful? Give feedback.
-
I am still launching ghidraDedug. There are still a few errors indicated... Last login: Wed Mar 6 13:07:31 on ttys001 Frame is not validINFO *** State Changed: 1 (DebugClientImpl.java:331) ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged(r) (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process>
consoleOutput: error: 'registers' is not a valid command.consoleOutput: Commands to access registers for the current thread and stack frame. Syntax: register [read|write|info] ...The following subcommands are supported:
For more help on any particular subcommand, type 'help '. consoleOutput: error: Command requires a process, which is currently stopped. INFO *** State Changed: 1 (DebugClientImpl.java:331) ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> consoleOutput: Process 57005 stopped
consoleOutput: Process 57005 resuming INFO *** State Changed: 1 (DebugClientImpl.java:331) ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> ERROR Listener ghidra.app.plugin.core.debug.gui.objects.DebuggerObjectsProvider$MyObjectListener@52585b48 caused exception processing attributesChanged (DebuggerCallbackReorderer.java:116)java.util.NoSuchElementException: No mapper for target: <LldbModelTargetProcessImpl: path=Sessions[dead].Processes[dead] model=agent.lldb.model.impl.LldbModelImpl@4d767e38 schema=Process> |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Alternatively, you can enter a command in the Interpreter - trying to find that right now.... |
Beta Was this translation helpful? Give feedback.
-
I think it's going to be something like: set target.default-arch XXX or set platform.plugin.qemu-ser.architecture XXX or possibly platform select remote-gdb-server If you guess correctly, I believe the "register read" command will work. |
Beta Was this translation helpful? Give feedback.
-
OK, may have to do some more googling to find that command syntax. Am guessing the third command did not enable “register read”. The picture of the JLink however is very interesting - it shows which gdb/RSP packets are being sent. That could be very helpful. Does something get displayed when you issue “register read”? |
Beta Was this translation helpful? Give feedback.
-
OK, the correct syntax for the first two commands above would be "settings set ...." (vs "set ...). If it's supported "settings show", should list all the things on your target that can be set. Am hoping (a) that command is supported, and (b) it lists something related to "architecture". |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Yes tried armv7 and arm32....no dice "help set" results in the same output as "help settings". The help listing for "set" starts off with "Commands for managing LLDB settings." I use "set set" and that works... Interesting that searching on " target.default-arch" doesn't produce anything helpful nor does "LLDB architecture settings" You have to love the phrase "when there's a choice" and none are listed or help doesn't provide anything for acceptable values... |
Beta Was this translation helpful? Give feedback.
-
Thank you for all of your assistance. Heading back to Ozone with ghidra approach... |
Beta Was this translation helpful? Give feedback.
-
Am sorry we couldn't get things working via lldb! Good luck! |
Beta Was this translation helpful? Give feedback.
-
Ghidra version 11.0.1. Jlink GDB Server version V7.94k
I start the server...
I select GDB via ssh:user@localhost"? which result in this (connected but indicating 0 connections
The I repeat the above and get this with 2 connected.
But, nothing ever goes beyond the waiting to connect at 0%?????
Beta Was this translation helpful? Give feedback.
All reactions