svn commit: r345196 - head/sys/sys

John Baldwin jhb at FreeBSD.org
Fri Mar 15 18:43:45 UTC 2019


On 3/15/19 11:28 AM, John Baldwin wrote:
> On 3/15/19 11:18 AM, Gleb Smirnoff wrote:
>> Author: glebius
>> Date: Fri Mar 15 18:18:05 2019
>> New Revision: 345196
>> URL: https://svnweb.freebsd.org/changeset/base/345196
>>
>> Log:
>>   Deanonymize thread and proc state enums, so that a userland app can
>>   use them without redefining the value names. New clang no longer
>>   allows to redefine a enum value name to the same value.
>>   
>>   Bump __FreeBSD_version, since ports depend on that.
>>   
>>   Discussed with:	jhb
> 
> Note that devel/mdb from before this commit will no longer work on
> kernels built with this commit (so you can't use mdb on a 12.x box
> to cross-debug a crash with this change anymore).  Similarly, once
> mdb is fixed to build with this change, a new mdb built with this
> won't work with older kernels.

For background, mdb makes "clever" use of CTF debug info.  You
declare a structure in the debugger (or one of the debugger modules)
that contains a subset of the fields of the type from the thing you
are debugging.  mdb then compares the CTF of the two structures
and figures out how to copy the needed fields from the target structure
into the smaller one in the debugger module handling endian-ness swaps,
integer size differences, etc.  However, it requires the types of
each field to be identical.  The simplest way to do this is to make
a copy of the field by literally copying the fields (in this case
from sys/proc.h).  This meant that mdb had structs like this:

typedef struct {
    ...
    enum {
         TDS_INACTIVE = 0,
         ...
    } td_state;
} mdb_thread_t;

clang 8, in its infinite wisdom decided that the existing enum values
in <sys/proc.h> conflicted with the ones in mdb_thread_t even though
the numerical value of the enumerators was identical.

Note that even with this change, the existing code can't be copied
verbatim to mdb as using 'enum td_states { TDS_INACTIVE' once again
triggers clang 8's hyper-sensitivity.  Thus, with clang 8 it is now
impossible to copy and paste enum fields from the target structure to
the debugger version of the structure if you ever include the original
header for some other reason.  I consider this to be a compiler bug that
it isn't able to understand that 0 == 0.

-- 
John Baldwin


More information about the svn-src-all mailing list