<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="">Ethin,<div class=""><br class=""></div><div class="">USB was designed in the 90’s and people actually worried about the number of Si gates in a mouse, so a vast majority of the complexity of USB is in the USB Host Controller (XHCI is the common  host controller, aka HC). The devices are just end points on the bus. The end points are abstracted via the USB IO protocol. So you just need to match up the USB IO protocol to the USB sub spec for audio devices. The XHCI complexity is abstracted via a USB HC (Host Controller) driver that is consumed by the generic USB Bus driver that enumerates all the devices and produces USB IO. So you can just treat the USB IO protocol as a black box. </div><div class=""><br class=""></div><div class="">So I think your 1st task is getting your Driver Bindging Supported() function matching on an audio endpoint you want to support. The Supported() will need to return success before your Start() function is called. So maybe take a look at some example USB drivers that sit in the same layer in the stack for different devices? [1]</div><div class=""><br class=""></div><div class="">[1] </div><div class=""><a href="https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c#L68" class="">https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Bus/Usb/UsbMouseDxe/UsbMouse.c#L68</a></div><div class=""><a href="https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c#L72" class="">https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Bus/Usb/UsbKbDxe/EfiKey.c#L72</a></div><div class=""><a href="https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c#L706" class="">https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassImpl.c#L706</a></div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Andrew Fish<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 11, 2021, at 9:47 PM, 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="">Yeah, maybe. Now I just have to figure out where to even begin with</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="">USB audio. The specs aren't useful in determining where to begin -- 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="">at least they aren't from my POV (though that might just be my</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="">inexperience with USB/XHCI showing).</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=""><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 4:29 PM, Ethin Probst <<a href="mailto:harlydavidsen@gmail.com" class="">harlydavidsen@gmail.com</a>><br class="">wrote:<br class=""><br class="">Your suggestion of adding 0x240 worked. I'm able to successfully step<br class="">through the code now. Thank you!<br class=""><br class=""></blockquote><br class="">OK that makes sense. The address in the add-symbol-file command is not the<br class="">load address of the image, but the start address of the text section. So<br class="">that is why you had to add 0x240.<br class=""><br class="">Sorry I had to work backwards from how it works, but maybe that info will be<br class="">helpful for others?<br class=""><br class="">Thanks,<br class=""><br class="">Andrew Fish<br class=""><br class=""><blockquote type="cite" class="">On 6/11/21, Andrew Fish <<a href="mailto:afish@apple.com" class="">afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>> wrote:<br class=""><blockquote type="cite" class=""><br class=""><br class=""><blockquote type="cite" class="">On Jun 11, 2021, at 2:29 PM, Ethin Probst <<a href="mailto:harlydavidsen@gmail.com" class="">harlydavidsen@gmail.com</a>><br class="">wrote:<br class=""><br class="">Initial connection and loading symbols:<br class="">Remote debugging using :1234<br class="">0x000000007e4b9517 in ?? ()<br class="">add symbol table from file<br class="">"Build/MdeModule/DEBUG_GCC5/X64/UsbAudio.debug"<br class="">at<br class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>.text_addr = 0x7e4b8000<br class="">Reading symbols from Build/MdeModule/DEBUG_GCC5/X64/UsbAudio.debug...<br class="">Expanding full symbols from<br class="">Build/MdeModule/DEBUG_GCC5/X64/UsbAudio.debug...<br class="">Backtrace:<br class="">#0  0x000000007e4b9517 in UefiMain (st=0x7f9ee018,<br class="">imageHandle=0x7e4f7518) at<br class="">/home/ethin/source/edk/edk2/MdeModulePkg/Application/UsbAudio/UsbAudio.c:72<br class="">#1  ProcessModuleEntryPointList (SystemTable=0x7f9ee018,<br class="">ImageHandle=0x7e4f7518) at<br class="">/home/ethin/source/edk/edk2/Build/MdeModule/DEBUG_GCC5/X64/MdeModulePkg/Application/UsbAudio/UsbAudio/DEBUG/AutoGen.c:300<br class="">#2  _ModuleEntryPoint (ImageHandle=0x7e4f7518, SystemTable=0x7f9ee018)<br class="">at<br class="">/home/ethin/source/edk/edk2/MdePkg/Library/UefiApplicationEntryPoint/ApplicationEntryPoint.c:59<br class="">#3  0x000000007fead316 in ?? ()<br class="">#4  0x000000007e4f7518 in ?? ()<br class="">#5  0x000000007feab5c7 in ?? ()<br class="">#6  0x000000007fea3520 in ?? ()<br class="">#7  0x0000000101000000 in ?? ()<br class="">#8  0x0000000000000030 in ?? ()<br class="">#9  0x000000007e4f6018 in ?? ()<br class="">#10 0x000000007e60a918 in ?? ()<br class="">#11 0x000000000000011d in ?? ()<br class="">#12 0x000000007fea3528 in ?? ()<br class="">#13 0x000000007e4f7818 in ?? ()<br class="">#14 0x000000007e4f7c98 in ?? ()<br class="">#15 0x000000007fea3538 in ?? ()<br class="">#16 0x000000007e3abfca in ?? ()<br class="">#17 0x000000007e4f7418 in ?? ()<br class="">#18 0x000000007fea3528 in ?? ()<br class="">#19 0x0000000000000000 in ?? ()<br class="">Source-code listing:<br class="">1<span class="Apple-tab-span" style="white-space: pre;">  </span>/** @file<br class="">2<span class="Apple-tab-span" style="white-space: pre;">   </span><span class="Apple-converted-space"> </span> GCC inline implementation of BaseLib processor specific functions.<br class="">3<span class="Apple-tab-span" style="white-space: pre;">     </span><br class="">4<span class="Apple-tab-span" style="white-space: pre;">    </span><span class="Apple-converted-space"> </span> Copyright (c) 2006 - 2020, Intel Corporation. All rights<br class="">reserved.<BR><br class="">5<span class="Apple-tab-span" style="white-space: pre;">       </span><span class="Apple-converted-space"> </span> Portions copyright (c) 2008 - 2009, Apple Inc. All rights<br class="">reserved.<BR><br class="">6<span class="Apple-tab-span" style="white-space: pre;">      </span><span class="Apple-converted-space"> </span> SPDX-License-Identifier: BSD-2-Clause-Patent<br class="">7<span class="Apple-tab-span" style="white-space: pre;">   </span><br class="">8<span class="Apple-tab-span" style="white-space: pre;">    </span>**/<br class="">9<span class="Apple-tab-span" style="white-space: pre;"> </span><br class="">10<span class="Apple-tab-span" style="white-space: pre;">   </span><br class="">Attempt to use "next":<br class="">72<span class="Apple-tab-span" style="white-space: pre;">      </span>} else if (interfaceDescriptor.InterfaceClass == 0x01 &&<br class="">interfaceDescriptor.InterfaceSubClass == 0x03) {<br class="">(This is my code but it continuously prints this same line over and<br class="">over every time "next" is used.)<br class="">Attempt to use "print Index":<br class="">No symbol "Index" in current context.<br class="">info local:<br class="">UsbIo = 0x0<br class="">interfaceDescriptor = {Length = 0 '\000', DescriptorType = 8 '\b',<br class="">InterfaceNumber = 1 '\001', AlternateSetting = 0 '\000', NumEndpoints<br class="">= 0 '\000', InterfaceClass = 0 '\000', InterfaceSubClass = 0 '\000',<br class="">InterfaceProtocol = 0 '\000',<br class="">Interface = 0 '\000'}<br class="">i = 2118887920<br class="">numHandles = 264<br class="">handles = 0x4<br class="">status = <optimized out><br class="">info symbol 0x0007E4B9440:<br class="">_ModuleEntryPoint + 576 in section .text of<br class="">/home/ethin/source/edk/edk2/Build/MdeModule/DEBUG_GCC5/X64/UsbAudio.debug<br class=""></blockquote><br class="">OK that is interesting…. +576 -> 0x240 witch is about the size of the<br class="">PE/COFF header.<br class=""><br class="">For mach-O (macOS executables) we have to link at 0x240 to make space<br class="">for<br class="">the PE/COFF header in memory….<br class=""><br class="">So the PE/COFF header starts at 0x7e4b8000 it is likely the text section<br class="">starts at 0x7e4b8240? So try adding 0x240 to the load address on the<br class="">add-symbol-file command. If that does not work trip subtracting 0x240<br class="">from<br class="">the load address.<br class=""><br class="">We would need to dump out the UsbAudio.efi file to figure out exactly<br class="">what<br class="">is going on. What distro are you on? Do you have the readpe utility? I’m<br class="">not<br class="">sure what you can dump with objcopy?<br class=""><br class="">Can you mail me a copy of UsbAudio.efi off list? I can take a quick<br class="">look.<br class=""><br class="">Thanks,<br class=""><br class="">Andrew Fish<br class=""><br class=""><blockquote type="cite" class="">The extra weird thing about this is that CpuDeadLoop() is at the start<br class="">of the UefiMain function, its not on line 72. The program doesn't even<br class="">start there -- it starts by attempting to get the list of<br class="">EFI_USB_IO_PROTOCOL handles available. And GDB is making it look like<br class="">its skipping all of that.<br class=""><br class="">On 6/11/21, Andrew Fish <<a href="mailto:afish@apple.com" class="">afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>>> wrote:<br class=""><blockquote type="cite" class=""><br class=""><br class=""><blockquote type="cite" class="">On Jun 11, 2021, at 1:48 PM, Ethin Probst <<a href="mailto:harlydavidsen@gmail.com" class="">harlydavidsen@gmail.com</a><br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a>>><br class="">wrote:<br class=""><br class="">Okay, so I just tried exactly what you told me to do -- use<br class="">CpuDeadLoop() and then just modify index to get out of it. Here's<br class="">what<br class="">I do in GDB:<br class="">- Load the EFI application and connect via target remote :1234<br class="">- type `add-symbol-file Build/MdeModule/DEBUG_GCC5/X64/UsbAudio.debug<br class="">0x0007E4B8000` and answer yes when it prompts me to do so.<br class="">(0x0007E4B8000 is the image base, the entry point is at<br class="">0x0007E4B9440.)<br class="">- When I try to print the Index symbol, GDB tells me that it isn't in<br class="">the current context.<br class="">I feel like I'm missing something. I'm also not the best with GDB<br class="">myself.<br class="">:)<br class=""></blockquote><br class="">What do you get from the following gdb commands?<br class="">bt<br class="">info local<br class="">info symbol 0x0007E4B9440<br class=""><br class="">What exactly is gdb showing you?<br class=""><br class="">Thanks,<br class=""><br class="">Andrew Fish<br class=""><br class=""><blockquote type="cite" class=""><br class="">On 6/11/21, Andrew Fish <<a href="mailto:afish@apple.com" class="">afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>>>> wrote:<br class=""><blockquote type="cite" class=""><br class=""><br class=""><blockquote type="cite" class="">On Jun 11, 2021, at 11:39 AM, Ethin Probst <<a href="mailto:harlydavidsen@gmail.com" class="">harlydavidsen@gmail.com</a><br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a>><br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a><span class="Apple-converted-space"> </span><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a>>>><br class="">wrote:<br class=""><br class="">Hi Andrew,<br class="">How do you debug the EFI binary with LLDB? Can LLDB use GDB stubs<br class="">or<br class="">does that work differently?<br class=""><br class=""></blockquote><br class="">Ethin,<br class=""><br class="">Lldb is the command line debugger that comes with Xcode on Mac.<br class="">There<br class="">is<br class="">no<br class="">gdb with Xcode, so I have to use lldb for my day job.<br class=""><br class="">Lldb can speak the gdb remote serial protocol: lldb -o “gdb-remote<br class="">9000”<br class="">That assumes you passed `-gdb tcp::9000`to QEMU.<br class=""><br class="">Thanks,<br class=""><br class="">Andrew Fish<br class=""><br class=""><blockquote type="cite" class="">On 6/11/21, Andrew Fish <<a href="mailto:afish@apple.com" class="">afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>><br class=""><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a><span class="Apple-converted-space"> </span><<a href="mailto:afish@apple.com" class="">mailto:afish@apple.com</a>>>>>> wrote:<br class=""><blockquote type="cite" class=""><br class=""><br class=""><blockquote type="cite" class="">On Jun 11, 2021, at 10:06 AM, Ethin Probst<br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">harlydavidsen@gmail.com</a><span class="Apple-converted-space"> </span><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a>><br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a><span class="Apple-converted-space"> </span><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a>>><br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a><span class="Apple-converted-space"> </span><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a>><br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">mailto:harlydavidsen@gmail.com</a><br class=""><<a href="mailto:harlydavidsen@gmail.com" class="">mailto: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<br class="">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<br class="">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><br class=""><<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a>><br class=""><<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a><br class=""><<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a>>><br class=""><<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a><br class=""><<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a>><br class=""><<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a><br class=""><<a href="https://github.com/Richard-W/uefi-run" class="">https://github.com/Richard-W/uefi-run</a>>>>) like this (from the<br class="">main<br class="">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<br class="">-device<br class="">qemu-xhci -device usb-audio,audiodev=audio -audiodev<br class="">alsa,id=audio<br class="">-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<br class="">-device<br class="">qemu-xhci -device usb-audio,audiodev=audio -audiodev<br class="">alsa,id=audio<br class="">-s<br class="">-debugcon stdio -global isa-debugcon.iobase=0x402<br class="">- I connect to the remote GDB stub (localhost:1234) and wait<br class="">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<br class="">this<br class="">point:<br class="">1. Either I get the wrong debug information (I get source code<br class="">but<br class="">the<br class="">image isn't loaded anymore), and resetting the system and placing<br class="">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<br class="">and<br class="">the image base and entry point addresses, and then appears to<br class="">just<br class="">sit<br class="">there waiting for something. Once I load the symbols using the<br class="">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<br class="">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<br class="">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<br class="">might<br class="">be<br class="">a<br class="">little off on gdb specifics…. Also my terminology may be lldb<br class="">centric.<br class=""><br class="">Easy one 1st. When you run on top of a debugger using<br class="">CpuBreakpoint()<br class="">works<br class="">great as the debugger hides its self from you. On x86<br class="">CpuBreakpoint()<br class="">is<br class="">an<br class="">INT 3h instruction (0xCC) and it causes an exception 3. If you<br class="">don’t<br class="">have<br class="">a<br class="">debugger hooked in underneath  the exception 3 is going to get<br class="">handled<br class="">in<br class="">the unexpected exception handler, and that is probably in the CPUD<br class="">DXE<br class="">driver or DXE Core or some such. So you are going to end up with<br class="">the<br class="">PC/IP/RIP in the wrong driver. A lot of times for hardware<br class="">debuggers<br class="">it<br class="">works better to use CpuDeadLoop(). The gdb-remote stub from QEMU<br class="">acts<br class="">a<br class="">lot<br class="">more like a JTAG hardware debugger than a pure software debugger.<br class="">Also<br class="">note<br class="">that CpuDeadLoop() is an infinite loop, so you can modify the loop<br class="">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<br class="">CpuDeadLoop(),<br class="">attach gdb. Now after you have the target established load the<br class="">symbols.<br class="">The<br class="">reason for me suggesting this flow is the debugger has a flexible<br class="">concept<br class="">of<br class="">what the target is. If you load symbols that will create a target<br class="">for<br class="">a<br class="">stock x86-64 image. When you connect to the QEMU gdb-remote there<br class="">is<br class="">a<br class="">handshake that describes the target and what registers are<br class="">available.<br class="">I<br class="">seem<br class="">to remember QEMU exports some of the system registers, like the<br class="">control<br class="">registers, so it is an extended version of the x86-64 target. So<br class="">this<br class="">changing the target definition might confuse the debugger. To be<br class="">safe<br class="">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<br class="">around<br class="">zero. They get loaded into memory and relocated, so that is why<br class="">you<br class="">need<br class="">to<br class="">specify the load address to get the symbols to resolve. One trick<br class="">I<br class="">use<br class="">is<br class="">to load the ELF (or PE/COFF) build output directly into the<br class="">debugger.<br class="">This<br class="">lets you poke around the image at the linked address. You can<br class="">disassemble<br class="">the functions to see what they look like, obviously you can read<br class="">any<br class="">variables. This can be useful if you get the unhandled exception<br class="">and<br class="">it<br class="">prints out the load address and offset (you can use the offset<br class="">directly).<br class="">It<br class="">is also a good way to debug why your symbols are not quite loaded<br class="">at<br class="">the<br class="">correct address, as you can see what bytes/instructions should be<br class="">at<br class="">a<br class="">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 class=""><br class="">--<br class="">Signed,<br class="">Ethin D. Probst<br class=""><br class=""><br class=""><br class=""></blockquote><br class=""><br class=""></blockquote><br class=""><br class="">--<br class="">Signed,<br class="">Ethin D. Probst<br class=""><br class=""><br class=""><br class=""></blockquote><br class=""><br class=""></blockquote><br class=""><br class="">--<br class="">Signed,<br class="">Ethin D. Probst<br class=""></blockquote><br class=""><br class=""></blockquote><br class=""><br class="">--<br class="">Signed,<br class="">Ethin D. Probst<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=""></div></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/76434">View/Reply Online (#76434)</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>