[Lldb-commits] [lldb] [lldb] Clear thread name container before writing UTF8 bytes (PR #134150)

2025-04-03 Thread Jeremy Day via lldb-commits

z2oh wrote:

Cherrypick is up: https://github.com/swiftlang/llvm-project/pull/10415. Thanks 
@JDevlieghere!

@ktraunmueller, ah I should've checked for an issue first, you had already done 
the investigation! I'm in favor of the documentation change you propose. I'd 
_also_ be in favor of just removing the assertion, but it's very possible I'm 
overlooking some reason why it's there in the first place (and it has been 
there for 12 years now).

https://github.com/llvm/llvm-project/pull/134150
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Clear thread name container before writing UTF8 bytes (PR #134150)

2025-04-03 Thread Jeremy Day via lldb-commits

z2oh wrote:

I captured one above:
```
 # Child-SP  RetAddr   Call Site
00 00d2`44b8ea48 7ff8`beefc12e ntdll!NtTerminateProcess+0x14
01 00d2`44b8ea50 7ff8`bcf518ab ntdll!RtlExitUserProcess+0x11e
02 00d2`44b8ea80 7ff8`bc0e0143 
KERNEL32!ExitProcessImplementation+0xb
03 00d2`44b8eab0 7ff8`bc0e4c49 ucrtbase!common_exit+0xc7
04 00d2`44b8eb10 7ff8`bc102ae6 ucrtbase!abort+0x69
05 00d2`44b8eb40 7ff8`bc102cc1 
ucrtbase!common_assert_to_stderr+0x6e
06 00d2`44b8eb80 7fff`b8e27a80 ucrtbase!wassert+0x71
07 00d2`44b8ebb0 7fff`b8b821e1 
liblldb!llvm::convertUTF16ToUTF8String+0x30 
[D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\llvm\lib\Support\ConvertUTFWrapper.cpp
 @ 88] 
08 00d2`44b8ec30 7fff`b83e9aa2 
liblldb!lldb_private::TargetThreadWindows::GetName+0x1b1 
[D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\lldb\source\Plugins\Process\Windows\Common\TargetThreadWindows.cpp
 @ 198] 
09 00d2`44b8eca0 7ff7`2a3c3c14 
liblldb!lldb::SBThread::GetName+0x102 
[D:\r\_work\swift-build\swift-build\SourceCache\llvm-project\lldb\source\API\SBThread.cpp
 @ 432] 
0a 00d2`44b8ed70 7ff7`2a3a5ac6 
lldb_dap!lldb_dap::CreateThread+0x1f4 
[S:\SourceCache\llvm-project\lldb\tools\lldb-dap\JSONUtils.cpp @ 877] 
0b 00d2`44b8ef10 7ff7`2a3b0ab5 lldb_dap!`anonymous 
namespace'::request_threads+0xa6 
[S:\SourceCache\llvm-project\lldb\tools\lldb-dap\lldb-dap.cpp @ 3906] 
0c 00d2`44b8f010 7ff7`2a3b0fe8 
lldb_dap!lldb_dap::DAP::HandleObject+0x1c5 
[S:\SourceCache\llvm-project\lldb\tools\lldb-dap\DAP.cpp @ 796] 
0d 00d2`44b8f130 7ff7`2a3a8b96 lldb_dap!lldb_dap::DAP::Loop+0x78 
[S:\SourceCache\llvm-project\lldb\tools\lldb-dap\DAP.cpp @ 812] 
0e 00d2`44b8f1d0 7ff7`2a4b5fbc lldb_dap!main+0x1096 
[S:\SourceCache\llvm-project\lldb\tools\lldb-dap\lldb-dap.cpp @ 5319] 
0f (Inline Function) ` lldb_dap!invoke_main+0x22 
[D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 78] 
10 00d2`44b8fb80 7ff8`bcf3e8d7 
lldb_dap!__scrt_common_main_seh+0x10c 
[D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
11 00d2`44b8fbc0 7ff8`beefbf6c KERNEL32!BaseThreadInitThunk+0x17
12 00d2`44b8fbf0 ` ntdll!RtlUserThreadStart+0x2c
```

We are reusing the `TargetThreadWindows` objects, so the second time that 
`TargetThreadWindows::GetName` is called, `m_name` has already been set, which 
triggers the assertion (without first clearing the string that is).

`convertUTF16ToUTF8String` calls `Out.resize` so clearly expects to be able to 
freely mutate the string, but this is a different precondition than requiring 
the string be explicitly empty. The only thing I can think of is that 
`convertUTF16ToUTF8String` would be trying to prevent accidental reuse of 
strings, but IMO it should not the responsibility of that function to care.

https://github.com/llvm/llvm-project/pull/134150
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits