Bug 15611 - macros don't work with CWEB, or Perl XS, or other use of #line directives
Summary: macros don't work with CWEB, or Perl XS, or other use of #line directives
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: macros (show other bugs)
Version: 7.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-12 17:32 UTC by don knuth
Modified: 2015-10-20 13:39 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
self-explanatory shell log (1.01 KB, text/plain)
2013-06-12 17:32 UTC, don knuth
Details

Note You need to log in before you can comment on or make changes to this bug.
Description don knuth 2013-06-12 17:32:32 UTC
Created attachment 7074 [details]
self-explanatory shell log

I've used CWEB for all my programs for more than 20 years (and more than
a thousand programs!). And I unwittingly introduce bugs, so I'm a heavy user
of GDB. Because of the #line directives, GDB works quite beautifully in
connection with CWEB, and I consider it to be a great treasure.

But I just learned about the "macro" abilities of GDB, and I find that
they are totally useless to me because the #line directives make the
macros invisible.

I know that CWEB accounts for only a relatively small subset of today's
users, even though it comes already installed with many Linux distributions.
In order to understand my problem with GDB's macros, you don't need to
know anything about CWEB except that it's a super-duper way to construct
C programs, using a processor called CTANGLE.

CTANGLE converts *.w files to *.c files. Those files contain #line directives, which allow gcc and gdb etc. to sync with the original *.w source lines.
CTANGLE also changes CWEB constructs like "@d foo bar" into "#define foo bar".

The attached file is hopefully self-explanatory: I show a CWEB source file
"macrotest.w", I show the file "macrotest.c" produced by CTANGLE, and I show
GDB's inability to see the macros. Then I change "macrotest.c"
to "mcrtst.c", which is identical except for the #line directives;
and all works fine.
Comment 1 Cary Coutant 2013-06-14 17:10:11 UTC
Have you tried the -a option?

(gdb) info macro -a a
Defined at /usr/local/google/home/ccoutant/scratch/macro/macrotest.c:2
#define a(x) b[x]

Without -a, GDB looks for macro definitions only in the current compilation unit, and it thinks the macro is defined in macrotest.c, while you are currently in macrotest.w.

I noticed that CTANGLE isn't putting a #line directive in front of the translated macro definitions, so there's not even an expectation that they would appear as coming from the original .w source file. That seems like a bug in CTANGLE.

Nevertheless, when I added the #line directive manually, GCC seems to ignore it when it generates the macro information in the DWARF (I tested with both the older .debug_macinfo and the newer .debug_macro). That seems like a bug in GCC.
Comment 2 ChristianJ 2015-10-20 13:29:13 UTC
This problem is not limited to CWEB, of course. I just spent an hour trying to figure out why macro debugging doesn't work for Perl modules that are using XS code, which is C extended with more syntax which is translated to plain .c files with #line directives of course to map back to the original source file. And that breaks the macro debugging feature.

Also, while "info macro -a" works, there's no "-a" for "p" ("print"), and it's print that I really want to be able to handle macros.
Comment 3 ChristianJ 2015-10-20 13:39:33 UTC
PS. these are the gdb versions that I've tested, all with the same result (from Debian oldstable, stable, and testing):

GNU gdb (GDB) 7.4.1-debian
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
GNU gdb (Debian 7.10-1) 7.10