int main (int argc, char *argv[])
{
	int i;
	int a = 1;
	int b = 2;
	int c = 3;

	for (i = 0; i < N; i++)
		vec[i] = i;

	UNREFERENCED_PARAMETER(argc);
	UNREFERENCED_PARAMETER(argv);
	
	Extrae_Vector_Init (&v);
	Extrae_Vector_Init (&v2);

	Extrae_Vector_Append (&v, &a);
	Extrae_Vector_Append (&v, &b);
	Extrae_Vector_Append (&v, &c);
	Extrae_Vector_Append (&v, &d);
	Extrae_Vector_Append (&v, &e);

	assert (Extrae_Vector_Count(&v) == 5);
	assert (Extrae_Vector_Count(&v2) == 0);

	assert (Extrae_Vector_Get(&v,0) == &a);
	assert ((*(int*) Extrae_Vector_Get(&v,0)) == a);

	assert (Extrae_Vector_Get(&v,1) == &b);
	assert ((*(int*) Extrae_Vector_Get(&v,1)) == b);

	assert (Extrae_Vector_Get(&v,2) == &c);
	assert ((*(int*) Extrae_Vector_Get(&v,2)) == c);

	assert (Extrae_Vector_Get(&v,3) == &d);
	assert ((*(int*) Extrae_Vector_Get(&v,3)) == d);

	assert (Extrae_Vector_Get(&v,4) == &e);
	assert ((*(int*) Extrae_Vector_Get(&v,4)) == e);

	Extrae_Vector_Destroy (&v);
	assert (Extrae_Vector_Count(&v) == 0);

	for (i = 0; i < N; i++)
		Extrae_Vector_Append (&v2, &vec[i]);

	assert (Extrae_Vector_Count(&v2) == N);

	for (i = 0; i < N; i++)
	{
		assert (Extrae_Vector_Get(&v2,i) == &vec[i]);
		assert ((*(int*) Extrae_Vector_Get(&v2,i)) == vec[i]);
	}

	Extrae_Vector_Destroy (&v2);
	assert (Extrae_Vector_Count(&v2) == 0);

	return 0;
}
Ejemplo n.º 2
0
/******************************************************************************
 *** Labels_loadSYMfile
 ******************************************************************************/
