Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

efidebug.tool can no longer extract EFI_DEBUG_IMAGE_INFO since OpenCore commit 43c4931 #2353

Closed
mikebeaton opened this issue Nov 24, 2023 · 3 comments
Assignees

Comments

@mikebeaton
Copy link
Contributor

mikebeaton commented Nov 24, 2023

efidebug.tool cannot extract EFI_DEBUG_IMAGE_INFO data since commit acidanthera/OpenCorePkg@43c4931.

The basic output is:

Michaels-Air:Debug mjsbeaton$ ./efidebug.tool 
(lldb) settings set plugin.process.gdb-remote.target-definition-file Scripts/x86_64_target_definition.py
(lldb) gdb-remote localhost:8864
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0x0000000006290bce
->  0x6290bce: movb   %al, -0x9(%rbp)
    0x6290bd1: jmp    0x6290bd6
    0x6290bd6: movq   -0x8(%rbp), %rdx
    0x6290bda: xorl   %ecx, %ecx
Target 0: (No executable module.) stopped.
(lldb) target create  GdbSyms/Bin/X64_XCODE5/GdbSyms.dll
Current executable set to '/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/GdbSyms/Bin/X64_XCODE5/GdbSyms.dll' (x86_64).
(lldb) command script import Scripts/lldb_uefi.py
(lldb) command script add -c lldb_uefi.ReloadUefi reload-uefi
(lldb) reload-uefi
Target 0 is 'No executable module.'
Target 1 is 'GdbSyms.dll'
EFI_SYSTEM_TABLE_POINTER @ 0x6c00000
EFI_SYSTEM_TABLE @ 0x73ec018
Connected to EDK II(Rev. 0x10000
ConfigurationTable @ 0x73ecc98, 0xb entries
DebugImageInfoTable @ 0x72ce018, 0x5c entries
Traceback (most recent call last):
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 522, in __call__
    self.parse_est(est)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 429, in parse_est
    self.parse_dh(dh)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 414, in parse_dh
    self.parse_edii(self.get_child_member_with_name(dh, 'EfiDebugImageInfoTable'), self.get_field(dh, 'TableSize'))
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 392, in parse_edii
    self.parse_image(self.get_child_member_with_name(entry, 'LoadedImageProtocolInstance'), syms)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 332, in parse_image
    sections = self.pe_sections(opt, file, base)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 245, in pe_sections
    name = UefiMisc.parse_utf8(name)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/common_uefi.py", line 56, in parse_utf8
    return cls.parse_string(value, 'B', 'utf-8')
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/common_uefi.py", line 43, in parse_string
    return data.tobytes().decode(charset)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 2: invalid continuation byte
(lldb) b DebugBreak
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) 

Adding some print statements to lldb_uefi.py to see what is going on, we get:

Michaels-Air:Debug mjsbeaton$ ./efidebug.tool 
(lldb) settings set plugin.process.gdb-remote.target-definition-file Scripts/x86_64_target_definition.py
(lldb) gdb-remote localhost:8864
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0x0000000006290bce
->  0x6290bce: movb   %al, -0x9(%rbp)
    0x6290bd1: jmp    0x6290bd6
    0x6290bd6: movq   -0x8(%rbp), %rdx
    0x6290bda: xorl   %ecx, %ecx
Target 0: (No executable module.) stopped.
(lldb) target create  GdbSyms/Bin/X64_XCODE5/GdbSyms.dll
Current executable set to '/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/GdbSyms/Bin/X64_XCODE5/GdbSyms.dll' (x86_64).
(lldb) command script import Scripts/lldb_uefi.py
(lldb) command script add -c lldb_uefi.ReloadUefi reload-uefi
(lldb) reload-uefi
Target 0 is 'No executable module.'
Target 1 is 'GdbSyms.dll'
EFI_SYSTEM_TABLE_POINTER @ 0x6c00000
EFI_SYSTEM_TABLE @ 0x73ec018
Connected to EDK II(Rev. 0x10000
ConfigurationTable @ 0x73ecc98, 0xb entries
DebugImageInfoTable @ 0x72ce018, 0x5c entries
array('B', [0, 72, 137, 69, 192, 72, 131, 125])

array('B', [0, 0, 0, 0, 0, 128, 72, 137])

array('B', [77, 48, 232, 49, 124, 5, 0, 72])
Traceback (most recent call last):
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 524, in __call__
    self.parse_est(est)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 431, in parse_est
    self.parse_dh(dh)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 416, in parse_dh
    self.parse_edii(self.get_child_member_with_name(dh, 'EfiDebugImageInfoTable'), self.get_field(dh, 'TableSize'))
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 394, in parse_edii
    self.parse_image(self.get_child_member_with_name(entry, 'LoadedImageProtocolInstance'), syms)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 334, in parse_image
    sections = self.pe_sections(opt, file, base)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/lldb_uefi.py", line 246, in pe_sections
    name = UefiMisc.parse_utf8(name)
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/common_uefi.py", line 56, in parse_utf8
    return cls.parse_string(value, 'B', 'utf-8')
  File "/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/Scripts/common_uefi.py", line 43, in parse_string
    return data.tobytes().decode(charset)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe8 in position 2: invalid continuation byte
(lldb) b DebugBreak
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) 

