有没有办法在远程调试期间搜索堆栈中当前位置可用的变量?
我正在远程调试 Java 应用程序(这不是第一次),我发现自己正在寻找一个值,但不知道哪个变量可能保存该值(如果有的话)。这是特别难找到的,因为我正在逐步浏览库代码而不是我自己的代码,所以我想知道;由于 Eclipse 可以显示堆栈上当前可用的变量以及所有包含的值,有什么方法可以搜索这些变量吗?或者至少将其作为文本转储到某个地方并 grep 或其他东西。
I'm remote debugging a Java application and (not for the first time) I find myself looking for a value without knowing what variable might hold it (if any at all). This is especially hard to find since I'm stepping through library code rather than my own code, so I was wondering; since eclipse can display the variables currently available on the stack, along with all contained values, is there any way I can search these? Or at the very least dump it out as text somewhere and grep it or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我通常使用 Jackson 的 ObjectMapper 每当我发现自己陷入必须在一堆数据中搜索的情况时价值观调试时捕获。在断点命中时,假设我想在 myObj 的文本表示形式中搜索某个字符串,这可能是一些带有嵌套对象的混乱的 POJO。只需评估以下内容:
然后在您刚刚创建的文件中 grep 您的值。
YMMV:如果您不知道从哪里开始搜索,您将不得不迭代堆栈上的可用内容。此外,JSON 表示形式可能并不适合所有类型的搜索。
I usually do an export to JSON using Jackson's ObjectMapper whenever I find myself into the situation of having to search among a bunch of values caught while debugging. On breakpoint hit, let's say I want to search some string inside a text representation of myObj, which could be some messy POJO deep with nested objects. Just evaluate the following:
and then go grep your value inside the file you just created.
YMMV: if you have no idea where to start the search you'll have to iterate through what's available on the stack. Also the JSON representation might not be suitable for every kind of search.
我不确定您所要求的功能,但您可以采取另一种方法。假设您知道一般区域并且您要查找的对象不太常见,则 Eclipse 支持条件断点,因此您可以在方法末尾设置断点以检查方法变量和对象状态。
I'm not sure about the feature you are asking for but there is another approach you could take. Assuming you know the general area AND the object you are looking for isn't too common, eclipse supports conditional breakpoints so you could set breakpoints on the end of methods chechking the method variables and object state.
您可以尝试evars。我还没有尝试过搜索功能,但它允许将堆栈上的所有变量扩展并导出到文件中,然后您可以 grep 获取您的值。我手动将最新版本安装到 Eclipse 中,即将 jar 放在 dropins/plugins 目录中。在 Eclipse 3.6.1 上为我工作。
You could try evars. I haven't tried the search function, but it allows expanding and exporting all the variables on the stack to a file, which you can then grep for your value. I installed the latest version into Eclipse manually, i.e. putting the jar in the dropins/plugins directory. Worked for me on Eclipse 3.6.1.