fix(traceback): stackmap 的文件名全部退化为 ?? —— _tb_parse_dec 不跳前导空格

dwarfdump 的方括号索引右对齐(file_names[  1] / include_directories[ 12]),_tb_bracket_idx 把 '  1]' 交给 _tb_parse_dec,首字符非数字使循环体一次不进 -> 全部 pidx=0;行记录 fidx=1..N 永不匹配 -> 每条记录落到 '??'(实证 9146/9146 条共用同一个 '??' 串,而函数名/行号均正确)

_tb_parse_dec 增跳前导空格与制表符(修复文件名与目录索引两处)

dir_index: 偏移 st+9 指向冒号本身,恒解析为 0 -> 相对文件名拼不出绝对路径;改为 st+10
This commit is contained in:
TermiNexus committed 2026-09-27 19:01:23 +08:00
1 parent 31898ab4a5
commit bb864dff6f
1 file changed
+16 -1
+16 -1
View File
@@ -1403,8 +1403,21 @@ def _tb_join(mb: memhub.MemBuddy*, base: str, name: str) -> str:
def _tb_parse_dec(s: str) -> int:
"""Parse a leading decimal integer, skipping leading blanks.
dwarfdump right-aligns the bracketed indices to a 3-wide field
(`file_names[ 1]:` / `include_directories[ 12]`), so `_tb_bracket_idx`
hands us a string whose first char is a space. Without the blank skip the
digit loop never runs and every index parses as 0 -> every file record's
pidx becomes 0 while a row's fidx is the real 1..N fit -> `_tb_file_rec`
never matches and EVERY row degrades to the "??" placeholder. Measured on
Test/LLvmLiteTest: all 9146 stackmap records carried the single '??' file
string while function names and line numbers were correct.
"""
v: int = 0
i: sizet = 0
while _tb_cc(s, i) == 32 or _tb_cc(s, i) == 9:
i += 1
while _tb_cc(s, i) >= 48 and _tb_cc(s, i) <= 57:
v = v * 10 + (_tb_cc(s, i) - 48)
i += 1
@@ -1834,7 +1847,9 @@ def _tb_parse_dump(mb: memhub.MemBuddy*, dump: str) -> TbDump | t.CPtr:
pkind = 0
continue
if _tb_startswith(st, "dir_index:") != 0 and pkind == 1:
pdir = _tb_parse_dec(_tb_ltrim(st + 9))
# `"dir_index:"` 含冒号共 10 字符:st + 9 指向冒号本身,解析恒得 0
# (目录索引全丢 → 相对文件名拼不出绝对路径,File 行只剩裸文件名)。
pdir = _tb_parse_dec(_tb_ltrim(st + 10))
continue
if _tb_startswith(st, "Address") != 0 and _tb_contains(st, "Column") != 0:
if pkind == 1 and pname is not None and file_count < TB_FILE_CAP: