Bug 317675 - "-gdb-set" wrong quoting
Summary: "-gdb-set" wrong quoting
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 7.0   Edit
Hardware: Other Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-23 06:17 EDT by Vladimir Prus CLA
Modified: 2020-09-04 15:22 EDT (History)
4 users (show)

See Also:


Attachments
Proposed patch (7.73 KB, patch)
2012-11-15 13:07 EST, Dmitry Kozlov CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Prus CLA 2010-06-23 06:17:45 EDT
Build Identifier: 

I've tried this:

    f.createMIGDBSet(ctx, new String[]{"backtrace limit", "100"}

where the result is queued with IGDBControl. As result, DSF sends:

    -gdb-set "backtrace limit" 100

And to the best of my knowledge, no version of GDB accepts this, because "gdb-set" is not a "real" MI command. Instead, DSF should use:

    -gdb-set backtrace limit 100

without any quotes.

Reproducible: Always
Comment 1 Marc Khouzam CLA 2010-06-23 11:26:02 EDT
I don't understand the impacts of "gdb-set is not a real MI command", on quoting, but there should be a way to fix that for the MIGDBSet class.

Temporarily, you could also try 
    f.createMIGDBSet(ctx, new String[]{"backtrace","limit", "100"}
Comment 2 Dmitry Kozlov CLA 2012-10-01 14:36:17 EDT
I have experienced the same problem with set trace-notes gdb command. Once you use spaces in notes MI sends quoted command 
-gdb-set trace-notes "some notes with spaces"
and then trace-status returns 
start-notes="\"some notes with spaces\""
which require workaround in Trace Control View.

See gerrit for patch: https://git.eclipse.org/r/#/c/8004/
Comment 3 Marc Khouzam CLA 2012-10-05 07:02:10 EDT
I wonder about some -gdb-set commands and quotes.

1- What about when a directory has a space in it?
Do we want to send:
  -gdb-set solib-search-path /home/marc/my dir/test
or 
  -gdb-set solib-search-path "/home/marc/my dir/test"

2- what about arguments to the inferior that have spaces?
We surely need:
  -gdb-set --thread-group i1 args firstArg "second arg"

In this #2 case though, the user would have to input the double-quotes themselves to indicate that the two words are a single argument.  So maybe it is up to DSF-GDB to retain those quotes.  But then we should not escape those quotes, which currently I believe we would do, so it will require some changes.

Maybe a safer solution to the problem of 
  -gdb-set trace-notes "some notes with spaces"
is to turn off quoting directly in MIGDBSetTraceNote as we do in MIBreakCondition.  That way, we don't impact other commands.

WDYT?
Comment 4 Vladimir Prus CLA 2012-10-05 07:37:02 EDT
Marc,

in the first case, you shall not use quotes. If you use, they become part of the value, and nothing will work.

in the second case, the entire args string should be passed unmodified as provided by user, no quoting either.

The point is -gdb-set does not perform MI quote processing, so any such quoting is wrong. Also, this is actually not a new patch; we had it in our product for at least a year, and did not run into issues.
Comment 5 Marc Khouzam CLA 2012-10-05 09:12:35 EDT
(In reply to comment #4)
> Marc,
> 
> in the first case, you shall not use quotes. If you use, they become part of
> the value, and nothing will work.

Ok, that makes sense.

> in the second case, the entire args string should be passed unmodified as
> provided by user, no quoting either.

I don't think that's what's happening.
If you try this program:

int main(int argc, char **argv) {
    for (int i = 0; i < argc; ++i) {
      printf("arg %d is is: %s\n", i, argv[i]);
    }
    return 0;
}

and in the launch, in the Arguments tab, you put the following line:

firstArg "second arg" third\ arg

the output I get (with the proposed patch) is:

arg 0 is is: /home/lmckhou/runtime-TestDSF/DSFTestApp/Debug/DSFTestApp
arg 1 is is: firstArg
arg 2 is is: second
arg 3 is is: arg
arg 4 is is: third
arg 5 is is: arg

which is wrong, while before the patch I get:

arg 0 is is: /home/lmckhou/runtime-TestDSF/DSFTestApp/Debug/DSFTestApp
arg 1 is is: firstArg
arg 2 is is: second arg
arg 3 is is: third arg

Which is right, although it illustrates another possible problem where the
  third\ arg
works because we quote it, but we don't keep the \.  Actually, we don't keep the original quotes either, but happen to put in our own.  This should probably all be fixed.

The actual gdb command is:
  -gdb-set --thread-group i1 args firstArg "second arg" "third arg"

> The point is -gdb-set does not perform MI quote processing, so any such
> quoting is wrong. Also, this is actually not a new patch; we had it in our
> product for at least a year, and did not run into issues.

Do you have another patch maybe that handles this args case?
Comment 6 Dmitry Kozlov CLA 2012-10-12 06:01:30 EDT
Hi Marc, I have uploaded new patch due my poor knowledge of egit, which uploaded everything what I have locally. This patch is a just cosmetics, doesn't answer your question about gdb-set usage. Don't waste your time on it.
Comment 7 Dmitry Kozlov CLA 2012-11-15 13:07:57 EST
Created attachment 223625 [details]
Proposed patch

Hi Marc, I'm unable to feed in the new patch into gerrit because of gerrit issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=393735,
attaching it here. Thank you for catching problem with previous patch.
Comment 8 Marc Khouzam CLA 2012-11-16 15:23:31 EST
(In reply to comment #7)
> Created attachment 223625 [details]
> Proposed patch
> 
> Hi Marc, I'm unable to feed in the new patch into gerrit because of gerrit
> issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=393735,
> attaching it here. Thank you for catching problem with previous patch.

Thanks.
The change seems to fix the problem.

I've pushed the new version to Gerrit for you.
I'll comment there.
Comment 9 Marc Khouzam CLA 2012-11-16 16:09:49 EST
I found that soem JUnit tests broke with this change because we don't handle \n properly anymore.  Comments are in Gerrit.
Comment 10 Marc Khouzam CLA 2013-03-14 15:50:09 EDT
As can be seen from the Gerrit fix, this quoting problem affects -target-select as well.  For example:

(gdb) -target-select core "Core File"
^error,msg="/home/lmckhou/\"Core File\": No such file or directory."
(gdb) -target-select core "/home/lmckhou/Core File"
^error,msg="/home/lmckhou/\"/home/lmckhou/Core File\": No such file or directory."
(gdb) -target-select core Core File
^connected,...

Same for "-target-select tfile"