Want to watch consistently and examine occasionally the variable outside the current frame in gdb

痞子三分冷 提交于 2019-12-11 13:13:35

问题


Say I define a variable named varin the main function. And the I set a watchpoint to it. Then I enter another function called func(). At this time, the watchpoints may be deleted so that I have no access to that variable. Any method to make to possible to always keep the watchpoint whenever you are?

Also, I know I can use syntax like print main::var to print out the value of the variable. But that is not sufficient enough. Any good idea?


回答1:


An oddity of gdb is that watch tries to respect the scope of all the constituent parts of the expression. So, if you watch var, and var goes out of scope, the watchpoint is removed. This applies to the elements of a more complicated expression as well, like watch a + b.

This has a justification, of course, and is sort of cool in a way -- but it is rarely what you actually want. It's far more normal, in my experience, not to care about the scope and to just want to watch some bit of memory.

To do this, pass -location to the watch command. This will do what you more commonly want to do -- just want the memory referred to by the expression. So, watch -location var.



来源:https://stackoverflow.com/questions/30959819/want-to-watch-consistently-and-examine-occasionally-the-variable-outside-the-cur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!