Bug 31084 - -break-condition compare strings
Summary: -break-condition compare strings
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: mi (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-24 19:05 UTC by Ernie Pasveer
Modified: 2023-11-25 16:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ernie Pasveer 2023-11-24 19:05:49 UTC
What is the proper syntax to add a condition to a breakpoint to break if a string matches a text.  Same question to -break-insert.


gdb) 
-break-condition 1 name.c_str() == "ernie"
^error,msg="No symbol \"ernie\" in current context."
(gdb) 
-break-condition 1 $_streq(name.c_str(), "ernie")
^error,msg="Problem parsing arguments: break-condition 1 $_streq(name.c_str(), \"ernie\")"
(gdb) 






$ more gdbmi_condition.cpp 
#include <iostream>
#include <string>

int main (int argc, char* argv[]) {

    std::string name = "";

    name = "ernie";

    // Create the breakpoint with a string condition.
    //
    // -break-insert -c 'name.c_str() == "ernie"' gdbmi_condition.cpp:16             // Failed parsing.
    // -break-insert -c '$_streq(name.c_str(), "ernie")' gdbmi_condition.cpp:16      // Failed parsing.
    // -break-insert -c 'strcmp("xxxxx", name.c_str() == 0' gdbmi_condition.cpp:16   // Is accepted but breaks eventhough strings are different.

    std::cout << "Name is: " << name << std::endl;

    return 0;
}
Comment 1 Hannes Domani 2023-11-24 20:10:57 UTC
I think it should work if you quote the whole condition, like this:

-break-condition 1 "$_streq(name.c_str(), \"ernie\")"
Comment 2 Ernie Pasveer 2023-11-25 15:36:22 UTC
Sweet!  Yes, indeed.  It does work after all the escape'isms.

I can implement this in my Seergdb debugger.

Thanks for your quick help.
Comment 3 Tom Tromey 2023-11-25 16:22:51 UTC
Answered so closing.  Thank you Hannes.