bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Error in evaluating enumerated types


From: Vuong Tran
Subject: Error in evaluating enumerated types
Date: Wed, 21 Mar 2001 11:26:12 -0800

I'm not sure whether this can be categorized as a gcc bug or a gdb
bug. Given that the generated code is doing the correct thing, I'm
leaning toward seeing this one as a gdb bug.

With this program, gdb gives <error type> message when I'm
trying to evaluate anything with type MyTypes. This only happens
when the enumeration of MyTypes has a somewhat complex
expression within it. With simple expressions, everything works
just fine.
You can easily reproduce this scenario by examining entries
of MyTypeXlateTbl[] using gdb. Please help

Thanks in advance

Vuong Tran
Mgr, SW Development
Andiamo Systems, Inc.
(408) 527-0766
/*
 **** **** **** **** **** **** **** **** **** **** **** **** **** ****
 *------------------------------------------------------------------
 * 3/98         V.Tran
 *
 * Copyright (c) 1998-2001 by cisco Systems, Inc.
 * All rights reserved.
 *------------------------------------------------------------------
 * - IMPORTANT NOTE - READ ME FIRST - 
 *
 * This file consists of two parts where the first part of this file
 * pretty much behaves like any other include file with its declaration
 * of the MyTypes enumeration. The second part of this file consists
 * of the list of device items that will be expanded when we re-include
 * this file with the correct macro definitions.
 * Instead of splitting this file into two (as suggested by others), I'm
 * keeping everything in one file so that one can have all the definitions
 * at one's fingertips rather than having to open up two separate files
 * side by side just to look at the macro expansions.
 * 
 * The logic goes as follows: myTypes.h is included in the C-file and
 * will set up the appropriate macros (_MYTYPES_INCLUDE_ and _MY_ITEM).
 * It declares the MyTypes enumerated type and recursively includes
 * itself (myTypes.h) again to fill in the enumeration entries.
 * In the special case where the MyTypeXlateTbl needs to be defined
 * in a C-file, the user must define _DEFINE_MYTYPE_TRANSLATION_TABLE_
 * before including myTypes.h in the definition of MyTypeXlateTbl[].
 *
 * Example:
 *
 * #define _DEFINE_MYTYPE_TRANSLATION_TABLE_
 * const MyTypeXlateEntry MyTypeXlateTbl[] = {
 * #include "myTypes.h"
 * };
 *
 * Hint: 'gcc -E -o <outputfile> <filename>' command can be used to
 * look at the output C-file after pre-processing.
 * 
 **** **** **** **** **** **** **** **** **** **** **** **** **** ****
 */

// Assigning a unique signature to _INCLUDING_DEVICE_ITEMS for
// verification before re-including this file with the MY_ITEM
// macro expansion.
#ifndef _MAGIC_SIGNATURE_
#define _MAGIC_SIGNATURE_               0x12345678
#define _MYTYPE_FILE_INCLUDED_          _MAGIC_SIGNATURE_
#define _INCLUDING_DEVICE_ITEMS_        _MAGIC_SIGNATURE_+1
#endif

/*
 * Constellation-specific device types...
 */
#ifndef _MYTYPES_INCLUDE_
#define _MYTYPES_INCLUDE_       _INCLUDING_DEVICE_ITEMS_


// Defining _MY_ITEM_ to be an expansion of enumerated entry
#define _MY_ITEM(_type, _val)   _type = (_val)

// Declaring the MyTypes enumerated type and re-include this file
// again for the macro expansion to list the enums.
typedef enum _MyTypes {
#include "myTypes.h"
} MyTypes;

// Structure to provide MyTypes-to-String translation...
typedef struct _MyTypeXlateEntry {
  MyTypes value;
  char *str;
} MyTypeXlateEntry;

extern const MyTypeXlateEntry MyTypeXlateTbl[];


/**** **** **** ITEMIZED LIST OF DEVICES **** **** **** **** ****/
// This is the 2nd part of this include file where the actual
// device-types and their values are defined. We're including this
// portion within an enumerated type declaration to support a centralized
// place where this section could be re-used in an array to support
// translation of MyTypes into strings for debugging printfs.
// In order for this section to make sense, the _MY_ITEM macro has to
// be defined appropriately.

#elif (_INCLUDING_DEVICE_ITEMS_ == _MYTYPES_INCLUDE_)

// Error checking just because we're kinda paranoid.
#ifndef _MY_ITEM
#error "ERROR - _MY_ITEM macro is not defined!"
#endif

_MY_ITEM(ITEM1, 1),
_MY_ITEM(ITEM2, 3),
_MY_ITEM(ITEM3, 0x100),
_MY_ITEM(ITEM4, 0x200),
_MY_ITEM(ITEM5, 0xff10),
_MY_ITEM(ITEM6, 0xabcd),

// Cleaning up the _MY_ITEM to make sure it's not lingering in
// unwanted places.
#undef _MY_ITEM

// Now, we need to clean up so that we're not accidentally including
// this section elsewhere.
#undef _MYTYPES_INCLUDE_
#define _MYTYPES_INCLUDE_       _MYTYPES_FILE_INCLUDED_


/*
 **** **** **** **** **** **** **** **** **** **** **** **** **** ****
 *
 * -- IMPORTANT NOTE --
 * The following section is used to expand the device types into strings
 * for initializations of the myType-to-strings translation table.
 * This section is included only ONCE in a C-file.
 *
 **** **** **** **** **** **** **** **** **** **** **** **** **** ****
 */
#elif defined(_DEFINE_MYTYPE_TRANSLATION_TABLE_)

// By defining _DEFINE_MYTYPE_TRANSLATION_TABLE_ we're declaring
// and initializing the MyTypeXlateTbl array by re-including the
// 2nd part with the correct _MY_ITEM macro expansion.
// The macros in this section are setup so that the MyTypeXlateTbl
// can be initialized correctly by including this file (again) in
// its declaration in the C file.

// Error checking just because we're kinda paranoid.
#ifdef _MYTYPE_TRANSLATION_DEFINED_
#error "ERROR - Device Translation Table has already been defined!!"
#endif

#define _MYTYPE_TRANSLATION_DEFINED_

#undef _MYTYPES_INCLUDE_
#define _MYTYPES_INCLUDE_       _INCLUDING_DEVICE_ITEMS_

// For the string translation table, we're now defining _MY_ITEM
// to be the initialization of a MyTypeXlateEntry with the MyType
// and its associated string.
#define _MY_ITEM(_type, _unused_value)  {_type, #_type}
#include "myTypes.h"

#endif  // defined _MYTYPES_INCLUDE_
#include <stdio.h>
#include "myTypes.h"

#define _DEFINE_MYTYPE_TRANSLATION_TABLE_
const MyTypeXlateEntry MyTypeXlateTbl[] = {
#include "myTypes.h"
};

int main(int argc, char *argv[])
{
        int i;
        int nEntries = sizeof(MyTypeXlateTbl)/sizeof(MyTypeXlateEntry);

        printf("Hello World\n");

        for (i=0; i<nEntries; i++) {
                printf("%d: String: %s, Value=%04x\n",
                        i, MyTypeXlateTbl[i].str, MyTypeXlateTbl[i].value);
        }

        return(0);
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]