Bug 486541 - Embedded null character and subsequent characters in a watched QString are not displayed while debugging
Summary: Embedded null character and subsequent characters in a watched QString are no...
Status: REPORTED
Alias: None
Product: kdevelop
Classification: Applications
Component: CPP Debugger (other bugs)
Version First Reported In: 5.14.240480
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-04 07:18 UTC by Igor Kushnir
Modified: 2024-05-04 07:18 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Kushnir 2024-05-04 07:18:12 UTC
STEPS TO REPRODUCE
1.  Debug the following (Qt 5) code: 
```
QString str = "abcdef"; // (1)
str[3] = 0;             // (2)
```
2. Look at the value of `str` before and after the line (2) in Variables tool view and in the debugger tooltip for the variable `str`.
3. Run the GDB command  `print str` in GDB tool view before and after the line (2).

OBSERVED RESULT
2. The value of `str` is "abcdef" before the line (2) and "abc" after it - both in Variables tool view and in the debugger tooltip.
3. GDB tool view displays `$1 = "abcdef"` before the line (2) and `$2 = "abc\000ef"` after it. Incidentally, the same value is displayed while debugging with GDB in terminal outside of KDevelop but using KDevelop's pretty printers.

EXPECTED RESULT
The value of `str` is something like "abc\0ef" in Variables tool view, debugger tooltip and GDB tool view.
"\000" in GDB tool view is indisputably better than truncating the string, but I think "\0" would be a clearer representation of the null character, at least to C++ developers.

ADDITIONAL INFORMATION
The bug is present as early as in MIDebugger::readyReadStandardOutput(), where the values of `reply` received from GDB are:
1 (before the line (2)): "35^done,name=\"var0\",numchild=\"0\",value=\"\\\"abcdef\\\"\",type=\"QString\",displayhint=\"string\",dynamic=\"1\",has_more=\"0\""
2 (after the line (2)): "35^done,name=\"var3\",numchild=\"0\",value=\"\\\"abc\\\"\",type=\"QString\",displayhint=\"string\",dynamic=\"1\",has_more=\"0\""
3 (GDB tool view after the line (2)): "~\"$1 = \\\"abc\\\\000ef\\\"\\n\""

For some reason, GDB returns only 3 characters "abc" for variable display, but the entire string "abc\000ef" as the reply to the manual GDB print command.

After the truncated string value "abc" is read in MIDebugger::readyReadStandardOutput(), it eventually ends up in MIParser::parseStringLiteral() and then is displayed in the UI.

The same issue affects QByteArray in almost identical fashion and with practically the same results (except for minor differences because of divergent pretty-printing formats of KDevelop's QStringPrinter and QByteArrayPrinter).