Bug 279403 - typedef redeclaration in base include becoming an issue for DTrace
Summary: typedef redeclaration in base include becoming an issue for DTrace
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 14.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-05-30 15:20 UTC by Antranig Vartanian
Modified: 2024-05-30 19:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antranig Vartanian 2024-05-30 15:20:14 UTC
root@srv0:~ # cat test.d

#include <sys/socket.h>

tcp:::accept-established
{
}

root@srv0:~ # dtrace -C -s test.d
dtrace: failed to compile script test.d: line 1: typedef redeclared: __uint8_t
root@srv0:~ # dtrace -H -C -s test.d
. /usr/include/sys/socket.h
.. /usr/include/sys/cdefs.h
.. /usr/include/sys/_types.h
... /usr/include/machine/_types.h
.... /usr/include/x86/_types.h
..... /usr/include/machine/_limits.h
...... /usr/include/x86/_limits.h
.. /usr/include/sys/_iovec.h
.. /usr/include/machine/_align.h
... /usr/include/x86/_align.h
.. /usr/include/sys/_sockaddr_storage.h
dtrace: failed to compile script test.d: line 1: typedef redeclared: __uint8_t
root@srv0:~ #
Comment 1 Mark Johnston freebsd_committer freebsd_triage 2024-05-30 19:56:50 UTC
Has this example ever worked on FreeBSD?

The problem isn't with duplicate typedefs; those are errors in C as well.

In dt_parser.c we have:

1451         /*                                                                                                                                                                                                                 
1452          * If we are nested inside of a C include file, add the declaration to                                                                                                                                             
1453          * the C definition module; otherwise use the D definition module.                                                                                                                                                 
1454          */                                                                                                                                                                                                                
1455         if (yypcb->pcb_idepth != 0)                                                                                                                                                                                        
1456                 dmp = dtp->dt_cdefs;                                                                                                                                                                                       
1457         else                                                                                                                                                                                                               
1458                 dmp = dtp->dt_ddefs;

When we hit the error, we're actually using ddefs instead of cdefs, which is incorrect according to the comment.  How is pcb_idepth set?  It's adjusted when we see line control directives emitted by the processor, but it looks like our version of the D lexer isn't handling this properly somehow.