Skip to content

Commit

Permalink
Debug: Changed ImageBase field to load address for debug info search. (
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailKrichanov authored Jan 13, 2023
1 parent 40dfc3a commit 218db2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions Debug/Scripts/gdb_uefi.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ def pe_optional(self, pe):
# Returns the symbol file name for a PE image.
#

def pe_parse_debug(self, pe):
def pe_parse_debug(self, base):
pe = self.pe_headers(base)
opt = self.pe_optional(pe)
debug_dir_entry = opt['DataDirectory'][6]
dep = debug_dir_entry['VirtualAddress'] + opt['ImageBase']
dep = debug_dir_entry['VirtualAddress'] + int(base)
dep = dep.cast(self.ptype('EFI_IMAGE_DEBUG_DIRECTORY_ENTRY'))
cvp = dep.dereference()['RVA'] + opt['ImageBase']
cvp = dep.dereference()['RVA'] + int(base)
cvv = cvp.cast(self.ptype('UINT32')).dereference()
if cvv == self.CV_NB10:
return cvp + self.sizeof('EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY')
Expand Down Expand Up @@ -328,7 +329,7 @@ def parse_image(self, image, syms):
pe = self.pe_headers(base)
opt = self.pe_optional(pe)
file = self.pe_file(pe)
sym_name = self.pe_parse_debug(pe)
sym_name = self.pe_parse_debug(base)
sections = self.pe_sections(opt, file, base)

# For ELF and Mach-O-derived images...
Expand Down Expand Up @@ -362,7 +363,7 @@ def parse_edii(self, edii, count):
entry = entry['NormalImage']
self.parse_image(entry['LoadedImageProtocolInstance'], syms)
else:
print(f"Skipping unknown EFI_DEBUG_IMAGE_INFO(Type 0x{entry['ImageInfoType'].dereference():x})")
print(f"Skipping unknown EFI_DEBUG_IMAGE_INFO(Type {str(entry['ImageInfoType'].dereference())})")
index += 1
gdb.execute('symbol-file')
print('Loading new symbols...')
Expand Down
11 changes: 6 additions & 5 deletions Debug/Scripts/lldb_uefi.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,13 @@ def pe_optional(self, pe):
# Returns the symbol file name for a PE image.
#

def pe_parse_debug(self, pe):
def pe_parse_debug(self, base):
pe = self.pe_headers(base)
opt = self.pe_optional(pe)
debug_dir_entry = opt.GetValueForExpressionPath('.DataDirectory[6]')
dep = self.get_field(debug_dir_entry, 'VirtualAddress') + self.get_field(opt, 'ImageBase')
dep = self.get_field(debug_dir_entry, 'VirtualAddress') + base
dep = self.typed_ptr(self.ptype('EFI_IMAGE_DEBUG_DIRECTORY_ENTRY'), dep)
cvp = self.get_field(dep, 'RVA') + self.get_field(opt, 'ImageBase')
cvp = self.get_field(dep, 'RVA') + base
# FIXME: UINT32 should be used here instead of unsigned, but LLDB+PDB type system is broken.
cvv = self.typed_ptr(self.ptype('unsigned'), cvp).Dereference().GetValueAsUnsigned()
if cvv == self.CV_NB10:
Expand Down Expand Up @@ -310,7 +311,7 @@ def parse_image(self, image, syms):
pe = self.pe_headers(base)
opt = self.pe_optional(pe)
file = self.pe_file(pe)
sym_address = self.pe_parse_debug(pe)
sym_address = self.pe_parse_debug(base)
sections = self.pe_sections(opt, file, base)

if sym_address == 0:
Expand Down Expand Up @@ -373,7 +374,7 @@ def parse_edii(self, edii, count):
entry = entry.GetChildMemberWithName('NormalImage')
self.parse_image(entry.GetChildMemberWithName('LoadedImageProtocolInstance'), syms)
else:
print(f'Skipping unknown EFI_DEBUG_IMAGE_INFO (Type 0x{image_type:x})')
print(f'Skipping unknown EFI_DEBUG_IMAGE_INFO (Type {str(image_type)})')
index = index + 1
print('Loading new symbols...')
for sym in syms:
Expand Down

0 comments on commit 218db2a

Please sign in to comment.