Java 在 Eclipse 中调试时查看完整字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2873949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 13:55:03  来源:igfitidea点击:

Viewing complete strings while debugging in Eclipse

javaeclipsedebugging

提问by ragebiswas

While debugging Java code, Strings in the views "Variables" and "Expressions" show up only till a certain length, after which Eclipse shows "..."

在调试 Java 代码时,视图“变量”和“表达式”中的字符串只显示到一定长度,之后 Eclipse 显示“...”

Is there any way to inspect the entire string? (This eases the pain of adding logging statements for debugging everywhere)

有没有办法检查整个字符串?(这减轻了添加日志语句以便在任何地方进行调试的痛苦)

采纳答案by Eugene Kuleshov

In the Variables view you can right click on Details pane (the section where the string content is displayed) and select "Max Length..." popup menu. The same length applies to expression inspector popup and few other places.

在变量视图中,您可以右键单击详细信息窗格(显示字符串内容的部分)并选择“最大长度...”弹出菜单。相同的长度适用于表达式检查器弹出窗口和其他几个地方。

enter image description here

在此处输入图片说明

回答by zvikico

If you have a really long string, I use a different strategy: dump it to a file. I have a snippet of code I use in the Display view, which is evaluated to dump the data to a file. I use Commons IO, but you can do it with JDK only methods.

如果您有一个很长的字符串,我会使用不同的策略:将其转储到文件中。我在“显示”视图中使用了一段代码,该代码被评估为将数据转储到文件中。我使用 Commons IO,但您可以仅使用 JDK 方法来完成。

org.apache.commons.io.FileUtils.writeStringToFile(new java.io.File("<filename>"), <expression to evaluate>);

Naturally, you will need the Commons IO JAR in your classpath for that to work. If you don't, resort to JDK work.

自然,您将需要在类路径中使用 Commons IO JAR 才能使其工作。如果不这样做,请使用 JDK 工作。

回答by Umberto

In the Variablesview you right-click on the variable and select Change value. If your variable is huge you have to wait a few minutes (in this case Eclipse doesn't respond to commands) but in the end Eclipse will show your variable entirely.

变量视图中,右键单击变量并选择更改值。如果您的变量很大,您必须等待几分钟(在这种情况下 Eclipse 不响应命令),但最终 Eclipse 将完全显示您的变量。

回答by Prince Champappilly

For javascript based debugging on eclipse, "change value" method and "Max length" method both failed for me, adding the required object to watch(Expressions) and then Right Clicking the watched expression to select "Load Full Value"is the only solution that works for me, but even this inserts unwanted "\n" in the output.

对于eclipse上基于javascript的调试,“更改值”方法和“最大长度”方法对我来说都失败了,添加所需的对象来观察(表达式)然后右键单击被观察的表达式以选择“加载完整值”是唯一的解决方案这对我有用,但即使这样也会在输出中插入不需要的“\n”

Note- "Max length" must be set for the "Load Full Value" to work as it loads values till max length(default in eclipse is 10000). Refer above answer to see how to set Max length.

注意- 必须为“加载完整值”设置“最大长度”,因为它加载值直到最大长度(eclipse 中的默认值为 10000)。请参阅上面的答案以了解如何设置最大长度。

回答by Sonali

When debugger reaches the point where you want the String value, just type a sysOut statement

当调试器到达您想要字符串值的位置时,只需键入 sysOut 语句

System.out.println("The value is : \n " + query);

Select the above the statement, right click-> Execute

选择上面的语句,右键->执行

It will print the value on the console

它将在控制台上打印值

回答by Waqas Ahmed

The best way to view a String value from eclipse debug view is as below.

从 Eclipse 调试视图查看字符串值的最佳方法如下。

1) Switch to debug view in Eclipse

1) 在 Eclipse 中切换到调试视图

2) Select the desired variable in variable pane.

2) 在变量窗格中选择所需的变量。

3) Right click on display area of variable pane where value is shown and click on Max Length. Enter the maximum char value in Configure Details Pane .

3) 右键单击​​显示值的变量窗格的显示区域,然后单击最大长度。在配置详细信息窗格中输入最大字符值。

4) Cheers

4)干杯

enter image description here

在此处输入图片说明

回答by WesternGun

There is no "maxLength" in Eclipse Mars. And, the "change value" only works with "Variables", not "Expressions", so none of above works for me.

Eclipse Mars 中没有“maxLength”。而且,“更改值”仅适用于“变量”,而不适用于“表达式”,因此以上都不适合我。

enter image description here

在此处输入图片说明

And, the expression are cut in the middle, not at the end. I guess they changed the default behaviour.

而且,表达式是在中间切的,而不是在末尾。我猜他们改变了默认行为。

The only thing working for me, is to expand the expression name column's width, and click the expression to select it all to see the full length content.

唯一对我有用的是扩展表达式名称列的宽度,然后单击表达式以将其全部选中以查看全长内容。

回答by user07

Nothing from the above worked for me, moreover, some user interface elements in my Eclipse can not be found as described. I'm using STS 4.3.1.

上面没有任何内容对我有用,而且,我的 Eclipse 中的某些用户界面元素无法按照描述找到。我正在使用 STS 4.3.1。

The value I needed was really big, it is part of a huge JSON request. Workaround is to use an expression in Eclipse Debug Shell console and to output the substring of the whole value. Since you can see the partial value, inspect it and use the last few literals as the position to output the next chunk of the string. Repeat this approach until get what you need:

我需要的值非常大,它是巨大 JSON 请求的一部分。解决方法是在 Eclipse Debug Shell 控制台中使用表达式并输出整个值的子字符串。由于您可以看到部分值,请检查它并使用最后几个文字作为输出字符串下一个块的位置。重复这种方法,直到得到你需要的:

String result = new String(reallyBigByteArrayValue, "UTF-8");
result.substring(result.indexOf("some-unique-text"));