Normal output (acidanthera/OpenCorePkg@b5984a3 and before) with the same print output added is:

Michaels-Air:Debug mjsbeaton$ ./efidebug.tool 
(lldb) settings set plugin.process.gdb-remote.target-definition-file Scripts/x86_64_target_definition.py
(lldb) gdb-remote localhost:8864
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
    frame #0: 0x000000000600abce
->  0x600abce: movb   %al, -0x9(%rbp)
    0x600abd1: jmp    0x600abd6
    0x600abd6: movq   -0x8(%rbp), %rdx
    0x600abda: xorl   %ecx, %ecx
Target 0: (No executable module.) stopped.
(lldb) target create  GdbSyms/Bin/X64_XCODE5/GdbSyms.dll
Current executable set to '/Users/mjsbeaton/OpenSource/OpenCorePkg/Debug/GdbSyms/Bin/X64_XCODE5/GdbSyms.dll' (x86_64).
(lldb) command script import Scripts/lldb_uefi.py
(lldb) command script add -c lldb_uefi.ReloadUefi reload-uefi
(lldb) reload-uefi
Target 0 is 'No executable module.'
Target 1 is 'GdbSyms.dll'
EFI_SYSTEM_TABLE_POINTER @ 0x6c00000
EFI_SYSTEM_TABLE @ 0x73ec018
Connected to EDK II(Rev. 0x10000
ConfigurationTable @ 0x73ecc98, 0xb entries
DebugImageInfoTable @ 0x72ce018, 0x5c entries
array('B', [46, 116, 101, 120, 116, 0, 0, 0])
.text
array('B', [46, 114, 100, 97, 116, 97, 0, 0])
.rdata
array('B', [46, 100, 97, 116, 97, 0, 0, 0])
.data
array('B', [46, 114, 101, 108, 111, 99, 0, 0])
.reloc
.
.
.

The issue applies in 64-bit and 32-bit, and in LLDB and GDB.

Example GDB output:

Mikes-iMac:Debug mjsbeaton$ EFI_DEBUGGER=GDB ./efidebug.tool 
GNU gdb (GDB) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin21.6.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from GdbSyms/Bin/X64_XCODE5/GdbSyms.dll...
The target architecture is set to "i386:x86-64:intel".
Remote debugging using localhost:8864
0x0000000006290be6 in ?? ()
EFI_SYSTEM_TABLE_POINTER @ 0x6c00000
EFI_SYSTEM_TABLE @ 0x121552920:x
Connected to EDK II (Rev. 0x10000)
ConfigurationTable @ 0x73ecc98, 0xa entries
DebugImageInfoTable @ 0x72ce018, 0x5c entries
Found 92 images...
Python Exception <class 'gdb.MemoryError'>: Cannot access memory at address 0x85610014
Error occurred in Python: Cannot access memory at address 0x85610014
Function "DebugBreak" not defined.
Make breakpoint pending on future shared library load? (y or [n]) 

From the above logs, the data in EfiDebugImageInfoTable appears to be present but corrupt.

NB I assumed, once I noticed it, that setting gEfiMdePkgTokenSpaceGuid.PcdImageLoaderDebugSupport to TRUE in OpenCorePkg.dsc would resolve the issue, but it does not.

I am using what is I believe a completely standard way to set up OC code for debugging with OVMF, as mentioned e.g. in the first three bullet points in #2195 or documented in https://github.com/acidanthera/OpenCorePkg/tree/master/Debug README.

cc @MikhailKrichanov

@mikebeaton
Copy link
Contributor Author

mikebeaton commented Nov 26, 2023

With help from @mhaeuser in understanding the new standard format and new info made available in the EfiDebugImageInfoTable, I am updating efidebug.tool to support this.

@mikebeaton mikebeaton self-assigned this Nov 26, 2023
@mikebeaton
Copy link
Contributor Author

cf acidanthera/audk#59

@mikebeaton
Copy link
Contributor Author

Fixed by acidanthera/OpenCorePkg#510 and acidanthera/audk#59.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant