<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 Jul 30, 2021, at 3:37 AM, Marvin Häuser <<a href="mailto:mhaeuser@posteo.de" class="">mhaeuser@posteo.de</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Good day everyone,<br class=""><br class="">I'm currently refining the port of EmulatorPkg to my new PE/COFF loader library instance.<br class="">In the process, I found the function DlOpenImage() [1], which loads UEFI Images via the OS loader to utilise its symbol loading capability. Theoretically, this should e.g. allow arbitrary debuggers using the OS APIs to symbolise the backtrace.<br class=""><br class="">macOS: The function seems to be unused entirely. [2]<br class=""><br class="">Linux: On my system running Fedora 34, the function neither works out-of-the-box, nor after significant time of trying to fix it. The first issue is that it only proceeds if the Image has a PDB path with ".pdb" extension [3], while the GCC5 toolchain generates Images with ".dll" files for PDB paths (see errors below). Once this is resolved, there is an error message indicating insufficient Image section alignment:<br class=""><br class="">[...]/Build/EmulatorX64/DEBUG_GCC5/X64/MdeModulePkg/Universal/EbcDxe/EbcDxe/DEBUG/EbcDxe.dll: ELF load command alignment not page-aligned<br class=""><br class=""></div></div></blockquote><div><br class=""></div><div>The requiring *.pdb seems like something that rotted out and could be fixed. </div><br class=""><blockquote type="cite" class=""><div class=""><div class="">Resolving this yields an error that executable files cannot be loaded dynamically:<br class=""><br class="">[...]/Build/EmulatorX64/DEBUG_GCC5/X64/MdeModulePkg/Core/Pei/PeiMain/DEBUG/PeiCore.dll: cannot dynamically load executable<br class=""><br class="">With my very limited knowledge about Linux and ELF I tried the naive approach of building the Images as shared (hoping it would be similar to DLLs, which are built on Windows), but this just silently crashes.<br class=""><br class=""></div></div></blockquote><div><br class=""></div><div>This code is very very old. Notice the comment about gdb predates gdb Python support [1].</div><div><br class=""></div><div>What happens if you comment out the DlLoadImage path? There seems to be some gdb scripts? The macOS path sets breakpoints on SecGdbScriptBreak() in an lldb script and loads symbols via that path. That his probably the best path forward for gdb too? </div><div><br class=""></div><div>It looks like if you `build.sh run` you should launch the emulator under gdb and source the symbol loading file.</div><div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">EmulatorPkg/build.sh</span><span style="font-variant-ligatures: no-common-ligatures; color: #2eaebb" class="">:</span><span style="font-variant-ligatures: no-common-ligatures" class="">221</span><span style="font-variant-ligatures: no-common-ligatures; color: #2eaebb" class="">:</span><span style="font-variant-ligatures: no-common-ligatures" class="">  /usr/bin/gdb $BUILD_ROOT_ARCH/Host -q -cd=$BUILD_ROOT_ARCH -x $WORKSPACE/EmulatorPkg/Unix/</span><span style="font-variant-ligatures: no-common-ligatures; color: #b42419" class=""><b class="">GdbRun.sh</b></span></div><div class=""><br class=""></div></div>If you comment out the dlopen() path does it start working? Looks like breaking in with gdb should get symbols loaded? </div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="">So my questions are:<br class="">1) Does this code currently work for anyone?<br class="">2) Does anyone use a debugging setup that is incompatible with Images loaded by EDK II rather than the OS?<br class=""></div></div></blockquote><div><br class=""></div><div>Not a 100% sure what you are asking? In a lot of cases you are debugging what is compatible with the OS? For example on macOS we build a mach-O and convert that to PE/COFF. We point the PDB entry at the mach-O file and that is what the debugger sees. As long as the PE/COFF lines up with the mach-O it does not really matter, as at the end of the day the debugger is just processing the dwarf debug info associated with addresses in system memory. </div><br class=""><blockquote type="cite" class=""><div class=""><div class="">3) Are the issues above known and planned to be fixed?<br class=""><br class=""></div></div></blockquote><div><br class=""></div><div>Not likely please file a BZ. </div><div><br class=""></div><div>Note I’m working on getting a generic gdb debugging script into the edk2 [2] and that should also work with the Emulator. I think you could replace the ` -x $WORKSPACE/EmulatorPkg/Unix/GdbRun.sh` with `-ex efi_gdb.py’. There is not a break hook in those scripts so you would have to run the `efi` command the 1st time you attach to load symbols. The efi_gdb.py script works on stock EFI so it does not depend on any of the hooks in the EmulatorPkg to work. </div><br class=""><blockquote type="cite" class=""><div class=""><div class="">Thank you for your time!<br class=""><br class="">Best regards,<br class="">Marvin<br class=""><br class=""><br class="">[1]<br class=""><a href="https://github.com/tianocore/edk2/blob/be282b14938846960cce30825a9fe762e14ca8c9/EmulatorPkg/Unix/Host/Host.c#L1065-L1113" class="">https://github.com/tianocore/edk2/blob/be282b14938846960cce30825a9fe762e14ca8c9/EmulatorPkg/Unix/Host/Host.c#L1065-L1113</a><br class=""><br class="">[2]<br class="">https://github.com/tianocore/edk2/blob/be282b14938846960cce30825a9fe762e14ca8c9/EmulatorPkg/Unix/Host/Host.c#L1071-L1073<br class=""><br class="">[3]<br class="">https://github.com/tianocore/edk2/blob/be282b14938846960cce30825a9fe762e14ca8c9/EmulatorPkg/Unix/Host/Host.c#L1084-L1086<br class="">https://github.com/tianocore/edk2/blob/be282b14938846960cce30825a9fe762e14ca8c9/EmulatorPkg/Unix/Host/Host.c#L1003-L1026<br class=""><br class=""></div></div></blockquote></div><br class=""><div class="">[1] <a href="https://github.com/tianocore/edk2/blob/be282b14938846960cce30825a9fe762e14ca8c9/EmulatorPkg/Unix/Host/Host.c#L1179" class="">https://github.com/tianocore/edk2/blob/be282b14938846960cce30825a9fe762e14ca8c9/EmulatorPkg/Unix/Host/Host.c#L1179</a></div><div class="">[2] <a href="https://github.com/ajfish/edk2/blob/BZ3500-gdb/efi_gdb.py" class="">https://github.com/ajfish/edk2/blob/BZ3500-gdb/efi_gdb.py</a></div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Andrew Fish</div><div class=""><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/78443">View/Reply Online (#78443)</a> |    |  <a target="_blank" href="https://groups.io/mt/84547497/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>