Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: John Baldwin <jhb@FreeBSD.org>, gdb-patches@sourceware.org
Subject: Re: [PATCH 1/3] [gdb/tetsuite] Add missing include in gdb.base/ctf-ptype.c
Date: Fri, 29 Mar 2024 11:39:17 +0100	[thread overview]
Message-ID: <15b697d1-41ce-49ea-96e1-bad47a7796af@suse.de> (raw)
In-Reply-To: <364a5861-a4a2-47ba-9253-5c564c41ebe3@FreeBSD.org>

On 3/28/24 18:21, John Baldwin wrote:
> On 3/27/24 10:30 AM, Tom de Vries wrote:
>> On fedora rawhide, when running test-case gdb.base/ctf-ptype.exp, I get:
>> ...
>> gdb compile failed, ctf-ptype.c: In function 'main':
>> ctf-ptype.c:242:29: error: implicit declaration of function 'malloc' \
>>    [-Wimplicit-function-declaration]
>>    242 |   v_char_pointer = (char *) malloc (1);
>>        |                             ^~~~~~
>> ctf-ptype.c:1:1: note: include '<stdlib.h>' or provide a declaration 
>> of 'malloc'
>>    +++ |+#include <stdlib.h>
>>      1 | /* This test program is part of GDB, the GNU debugger.
>> ...
>>
>> Fix this by adding the missing include.
>>
>> Tested on aarch64-linux.
> 
> Patches 2 and 3 look obvious to me (so Approved-By on this is fine by me)
> 

Hi John,

thanks for the reviews.

I've committed these two.

>> ---
>>   gdb/testsuite/gdb.base/ctf-ptype.c | 5 ++---
>>   1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/gdb/testsuite/gdb.base/ctf-ptype.c 
>> b/gdb/testsuite/gdb.base/ctf-ptype.c
>> index 4d2df33c53c..ca347893349 100644
>> --- a/gdb/testsuite/gdb.base/ctf-ptype.c
>> +++ b/gdb/testsuite/gdb.base/ctf-ptype.c
>> @@ -24,6 +24,8 @@
>>    *    First the basic C types.
>>    */
>> +#include <stdlib.h>
>> +
>>   #if !defined (__STDC__) && !defined (_AIX)
>>   #define signed  /**/
>>   #endif
>> @@ -234,9 +236,6 @@ func_type v_func_type;
>>   int main ()
>>   {
>> -  /* Ensure that malloc is a pointer type; avoid use of "void" and 
>> any include files. */
>> -/*  extern char *malloc();*/
>> -
> 
> This certainly seems curious.  Nothing in the commit log for when this 
> was added
> gives any clue to why this comment is here, nor why the prototype is 
> commented
> out.  Other comments later in this function mention limitations of the 
> linker on
> AIX, which makes me wonder how it was tested originally.  Did you 
> confirm that
> the test program compiled contained CTF but not DWARF when the test passed?
> 

I did not, but I've done so now, I tested this on fedora asahi 39, 
aarch64-linux, and there's no dwarf in the exec, only ctf.

My guess of what happened during development of the test-case is:
- copy ptype.c to ctf-ptype.c
- run into some problem with including stdlib.h
- remove the include
- anticipate that compilation will fail due to malloc defaulting to
   int return type, and add comment and declaration
- either:
   - accidentally comment out declaration, or
   - intentionally comment out declaration, see that compilation actually
     works because a compiler-builtin declaration is used, rely on it and
     forget to update the comment to point that out

Avoiding void also doesn't make sense, given that the same commit that 
introduces the comment also introduces void.

Anyway, since it was commented out we've been using the gcc builtin 
prototype which has a void * return type.

So, I think reverting to using the include is the right thing to do.

It's possible the include was removed in early stages of support in the 
compiler or gdb where pulling in a header file pulled in unsupported stuff.

If there is indeed a problem, it'll pop up and we'll be able to fix it 
and add a proper comment explaining why we should avoid void or include 
files.

Thanks,
- Tom	

  reply	other threads:[~2024-03-29 10:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 14:30 Tom de Vries
2024-03-27 14:30 ` [PATCH 2/3] [gdb/testsuite] Fix missing return type in gdb.linespec/break-asm-file.c Tom de Vries
2024-03-27 14:30 ` [PATCH 3/3] [gdb/testsuite] Add missing includes in gdb.trace/collection.c Tom de Vries
2024-03-28 17:21 ` [PATCH 1/3] [gdb/tetsuite] Add missing include in gdb.base/ctf-ptype.c John Baldwin
2024-03-29 10:39   ` Tom de Vries [this message]
2024-04-01 15:49   ` Tom Tromey
2024-04-02 14:23     ` Tom de Vries

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=15b697d1-41ce-49ea-96e1-bad47a7796af@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    /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