Skip to content

Commit

Permalink
UeImageLib: Fix image debug address
Browse files Browse the repository at this point in the history
  • Loading branch information
mhaeuser authored and mikebeaton committed Dec 7, 2023
1 parent d1d2a0e commit 948e8e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions BaseTools/ImageTool/UeEmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ ToolImageEmitUeDebugTable (
)
{
UE_DEBUG_TABLE DebugTable;
uint8_t SymOffsetFactor;
uint8_t SymSubtrahendFactor;
uint32_t DebugTableOffset;
uint32_t DebugTableSize;
uint16_t Index;
Expand All @@ -609,14 +609,14 @@ ToolImageEmitUeDebugTable (
assert (Image->DebugInfo.SymbolsPathLen <= MAX_UINT8);
assert (IS_ALIGNED (BaseAddressSubtrahend, Image->SegmentInfo.SegmentAlignment));

SymOffsetFactor = (uint8_t)(BaseAddressSubtrahend / Image->SegmentInfo.SegmentAlignment);
if (SymOffsetFactor > 0x03) {
SymSubtrahendFactor = (uint8_t)(BaseAddressSubtrahend / Image->SegmentInfo.SegmentAlignment);
if (SymSubtrahendFactor > 0x03) {
DEBUG_RAISE ();
return false;
}

DebugTable.ImageInfo = SymOffsetFactor;
assert (UE_DEBUG_TABLE_IMAGE_INFO_SYM_OFFSET_FACTOR (DebugTable.ImageInfo) == SymOffsetFactor);
DebugTable.ImageInfo = SymSubtrahendFactor;
assert (UE_DEBUG_TABLE_IMAGE_INFO_SYM_SUBTRAHEND_FACTOR (DebugTable.ImageInfo) == SymSubtrahendFactor);
assert ((DebugTable.ImageInfo & 0xFCU) == 0);

DebugTable.SymbolsPathLength = (uint8_t)Image->DebugInfo.SymbolsPathLen;
Expand Down
4 changes: 2 additions & 2 deletions MdePkg/Include/IndustryStandard/UeImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ typedef struct {
(OFFSET_OF (UE_DEBUG_TABLE, SymbolsPath) + 1U)

/**
Retrieves the UE symbols address offset in SegmentAlignment-units.
Retrieves the UE symbol address subtrahend in SegmentAlignment-units.
@param[in] ImageInfo The UE debug table image information.
**/
#define UE_DEBUG_TABLE_IMAGE_INFO_SYM_OFFSET_FACTOR(ImageInfo) \
#define UE_DEBUG_TABLE_IMAGE_INFO_SYM_SUBTRAHEND_FACTOR(ImageInfo) \
((UINT8)((ImageInfo) & 0x03U))

/**
Expand Down
10 changes: 5 additions & 5 deletions MdePkg/Library/BaseUeImageLib/UeImageLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,21 +1231,21 @@ UeLoaderGetImageDebugAddress (
RETURN_STATUS Status;
CONST UE_DEBUG_TABLE *DebugTable;
UINT8 SymOffsetFactor;
UINT32 SymOffsetAddend;
UINT32 SymOffsetSubtrahend;

ASSERT (Context != NULL);

SymOffsetAddend = 0;
SymOffsetSubtrahend = 0;

Status = InternalGetDebugTable (Context, &DebugTable);
if (!RETURN_ERROR (Status)) {
SymOffsetFactor = UE_DEBUG_TABLE_IMAGE_INFO_SYM_OFFSET_FACTOR (
SymOffsetFactor = UE_DEBUG_TABLE_IMAGE_INFO_SYM_SUBTRAHEND_FACTOR (
DebugTable->ImageInfo
);
SymOffsetAddend = (UINT32)SymOffsetFactor * Context->SegmentAlignment;
SymOffsetSubtrahend = (UINT32)SymOffsetFactor * Context->SegmentAlignment;
}

return UeLoaderGetImageAddress (Context) + SymOffsetAddend;
return UeLoaderGetImageAddress (Context) - SymOffsetSubtrahend;
}

RETURN_STATUS
Expand Down

0 comments on commit 948e8e8

Please sign in to comment.