從給定進程的內存轉儲中,我想提取thread_info的值,例如, preempt_count。給定進程的thread_info的打印值
它是在在x86定義:
struct thread_info {
struct task_struct *task;
struct exec_domain *exec_domain;
__u32 flags;
__u32 status;
__u32 cpu;
int preempt_count;
mm_segment_t addr_limit;
struct restart_block restart_block;
void __user *sysenter_return;
#ifdef CONFIG_X86_32
unsigned long previous_esp;
__u8 supervisor_stack[0];
#endif
int uaccess_err;
};
並駐留在進程的堆棧的底部。
在x86上,可以通過屏蔽堆棧指針的13個最低有效位(假設堆棧大小爲8KB)來獲取thread_info結構的地址。這由current_thread_info()函數完成(參見Love,「Linux Kernel Development」)。
我測試用於與PID 2419的處理(I開始/斌/慶典),用gdb獲得stackpointer和python的值,以獲得所述存儲器地址:
$ gdb --pid 2419
(gdb) print $sp
$1 = (void *) 0xbf870fa8
(gdb) python print "%x" % (0xbf870fa8 & 0xffffe000)
bf870000
因此,的thread_info應駐留在bf870000:
(gdb) x/40xb 0xbf870000
0xbf870000: 0x08 0x66 0x2d 0x0a 0x08 0x66 0x2d 0x0a
0xbf870008: 0x88 0x8f 0x08 0x0a 0xb8 0x18 0x07 0x08
0xbf870010: 0xe8 0xe6 0x60 0x0a 0x08 0x65 0x2d 0x0a
0xbf870018: 0x08 0x60 0x61 0x0a 0x88 0x8f 0x08 0x0a
0xbf870020: 0x08 0x66 0x2d 0x0a 0x88 0x8f 0x08 0x0a
問題是:如何將此數據連接到thread_info結構?
現在我可以映射結構來存儲,但是,我想地址0xbf870000是錯誤的...
(gdb) symbol-file /usr/lib/debug/boot/vmlinux-3.2.0-52-generic-pae
Reading symbols from /usr/lib/debug/boot/vmlinux-3.2.0-52-generic-pae...done.
(gdb) p (struct thread_info *)0xbf870000
$2 = (struct thread_info *) 0xbf870000
(gdb) p *$2
$4 = {task = 0xa2d6608, exec_domain = 0xa2d6608, flags = 168333192, status = 134682808, cpu = 174122728, preempt_count = 170747144, addr_limit = {seg = 174153736}, restart_block = {
fn = 0xa088f88, {futex = {uaddr = 0xa2d6608, val = 168333192, flags = 174153736, bitset = 134622139, time = 580707212407115656, uaddr2 = 0x1524}, nanosleep = {clockid = 170747400,
rmtp = 0xa088f88, expires = 578197684496719880}, poll = {ufds = 0xa2d6608, nfds = 168333192, has_timeout = 174153736, tv_sec = 134622139, tv_nsec = 168333192}}},
sysenter_return = 0xbf87007c, previous_esp = 4294967264, supervisor_stack = 0xbf870044 "\274F\017\b\002", uaccess_err = 135218876}
感謝您的幫助!
可以映射結構來存儲,我想地址0xbf870000是錯誤的... (GDB)符號文件/usr/lib/debug/boot/vmlinux-3.2.0-52-generic -pae 讀取/usr/lib/debug/boot/vmlinux-3.2.0-52-generic-pae...done中的符號。 (gdb)p(struct thread_info *)0xbf870000 $ 2 =(struct thread_info *)0xbf870000 (gdb)p * $ 2 $ 4 = {task ... – Markus