Path: csiph.com!aioe.org!.POSTED.IXP4sbumLrdkG2n6/syALg.user.gioia.aioe.org!not-for-mail From: Louis Valence Newsgroups: comp.lang.c Subject: Re: on gdb's sizeof versus gcc's sizeof Date: Sat, 28 Sep 2019 16:57:37 -0300 Organization: Aioe.org NNTP Server Lines: 73 Message-ID: <86pnjki47i.fsf@example.com> References: <867e5vkgw2.fsf@example.com> NNTP-Posting-Host: IXP4sbumLrdkG2n6/syALg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (windows-nt) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:0rY+mjXBmIfboa2AMSq4rIotgQU= Xref: csiph.com comp.lang.c:146399 Keith Thompson writes: > scott@slp53.sl.home (Scott Lurndal) writes: >> Louis Valence writes: >>>Can you explain this? I don't get it. >>> >>>%cat sizeof-long.c >>>#include >>> >>>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---