<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/92541>92541</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lldb] Connecting to GDB remote target crashes when XML data contains no registers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aragners
</td>
</tr>
</table>
<pre>
If the XML target from gdb-remote server contains no register then lldb will fallback by calling `DynamicRegisterInfo::SetRegisterInfo` on the on registers returned by `GetFallbackRegisters`. But `DynamicRegisterInfo:Finalize` will have been called and `m_finalized` set. This result in an assertion in `SetRegisterInfo` for debug builds or a crash for release builds.
Find that `GetGDBServerRegisterInfo(arch_to_use)`, that is called from `ProcessGDBRemote::BuildDynamicRegisterInfo`, will return false if there is an empty set of registers, which causes the fallback. But `SetRegisterInfo` (via `AddRemoteRregisters`) will have been called with that empty set of registers, which causes the initial `Finalize` call.
Backtrace of the crash:
[bt-crash.txt](https://github.com/llvm/llvm-project/files/15349590/bt-crash.txt)
Backtrace of the call up to Finalize:
[bt-finalize.txt](https://github.com/llvm/llvm-project/files/15349601/bt-finalize.txt)
The lldb version this bug was found for is:
`lldb version 19.0.0git (https://github.com/llvm/llvm-project.git revision 3f0e1d4cf09b0c90abfb1d06a26cc4c85c1f9568)`
The use case is connecting to a simulator and the simulator's gdb server only provides some data, such as architecture, in the XML. And then relies on the default register layout. This works fine with gdb as client.
When filing a bug I am asked to attach the content of the diagnostics directory, but diagnostics.log file is empty so not attaching that.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVU2P4zYM_TXKhVhDlj8SH3KYbJDBAi1Q7C7Q3hayRNvqKNJAlJOmv76QnMxMitkCA_SSwJJIPvI9kpLIjA5xy5oda_YrOcfJh60McnQYaNV7fdl-GSBOCH_8-gtEGUaMMAR_hFH3nwIefUQgDCcMoLyL0jgC5yHgaChiSKYOr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