Bug 14607 - -var-list-children reports wrong numchild count
Summary: -var-list-children reports wrong numchild count
Status: RESOLVED INVALID
Alias: None
Product: gdb
Classification: Unclassified
Component: mi (show other bugs)
Version: 7.5
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-22 09:19 UTC by Niko Sams
Modified: 2023-08-31 17:29 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 Niko Sams 2012-09-22 09:19:11 UTC
To reproduce see this example debug session:

cat main.cpp
#include <vector>

int main()
{
    struct {
        std::vector<int> a;
    } struct1;

    struct1.a.push_back(10);
    struct1.a.push_back(100);

    return 0;
}


gdb --interpreter=mi2 testdebugee

-enable-pretty-printing
break main.cpp:12
-exec-run

-var-create struct1 @ struct1

-var-list-children --all-values struct1
^done,numchild="1",children=[child={name="struct1.public",exp="public",numchild="1",value="",thread-id="1"}],has_more="0"

-var-list-children --all-values struct1.public
^done,numchild="1",children=[child={name="struct1.public.a",exp="a",numchild="0",value="{...}",type="std::vector<int, std::allocator<int> >",thread-id="1",displayhint="array",dynamic="1"}],has_more="0"
                                                                             ^^^^ should be "2"

#correct:
-var-list-children --all-values struct1.public.a
^done,numchild="2",displayhint="array",children=[child={name="struct1.public.a.[0]",exp="[0]",numchild="0",value="10",type="int",thread-id="1"},child={name="struct1.public.a.[1]",exp="[1]",numchild="0",value="100",type="int",thread-id="1"}],ha

#correct:
-var-info-num-children struct1.public.a
^done,numchild="2"
Comment 1 Niko Sams 2012-09-22 09:21:48 UTC
ok the ^^^^ doesn't point where I wanted it to. To be more clear:
Current output:
{name="struct1.public.a",exp="a",numchild="0"

Expected output:
{name="struct1.public.a",exp="a",numchild="2"

(after -var-list-children --all-values struct1.public)
Comment 2 Tom Tromey 2022-05-25 19:00:41 UTC
'numchild' isn't reliable for a dynamic varobj.
This is documented in the MI docs:

'numchild'
     The number of children of the varobj.  This number is not
     necessarily reliable for a dynamic varobj.  Instead, you must
     examine the 'has_more' attribute.

This is a little confusing because in this command:

-var-list-children --all-values struct1.public
^done,numchild="1",children=[child={name="struct1.public.a",exp="a",numchild="0",value="{...}",type="std::vector<int, std::allocator<int> >",displayhint="array",dynamic="1"}],has_more="0"

... the has_more here refers to 'struct1.public' (which really only
does have one child), and 'a' doesn't have a has_more here.
Instead one must list the children of 'a' to find out.

So, I'm somewhat inclined to mark this as not a bug.
Comment 3 Tom Tromey 2023-08-31 17:29:03 UTC
Finally came back around to this.
I think it isn't a bug.