This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/53936] New: Adding a PRETTY_ARGUMENT and ARGUMENT_COUNT macro/variable


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53936

             Bug #: 53936
           Summary: Adding a PRETTY_ARGUMENT and ARGUMENT_COUNT
                    macro/variable
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mail.pourri@laposte.net


Since GCC has a __PRETTY_FUNCTION__ variable, it would be very useful to have a
__PRETTY_ARGUMENT__ variable that would output the example below.
Ideally a __ARGUMENT_COUNT__ macro and a __ARGUMENT__ array would be very
useful indeed, like this pseudo code:

struct A { int c; };

void myFunc(int a, A b)
{
    printf("Func: %s\n", __PRETTY_FUNCTION__); // Outputs: "Func: void
myFunc(int, struct A)"
    printf("Args: %s\n", __PRETTY_ARGUMENTS__); // Outputs: "Args: int, struct
A"
    printf("ArgsCount: %d\n", __ARGUMENT_COUNT__); // Outputs: "ArgsCount: 2"
    for (int i = 0; i < __ARGUMENT_COUNT__; i++)
    {
        printf("Arg[%d]: Type '%s', RelativePos %d\n", __ARGUMENT__[i],
__ARGUMENT__OFFSET__[i]);    
    } // Outputs: "Arg[0]: Type 'int', RelativePos -4"
      // Outputs: "Arg[1]: Type 'struct A', RelativePos -8"
} 


The reason for this is that extracting the arguments from the
__PRETTY_FUNCTION__ can be complex (think of function pointers passed as
argument, taking themselves arguments), and the compiler already has this
information.
__ARGUMENT_COUNT__ contains the equivalent of sizeof(argumentList)
__ARGUMENT__ is the equivalent of const char * argumentType[__ARGUMENT_COUNT__]
__ARGUMENT__OFFSET__ is the equivalent of size_t
offsetFromFrameAddressToArgument[__ARGUMENT_COUNT__]

We could then print the argument of a function in an assert for example,
provided we know how to convert from the type "name" and the right printf's
statement, and using the builtin frame address.

What do you think ?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]