When trying to place a watchpoint on a rust binary build with `cargo build` it throws an error: ``` Breakpoint 1, 0x000055555555c8b0 in main.rs:1 () (gdb) watch *0x123456789 Attempt to take contents of a non-pointer value. (gdb) watch *(char*)0x123456789 unexpected token ``` if you put it between quote it seems to at least place the watchpoint but its unclear if its working or not ``` fn main() { let mut a = 123; a = 321; a = 555; a = 222; } Breakpoint 1, example::main () at src/main.rs:2 2 let mut a = 123; (gdb) next 3 a = 321; (gdb) p &a $1 = (*mut i32) 0x7fffffffd214 (gdb) watch "0x7fffffffd214" Watchpoint 2: "0x7fffffffd214" (gdb) watch a Hardware watchpoint 3: a (gdb) next Watchpoint 2: "0x7fffffffd214" Old value = "0x7fffffffd214" New value = "0x7fffffffd214" Watchpoint 2: "0x7fffffffd214" Old value = "0x7fffffffd214" New value = "0x7fffffffd214" Watchpoint 2: "0x7fffffffd214" Old value = "0x7fffffffd214" New value = "0x7fffffffd214" example::main () at src/main.rs:4 4 a = 555; ``` also using -l/-location doesn't seem to make any difference ``` (gdb) watch -l *0x123456789 Attempt to take contents of a non-pointer value. (gdb) watch -location *0x123456789 Attempt to take contents of a non-pointer value. (gdb) ``` Took the examples from: https://sourceware.org/gdb/current/onlinedocs/gdb.html/Set-Watchpoints.html#Set-Watchpoints How to reproduce: ``` mkdir example cd example cargo init . cargo build cargo build --release gdb -nh -nx -ex 'b main.rs:1' -ex 'run' -ex 'watch *0x12345678' --batch target/debug/example gdb -nh -nx -ex 'b main.rs:1' -ex 'run' -ex 'watch *0x12345678' --batch target/release/example ``` Both of the examples above work normally in the release build. Tested on gdb 13.1 and on master Rust versions 1.64, 1.66
Hi. Thanks for the bug report. (gdb) watch *0x123456789 Attempt to take contents of a non-pointer value. Here you're attempting to dereference just some random int. gdb used to allow this in the old days (maybe it still does in C mode, not sure). However you really need a typed pointer here. Or you can just watch an expression -- best is with "-location", like: (gdb) watch -location a (gdb) watch *(char*)0x123456789 unexpected token This one is C syntax, not Rust. (gdb) watch "0x7fffffffd214" Watchpoint 2: "0x7fffffffd214" This one watches that particular string, which is not really what you want. Perhaps this should be an error, except strings are coerced to memory and so gdb thinks this might actually change at some point. > Both of the examples above work normally in the release build. This probably works because gdb doesn't see any Rust debug info and so defaults to the "minimal" language, which is basically the same as C. Anyway I don't think there's a bug here. I'm going to close this report.
Hi, thanks for the answer. For some reason i assumed that i could do everything with C syntax. Anyway, after looking at the rust testcases i realize that i could accomplish what i wanted with: `watch *(0x7fffffffd4cc as *mut [u8; 4])` Completely forgot about the `as` keyword.