<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/66590>66590</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lldb][gui] Local variables aren't updated when function goes into recursion
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kblinichkin
</td>
</tr>
</table>
<pre>
### Description
For example we have a recursive function like this:
```c++
template <typename T>
T numOfCoinChangesSubProblem(Matrix<T>& mem, const std::vector<T>& coins,
const T sum, size_t coinIdx) {
if (sum == 0) {
mem.at(coinIdx, 0) = 1;
return 1;
}
T first;
if (coins[coinIdx] > sum)
first = 0;
else if (mem.at(coinIdx, sum - coins[coinIdx]) != std::numeric_limits<T>::max())
first = mem.at(coinIdx, sum - coins[coinIdx]);
else
first = numOfCoinChangesSubProblem(mem, coins, sum - coins[coinIdx], coinIdx);
T second;
if (coinIdx == 0)
second = 0;
else if (mem.at(coinIdx - 1, sum) != std::numeric_limits<T>::max())
second = mem.at(coinIdx - 1, sum);
else
second = numOfCoinChangesSubProblem(mem, coins, sum, coinIdx - 1);
mem.at(coinIdx, sum) = first + second;
return mem.at(coinIdx, sum);
}
```
Once we go to the second layer of recursive call and further, the variable `sum` and `coinIdx` remain the same.
### Details
Here we have a first call with `sum=6` and `coinIdx=3`
<img width="1439" alt="Screenshot 2023-09-16 at 19 48 40" src="https://github.com/llvm/llvm-project/assets/10687845/80db924a-b5c7-4470-90b0-3175f4ceaa97">
After that we enter the first recursive call and can see in the call stack that we are in the second call already, but the variables didn't change.
<img width="1439" alt="Screenshot 2023-09-16 at 19 50 24" src="https://github.com/llvm/llvm-project/assets/10687845/4b330c80-416f-41cc-a050-f3f1b04136b0">
The `coins[coinIdx]` variable in this case equals `6` as seen at the next screenshot. Thus the variable `sum` have to be equal to `0` in the second recursion layer.
<img width="687" alt="Screenshot 2023-09-16 at 19 53 26" src="https://github.com/llvm/llvm-project/assets/10687845/0b768601-d824-4392-8f95-2004d652a0ed">
When quitting **gui** mode and checking variables over the command line, values are as expected.
<img width="228" alt="Screenshot 2023-09-16 at 19 55 32" src="https://github.com/llvm/llvm-project/assets/10687845/4072534e-bb8e-406c-95a5-5a7f42eb0642">
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vttu4zYQ_Rr6ZSCDInV98ENib9AFWmyBNdDHBUWNLDYU5SUpx-nXF5TkSy7e7gJpICQKOZzLOWdGFM6pnUFckfSepJuFGHzb29VjpZVRsn1UZlH19fOKMD49sEEnrdp71RtCN4TePfQW8Ci6vUZ4QmjFAUGARTlYpw4IzWBksAatHhF8qxzhd9NRktHpkYTdh2dc9djttfAIhK_98x6N6BC2hH-atrdghu5Ls-6VWbfC7NB9Hao_bV9p7Agr_hDeqiPh6_EEy6ALy2uQvXEenK9DdH53QOl7e2Ume2UcYespyGy-BTeMp536B7_50ehzfSSsBJLP6QIAqAYIK9zQAeEbwjdA35iEnw67pfCEFWc_69mSbyAm_JW5RT9Y82qD5JsZvGlpC42yzr-wmdKZKkrvT8HSDRD-aaqofBlpdAFT4mdHqB3Ort5LPFQbwdsgYz0sDs7OaJuhQ6vkN6065d0J9XGrE0fCipDR7aR-MfwLLEIVt_z-UEhn3Uy6-EHA9ZUuzrEvMbfgUPamvkHR5_p4rZqXuU4nXzMzl3WDHIggnhP-MC6u8vhxuP_A_srPr4J_hfMU8j2sbyjl1GMz9ez-DSVzr90-fwl2bsDT9LpO4ouR4xjc9eB78C2eStbiGS30zdVklEJrEKaGZrC-RRuChRMHYZWoNALJaAie0dEqzMk5q4yCxU4oM0UQHS6vk7ie1l4o7abl39Bej-gJjDGJJ-XbUzS-yd6JyDf8Uilfq24HT6r2bVAuY3HCS8IYCO2nha_SIhrX9h4YZTyiZRRnIDzEJSQFJDRYOysn69b7_fhVYA-EPeyUb4dqKfuOsAetD6c_0d72f6P0hD0I59A7wh5imhV5kaSEPR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