ChatGPT解决这个技术问题 Extra ChatGPT

Viewing complete strings while debugging in Eclipse

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

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

where are you seeing this behaviour? which part of the debugger?
On a side note, this might be a misnomer, because it might not work for you, but if you use a debugging library like java.util.logging or log4j, you can easily turn your debug statements (with different levels of debugging) into printouts or to logfiles and it may give you the edge that sifting through strings in the debug window might not. Just a thought =)

M
Matt Ball

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.

https://i.stack.imgur.com/eWgSM.png


Way better solution than the selected one. Thank you!
Good to point out that Details Pane is the section where the string content is displayed.
How to do this in eclipse kepler? Pls help
The good news is this change also seems to affect the length displayed when hovering over a variable, inspecting in the "Inspect" window or "Expressions" view and displaying values in the "Display" view.
I've updated the correct solution (the one accepted earlier was the only solution for really old Eclipse versions).
U
Umberto

In the Variables view 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.


I can see only "data:image/bitmap;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQE... (length: 22869)". Set "Max Length" option not work and "Change value" also.
@falko "Max Length" didn't work for me, "Change value" was ok (after waiting for some seconds, depending on the variable length).
At least on my system, this is considerably slower than increasing "Max Length" (see other answer).
eclipse is not quite happy about your idea.. Ive tried this and I wait since 30mins now, for any response of eclipse.. Buuut: It seems to work ;)
z
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.

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.


cool workaround. I, personally, would accept this one as best answer. Caveat: has to be defined for the system where the JVM is running, which makes a difference if you're remote debugging, in which case the file will be written on the remote system, not on the workstation where eclipse is running.
W
Waqas Ahmed

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

1) Switch to debug view in Eclipse

2) Select the desired variable in variable pane.

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 .

4) Cheers

https://i.stack.imgur.com/EWS69.png


This graphical explanation is really helpful. +1
S
Sonali

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

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

Select the above the statement, right click-> Execute

It will print the value on the console


P
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.

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.


W
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.

https://i.stack.imgur.com/TwjCv.png

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.


u
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.

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:

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

W
Wolfgang Fahl

https://i.stack.imgur.com/zMyNe.png

From the console the copying is possible at full length.