Skip to content

Support ',<number>' to visualize a pointer as an array #715

Closed

Description

Hi, with a VC++ project in VS, if I have a pointer like this:
int *myArr = new int[20];

I can watch the pointer "myArr" as an array in "Watch" windows, namely if I enter "myArr,2", it will show "myArr" as an array of int[2] like below
image

With my MIEngine debugger, that does not work. So my question it, is there a way to do that with MIEngine ? Or is there a workaround ?
Thanks !

Activity

  1. gregg-miskelly commented on May 1, 2018

    @gregg-miskelly
    Member
  2. gregg-miskelly commented on May 1, 2018

    @gregg-miskelly
    Member

    Ling Wang (@digittigerw) I believe you would evaluate something like (int[20])myArr.

    Andrew Wang (@WardenGnaw) do I have that right?

  3. digittigerw commented on May 1, 2018

    @digittigerw
    ContributorAuthor

    Yeah, actually (int[20])*myArr works. Thanks for the help ! Andrew Wang (@WardenGnaw) Gregg Miskelly (@gregg-miskelly)

  4. changed the title [-]how to watch a pointer as array [/-] [+]Support ',<number>' to visualize a pointer as an array[/+] on May 1, 2018
  5. gregg-miskelly commented on May 1, 2018

    @gregg-miskelly
    Member

    Ling Wang (@digittigerw) Excellent. I will leave this open to track the possible future feature of supporting ','.

  6. digittigerw commented on May 2, 2018

    @digittigerw
    ContributorAuthor

    Gregg Miskelly (@gregg-miskelly) Cool. I'm really curious, can we add that support in MIEngine ? is interpretation (parsing) of the watch expression done by VS debugger engine or by debugger extension like MIEngine ?
    Issue #709 is my other more general question related to this.

  7. gregg-miskelly commented on May 2, 2018

    @gregg-miskelly
    Member

    The MIEngine has a tiny bit of support for format specifier today. I think the only thing we implemented was ,x and ,d. The array size format specifier could be implemented using this code: https://github.com/Microsoft/MIEngine/blob/72df3ee1ad81a9698a35ced2410016ea9910c5e0/src/MIDebugEngine/Natvis.Impl/Natvis.cs#L501

  8. Trass3r commented on Jun 9, 2022

    @Trass3r
    Contributor

    // array with static size
    // TODO: could return '(T(*)[n])(exp)' but requires T
    var m = Regex.Match(trimmed, @"^\[?(\d+)\]?$");
    if (m.Success)
    return exp.Substring(0, lastComma);
    // array with dynamic size
    if (Regex.Match(trimmed, @"^\[([a-zA-Z_][a-zA-Z_\d]*)\]$").Success)
    return exp.Substring(0, lastComma);

    We could actually use the *array@(len) syntax to make it work.
    Though that seems to be gdb only syntax.

  9. WardenGnaw commented on Oct 10, 2022

    @WardenGnaw
    Member

    Addressed with:
    #1329
    #1345

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions