You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nudt-compiler-cpp/test_tmp/debug_frame5.py

56 lines
2.0 KiB

# 检查帧槽索引和参数索引之间的对应关系
num_params = 390
num_reg_params = 8
# 模拟帧槽分配
frame_slots = []
for param_idx in range(num_params):
# 创建参数帧槽
frame_slots.append({"type": "param", "param_idx": param_idx, "is_stack_arg": False})
# 如果参数在栈上,创建 callee_stack_arg 帧槽
if param_idx >= num_reg_params:
frame_slots.append({"type": "callee_stack_arg", "param_idx": param_idx, "is_stack_arg": True})
# 计算负偏移帧槽的偏移量
local_cursor = 0
for i, slot in enumerate(frame_slots):
if not slot["is_stack_arg"]:
local_cursor += 4
frame_slots[i]["offset"] = -local_cursor
# 检查第 1, 9, 10, 220, 221, 222 个参数的帧槽索引和偏移
for param_idx in [0, 8, 9, 219, 220, 221]:
# 找到对应的参数帧槽
for i, slot in enumerate(frame_slots):
if slot["type"] == "param" and slot["param_idx"] == param_idx:
print(f"参数索引 {param_idx} (第 {param_idx+1} 个参数): 帧槽索引 {i}, 偏移 {slot['offset']}")
break
# 检查汇编代码中的偏移
# 根据汇编代码:
# - 第 1 个参数存储在 x29-4
# - 第 9 个参数存储在 x29-36
# - 第 10 个参数存储在 x29-40
# - 第 220 个参数存储在 x29-884
# - 第 221 个参数存储在 x29-888
# - 第 222 个参数存储在 x29-892
print("\n汇编代码中的偏移:")
print(f"第 1 个参数: -4")
print(f"第 9 个参数: -36")
print(f"第 10 个参数: -40")
print(f"第 220 个参数: -884")
print(f"第 221 个参数: -888")
print(f"第 222 个参数: -892")
# 计算偏移差
print("\n偏移差:")
print(f"第 1 个参数: 预期 -4, 实际 -4, 差 0")
print(f"第 9 个参数: 预期 -36, 实际 -36, 差 0")
print(f"第 10 个参数: 预期 -40, 实际 -40, 差 0")
print(f"第 220 个参数: 预期 -880, 实际 -884, 差 -4")
print(f"第 221 个参数: 预期 -884, 实际 -888, 差 -4")
print(f"第 222 个参数: 预期 -888, 实际 -892, 差 -4")