From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb@sourceware.org
Cc: Siddhesh Poyarekar <siddhesh@redhat.com>
Subject: 64-bit (>4GB) inferior data types rules; TYPE_LENGTH: unsigned -> ULONGEST
Date: Fri, 28 Sep 2012 17:32:00 -0000 [thread overview]
Message-ID: <20120928173229.GA10406@host2.jankratochvil.net> (raw)
Hello,
original problem - GCC produces working >4GB data types code while GDB cannot
handle them:
[PATCH] Expand bitpos to LONGEST to allow access to large offsets within a struct
http://sourceware.org/ml/gdb-patches/2012-02/msg00403.html
There should be checked in soon thanks to Siddhesh Poyarekar an extension of
TYPE_LENGTH from 'unsigned int' to ULONGEST:
[PATCH 0/4] bitpos expansion summary reloaded
http://sourceware.org/ml/gdb-patches/2012-09/msg00628.html
Anything checked-in since the following commit would be great to no longer
break this goal to handle it correctly:
http://sourceware.org/ml/gdb-cvs/2012-09/msg00161.html
commit cec90d9d386f57f116e114c50e4287281420f531
Author: siddhesh <siddhesh>
Date: Thu Sep 27 10:39:58 2012 +0000
* amd64-tdep.c (amd64_return_value): Revert previous change
that used TYPE_LENGTH directly.
[...]
* vax-tdep.c (vax_return_value): Likewise.
So far GDB was freely using 'int' for any inferior sizes. This is no longer
compatible, use always wide enough types:
(1) signed vs. unsigned types do not matter for inferior data types sizes.
Such as LONGEST vs. ULONGEST or ssize_t vs. size_t.
GDB will never successfully allocate more than 2GB on 32-bit host (size_t
max larger than ssize_t). And it does not make sense to consider anyhow
sizes above 9 quintillion (ULONGEST max larger than LONGEST on any host or
size_t larger than ssize_t on 64-bit hosts).
(2) Use the smallest valid type, therefore use size_t/ssize_t for objects
present in host GDB memory - not LONGEST/ULONGEST. On 32-bit hosts it
cheaper and also IMO the code is more readable with appropriate types.
BTW for size_t/ssize_t format string is "%z".
Also use CORE_ADDR where appropriate, GDB was also using sometimes
incorrectly LONGEST/ULONGEST instead.
BTW for CORE_ADDR format string is "%s", paddress (gdbarch, X).
BTW for LONGEST/ULONGEST format string
is "%s", plongest (X) or "%s", pulongest (X) accordingly.
Never use long / unsigned long (it is host platform dependent).
(3) For allocating inferior data in host GDB memory, therefore assigning
LONGEST/ULONGEST (type of TYPE_LENGTH) to size_t/ssize_t variable:
One needs to manually check the value fits in.
Call ulongest_fits_host_or_error for that.
It will ensure the size <= SIZE_MAX / 8 so even small additions after the
check will not overflow the type before it gets passed to xmalloc.
(4) Copying >2GB inferior data to host memory is probably unreal. In reality
GDB should copy the data on-demand. But that is a future patch outside of
the scope of this patchset.
IIUC such patch will be at least easier to write when the code already
knows the valid 64-bit size of the inferior object. Still it is currently
more correct to "lock up" GDB (interruptible by CTRL-C) than to respond to
user with invalid/shortened data without printing any error.
(5) Patched GDB expects only these inferior types may have >2GB size:
TYPE_CODE_ARRAY, TYPE_CODE_STRUCT, TYPE_CODE_UNION
And of course where applicable:
TYPE_CODE_TYPEDEF
While a compiler may create
<1><57>: Abbrev Number: 3 (DW_TAG_base_type)
<58> DW_AT_byte_size : 0x123456789
<59> DW_AT_encoding : 5 (signed)
<5a> DW_AT_name : veryhugeint
it is OK GDB will not internally handle it correctly, not giving any error.
There could be a new patch to reject such types in dwarf2read.c on read-in.
(6) If a function is called only for small inferior types (scalars) then it is
OK to have there / keep there 'int' type for the inferior type size.
Callers have to ensure array/struct/union type cannot be passed there.
If a function does
gdb_assert (length < 16);
then sure it should not happen - it is an assert. But still one needs to
keep the 'length' parameter as LONGEST/ULONGEST so that the assert makes
sense.
Thanks,
Jan
next reply other threads:[~2012-09-28 17:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-28 17:32 Jan Kratochvil [this message]
2012-09-28 20:23 ` Sergio Durigan Junior
2012-09-29 6:08 ` Jan Kratochvil
2012-09-29 16:58 ` Jan Kratochvil
2012-09-30 16:56 ` Joel Brobecker
2012-10-01 16:48 ` Old OSes compatibility [Re: 64-bit (>4GB) inferior data types rules; TYPE_LENGTH: unsigned -> ULONGEST] Jan Kratochvil
2012-10-01 17:18 ` Pedro Alves
2012-10-01 17:38 ` Eli Zaretskii
2012-10-01 18:01 ` Pedro Alves
2012-10-01 19:14 ` Eli Zaretskii
2012-10-01 17:32 ` Eli Zaretskii
2012-10-01 17:55 ` Jan Kratochvil
2012-10-01 17:57 ` Joel Brobecker
2012-10-01 18:08 ` Jan Kratochvil
2012-10-01 18:13 ` Joel Brobecker
2012-10-01 18:29 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120928173229.GA10406@host2.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb@sourceware.org \
--cc=siddhesh@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox