From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7873) id 7C7B53858CDB; Thu, 2 Mar 2023 14:34:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C7B53858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677767690; bh=4gBfKFIUOzCgp+MK8tJ1w81Pp1+Iq/t3YIal4tEpanA=; h=From:To:Subject:Date:From; b=OMxwWn4JQmKnRuPbkPc257IWftKDjcxN4/gd/Gc4kyiRP378uXrfvZYvzCG1RO5Kx YuGusJR9KH/+3s9sBprIVClZbgUynszy/HGk/iIG7f74l69qlfwzVMuzrRU6nlQOYD g+CSfIgyneaIrIdescqCEzVwe7ejnTLwlmpShDzE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tiezhu Yang To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: LoongArch: Add support for static data member in struct X-Act-Checkin: binutils-gdb X-Git-Author: Hui Li X-Git-Refname: refs/heads/master X-Git-Oldrev: 281309f3c8c692d0246f4437ad3c635fe69dbaf7 X-Git-Newrev: 78c7a5288e2ba8c9fd00ee948d1f20e4decb800c Message-Id: <20230302143450.7C7B53858CDB@sourceware.org> Date: Thu, 2 Mar 2023 14:34:50 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D78c7a5288e2b= a8c9fd00ee948d1f20e4decb800c commit 78c7a5288e2ba8c9fd00ee948d1f20e4decb800c Author: Hui Li Date: Fri Feb 24 06:47:39 2023 +0800 gdb: LoongArch: Add support for static data member in struct =20 As described in C++ reference [1], static data members are not part of objects of a given class type. Modified compute_struct_member () to ignore static data member so that we can get the expected result. =20 loongson@linux:~$ cat test.c #include struct struct_01 { static unsigned a; float b;}; unsigned struct_01::a =3D 66; struct struct_01 struct_01_val =3D { 99.00 }; int check_arg_struct(struct struct_01 arg) { printf("arg.a =3D %d\n", arg.a); printf("arg.b =3D %f\n", arg.b); return 0; } int main() { check_arg_struct(struct_01_val); return 0; } loongson@linux:~$ g++ -g test.c -o test++ loongson@linux:~$ gdb test++ =20 Without this patch: ... (gdb) start ... (gdb) p check_arg_struct(struct_01_val) arg.a =3D 66 arg.b =3D 0.000000 $1 =3D 0 =20 With this patch: ... (gdb) start ... (gdb) p check_arg_struct(struct_01_val) arg.a =3D 66 arg.b =3D 99.000000 $1 =3D 0 =20 [1] https://learn.microsoft.com/en-us/cpp/cpp/static-members-cpp?view= =3Dmsvc-170 =20 Signed-off-by: Hui Li Reviewed-By: Tom Tromey Signed-off-by: Tiezhu Yang Diff: --- gdb/loongarch-tdep.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/loongarch-tdep.c b/gdb/loongarch-tdep.c index f5ddad0ba65..b380bd7e2d4 100644 --- a/gdb/loongarch-tdep.c +++ b/gdb/loongarch-tdep.c @@ -520,6 +520,10 @@ compute_struct_member (struct type *type, { for (int i =3D 0; i < type->num_fields (); i++) { + /* Ignore any static fields. */ + if (field_is_static (&type->field (i))) + continue; + struct type *field_type =3D check_typedef (type->field (i).type ()); =20 if (field_type->code () =3D=3D TYPE_CODE_INT