-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
添加line命令,用来观测方法内的局部变量,可以通过行号或者LineCode来指定位置 #2852
Open
isadliliying
wants to merge
2
commits into
alibaba:master
Choose a base branch
from
isadliliying:wingli-add-line-command
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jun 21, 2024
@hengyunabc 大佬麻烦看看 |
@isadliliying 有时候 我们观察局部变量是观察一个变化过程,比如 方法methodX内部 局部变量 a,b, 从35到55行 a,b变量发生了哪些变化,也就是方法methodX 执行一次就打印20行的(55-35)变化结果类似于表格记录吧 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
为什么要做这个呢?
为什么要定义新的命令?
watch
,但是watch的对象是method
,而我们观测local variables
的时候,用行
来作为定位点是比较合适的(因为同一个变量会被多次重复赋值),两者的回调监听是不一致的实现思路:
Advice
变量varMap
,类型是HashMap
,key是变量名,value是变量值已经做的基本测试:
local variables
,并能在express
和condition-express
中使用LocationFilter
,避免重复插桩trace
及watch
命令的同时使用为什么会需要使用LineCode?
主要是kotlin编译后的字节码跟源码相差甚远,如下:
kotlin源码:
jad出来的样子:
问题:
反编译后,它的行号分布是乱序的,另外实践中还发现有重复行号的问题,而且反编译后与源代码大相径庭,也生成了很多的额外的零时变量,也有很多行是没有行号的,所以使用行号定位的话,是不够完善的,有些点无法进行定位插入监听!
解法:
如何能监听到所有本地变量的变化过程呢? -> 变量在何时会被改变呢? -> 赋值、作为方法参数被调用
基于此,通过筛选方法中的InsnNode,只保留 VarInsnNode 和 MethodInsnNode 作为备选插入点,然后生成类似如下的标记行并以此为变量监测的插入点.
目前格式如: 行号 + LineCode + 指令(方法调用/变量赋值 )
使用示例:
源码(部分):
使用行号:
查看LineCode:
使用LineCode:
其它:
line -h
查看