Skip to content

Fix file/directory table count in pre-DWARF5 line table parsing#802

Open
portbuster1337 wants to merge 1 commit into
EpicGamesExt:masterfrom
portbuster1337:fix/dwarf-file-table-count
Open

Fix file/directory table count in pre-DWARF5 line table parsing#802
portbuster1337 wants to merge 1 commit into
EpicGamesExt:masterfrom
portbuster1337:fix/dwarf-file-table-count

Conversation

@portbuster1337
Copy link
Copy Markdown

Bug

ctx->unit_dir and ctx->unit_file in DW2_ParseCtx are never populated by the caller (rdi_from_dwarf_2.c), but dw2_read_line_table_header unconditionally pushed them as the first directory and file entries for pre-DWARF5 line tables. This created an empty leading entry, making dirs.count and files.count one greater than the actual data.

Additionally, DW_StdOpcode_File in the line VM sets file_index to 1-based values for pre-DWARF5 and 0-based for DWARF 5, but the array lookup used the raw 1-based index directly on a 0-based array, and the initial file_index was unconditionally set to 1 (wrong for DWARF 5 where it should be 0).

Changes

src/dwarf/dwarf_parse_2.c: Guard the first-entry pushes behind size != 0 checks so the DWARF data's own entries stand on their own when the context fields are unpopulated.

src/rdi_from_dwarf/rdi_from_dwarf_2.c:

  • Initialize file_index to 0 for DWARF 5, 1 for pre-DWARF5
  • Convert 1-based file indices to 0-based array indices for pre-DWARF5 in the source file lookup
  • Fix the bounds check for each DWARF version's indexing scheme

Bug: ctx->unit_dir and ctx->unit_file are never populated by the caller
(rdi_from_dwarf_2.c), but dw2_read_line_table_header unconditionally pushed
them as the first directory/file entries. This created an empty leading entry,
making dirs.count and files.count one greater than the actual data. All
subsequent directory indices and file indices were off by one.

Fix:
1. Guard the first-entry pushes behind non-empty size checks in
   dw2_read_line_table_header (dwarf_parse_2.c).
2. Fix the file_index mapping in the line VM (rdi_from_dwarf_2.c):
   - Initialize file_index to 0 for DWARF 5, 1 for pre-DWARF5
   - Convert 1-based file indices to 0-based array indices for pre-DWARF5
   - Fix the bounds check to be correct for each version's indexing scheme
@nerbert123
Copy link
Copy Markdown

both changed files got deleted

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants