免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8895 | 回复: 3

[内核模块] gdb中如何显示一个结构体中成员的偏移? [复制链接]

论坛徽章:
0
发表于 2013-10-11 11:12 |显示全部楼层
分析内核core 可以使用crash工具,它可以打印结构体中成员的偏移; 而在用gdb分析用户态程序的core时,没有发现该功能,请问gdb中有这功能吗?

crash> struct -o task_struct
struct task_struct {
     [0] volatile long int state;
     [8] void *stack;
    [16] atomic_t usage;
    [20] unsigned int flags;
    [24] unsigned int ptrace;
    [28] int lock_depth;
    [32] int prio;
    [36] int static_prio;
    [40] int normal_prio;
    [44] unsigned int rt_priority;

        (gdb) ptype struct malloc_chunk
type = struct malloc_chunk {
    size_t prev_size;
    size_t size;
    struct malloc_chunk *fd;
    struct malloc_chunk *bk;
    struct malloc_chunk *fd_nextsize;
    struct malloc_chunk *bk_nextsize;
}

论坛徽章:
0
发表于 2013-10-11 12:42 |显示全部楼层
回复 1# todaygood
(gdb) p &((struct task_struct *)0)->prio
$1 = (int *) 0x30
(gdb) p &((struct task_struct *)0)->state
$2 = (volatile long int *) 0x0
(gdb)


   

论坛徽章:
6
金牛座
日期:2013-10-08 10:19:10技术图书徽章
日期:2013-10-14 16:24:09CU十二周年纪念徽章
日期:2013-10-24 15:41:34狮子座
日期:2013-11-24 19:26:19未羊
日期:2014-01-23 15:50:002015年亚洲杯之阿联酋
日期:2015-05-09 14:36:15
发表于 2013-10-11 13:37 |显示全部楼层
回复 2# xs3c
(gdb) p &((struct task_struct *)0)->prio
$1 = (int *) 0x30
(gdb) p &((struct task_struct *)0)->state
$2 = (volatile long int *) 0x0
(gdb


Great, just like container_of!

   

论坛徽章:
0
发表于 2013-10-11 17:05 |显示全部楼层
回复 2# xs3c


    牛叉!膜拜!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP