x86 汇编指令执行计数
大家好 我有一段代码,我想找到每个装配线执行的次数。我不在乎是通过分析还是仿真,但我想要高精度的结果。我曾经遇到过一个论坛,它提供了一些脚本代码来执行此操作,但我丢失了链接。谁能帮我集思广益一些方法来做到这一点? 问候
编辑: 好吧,我想我已经成功了一半。我根据一篇帖子对英特尔手册 3A 第 16.4.5 节提供的 BTS(分支跟踪存储)进行了一些研究。此功能提供分支历史记录。所以现在我需要您的帮助来查找是否有任何开源脚本或工具可以执行此操作。等待检查您的反馈
欢呼=)!
Hello everyone
I have a code and I want to find the number of times each assembly line executed. I dont care whether through profiling or emulation, yet I want high precision results. I came across a forum once that gave some scripting code to do so, yet I lost the link. Can anyone help me brainstorm some ways to do so?
Regards
Edit:
Okey I think I am halfway there. I have done some research on the BTS (Branch Trace Store) provided by Intel Manual 3A section 16.4.5 according to one the posts. This feature provides branch history. So now I need your help to find if there are any open source scripts or tools to do this. Waiting to check your feedback
cheers=)!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的处理器支持,您可以启用分支跟踪存储 (BTS)。 BTS 将所有采用的分支的日志存储在内存中的预定义区域中。每个条目包含分支源和目的地。使用它,您可以计算您在每个代码段中出现的次数。
请参阅 第 3A 卷 www.intel.com/products/processor/manuals/" rel="nofollow">英特尔软件开发人员手册,第 16.4.5 节(当前版本),了解有关如何启用它的详细信息。
If your processor supports it, you can enable Branch Trace Store (BTS). BTS stores a log of all of the taken branches in a predefined area in memory. Each entry contains the branch source and destination. Using that, you can count how many times you were in each code segment.
Look at volume 3A of the Intel Software Developer's Manual, section 16.4.5 (in the current edition) for details on how to enable it.
如果你不关心性能,你可以做一个小技巧来计算它。引发单步异常,并在输入自定义 seh 处理程序后,引发另一个异常并单步执行下一个命令。
也许某些分析器工具(例如 pin 或 valgrind)可以更轻松地为您做到这一点。我建议你看一下。
If you do not care about performance, you can do a small trick to count that. Raise a single step exception and upon entering your custom seh handler, raise another one and step over to the next command.
Maybe some profiler tools like pin or valgrind do that for you in an easier manner. I would suggest that you take a look.
一种(尽管很慢)方法是编写自己的调试器。然后,它会在程序的入口点处设置断点,当它被击中时,它会在上下文中的 EFlags 上设置跟踪标志,因此它也会在下一条指令上中断到调试器。然后,您可以使用带有 EIP 的哈希表来计算命中次数。
唯一的问题是开销会很大并且应用程序运行速度会非常慢。
One (although slow) method would be to write your own debugger. It would then breakpoint the entry point of your program, and when it was hit it would set the trace flag on the EFlags in the context, so it would break to the debugger on the next instruction as well. You could then use a hash table with the EIP to count the number of times hit.
Only problem is that the overhead would be extreme and the application would run very slowly.