<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 11, 2021, at 11:39 AM, Ethin Probst <<a href="mailto:harlydavidsen@gmail.com" class="">harlydavidsen@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Hi Andrew,</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">How do you debug the EFI binary with LLDB? Can LLDB use GDB stubs or</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">does that work differently?</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div></blockquote><div><br class=""></div><div>Ethin,</div><div><br class=""></div><div>Lldb is the command line debugger that comes with Xcode on Mac. There is no gdb with Xcode, so I have to use lldb for my day job. </div><div><br class=""></div><div>Lldb can speak the gdb remote serial protocol: lldb -o “gdb-remote 9000” </div><div>That assumes you passed `<span style="font-family: Consolas, "Bitstream Vera Sans Mono", "Courier New", Courier, monospace; font-size: 14.000000953674316px; white-space: nowrap; background-color: rgb(255, 255, 255);" class="">-gdb tcp::9000`</span>to QEMU.</div><div><br class=""></div><div>Thanks,</div><div><br class=""></div><div>Andrew Fish</div><br class=""><blockquote type="cite" class=""><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">On 6/11/21, Andrew Fish <</span><a href="mailto:afish@apple.com" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">afish@apple.com</a><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">> wrote:</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class=""><br class=""><blockquote type="cite" class="">On Jun 11, 2021, at 10:06 AM, Ethin Probst <<a href="mailto:harlydavidsen@gmail.com" class="">harlydavidsen@gmail.com</a>><br class="">wrote:<br class=""><br class="">Hey all,<br class=""><br class="">So Leif and I have discussed this at length but I thought I'd reach<br class="">out to all of you for more help.<br class=""><br class="">I'm having a lot of trouble debugging my UEFI app. Here's how I do<br class="">things:<br class=""><br class="">- I load the app using uefi-run<br class="">(<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a>) like this (from the main EDK<br class="">II directory): uefi-run -b Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd<br class="">Build/OvmfX64/DEBUG_GCC5/X64/Shell.efi -- -M q35 -m 24G -usb -device<br class="">qemu-xhci -device usb-audio,audiodev=audio -audiodev alsa,id=audio -s<br class="">-debugcon file:../debug.log -global isa-debugcon.iobase=0x402<br class="">-nographic<br class="">Or:<br class="">uefi-run -b Build/OvmfX64/DEBUG_GCC5/FV/OVMF.fd<br class="">Build/OvmfX64/DEBUG_GCC5/X64/Shell.efi -- -M q35 -m 24G -usb -device<br class="">qemu-xhci -device usb-audio,audiodev=audio -audiodev alsa,id=audio -s<br class="">-debugcon stdio -global isa-debugcon.iobase=0x402<br class="">- I connect to the remote GDB stub (localhost:1234) and wait until<br class="">OVMF gives me the image base. Then I use:<br class="">add-symbol-file UsbAudio.debug <image base><br class="">Here's where everything breaks down. One of two things happens at this<br class="">point:<br class="">1. Either I get the wrong debug information (I get source code but the<br class="">image isn't loaded anymore), and resetting the system and placing a<br class="">breakpoint (either software or hardware) has no effect; or<br class="">2. If I use CpuBreakpoint(), the firmware gives me the registers and<br class="">the image base and entry point addresses, and then appears to just sit<br class="">there waiting for something. Once I load the symbols using the image<br class="">base it gives me, I can't actually do anything in the debugger; I<br class="">can't list code because I get "1 in <artificial>", I can't jump into<br class="">my code without triggering a general protection exception or not<br class="">actually causing anything to happen... You get the idea.<br class=""><br class="">So I'm really, really confused on what's going wrong. Do you guys have<br class="">any advice?<br class=""></blockquote><br class="">Ethin,<br class=""><br class="">Caveat emptor as I use lldb for my daily driver debugger so I might be a<br class="">little off on gdb specifics…. Also my terminology may be lldb centric.<br class=""><br class="">Easy one 1st. When you run on top of a debugger using CpuBreakpoint() works<br class="">great as the debugger hides its self from you. On x86 CpuBreakpoint() is an<br class="">INT 3h instruction (0xCC) and it causes an exception 3. If you don’t have a<br class="">debugger hooked in underneath  the exception 3 is going to get handled in<br class="">the unexpected exception handler, and that is probably in the CPUD DXE<br class="">driver or DXE Core or some such. So you are going to end up with the<br class="">PC/IP/RIP in the wrong driver. A lot of times for hardware debuggers it<br class="">works better to use CpuDeadLoop(). The gdb-remote stub from QEMU acts a lot<br class="">more like a JTAG hardware debugger than a pure software debugger. Also note<br class="">that CpuDeadLoop() is an infinite loop, so you can modify the loop variable<br class="">with the debugger to continue.<br class=""><br class="">I’d suggest a work flow of run your App/Driver, hit the CpuDeadLoop(),<br class="">attach gdb. Now after you have the target established load the symbols. The<br class="">reason for me suggesting this flow is the debugger has a flexible concept of<br class="">what the target is. If you load symbols that will create a target for a<br class="">stock x86-64 image. When you connect to the QEMU gdb-remote there is a<br class="">handshake that describes the target and what registers are available. I seem<br class="">to remember QEMU exports some of the system registers, like the control<br class="">registers, so it is an extended version of the x86-64 target. So this<br class="">changing the target definition might confuse the debugger. To be safe I<br class="">always connect 1st and then load symbols.<br class=""><br class="">The EFI images are PE/COFF relocatable executables that are linked around<br class="">zero. They get loaded into memory and relocated, so that is why you need to<br class="">specify the load address to get the symbols to resolve. One trick I use is<br class="">to load the ELF (or PE/COFF) build output directly into the debugger. This<br class="">lets you poke around the image at the linked address. You can disassemble<br class="">the functions to see what they look like, obviously you can read any<br class="">variables. This can be useful if you get the unhandled exception and it<br class="">prints out the load address and offset (you can use the offset directly). It<br class="">is also a good way to debug why your symbols are not quite loaded at the<br class="">correct address, as you can see what bytes/instructions should be at a given<br class="">address.<br class=""><br class="">Thanks,<br class=""><br class="">Andrew Fish<br class=""><br class=""><blockquote type="cite" class=""><br class="">--<br class="">Signed,<br class="">Ethin D. Probst<br class=""><br class=""><br class=""><br class=""><br class=""><br class=""></blockquote><br class=""><br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Signed,</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Ethin D. Probst</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span></div></blockquote></div><br class=""></body></html>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/76406">View/Reply Online (#76406)</a> |    |  <a target="_blank" href="https://groups.io/mt/83473484/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>