Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Pedro Alves <pedro@palves.net>,
	Simon Marchi <simon.marchi@efficios.com>,
	 gdb-patches@sourceware.org
Subject: Re: [PATCH v2 3/4] gdb, gdbserver, gdbsupport: include early header files with `-include`
Date: Tue, 26 Mar 2024 10:39:10 -0400	[thread overview]
Message-ID: <e04db2ab-1be9-4c8c-b02c-521db68e1d0e@simark.ca> (raw)
In-Reply-To: <dda84ef1-aa7a-4d38-9a7c-3ea4d2fb3125@palves.net>

On 3/26/24 7:57 AM, Pedro Alves wrote:
> On 2024-03-23 02:14, Simon Marchi wrote:
> 
>> With this change, clangd picks up the -include option from the compile
>> command, and is able to analyze the header file correctly, as it sees
>> all that stuff included or defined but that -include option.  That works
> 
> but that -> by that

Fixed.

>>  - There is one problem for gdbserver's Makefile: we do not want to
>>    include server.h when building `gdbreplay.o`.  So we can't simply put
>>    the `-include` in `INTERNAL_CFLAGS`.  I added the `-include` option
>>    to the `COMPILE` and `IPAGENT_COMPILE` variables, and added a special
>>    rule to compile `gdbreplay.o`.
>>
> 
> ...
> 
> 
>> diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in
>> index 45073abca493..4d29491a8721 100644
>> --- a/gdbserver/Makefile.in
>> +++ b/gdbserver/Makefile.in
>> @@ -69,9 +69,11 @@ COMPILE.pre = $(CXX) $(CXX_DIALECT)
>>  COMPILE.post = -c -o $@
>>  POSTCOMPILE = @true
>>  
>> +INCLUDE_SERVER_H = -include $(srcdir)/server.h
>> +
> 
> ...
> 
>> +# Rule for gdbreplay.o.  This is the same as COMPILE, without INCLUDE_SERVER_H.
>> +
>> +gdbreplay.o: gdbreplay.cc
>> +	$(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(CXXFLAGS) $(COMPILE.post) $<
> 
> It would seem better to make gdbreplay include common-defs.h with -include, to me.  Any
> reason not to do that?

No, I just didn't give much attention to gdbreplay because... I never
used it.

Really the simplest would be if gdbreplay could use the same -include as
the rest of gdbserver.  The immediate problem I got when using `-include
server.h` for gdbreplay.cc is:

      CXX    gdbreplay.o
    /home/smarchi/src/binutils-gdb/gdbserver/gdbreplay.cc:80:1: error: ‘void remote_close()’ was declared ‘extern’ and later ‘static’ [-fpermissive]
       80 | remote_close (void)
          | ^~~~~~~~~~~~
    In file included from /home/smarchi/src/binutils-gdb/gdbserver/server.h:94,
                     from <command-line>:
    /home/smarchi/src/binutils-gdb/gdbserver/remote-utils.h:36:6: note: previous declaration of ‘void remote_close()’
       36 | void remote_close (void);
          |      ^~~~~~~~~~~~

That is, if gdbreplay includes server.h, it sees some declaration of
remote_close() which conflicts with its own declaration of
remote_close().

One quick solution to that could be renaming gdbreplay's remote_close
function.  Or, put all of gdbreplay.cc (except main()) in an anonymous
namespace, which would be the appropriate C++ thing to do anyway.  Now,
if gdbreplay.cc uses `-include server.h`, it will "see" more things than
it needs to, but if it builds, it should work?  I guess?  And anyway a
subsequent goal will be to strip server.h to the bare minimum.
Ultimately, it should only contain just a few things that should be
suitable to both gdbserver and gdbreplay (include of
gdbsupport/common-defs.h, include of gdbserver/config.h and a few other
basic things).  Does that sound good to you?

Simon

  reply	other threads:[~2024-03-26 14:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-23  2:14 [PATCH v2 0/4] Include early include " Simon Marchi
2024-03-23  2:14 ` [PATCH v2 1/4] gdb, gdbserver, gdbsupport: reformat some Makefile variables, one entry per line Simon Marchi
2024-03-23  2:14 ` [PATCH v2 2/4] {gdb, gdbserver}/Makefile.in: remove unnecessary intermediary variables Simon Marchi
2024-03-23  2:14 ` [PATCH v2 3/4] gdb, gdbserver, gdbsupport: include early header files with `-include` Simon Marchi
2024-03-26 11:57   ` Pedro Alves
2024-03-26 14:39     ` Simon Marchi [this message]
2024-03-26 15:31       ` Pedro Alves
2024-03-26 15:49         ` Simon Marchi
2024-03-23  2:14 ` [PATCH v2 4/4] gdb, gdbserver, gdbsupport: remove includes of early headers Simon Marchi
2024-03-26 11:59   ` Pedro Alves
2024-03-26 14:58     ` Simon Marchi

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=e04db2ab-1be9-4c8c-b02c-521db68e1d0e@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    --cc=simon.marchi@efficios.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