<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/85111>85111</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lldb modifies variable values when be watched with condition
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ZequanWu
      </td>
    </tr>
</table>

<pre>
    main.cpp:
```
#include <string>

int main(int argc, char* argv[]) {
  std::string response = "a";
  response = "b";
  response = "c";
  return 0;
}
```

correct output:
```
(lldb) target create "/tmp/main.exe"
Current executable set to '/tmp/main.exe' (x86_64).
(lldb) command source -s 0 '/tmp/right.cmd'
Executing commands in '/tmp/right.cmd'.
(lldb) b main
Breakpoint 1: where = main.exe`main + 22 at main.cpp:8:9, address = 0x0000000000001186
(lldb) r
Process 1985728 launched: '/tmp/main.exe' (x86_64)
Process 1985728 stopped
* thread #1, name = 'main.exe', stop reason = breakpoint 1.1
 frame #0: 0x0000555555555186 main.exe`main(argc=1, argv=0x00007fffffffd6d8) at main.cpp:8:9
   5        return y;
   6    }
   7    int main(int argc, char* argv[]) {
-> 8        int x = 1;
   9        foo(x);
 10       std::cout << x << std::endl;
   11     return 0;
(lldb) watchpoint set variable x
Watchpoint created: Watchpoint 1: addr = 0x7fffffffd5ac size = 4 state = enabled type = m
    declare @ '/tmp/main.cpp:8'
    watchpoint spec = 'x'
    watchpoint resources:
       #0: addr = 0x7fffffffd5ac size = 4
Watchpoint 1 hit:

new value: 32767
(lldb) c

Watchpoint 1 hit:
old value: 32767
new value: 1
Process 1985728 resuming
Process 1985728 stopped
* thread #1, name = 'main.exe', stop reason = watchpoint 1
 frame #0: 0x000055555555518d main.exe`main(argc=1, argv=0x00007fffffffd6d8) at main.cpp:9:5
   6    }
   7    int main(int argc, char* argv[]) {
   8        int x = 1;
-> 9        foo(x);
   10       std::cout << x << std::endl;
   11     return 0;
   12   }
(lldb) c

Watchpoint 1 hit:
old value: 1
new value: 11
Process 1985728 resuming
Process 1985728 stopped
* thread #1, name = 'main.exe', stop reason = watchpoint 1
    frame #0: 0x0000555555555163 main.exe`foo(y=0x00007fffffffd5ac) at main.cpp:5:12
   2
   3    int foo(int &y) {
   4        y += 10;
-> 5        return y;
   6 }
   7    int main(int argc, char* argv[]) {
   8        int x = 1;
(lldb) c
11
Process 1985728 resuming
Process 1985728 exited with status = 0 (0x00000000)
(lldb) exit
```

incorrect output:
```
(lldb) target create "/tmp/main.exe"
Current executable set to '/tmp/main.exe' (x86_64).
(lldb) command source -s 0 '/tmp/wrong.cmd'
Executing commands in '/tmp/wrong.cmd'.
(lldb) b main
Breakpoint 1: where = main.exe`main + 22 at main.cpp:8:9, address = 0x0000000000001186
(lldb) r
Process 1987691 launched: '/tmp/main.exe' (x86_64)
Process 1987691 stopped
* thread #1, name = 'main.exe', stop reason = breakpoint 1.1
    frame #0: 0x0000555555555186 main.exe`main(argc=1, argv=0x00007fffffffd6d8) at main.cpp:8:9
   5 return y;
   6    }
   7    int main(int argc, char* argv[]) {
-> 8 int x = 1;
   9        foo(x);
   10       std::cout << x << std::endl;
   11     return 0;
(lldb) watchpoint set variable x
Watchpoint created: Watchpoint 1: addr = 0x7fffffffd5ac size = 4 state = enabled type = m
    declare @ '/tmp/main.cpp:8'
    watchpoint spec = 'x'
    watchpoint resources:
       #0: addr = 0x7fffffffd5ac size = 4
Watchpoint 1 hit:

new value: 32767
(lldb) watchpoint modify -c x=11 1
1 watchpoints modified.
(lldb) c

Watchpoint 1 hit:
old value: 32767
new value: 11
Process 1987691 resuming
Process 1987691 stopped
* thread #1, name = 'main.exe', stop reason = watchpoint 1
 frame #0: 0x000055555555518d main.exe`main(argc=1, argv=0x00007fffffffd6d8) at main.cpp:9:5
   6    }
   7    int main(int argc, char* argv[]) {
   8        int x = 1;
-> 9        foo(x);
   10       std::cout << x << std::endl;
   11     return 0;
   12   }
(lldb) c
error: stopped due to an error evaluating condition of watchpoint Watchpoint 1: addr = 0x7fffffffd5ac size = 4 state = disabled type = m: "x=11"
error: <user expression 1>:1:1: use of undeclared identifier 'x'
    1 | x=11
 | ^


Watchpoint 1 hit:
old value: 11
new value: 21
Process 1987691 resuming
Process 1987691 stopped
* thread #1, name = 'main.exe', stop reason = watchpoint 1
    frame #0: 0x0000555555555163 main.exe`foo(y=0x00007fffffffd5ac) at main.cpp:5:12
   2
   3    int foo(int &y) {
   4        y += 10;
-> 5        return y;
   6 }
   7    int main(int argc, char* argv[]) {
   8        int x = 1;
(lldb) c
21
Process 1987691 resuming
Process 1987691 exited with status = 0 (0x00000000)
(lldb) exit
```

Notice that the incorrect output not only throws an error about undeclared identifier 'x' but also modified the value of x to 21.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWU9z4rgT_TTi0hXKkjA2Bw4khOOvfrep2suWkAT2rpFYSQ6wn36r5T84gWRmMsNUdiuuGcZI6m6p-73Wm0R4X26N1nOS3pN0ORJ1KKyb_6b_qoX5Uo_WVp3mO1GasdzvCV-QZEmSBZkm7Z_mK-OlkVWtNBD-4IMrzZbwx3YyfpYmALohLMdX4baSsAeQhXCELfD7U7MDwmZAsvvGCsAHhVH5ovEKTvu9NR4DLYEwJghjhPfLX06v356WL6dD7Qwk_RDJltcPHD-ldU7LALYO-zq8npy8qtQazxWE2-oA0mkRNMYnbBV2e8JWMcP6qHEsWj3UzmkTQB-1rINYVxq8DhAsEJZdMcuAsPyYT3-fTgibjS9CS7vbCaPA29pJDXcekmeeXLktwljuFA5G48cYGXPe2noozas2lxHXTb3j8L3T4s-9xcpTwhdwKLRritCfYJrgKxB2D4yBaNDSgi4nfDFDuAilnPY-WibHZPBQmk8vtuCakf87K9GKzvI0YzlUojay0Aisb8rmdS8-2P1eqy7oAkLhtFBAGKe4VyN2Hc6ygWecQlNwWnhr4or1ID1j2qJx46IDxhPcZ3PatHtoPn2ZOsLyyCq-jOEjo_iy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