Bug 395004 - Cannot install a conditional breakpoint with double quotes in the condition
Summary: Cannot install a conditional breakpoint with double quotes in the condition
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 8.1.1   Edit
Hardware: PC Linux
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
: 471997 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-11-24 07:25 EST by Dries Harnie CLA
Modified: 2021-02-16 11:31 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dries Harnie CLA 2012-11-24 07:25:47 EST
Steps to reproduce:
1) Create a new C++ "Hello World" executable project
2) Put a breakpoint on the line with return 0
3) Set its condition to: !strcmp("a","a")
4) Start project in debug mode

Expected result:
Program halts on that line.

Actual result:
Program doesn't halt, gdb traces shows the following output:
838,175 16-break-insert --thread-group i1 -c !strcmp(\"a\",\"a\") -f /home/dries/workspace/quotes-bug/src/quotes-bug.cpp:14
838,187 16^error,msg="Invalid character '\\' in expression."

---

Interestingly enough, if you change the condition to 0 == strcmp("a","a"), the expression is correctly wrapped in quotes, so the \" properly escape.
Comment 1 Bing-Yi Wong CLA 2013-03-04 01:58:13 EST
This problem basically blocks me from using conditional breakpoint with strcmp(), which was very handy.
If I use the condition 0 == strcmp("a","a"), it adds double-quotes to enclose the expression automatically, and it becomes "0 == strcmp(\"a\",\"a\")", which is correct.  Looks like the tool knows something about the input expression, so maybe it can do something more.  But, I think it would be better that the tool just copy&paste the expression into gdb command line without manipulation.
Comment 2 Bing-Yi Wong CLA 2013-03-04 03:12:57 EST
BTW, I found a simple workaround: adding a redundant whitespace in the expression.  I can set !strcmp("a", "a") as the expression (note the space after comma), and then the tool adds double-quotes automatically, making the backslashes correct.
Comment 3 Bing-Yi Wong CLA 2015-07-07 01:23:03 EDT
This WA doesn't work now.
Comment 4 Marc Khouzam CLA 2015-07-21 13:35:22 EDT
It's tricky to figure out exactly what GDB is expecting as escape characters and quotes in different situations.  It is particularly difficult when trying to support GDB versions ranging from 7.1 to 7.9.  This makes me very hesitant at changing the current quotation rules if we have a workaround.

I tried the workaround of adding a space and it still works for me.  So the following works:

!strcmp("a", "a")
0 == strcmp("a","a")

I believe with this, one can use strcmp in conditions to its full potential.

Bing-Yi, if the workaround still does not work for you with CDT 8.7 and GDB 7.9, can you provide the steps as to how to reproduce?
Comment 5 Bing-Yi Wong CLA 2015-08-16 23:21:22 EDT
Hi Marc, sorry I didn't notice you've replied here.

I think the step in the original description is good enough.

(1) Create a C++ "Hello World" project.
(2) *Before launching*, put a breakpoint on the line with cout.
(3) Set its condition to strcmp("a", "b").  In breakpoints view, observe the breakpoint has [condition: strcmp("a", "b")].  That is correct.
(4) Now launch it.  The program breaks on the line.  Observe the breakpoint now becomes [condition: strcmp(\].
(5) Launch it again.  This time the breakpoint doesn't work.

And here is another flow to reproduce:

(1) Create a C++ "Hello World" project.
(2) Set a normal breakpoint on the line with cout.
(3) Launch and break on that line.
(4) Set a conditional breakpoint on the next line.  Observe the breakpoint has [condition: strcmp("a", "b")].
(5) Continue and hit the breakpoint.  Now, observe the breakpoint becomes [condition: strcmp(\].

Put both experiments together, I suspect something wrong happens when the conditional breakpoint is hit.  The breakpoint surely works but only once.  In reality, that is totally useless.


Version info:
CBT 8.7.0
GDB 7.6.2
Comment 6 Marc Khouzam CLA 2016-03-17 13:12:03 EDT
*** Bug 471997 has been marked as a duplicate of this bug. ***
Comment 7 Liam Jackson CLA 2021-02-16 11:31:06 EST
It seems the breakpoint can be hit multiple times during one execution but gets changed upon exiting of the debugged executable. I guess some issue with re-loading in the breakpoint conditions after they have been escaped?