Debugger, set value only once
Answered
I have changed a local variable value through the watch window. It is used in a for loop, something similar to this:
int x;
for (int i=0; i<10; ++i)
modify(x);
However after setting the value through debugger the value doesn't change after being called by `modify()`. It is always stuck to whatever I set initially.
I don't think this is the intended behavior, are there any workarounds?
Please sign in to leave a comment.
Hi, Baris.
Please check whether you pass "x" to modify() by value. In this case if some modifications are applied to "x" inside modify(), they are applied to a local "x", not to the one defined in the int x; line (for which you set a value using the Debug window). If you would like to modify that "x" inside modify(), you need to pass it by reference.
If I misunderstood you, please let me know.
It is passed by reference of course. The signature is something like:
I am oversimplifying things to make it concise. The real code is working in production and messier than this.
Oh, sorry. I just wasn't able to reproduce the issue on my side when a variable is passed by reference and assumed that there might be some confusion. What CLion version and what debugger do you use?
I am using CLion 2018.1 on Ubuntu 16.04 with the bundled GDB 8.1.
Thanks a lot for the details! I was able to reproduce the problem with GDB and created the issue in our tracker: https://youtrack.jetbrains.com/issue/CPP-13295. Feel free to comment or upvote. Please follow it to get updates.
Note that I can't reproduce the problem with LLDB. So meanwhile in order to avoid the problem you can switch to LLDB if it's acceptable to you.
Perfect! I can do a workaround this is not a big blocker. Thank you for the immediate response and that issue in the tracker. Things went extremely fast, I am surprised :)
Thank you for your kind words! :)
Please don't hesitate to contact us here or via email (clion-support at jetbrains.com) if you face any other issues with CLion or report them directly in our tracker (https://youtrack.jetbrains.com/issues/CPP).