diff --git a/includes/_withcontent.vp b/includes/_withcontent.vp index 4bd7bd7..394a0bc 100644 --- a/includes/_withcontent.vp +++ b/includes/_withcontent.vp @@ -37,16 +37,21 @@ def _get_stack() -> _ProviderStack | t.CPtr: """Obtain current thread's provider stack. Allocate one if none exists.""" _init_tls() stack: _ProviderStack | t.CPtr = TlsGetValue(_tls_index) + stdio.printf("[wdbg] get_stack tls=%llu stack=%p\n", + t.CUInt64T(_tls_index), stack) if stack == None: stack = stdlib.malloc(_ProviderStack.__sizeof__()) string.memset(stack, 0, _ProviderStack.__sizeof__()) TlsSetValue(_tls_index, stack) + stdio.printf("[wdbg] get_stack NEW stack=%p\n", stack) return stack def _push_provider(field_name: str, ptr: t.CPtr): """Push a provider (field_name, ptr) onto the stack.""" stack: _ProviderStack | t.CPtr = _get_stack() + stdio.printf("[wdbg] push field=%s ptr=%p top=%lu\n", + field_name, ptr, stack.top) if stack.top >= _MAX_PROVIDER_DEPTH: stdio.printf("[with] ERROR: provider stack overflow (depth=%lu, max=%d), field '%s' not injected\n", stack.top, _MAX_PROVIDER_DEPTH, field_name) return @@ -66,10 +71,12 @@ def _find_provider(field_name: str) -> t.CPtr: """Search for matching field_name starting from stack top. Return associated pointer, or NULL if no match found.""" stack: _ProviderStack | t.CPtr = _get_stack() + stdio.printf("[wdbg] find field=%s top=%lu\n", field_name, stack.top) for i in range(stack.top - 1, -1, -1): # 字段名用 strcmp 内容比较:编译器对每次 create_global_string 生成 # 独立的字符串常量(TPV 不去重),push/find 的指针地址不同, # 指针 == 永假会导致 provider 匹配失败(__mbuddy__ 注入不上)。 if string.strcmp((str)(stack.names[i]), field_name) == 0: + stdio.printf("[wdbg] find HIT i=%d ptr=%p\n", i, stack.ptrs[i]) return stack.ptrs[i] return None \ No newline at end of file