0

Is there anyway to break on gdb when $r1 equals to a certain string I know there is :

break [addr] if ((int)strcmp($r1, "hello")) == 0

But what to set in addr when I just wanna break when the r1 is "hello" no matter the current function/address?

Neolex
  • 235
  • 3
  • 15
  • 1
    I'm on x86 and you're probably not, so I can't test this, but: `watch $r1 if strcmp((char *)$r1, "hello")==0` or `watch $r1 if $_streq((char *)$r1, "hello")` ought to work but will raise an exception (and throw you out to the gdb prompt) if $r1 does not contain the address of a valid string. Will probably need to write a python convenience function if you need something more robust. – Mark Plotnick Mar 29 '18 at 15:06
  • I think watch $r1 if .. works but the program run for ages even if it's just a single printf in main so I cant get any output – Neolex Mar 29 '18 at 16:45
  • I don't know of any architectures that support hardware watchpoints on registers. (Maybe some in-circuit emulators can do this.) So gdb is single-stepping your program. That'll slow things down by several orders of magnitude. If you can narrow down your search to, say, a range of lines in one function, you can `disable` the watchpoint and `enable` it only within that range so it won't always slow things down. – Mark Plotnick Mar 29 '18 at 17:11
  • Oh i'll try that ! Thank you! – Neolex Mar 29 '18 at 18:31

0 Answers0