18345093167 发表于 2016-05-05 13:22

libdwarf

/*******************************************************************************
*函数名称:static void get_loc_list(Dwarf_Debug dbg, Dwarf_Die die, struct sub *sub)
*函数功能:解析一个函数类型die的下挂的寄存器偏移信息,保存到sub->loc链表中
*输入参数:
        @Dwarf_Debug dbg:libdwarf库的总数据结构
        @Dwarf_Die die:需要被解析的一个函数类型die
        @struct sub *sub:函数DIE对应的信息块指针
*输出参数:无
*函数返回值:无
*其他:dwarf_ 开头的函数都是libdwarf库提供的函数
*******************************************************************************/
static void get_loc_list(Dwarf_Debug dbg, Dwarf_Die die, struct sub *sub)
{
        Dwarf_Unsigned offset=0;
        Dwarf_Error error = 0;
        Dwarf_Addr hipc_off;
        Dwarf_Addr lopc_off;
        Dwarf_Ptr data;
        Dwarf_Unsigned entry_len;
        Dwarf_Error err;
        int res;
        Dwarf_Unsigned next_entry;
        Dwarf_Attribute t_attr;
        struct loc *tmp=NULL,*pos;

        res = dwarf_attr(die, DW_AT_frame_base, &t_attr, &error);//使用libdwarf库解析条目属性
        if (res == DW_DLV_OK)
        {
                res = dwarf_formudata(t_attr, &offset, &error);//使用libdwarf库获取属性对应的条目链
                if (res == DW_DLV_OK)
                        for(;;)
                                {
                                        res = dwarf_get_loclist_entry(dbg,offset,&hipc_off,&lopc_off,&data,&entry_len,&next_entry,&err);//遍历所有条目
                                        if (res == DW_DLV_OK)
                                        {//每成功取出一个条目
                                                if(entry_len == 0 )
                                                        break;
                                                if(entry_len > 1 )
                                                {
                                                tmp = (struct loc*) malloc(sizeof(struct loc));//申请内存
                                                if(tmp)
                                                {
                                                        memset(tmp,0,sizeof(struct loc));
                                                        tmp ->begin = cu_low_pc + lopc_off;
                                                        tmp ->end = cu_low_pc + hipc_off;
                                                        tmp ->reg = (unsigned short)*(char*)data;//保存条目信息
                                                        if(entry_len == 2)
                                                                tmp ->base = (unsigned short)*(char *)(data+1);
                                                        else
                                                                tmp ->base = (unsigned short)*(unsigned short *)(data+1);
                                                        if(sub->loc)
                                                        {
                                                                pos = sub->loc;//加入当前处理的函数的loc链表中
                                                                while(pos->next)
                                                                        pos = pos->next;
                                                                pos->next = tmp;
                                                        }
                                                        else
                                                                sub->loc = tmp;
                                                }
                                                else break;
                                                }
                                                offset = next_entry;
                                                continue;
                                        }
                                        else break;
                                }
        }
},
我的问题是res = dwarf_get_loclist_entry(dbg,offset,&hipc_off,&lopc_off,&data,&entry_len,&next_entry,&err);的个参数的含义这里条目的具体含义。

18345093167 发表于 2016-05-05 21:37

    if(entry_len == 2)
                                                                tmp ->base = (unsigned short)*(char *)(data+1);
                                                      else
                                                                tmp ->base = (unsigned short)*(unsigned short *)(data+1);
这句话是啥意思?

nswcfd 发表于 2016-05-06 15:41

本帖最后由 nswcfd 于 2016-05-06 17:11 编辑

---不好意思,请忽略此回复---

nswcfd 发表于 2016-05-06 17:15

http://www.unix.com/man-page/freebsd/3/dwarf_get_loclist_entry/

18345093167 发表于 2016-05-07 20:28

谢谢。现在我已经知道我用的部分的使用了
页: [1]
查看完整版本: libdwarf