public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Asking for the best way to implement a way to trigger watchpoint without changes
@ 2021-12-26  6:01 aldelaro5
  2021-12-26  7:04 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: aldelaro5 @ 2021-12-26  6:01 UTC (permalink / raw)
  To: gdb

Hi.

I have come into a situation where I need to be able to have watchpoint
triggers even if the underlying address has not changed.

My particular situation is the following: I am looking into reversing
engineering console games such as GBA games which have emulators like mgba
that implements a GDB stub which implements the different types of Z
packets so I can ask to have write only watchpoint (for this particular
case, I don't want read/write, only write). I want to be able to use a GDB
frontend like the one ghidra (reverse engineering tool) provides, meaning
it is preferable if what I want to do involves using regular GDB commands.

There are 2 problems that the current implementation of watchpoint causes
me:

   1. Most of the time, I actually care that a write happened regardless if
   the value changed. Let's say I care that something tried to refresh it. As
   a reverse engineer, knowing this can be helpful in a lot of cases.
   2. Console emulators like these usually implement a feature to restore
   the state of the emulation (memory, CPU, etc...) which means that the
   following can happen: I save a state, then let the inferior trigger a
   watchpoint, resume and then for whatever reason, I want to go back so I
   restore the state, trigger the watchpoint again which GDB will see, but it
   will proceed to ignore it because for GDB, it's as if the value never
   changed between the time it triggered. It is possible to workaround this by
   manually sending ctrl+c which will force GDB to reread the value on the
   next continue, but it's not ideal.

The way I see it is there would be 2 ways to solve the second problem, but
one of them solves both and it is to optionally have GDB trigger a
watchpoint regardless if it changed or not. The other solution is to
somehow have the stub inform GDB that things changed, but the only way I
could find was to send a stop reply with the information...except that it
still pauses the inferior so really it doesn't help me since I can send
ctrl + c anyway.

Which is why I am seriously considering implementing the watchpoint part
because as far as I could research, GDB cannot do this currently. I even
looked into the events part of the Python api and although it is possible
to register a stop event handler, such handler will not be called until GDB
decides to actually stop after verifying that the value has changed; so it
doesn't help me.

What seems interesting however is the only thing preventing me to do this
is an if statement in bpstat_check_watchpoint from breakpoint.c meaning as
someone who is relatively new to the internal structure to the project (I
had to debug GDB itself recently to uncover a nexti issue), this is
something I could try to implement.

My question is simple: what would be the best way to do this? should I add
a config option? a command line argument? I am open to hear suggestions on
this.

To note, there is actually a bug report filed on this (bug 19221), but it
seemed to not have any activity on it for years.

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

* Re: Asking for the best way to implement a way to trigger watchpoint without changes
  2021-12-26  6:01 Asking for the best way to implement a way to trigger watchpoint without changes aldelaro5
@ 2021-12-26  7:04 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2021-12-26  7:04 UTC (permalink / raw)
  To: aldelaro5; +Cc: gdb

> Date: Sun, 26 Dec 2021 01:01:15 -0500
> From: aldelaro5 via Gdb <gdb@sourceware.org>
> 
> I have come into a situation where I need to be able to have watchpoint
> triggers even if the underlying address has not changed.

Don't access watchpoints fit the bill?  If not, why not?

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

end of thread, other threads:[~2021-12-26  7:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-26  6:01 Asking for the best way to implement a way to trigger watchpoint without changes aldelaro5
2021-12-26  7:04 ` Eli Zaretskii

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).