* Question about struct type* ownership
@ 2025-01-08 13:32 Jan Vraný via Gdb
2025-01-09 0:30 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Jan Vraný via Gdb @ 2025-01-08 13:32 UTC (permalink / raw)
To: gdb; +Cc: tom
Hi Tom,
in response to my "Python JIT API" series [1] you pointed
out that there are rules about type ownership [2] I was not
aware of:
> The issue is that in gdb there is a hidden rule: an objfile-specific
> type may only refer to other types from that objfile or to arch->
specific
> types. Arch-specific types may only refer to other arch-specific
types.
While working on addressing this concern, more questions poped up:
Let's say I'd like to create new function type "int(struct s)", where
type "int" is arch-owned and "struct s" is objfile-owned. Am I correct
thinking that resulting function type should be objfile-owned?
Generally speaking, if composing new type out of other types, if at
least one of the types is objfile-owned then the new type must by
also objfile-owned (by that very objfile), right?
Looking at lookup_function_type_with_arguments, it allocated new
function type is always "owned" by whoever "owns" the return type
(first param to lookup_function_type_with_arguments). So if I'm correct
about the above, I'd have to extend lookup_function_type_with_arguments
to pass down type allocator (like in create_array_type). Or is there
a better way?
Also, when experimenting with the example above, I realized that
the arch-owner of "int" struct type* is a different struct gdbarch *
then gdbarch associated with objfile-owner of "struct s" type
(i mean, pointer values are different).
While I would think it is okay to compose new type from types owned by
two distinct gdbarchs from lifecycle POV, it still puzzles me why
there are two different gdbarch instances (both are i386:x86-64)?
Thanks!
Best, Jan
[1]:
https://inbox.sourceware.org/gdb-patches/20241121124714.419946-1-jan.vrany@labware.com/
[2]:
https://inbox.sourceware.org/gdb-patches/87y10ba1ms.fsf@tromey.com/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question about struct type* ownership
2025-01-08 13:32 Question about struct type* ownership Jan Vraný via Gdb
@ 2025-01-09 0:30 ` Tom Tromey
2025-01-09 11:02 ` Jan Vraný via Gdb
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2025-01-09 0:30 UTC (permalink / raw)
To: Jan Vraný; +Cc: gdb, tom
Jan> Let's say I'd like to create new function type "int(struct s)", where
Jan> type "int" is arch-owned and "struct s" is objfile-owned. Am I correct
Jan> thinking that resulting function type should be objfile-owned?
Yes, in particular by the same objfile that owns "struct s".
Jan> Generally speaking, if composing new type out of other types, if at
Jan> least one of the types is objfile-owned then the new type must by
Jan> also objfile-owned (by that very objfile), right?
Yes.
Jan> Looking at lookup_function_type_with_arguments, it allocated new
Jan> function type is always "owned" by whoever "owns" the return type
Jan> (first param to lookup_function_type_with_arguments). So if I'm correct
Jan> about the above, I'd have to extend lookup_function_type_with_arguments
Jan> to pass down type allocator (like in create_array_type). Or is there
Jan> a better way?
It's new territory, so just whatever looks reasonably clean. I think in
the past this wasn't an issue because essentially only symbol readers
made types.
Jan> Also, when experimenting with the example above, I realized that
Jan> the arch-owner of "int" struct type* is a different struct gdbarch *
Jan> then gdbarch associated with objfile-owner of "struct s" type
Jan> (i mean, pointer values are different).
Jan> While I would think it is okay to compose new type from types owned by
Jan> two distinct gdbarchs from lifecycle POV, it still puzzles me why
Jan> there are two different gdbarch instances (both are i386:x86-64)?
Offhand I don't know but there are a lot of ways a gdbarch can be
initialized. Maybe they have different registers available.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Question about struct type* ownership
2025-01-09 0:30 ` Tom Tromey
@ 2025-01-09 11:02 ` Jan Vraný via Gdb
0 siblings, 0 replies; 3+ messages in thread
From: Jan Vraný via Gdb @ 2025-01-09 11:02 UTC (permalink / raw)
To: tom; +Cc: gdb
On Wed, 2025-01-08 at 17:30 -0700, Tom Tromey wrote:
> Jan> Let's say I'd like to create new function type "int(struct s)",
> where
> Jan> type "int" is arch-owned and "struct s" is objfile-owned. Am I
> correct
> Jan> thinking that resulting function type should be objfile-owned?
>
> Yes, in particular by the same objfile that owns "struct s".
>
> Jan> Generally speaking, if composing new type out of other types, if
> at
> Jan> least one of the types is objfile-owned then the new type must
> by
> Jan> also objfile-owned (by that very objfile), right?
>
> Yes.
>
> Jan> Looking at lookup_function_type_with_arguments, it allocated new
> Jan> function type is always "owned" by whoever "owns" the return
> type
> Jan> (first param to lookup_function_type_with_arguments). So if I'm
> correct
> Jan> about the above, I'd have to extend
> lookup_function_type_with_arguments
> Jan> to pass down type allocator (like in create_array_type). Or is
> there
> Jan> a better way?
>
> It's new territory, so just whatever looks reasonably clean. I think
> in
> the past this wasn't an issue because essentially only symbol readers
> made types.
OK, I'll refactor the code a bit then. Thanks!
>
> Jan> Also, when experimenting with the example above, I realized
> that
> Jan> the arch-owner of "int" struct type* is a different struct
> gdbarch *
> Jan> then gdbarch associated with objfile-owner of "struct s" type
> Jan> (i mean, pointer values are different).
> Jan> While I would think it is okay to compose new type from types
> owned by
> Jan> two distinct gdbarchs from lifecycle POV, it still puzzles me
> why
> Jan> there are two different gdbarch instances (both are i386:x86-
> 64)?
>
> Offhand I don't know but there are a lot of ways a gdbarch can be
> initialized. Maybe they have different registers available.
OK, so I'll assume this is normal. Thanks!
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-09 11:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-08 13:32 Question about struct type* ownership Jan Vraný via Gdb
2025-01-09 0:30 ` Tom Tromey
2025-01-09 11:02 ` Jan Vraný via Gdb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox