【DynamoRIO 入门教程】六:inline.c

本文介绍了使用DynamoRIO进行执行优化,通过自定义跟踪API将call到return过程内联到trace中。详细阐述了dr_client_main()、event_analyze_bb()等DR主体函数的作用,以及如何利用hashtable管理和维护trace头信息。通过对基本块的分析,解释了如何确定call和return指令作为trace头,并讨论了end_trace event在确定trace结束时的角色。
摘要由CSDN通过智能技术生成

一、功能说明

执行优化,使用自定义跟踪API将整个callees 内联到跟踪中。
这句话什么意思,应用程序里会有 call 指令,通过该指令进入 子函数后,又会通过return指令返回。
我们要做的优化就是将 从call 到 return 的过程 内联(存放)到一个 自定义 trace中。

二、主要数据结构 和 配套函数

typedef struct _hashtable_t {
   
    hash_entry_t **table;
    hash_type_t hashtype;
    bool str_dup;
    void *lock;
    uint table_bits;
    bool synch;
    void (*free_payload_func)(void *);
    uint (*hash_key_func)(void *);
    bool (*cmp_key_func)(void *, void *);
    uint entries;
    hashtable_config_t config;
    uint persist_count;
} hashtable_t;

hashtable_t 结构体 定义在 hashtable.h 头文件里,不需要我们自己定义。并且这应该是属于 Container Data Structures 的文件。

不过这各结构体里面的东西有点多,后面看到我们再说吧。


/****************************************************************************/
/* We use a hashtable to know if a particular tag is for a call trace or a
 * normal back branch trace.
 */

typedef struct _trace_head_entry_t {
   
    void *tag;
    bool is_trace_head;
	// has_ret 的意义是该basic block 含有 return 指令
    bool has_ret;
    /* We have to end at the next block after we see a return. */
    int end_next;
    /* Some callees are too large to inline, so we have a size limit. */
    uint size;
    /* We use a ref count so we know when to remove in the presence of
     * thread-private duplicated blocks.
     */
    uint refcount;
    struct _trace_head_entry_t *next;
} trace_head_entry_t;

static trace_head_entry_t *
create_trace_head_entry(void *tag)
{
   
    trace_head_entry_t *e = (trace_head_entry_t *)dr_global_alloc(sizeof(*e));
    e->tag = tag;
    e->end_next = 0;
    e->size = 0;
    e->has_ret = false;
    e->is_trace_head = false;
    e->refcount = 1;
    return e;
}

static void
free_trace_head_entry(void *entry)
{
   
    trace_head_entry_t *e = (trace_head_entry_t *)entry;
    dr_global_free(e, sizeof(*e));
}

DR主体函数

1、dr_client_main()
DR_EXPORT void
dr_client_main(client_id_t id, int argc, const char *argv[])
{
   
    if (!drmgr_init())
        DR_ASSERT(false)
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值