Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #146345 > unrolled thread
| Started by | Louis Valence <lvalence@example.com> |
|---|---|
| First post | 2019-09-25 22:03 -0300 |
| Last post | 2019-09-28 16:57 -0300 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.c
on gdb's sizeof versus gcc's sizeof Louis Valence <lvalence@example.com> - 2019-09-25 22:03 -0300
Re: on gdb's sizeof versus gcc's sizeof Keith Thompson <kst-u@mib.org> - 2019-09-25 19:22 -0700
Re: on gdb's sizeof versus gcc's sizeof scott@slp53.sl.home (Scott Lurndal) - 2019-09-26 13:26 +0000
Re: on gdb's sizeof versus gcc's sizeof Keith Thompson <kst-u@mib.org> - 2019-09-26 13:08 -0700
Re: on gdb's sizeof versus gcc's sizeof Louis Valence <lvalence@example.com> - 2019-09-28 16:57 -0300
| From | Louis Valence <lvalence@example.com> |
|---|---|
| Date | 2019-09-25 22:03 -0300 |
| Subject | on gdb's sizeof versus gcc's sizeof |
| Message-ID | <867e5vkgw2.fsf@example.com> |
Can you explain this? I don't get it.
%cat sizeof-long.c
#include <stdio.h>
int main() {
printf("sizeof unsigned long: %ld\n", sizeof (unsigned long));
printf("sizeof long: %ld\n", sizeof (long));
}
%./sizeof-long
sizeof unsigned long: 8
sizeof long: 8
%gdb
GNU gdb (Ubuntu 8.0.1-0ubuntu1) 8.0.1
[...]
(gdb) p sizeof (unsigned long)
$1 = 4
(gdb) p sizeof (long)
$2 = 4
(gdb)
%uname -a
Linux e 4.13.0-21-generic #24-Ubuntu SMP Mon Dec 18 17:29:16 UTC 2017 \
x86_64 x86_64 x86_64 GNU/Linux
%lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful
%
[toc] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2019-09-25 19:22 -0700 |
| Message-ID | <lntv8z4wzq.fsf@kst-u.example.com> |
| In reply to | #146345 |
Louis Valence <lvalence@example.com> writes:
> Can you explain this? I don't get it.
>
> %cat sizeof-long.c
> #include <stdio.h>
>
> int main() {
> printf("sizeof unsigned long: %ld\n", sizeof (unsigned long));
> printf("sizeof long: %ld\n", sizeof (long));
> }
Use "%zu" to print values of type size_t.
> %./sizeof-long
> sizeof unsigned long: 8
> sizeof long: 8
>
> %gdb
> GNU gdb (Ubuntu 8.0.1-0ubuntu1) 8.0.1
>
> [...]
>
> (gdb) p sizeof (unsigned long)
> $1 = 4
> (gdb) p sizeof (long)
> $2 = 4
> (gdb)
>
> %uname -a
> Linux e 4.13.0-21-generic #24-Ubuntu SMP Mon Dec 18 17:29:16 UTC 2017 \
> x86_64 x86_64 x86_64 GNU/Linux
>
> %lsb_release -a
> No LSB modules are available.
> Distributor ID: Ubuntu
> Description: Ubuntu 17.10
> Release: 17.10
> Codename: artful
> %
I get the same result (Ubuntu 18.04 x86_64).
gdb is not a C implementation, and it can debug programs written in
languages other than C. If you invoke it without having it control
a program, I don't know how it decides what assumptions to make.
(It does seem to assume C, as indicated by "show language").
If you compile your C program with "-g" and then invoke gdb on that
program, you should get sizeof (long) == 8, as I did.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2019-09-26 13:26 +0000 |
| Message-ID | <a03jF.4165$hU2.239@fx20.iad> |
| In reply to | #146345 |
Louis Valence <lvalence@example.com> writes:
>Can you explain this? I don't get it.
>
>%cat sizeof-long.c
>#include <stdio.h>
>
>int main() {
> printf("sizeof unsigned long: %ld\n", sizeof (unsigned long));
> printf("sizeof long: %ld\n", sizeof (long));
>}
>
>%./sizeof-long
>sizeof unsigned long: 8
>sizeof long: 8
>
>%gdb
>GNU gdb (Ubuntu 8.0.1-0ubuntu1) 8.0.1
>
>[...]
>
>(gdb) p sizeof (unsigned long)
>$1 = 4
You may want to use a 64-bit build of GDB instead of the 32-bit:
(gdb) print sizeof(unsigned long)
$1 = 0x8
(gdb) quit
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2019-09-26 13:08 -0700 |
| Message-ID | <lnpnjm4y80.fsf@kst-u.example.com> |
| In reply to | #146348 |
scott@slp53.sl.home (Scott Lurndal) writes:
> Louis Valence <lvalence@example.com> writes:
>>Can you explain this? I don't get it.
>>
>>%cat sizeof-long.c
>>#include <stdio.h>
>>
>>int main() {
>> printf("sizeof unsigned long: %ld\n", sizeof (unsigned long));
>> printf("sizeof long: %ld\n", sizeof (long));
>>}
>>
>>%./sizeof-long
>>sizeof unsigned long: 8
>>sizeof long: 8
>>
>>%gdb
>>GNU gdb (Ubuntu 8.0.1-0ubuntu1) 8.0.1
>>
>>[...]
>>
>>(gdb) p sizeof (unsigned long)
>>$1 = 4
>
> You may want to use a 64-bit build of GDB instead of the 32-bit:
>
> (gdb) print sizeof(unsigned long)
> $1 = 0x8
> (gdb) quit
I don't believe that's the issue.
Were you debugging a program when you got that result, or did you invoke
gdb with no arguments as Louis and I both did?
On my system:
$ echo 'print sizeof (long)' | gdb
GNU gdb (Ubuntu 8.1-0ubuntu3.1) 8.1.0.20180409-git
[...]
This GDB was configured as "x86_64-linux-gnu".
[...]
(gdb) $1 = 4
(gdb) quit
$
As far as I can tell, gdb uses the environment of the program it's
debugging, falling back to some default environment if it's not given
a program to debug. In that default -- at least on my system --
long is 4 bytes.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Louis Valence <lvalence@example.com> |
|---|---|
| Date | 2019-09-28 16:57 -0300 |
| Message-ID | <86pnjki47i.fsf@example.com> |
| In reply to | #146363 |
Keith Thompson <kst-u@mib.org> writes:
> scott@slp53.sl.home (Scott Lurndal) writes:
>> Louis Valence <lvalence@example.com> writes:
>>>Can you explain this? I don't get it.
>>>
>>>%cat sizeof-long.c
>>>#include <stdio.h>
>>>
>>>int main() {
>>> printf("sizeof unsigned long: %ld\n", sizeof (unsigned long));
>>> printf("sizeof long: %ld\n", sizeof (long));
>>>}
>>>
>>>%./sizeof-long
>>>sizeof unsigned long: 8
>>>sizeof long: 8
>>>
>>>%gdb
>>>GNU gdb (Ubuntu 8.0.1-0ubuntu1) 8.0.1
>>>
>>>[...]
>>>
>>>(gdb) p sizeof (unsigned long)
>>>$1 = 4
>>
>> You may want to use a 64-bit build of GDB instead of the 32-bit:
>>
>> (gdb) print sizeof(unsigned long)
>> $1 = 0x8
>> (gdb) quit
>
> I don't believe that's the issue.
>
> Were you debugging a program when you got that result, or did you invoke
> gdb with no arguments as Louis and I both did?
>
> On my system:
>
> $ echo 'print sizeof (long)' | gdb
> GNU gdb (Ubuntu 8.1-0ubuntu3.1) 8.1.0.20180409-git
> [...]
> This GDB was configured as "x86_64-linux-gnu".
> [...]
> (gdb) $1 = 4
> (gdb) quit
> $
>
> As far as I can tell, gdb uses the environment of the program it's
> debugging, falling back to some default environment if it's not given
> a program to debug. In that default -- at least on my system --
> long is 4 bytes.
Thanks for the investigation, Keith. I think you're correct here.
Here's some evidence.
--8<---------------cut here---------------start------------->8---
%gdb
GNU gdb (Ubuntu 8.0.1-0ubuntu1) 8.0.1
[..]
(gdb) p sizeof (unsigned long)
$1 = 4
(gdb) set architecture
Requires an argument. Valid arguments are i386, i386:x86-64,
i386:x64-32, i8086, i386:intel, i386:x86-64:intel, i386:x64-32:intel,
i386:nacl, i386:x86-64:nacl, i386:x64-32:nacl, auto.
(gdb) set architecture i386:x86-64
The target architecture is assumed to be i386:x86-64
(gdb) p sizeof (unsigned long)
$2 = 8
(gdb) quit
%
--8<---------------cut here---------------end--------------->8---
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c
csiph-web