public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Expanding and debugging macros
@ 2020-06-27 11:23 Jeffrey Walton
  2020-06-27 11:47 ` Alexander Monakov
  2020-06-27 17:12 ` Edward Diener
  0 siblings, 2 replies; 3+ messages in thread
From: Jeffrey Walton @ 2020-06-27 11:23 UTC (permalink / raw)
  To: gcc-help

Hi Everyone,

I'm trying to debug a c function that is mostly a massive collection of macros.

I changed the makefile recipe to preprocess the source trying to
produce something I can step:

#blake2b:    blake2b.c
#        $(CC) blake2b.c -o $@ $(CFLAGS) $(POWER8_CFLAG) -DBLAKE2B_SELFTEST

blake2b:    blake2b.c
        $(CC) -E blake2b.c -o blake2b.E $(CFLAGS) $(POWER8_CFLAG)
-DBLAKE2B_SELFTEST
        $(CC) -x c blake2b.E -o $@ $(CFLAGS) $(POWER8_CFLAG) -DBLAKE2B_SELFTEST

But GDB is not stepping it:

238      ROUND( 0 );
(gdb) s
239      ROUND( 1 );
(gdb) s
240      ROUND( 2 );
(gdb) q

I also switched to -save-temps with the same result - no stepping.

blake2b:    blake2b.c
        $(CC) -E blake2b.c -o blake2b.i $(CFLAGS) -save-temps
$(POWER8_CFLAG) -DBLAKE2B_SELFTEST
        $(CC) blake2b.i -o $@ $(CFLAGS) $(POWER8_CFLAG) -DBLAKE2B_SELFTEST

Is there a way to achieve this using GCC without changing the source files?

Thanks in advance.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Expanding and debugging macros
  2020-06-27 11:23 Expanding and debugging macros Jeffrey Walton
@ 2020-06-27 11:47 ` Alexander Monakov
  2020-06-27 17:12 ` Edward Diener
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Monakov @ 2020-06-27 11:47 UTC (permalink / raw)
  To: noloader; +Cc: gcc-help

On Sat, 27 Jun 2020, Jeffrey Walton via Gcc-help wrote:

> Is there a way to achieve this using GCC without changing the source files?

Did you inspect the preprocessed file? It still has line directives pointing
to the original source. You'll need to remove them.

Alexander

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Expanding and debugging macros
  2020-06-27 11:23 Expanding and debugging macros Jeffrey Walton
  2020-06-27 11:47 ` Alexander Monakov
@ 2020-06-27 17:12 ` Edward Diener
  1 sibling, 0 replies; 3+ messages in thread
From: Edward Diener @ 2020-06-27 17:12 UTC (permalink / raw)
  To: gcc-help

On 6/27/2020 7:23 AM, Jeffrey Walton via Gcc-help wrote:
> Hi Everyone,
>
> I'm trying to debug a c function that is mostly a massive collection 
> of macros.
>
> I changed the makefile recipe to preprocess the source trying to
> produce something I can step:
>
> #blake2b: blake2b.c
> # $(CC) blake2b.c -o $@ $(CFLAGS) $(POWER8_CFLAG) -DBLAKE2B_SELFTEST
>
> blake2b: blake2b.c
> $(CC) -E blake2b.c -o blake2b.E $(CFLAGS) $(POWER8_CFLAG)
> -DBLAKE2B_SELFTEST
> $(CC) -x c blake2b.E -o $@ $(CFLAGS) $(POWER8_CFLAG) -DBLAKE2B_SELFTEST
>
> But GDB is not stepping it:
>
> 238 ROUND( 0 );
> (gdb) s
> 239 ROUND( 1 );
> (gdb) s
> 240 ROUND( 2 );
> (gdb) q
>
> I also switched to -save-temps with the same result - no stepping.
>
> blake2b: blake2b.c
> $(CC) -E blake2b.c -o blake2b.i $(CFLAGS) -save-temps
> $(POWER8_CFLAG) -DBLAKE2B_SELFTEST
> $(CC) blake2b.i -o $@ $(CFLAGS) $(POWER8_CFLAG) -DBLAKE2B_SELFTEST
>
> Is there a way to achieve this using GCC without changing the source 
> files?
>
> Thanks in advance.
>

You can do step by step expansion of a macro using the Wave tool from 
the Wave library in Boost. It is excellent and works as a C++ standard 
compliant preprocessor. I have also found gcc's preprocessor to also be 
excellent and completely C++ standards compliant, so I would not be 
surprised if the step by step expansion if a macro using the Wave tool 
mimicked exactly the same step by step expansion of a macro in the gcc 
preprocessor.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-27 17:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 11:23 Expanding and debugging macros Jeffrey Walton
2020-06-27 11:47 ` Alexander Monakov
2020-06-27 17:12 ` Edward Diener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).