public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug rust/31401] New: Error when placing watchpoint rust debug build
@ 2024-02-19 14:20 jlmacedomatos at gmail dot com
  2024-02-20 14:37 ` [Bug rust/31401] " tromey at sourceware dot org
  2024-02-21 16:00 ` jlmacedomatos at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: jlmacedomatos at gmail dot com @ 2024-02-19 14:20 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31401

            Bug ID: 31401
           Summary: Error when placing watchpoint rust debug build
           Product: gdb
           Version: 15.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: rust
          Assignee: unassigned at sourceware dot org
          Reporter: jlmacedomatos at gmail dot com
  Target Milestone: ---

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rust/31401] Error when placing watchpoint rust debug build
  2024-02-19 14:20 [Bug rust/31401] New: Error when placing watchpoint rust debug build jlmacedomatos at gmail dot com
@ 2024-02-20 14:37 ` tromey at sourceware dot org
  2024-02-21 16:00 ` jlmacedomatos at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: tromey at sourceware dot org @ 2024-02-20 14:37 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31401

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID
                 CC|                            |tromey at sourceware dot org

--- Comment #1 from Tom Tromey <tromey at sourceware dot org> ---
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug rust/31401] Error when placing watchpoint rust debug build
  2024-02-19 14:20 [Bug rust/31401] New: Error when placing watchpoint rust debug build jlmacedomatos at gmail dot com
  2024-02-20 14:37 ` [Bug rust/31401] " tromey at sourceware dot org
@ 2024-02-21 16:00 ` jlmacedomatos at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: jlmacedomatos at gmail dot com @ 2024-02-21 16:00 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31401

--- Comment #2 from Joao Luca <jlmacedomatos at gmail dot com> ---
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-21 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-19 14:20 [Bug rust/31401] New: Error when placing watchpoint rust debug build jlmacedomatos at gmail dot com
2024-02-20 14:37 ` [Bug rust/31401] " tromey at sourceware dot org
2024-02-21 16:00 ` jlmacedomatos at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).