Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format specifiers are wrongly stripped from -exec commands #1277

Closed
gareth-rees opened this issue Feb 24, 2022 · 0 comments · Fixed by #1278
Closed

Format specifiers are wrongly stripped from -exec commands #1277

gareth-rees opened this issue Feb 24, 2022 · 0 comments · Fixed by #1278

Comments

@gareth-rees
Copy link
Contributor

gareth-rees commented Feb 24, 2022

When entering an -exec command in the DEBUG CONSOLE in Visual Studio Code, I expect the remainder of the command to be passed as-is to GDB. In particular, if I enter the command

-exec echo abc,d

then I expect GDB to execute the command echo abc,d, producing the output abc,d in the DEBUG CONSOLE. But what I see instead is the output abc without the ,d. See screenshot below (using Visual Studio Code 1.64.2 and C/C++ extension v1.8.4):

Screenshot from 2022-02-24 10-26-11

The chain of calls that lead to this bug is:

  1. AD7DebugSession.HandleEvaluateRequestAsync receives expression="-exec echo abc,d" and calls:

    hr = expressionContext.ParseText(expression, enum_PARSEFLAGS.PARSE_EXPRESSION, Constants.ParseRadix, out expressionObject, out error, out errorIndex);

  2. IDebugExpression2.ParseText receives pszCode="-exec echo abc,d" and calls:

    ppExpr = new AD7Expression(Engine, Engine.DebuggedProcess.Natvis.GetVariable(pszCode, this));

  3. GetVariable receives expr="-exec echo abc,d" and calls:

    variable = new VariableInformation(expr, expr, frame.ThreadContext, frame.Engine, frame.Thread);

  4. The VariableInformation constructor receives expr="-exec echo abc,d" and calls:

    _strippedName = StripFormatSpecifier(expr, out _format);

  5. StripFormatSpecifier receives exp="-exec echo abc,d" and strips the ,d by executing:

    return exp.Substring(0, lastComma);

Note that the code in AD7DebugSession.HandleEvaluateRequestAsync already tests for the -exec case:

// If this is an -exec command (or starts with '`') treat it as a console command and log telemetry
if (expression.StartsWith("-exec", StringComparison.Ordinal) || expression[0] == '`')
isExecInConsole = true;

but this context has been lost by the time we get to the StripFormatSpecifier call.

Solution ideas:

  1. Pass the isExecInConsole flag down through ParseText and GetVariable to the VariableInformation constructor which can use it to skip the StripFormatSpecifier call. The problem with this approach is that ParseText implements the IDebugExpressionContext2::ParseText interface which we can't change.

  2. Test the -exec and backtick cases again inside StripFormatSpecifier and avoid stripping the specifier if these are found. The problem with this is that the test gets duplicated and so there is a risk of changing it in one place and not the other. Also, might there be a legitimate expression starting with -exec (meaning the negation of the value of a variable starting exec).

  3. Append a comma to expression in HandleEvaluateRequestAsync whose only purpose is to be stripped by StripFormatSpecifier.

I will prepare a pull request implementing solution (3) but if you have a better suggestion then let me know.

gregg-miskelly pushed a commit that referenced this issue Mar 3, 2022
…1278)

This prevents MIEngine from stripping (what appear to be) format specifiers from debug console commands prefixed by `-exec` or backtick. Fixes #1277.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants