0

I am trying to place a conditional breakpoint for a string comparison using strcmp. In the debug console, below command works

(char*)b->vec.buf.ptr.pointer,[b->vec.len]

However, when I want to use this in strcmp using below command,

strcmp(((char*)b->vec.buf.ptr.pointer,[b->vec.len]), "test") == 0

I get Invalid format specifier.. I think I am not able to use the () inside strcmp.

How to achieve this?

Selva
  • 951
  • 7
  • 23
  • The debugger can't compile c++ code. Put the test in an appropriate place in the source, recompile, and use the debugger there. You can test one char at a time and combine them in the debugger. `*(char*)b->vec.buf.ptr.pointer == 't'` – doug Feb 04 '22 at 04:56
  • Use `strncmp` instead if you don't have a 0 terminated string. `strncmp(((char*)b->vec.buf.ptr.pointer, "test", b->vec.len) == 0` – Retired Ninja Feb 04 '22 at 05:01
  • @doug Visual Studio can call some standard functions in the debugger. `strcmp` and `strncmp` work as well as others. https://learn.microsoft.com/en-us/visualstudio/debugger/expressions-in-the-debugger?view=vs-2022 – Retired Ninja Feb 04 '22 at 05:02
  • @RetiredNinja Cool. Didn't know that. Thanks. – doug Feb 04 '22 at 05:11
  • @doug -- I think the earlier versions of the debugger, back in the VS 2003 or 2005 days, the VS debugger had those issues you mentioned. – PaulMcKenzie Feb 04 '22 at 05:13
  • Thanks @RetiredNinja. Since this is doing first n char, I could see it is returning true even if my second string is `testabc`. Can I give 2 different length? – Selva Feb 04 '22 at 05:27
  • @PaulMcKenzie I don't remember the version they added it in either. I thought maybe 2008, but this looks like it was probably 2010 or 2012. https://stackoverflow.com/a/15196867/920069 Sadly the linked article is dead. :( – Retired Ninja Feb 04 '22 at 05:31
  • You can use additional logic in the breakpoint if you need to, like `(b->vec.len == strlen("testabc")) && (strncmp(((char*)b->vec.buf.ptr.pointer, "testabc", b->vec.len) == 0)` At some point though your eyes start to hurt trying to write all that in the conditional box so you just add an `if (...) { int zzzz = 0; }` in the code and put the breakpoint inside the `if`. :) – Retired Ninja Feb 04 '22 at 05:41
  • Thanks @RetiredNinja. This logic might work. I am doing this on Rust and Rust compile time is not that quicker for big code – Selva Feb 04 '22 at 05:54
  • @RetiredNinja - Can you add this as your answer? I can mark it answered – Selva Feb 04 '22 at 05:54

0 Answers0