GDB中遍历art::Thread打印local reference的脚本

本文提供了两种使用GDB脚本的方法来打印线程的LocalReference信息:一种是打印所有线程对应的LocalReference;另一种是根据指定线程ID打印其LocalReference。这两种方法有助于调试和理解应用程序中JNI环境下的内存引用情况。

#打印所有线程对应的local reference

def dump_all_local_refernce
    set $list_head = &art::Runtime::instance_.thread_list_.list_.__end_
    set $list_node = $list_head->__next_
    while $list_node != $list_head
        set $tid =  $list_node->__value_->tls32_.tid
        set $top_index = $list_node->__value_->tlsPtr_.jni_env->locals.segment_state_.parts.topIndex
        printf "tid = %d, top_index = %d\n",$tid,$top_index
        set $list_node = $list_node->__next_
    end
end

 

#打印指定线程的local reference

def dump_local_refernce_by_tid
    set $list_head = &art::Runtime::instance_.thread_list_.list_.__end_
    set $list_node = $list_head->__next_
    while $list_node != $list_head
        if  $list_node->__value_->tls32_.tid == $arg0
            set $local_table =  $list_node->__value_->tlsPtr_.jni_env->locals
            set $top_index = $local_table.segment_state_.parts.topIndex
            p $top_index
            set $index = 0
            while $index < $top_index
                set $irt_entry =  $local_table.table_[$index]
                set $serial = $irt_entry.serial_
                set $obj = (unsigned int *)$irt_entry.references_[$serial].root_.reference_
                if $obj != 0
                    p /x *$obj
                else
                    p /x 0x0
                end
                set $index += 1
            end
            loop_break
        end
        set $list_node = $list_node->__next_
    end

转载于:https://www.cnblogs.com/YYPapa/p/7002040.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值