Skip to content

feat: add TPBASE and TSD extraction for multi-thread Python unwind#11335

Open
kylewanginchina wants to merge 2 commits intomainfrom
fix-multithread-python
Open

feat: add TPBASE and TSD extraction for multi-thread Python unwind#11335
kylewanginchina wants to merge 2 commits intomainfrom
fix-multithread-python

Conversation

@kylewanginchina
Copy link
Contributor

@kylewanginchina kylewanginchina commented Jan 30, 2026

This PR is for:

  • Agent

This commit adds the infrastructure for multi-threaded Python stack unwinding:

Checklist

  • Added unit test.

Backport to branches

@kylewanginchina kylewanginchina force-pushed the fix-multithread-python branch 2 times, most recently from 238261f to 9aedb8c Compare January 30, 2026 06:21
@kylewanginchina
Copy link
Contributor Author

因为之前的代码迁移,原先提交的 支持多线程python unwind的PR 所对应的代码进行了拆分修改:一部分放入ce,一部分放入ee。

拆分修改后已经进行了重新测试,具体测试结果同原先的PR

@kylewanginchina kylewanginchina marked this pull request as ready for review January 30, 2026 11:19
// Pattern: mov XX(%rdi), %rXX or mov XX(%rsi), %rXX

// Look for 48 8b XX XX XX XX XX patterns (mov r64, m64)
for i in 0..code.len().saturating_sub(7) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也可以考虑用windows(7)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改,同样使用 windows(7) 优化


// Read the entire header section first to parse program headers
file.seek(SeekFrom::Start(0))?;
let mut header_data = vec![0u8; 4096]; // Should be enough for headers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个文件的大小一定大于 4096 吗?也要注释说明一下不会 eof

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已添加详细注释说明 /proc/kcore 是虚拟文件,ELF header + program headers 区域始终存在且远小于 4096 字节,不会发生 EOF

/// Thread Specific Data info for accessing per-thread PyThreadState.
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct TSDInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust 习惯写成TsdInfo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码中已经是 TsdInfo,符合 Rust 命名规范

@kylewanginchina kylewanginchina force-pushed the fix-multithread-python branch 2 times, most recently from 0575a43 to 12fc5ec Compare February 4, 2026 11:24
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