* [PATCH] gdb: LoongArch: Added support for static data member in struct
@ 2023-02-24 0:54 Hui Li
2023-02-24 19:14 ` Tom Tromey
2023-03-02 14:42 ` Tiezhu Yang
0 siblings, 2 replies; 4+ messages in thread
From: Hui Li @ 2023-02-24 0:54 UTC (permalink / raw)
To: gdb-patches
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.
loongson@linux:~$ cat test.c
#include<stdio.h>
struct struct_01 { static unsigned a; float b;};
unsigned struct_01::a = 66;
struct struct_01 struct_01_val = { 99.00 };
int check_arg_struct(struct struct_01 arg)
{
printf("arg.a = %d\n", arg.a);
printf("arg.b = %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++
Without this patch:
...
(gdb) start
...
(gdb) p check_arg_struct(struct_01_val)
arg.a = 66
arg.b = 0.000000
$1 = 0
With this patch:
...
(gdb) start
...
(gdb) p check_arg_struct(struct_01_val)
arg.a = 66
arg.b = 99.000000
$1 = 0
[1] https://learn.microsoft.com/en-us/cpp/cpp/static-members-cpp?view=msvc-170
Signed-off-by: Hui Li <lihui@loongson.cn>
---
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 = 0; i < type->num_fields (); i++)
{
+ /* Ignore any static fields. */
+ if (field_is_static (&type->field (i)))
+ continue;
+
struct type *field_type = check_typedef (type->field (i).type ());
if (field_type->code () == TYPE_CODE_INT
--
2.38.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gdb: LoongArch: Added support for static data member in struct
2023-02-24 0:54 [PATCH] gdb: LoongArch: Added support for static data member in struct Hui Li
@ 2023-02-24 19:14 ` Tom Tromey
2023-03-02 1:22 ` Hui Li
2023-03-02 14:42 ` Tiezhu Yang
1 sibling, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2023-02-24 19:14 UTC (permalink / raw)
To: Hui Li; +Cc: gdb-patches
>>>>> Hui Li <lihui@loongson.cn> writes:
> 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.
Looks good to me. I don't know this arch but it's normal for tdep code
to have to do this.
Reviewed-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gdb: LoongArch: Added support for static data member in struct
2023-02-24 19:14 ` Tom Tromey
@ 2023-03-02 1:22 ` Hui Li
0 siblings, 0 replies; 4+ messages in thread
From: Hui Li @ 2023-03-02 1:22 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 2023/2/25 上午3:14, Tom Tromey wrote:
>>>>>> Hui Li <lihui@loongson.cn> writes:
>
>> 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.
>
> Looks good to me. I don't know this arch but it's normal for tdep code
> to have to do this.
>
> Reviewed-By: Tom Tromey <tom@tromey.com>
>
> Tom
>
Thanks for your review.
Hui
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gdb: LoongArch: Added support for static data member in struct
2023-02-24 0:54 [PATCH] gdb: LoongArch: Added support for static data member in struct Hui Li
2023-02-24 19:14 ` Tom Tromey
@ 2023-03-02 14:42 ` Tiezhu Yang
1 sibling, 0 replies; 4+ messages in thread
From: Tiezhu Yang @ 2023-03-02 14:42 UTC (permalink / raw)
To: Hui Li, gdb-patches
On 2/24/23 08:54, Hui Li wrote:
> 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.
Looks good to me, tested on LoongArch, pushed.
Thanks,
Tiezhu
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-03-02 14:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-24 0:54 [PATCH] gdb: LoongArch: Added support for static data member in struct Hui Li
2023-02-24 19:14 ` Tom Tromey
2023-03-02 1:22 ` Hui Li
2023-03-02 14:42 ` Tiezhu Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).