void Labels_loadSYMfile (int taskid, int allobjects, unsigned ptask,
	unsigned task, char *name, int report)
{
#ifndef HAVE_BFD
	static int shown_BFD_missing = FALSE;
#endif
	static int Labels_loadSYMfile_init = FALSE;
	FILE *FD;
	char LINE[1024], Type;
	unsigned function_count = 0, hwc_count = 0, other_count = 0;

	if (!Labels_loadSYMfile_init)
	{
		Extrae_Vector_Init (&defined_user_event_types);
        Extrae_Vector_Init (&defined_basic_block_labels);
		Labels_loadSYMfile_init = TRUE;
	}
	event_type_t * last_event_type_used = NULL;

	if (!name)
		return;

	if (strlen(name) == 0)
		return;

	if (!file_exists(name))
		return;

	FD = (FILE *) fopen (name, "r");
	if (FD == NULL)
	{
		fprintf (stderr, "mpi2prv: WARNING: Task %d Can\'t open symbols file %s\n", taskid, name);
		return;
	}

	while (!feof (FD))
	{
		int args_assigned;

		if (fgets (LINE, 1024, FD) == NULL)
			break;

		args_assigned = sscanf (LINE, "%c %[^\n]", &Type, LINE);

		if (args_assigned == 2)
		{
			switch (Type)
			{
				case 'B':
					{
						unsigned long start, end, offset;
						char module[1024];
						int res = sscanf (LINE, "0 \"%lx-%lx %lx %[^\n\"]\"", &start, &end, &offset, module);
						if (res == 4)
						{
#ifdef HAVE_BFD
							ObjectTable_AddBinaryObject (allobjects, ptask, task, start, end, offset, module);
#else
							if (!shown_BFD_missing)
								fprintf (stdout, "mpi2prv: Ignoring symbols from the application execution because mpi2prv does not support BFD\n");
							shown_BFD_missing = TRUE;
							UNREFERENCED_PARAMETER(allobjects);
							UNREFERENCED_PARAMETER(ptask);
							UNREFERENCED_PARAMETER(task);
#endif
						}
						else
							fprintf (stderr, PACKAGE_NAME": Error! Invalid line ('%s') in %s\n", LINE, name);
					}
					break;

				case 'O':
				case 'U':
				case 'P':
					{
#ifdef HAVE_BFD
						/* Example of line: U 0x100016d4 fA mpi_test.c 0 */
						char fname[1024], modname[1024];
						int line;
						int type;
						int res;
						UINT64 address;

						res = sscanf (LINE, "%lx \"%[^\"]\" \"%[^\"]\" %d", &address, fname, modname, &line);
						if (res != 4)
							fprintf (stderr, PACKAGE_NAME": Error! Invalid line ('%s') in %s\n", LINE, name);

						if (!get_option_merge_UniqueCallerID())
						{
							if (Type == 'O')
								type = OTHER_FUNCTION_TYPE;
							else if (Type == 'U')
								type = USER_FUNCTION_TYPE;
							else /* if (Type == 'P') */
								type = OUTLINED_OPENMP_TYPE;
						}
						else
							type = UNIQUE_TYPE;

						Address2Info_AddSymbol (address, type, fname, modname, line);
						function_count++;
#endif /* HAVE_BFD */
					}
					break;

				case 'H':
					{
						int res, eventcode;
						char hwc_description[1024];

						res = sscanf (LINE, "%d \"%[^\"]\"", &eventcode, hwc_description);
						if (res != 2)
							fprintf (stderr, PACKAGE_NAME": Error! Invalid line ('%s') in %s\n", LINE, name);

						Labels_AddHWCounter_Code_Description (eventcode, hwc_description);
						hwc_count++;
					}
					break;

				case 'c':
				case 'C':
					{
						int res, eventcode;
						char code_description[1024];

						res = sscanf (LINE, "%d \"%[^\"]\"", &eventcode, code_description);
						if (res != 2)
							fprintf (stderr, PACKAGE_NAME": Error! Invalid line ('%s') in %s\n", LINE, name);

						Labels_Add_CodeLocation_Label (eventcode,
							Type=='C'?CODELOCATION_FUNCTION:CODELOCATION_FILELINE,
							code_description);
						other_count++;
					}
					break;

                case 'd':
                    {
                        int res, eventvalue;
                        char value_description[1024];
                        value_t * evt_value = NULL;
                        unsigned i, max = Extrae_Vector_Count (&last_event_type_used->event_values);

                        res = sscanf (LINE, "%d \"%[^\"]\"", &eventvalue, value_description);
                        if (res != 2)
                            fprintf (stderr, PACKAGE_NAME": Error! Invalid line ('%s') in %s\n", LINE, name);
                        
                        for (i = 0; i < max; i++)
                        {
                            value_t * evt = Extrae_Vector_Get (&last_event_type_used->event_values, i);
                            if(evt->value == eventvalue)
                            {
                                if(strcmp(evt->label, value_description))
                                {
                                    fprintf(stderr, PACKAGE_NAME"(%s,%d): Warning! Ignoring duplicate definition \"%s\" for value type %d,%d!\n",__FILE__, __LINE__, value_description,last_event_type_used->event_type.type, eventvalue);
                                }
                                evt_value = evt;
                                break;
                            }
                        }
                        if (!evt_value)
                        {
                            evt_value = (value_t*) malloc (sizeof (value_t));
                            if (evt_value == NULL)
                            {
                                fprintf (stderr, PACKAGE_NAME"(%s,%d): Fatal error! Cannot allocate memory to store the 'd' symbol in TRACE.sym file\n", __FILE__, __LINE__);
                                exit(-1);
                            }
                            evt_value->value = eventvalue;
                            strcpy(evt_value->label, value_description);
                            Extrae_Vector_Append (&last_event_type_used->event_values, evt_value);
                            other_count++;
                        }
                    }
                    break;
                case 'D':
                    {
                        int res, eventcode;
                        char code_description[1024];
                        unsigned i, max = Extrae_Vector_Count (&defined_user_event_types);
                        event_type_t * evt_type = NULL;

                        res = sscanf (LINE, "%d \"%[^\"]\"", &eventcode, code_description);
                        if (res != 2)
                            fprintf (stderr, PACKAGE_NAME": Error! Invalid line ('%s') in %s\n", LINE, name);

                        for (i = 0; i < max; i++)
                        {
                            event_type_t * evt = Extrae_Vector_Get (&defined_user_event_types, i);
                            if (evt->event_type.type == eventcode)
                            {
                                if(strcmp(evt->event_type.label, code_description))
                                {
                                    fprintf(stderr, PACKAGE_NAME"(%s,%d): Warning! Ignoring duplicate definition \"%s\" for type %d!\n", __FILE__, __LINE__, code_description, eventcode);
                                }
                                evt_type = evt;
                                break;
                            }
                        }

                        if (!evt_type)
                        {
                            evt_type = (event_type_t*)  malloc (sizeof (event_type_t));
                            if (evt_type == NULL)
                            {
                                fprintf (stderr, "Extrae (%s,%d): Fatal error! Cannot allocate memory to store the 'D' symbol in TRACE.sym file\n", __FILE__, __LINE__);
                                exit(-1);
                            }
                            evt_type->event_type.type = eventcode;
                            strcpy(evt_type->event_type.label, code_description);
                            Extrae_Vector_Init(&evt_type->event_values);
    
                            Extrae_Vector_Append(&defined_user_event_types, evt_type);
                            other_count++;
                        }
                        last_event_type_used = evt_type;
                    }
                    break;

                case 'b': // BasicBlocks symbol
                    {
                        int res, eventvalue;
                        char bb_description[1024];
                        unsigned i, max = Extrae_Vector_Count (&defined_basic_block_labels);
                        event_type_t * evt_type = NULL;
                        value_t * evt_value = NULL;

                        res = sscanf (LINE, "%d \"%[^\"]\"", &eventvalue, bb_description);
                        if (res != 2)
                            fprintf (stderr, PACKAGE_NAME": Error! Invalid line ('%s') in %s\n", LINE, name);
                        if (max==0){
                            evt_type = (event_type_t*)  malloc (sizeof (event_type_t));
                            if (evt_type == NULL)
                            {
                                fprintf (stderr, "Extrae (%s,%d): Fatal error! Cannot allocate memory to store the 'B' symbol in TRACE.sym file\n", __FILE__, __LINE__);
                                exit(-1);
                            }
                            evt_type->event_type.type = USRFUNC_EV_BB;
                            strcpy(evt_type->event_type.label, "BASIC_BLOCKS");
                            Extrae_Vector_Init(&evt_type->event_values);
                            Extrae_Vector_Append(&defined_basic_block_labels, evt_type);
                        } else 
                        {
                            evt_type = Extrae_Vector_Get (&defined_basic_block_labels, 0); // There is only one event type in the vector
                        }

                        max = Extrae_Vector_Count (&evt_type->event_values);

                        for(i = 0; i < max; i++)
                        {
                            value_t * evt = Extrae_Vector_Get (&evt_type->event_values, i);
                            if(evt->value == eventvalue)
                            {
                                if(strcmp(evt->label, bb_description))
                                {
                                    fprintf(stderr, "Extrae (%s,%d): Warning! Ignoring duplicate definition \"%s\" for value type %d,%d!\n",__FILE__, __LINE__, bb_description,evt_type->event_type.type, eventvalue);
                                }
                                evt_value = evt;
                                break;
                            }
                        }

                        if (!evt_value)
                        {
                            evt_value = (value_t*) malloc (sizeof (value_t));
                            if (evt_value == NULL)
                            {
                                fprintf (stderr, "Extrae (%s,%d): Fatal error! Cannot allocate memory to store the 'B' symbol in TRACE.sym file\n", __FILE__, __LINE__);
                                exit(-1);
                            }
                            evt_value->value = eventvalue;
                            strcpy(evt_value->label, bb_description);
                            Extrae_Vector_Append (&evt_type->event_values, evt_value);
                            other_count++;
                        }
                    }
                    break;
				default:
					fprintf (stderr, PACKAGE_NAME" mpi2prv: Error! Task %d found unexpected line in symbol file '%s'\n", taskid, LINE);
					break;
			}
		}
	}

	if (taskid == 0 && report)
	{
		fprintf (stdout, "mpi2prv: A total of %u symbols were imported from %s file\n", function_count+hwc_count+other_count, name);
		fprintf (stdout, "mpi2prv: %u function symbols imported\n", function_count);
		fprintf (stdout, "mpi2prv: %u HWC counter descriptions imported\n", hwc_count);
	}

	fclose (FD);
}