<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/132182>132182</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lldb] coerce the breakpoint condition expression into a bool
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k4lizen
</td>
</tr>
</table>
<pre>
Currently, when a user sets an expression as a breakpoint condition, the expression can evaluate to an arbitrary type and that then gets interpreted into a boolean with the IsLogicalTrue
https://github.com/llvm/llvm-project/blob/main/lldb/source/Breakpoint/BreakpointLocation.cpp#L310
call. It would be smarter to wrap the condition into a `(bool)(..)` so that that conversion is handed off to the underlying compiler/type system.
Doing this would fix https://github.com/llvm/llvm-project/issues/132177 as the expression parser would return a clean error. It would also help detect errors like https://github.com/llvm/llvm-project/issues/132179 .
Also, if we take the example from https://github.com/llvm/llvm-project/issues/132179 , if we set the breakpoint condition to just `bol`, lldb will always return true due to https://github.com/llvm/llvm-project/issues/132177 (or error out if that is fixed) whereas a user might expect that the `operator bool()` will be called.
Importantly, wrapping the condition text into just ``(bool)(..)`` doesn't work because the condition can contain multiple statements like `st1; st2; expr`, but it would work if wrapped into a statement expression (https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) which is supported by clang. So wrapping it into a `"(bool)({ ... ;})"` should be fine (at least for C/C++).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVd1uqzgQfhpzMzqImBLIBRdNu0hH6t3ZFzBmCD4xNrKHptmnX42TtGm152JVqZJLbM_P9zNWMZqDQ2xFtRfVc6ZWmnxojw_W_IMu6_1wbp_WENCRPQv5BKcJHShYIwaISBGUA3xbAsZovAMVQUEfUB0XbxyB9m4wZLzjuzTh_VnNV1-VXRUhkOdIKvSGggpnoPOCoNwANCnimw4OnM44wrAEJBz4f8_pvLeoHJwMTSnHz_jiD0Yr-3dYURSPE9ES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