Ejemplo n.º 1
0
void
StandardIMInstance::imm_update_candidates_list (const IME_InputContext   *ic,
                                                const IME_CandidatesList *candidates)
{
    if (ic && ic->id >= 0 && candidates) {
        StandardIMInstance *inst = __global->find_instance (ic->id);
        if (inst) {
            inst->m_lookup_table.clear ();
            if (candidates->nr_candidates > 0 && candidates->candidates) {

                std::vector <WideString> labels;
                AttributeList attrs;
                WideString wstr;

                if ((candidates->page_state & IME_FIRST_PAGE) == 0)
                    inst->m_lookup_table.append_candidate ((ucs4_t) 0x20);

                for (int i = 0; i < candidates->nr_candidates; ++i) {
                    labels.push_back (inst->m_factory->convert_string (String (candidates->candidates [i].label)));

                    attrs.clear ();

                    for (int j = 0; j < candidates->candidates [i].content.nr_attributes; ++j)
                        attrs.push_back (convert_attribute (candidates->candidates [i].content.attributes [j]));

                    wstr = inst->m_factory->convert_string (String (candidates->candidates [i].content.string));
                    inst->m_lookup_table.append_candidate (wstr, attrs);
                }

                if ((candidates->page_state & IME_LAST_PAGE) == 0)
                    inst->m_lookup_table.append_candidate ((ucs4_t) 0x20);

                if ((candidates->page_state & IME_FIRST_PAGE) == 0) {
                    inst->m_lookup_table.set_page_size (1);
                    inst->m_lookup_table.page_down ();
                }

                inst->m_lookup_table.set_page_size (candidates->nr_candidates);
                inst->m_lookup_table.set_candidate_labels (labels);

                if (candidates->focused_candidate >= 0 && candidates->focused_candidate < candidates->nr_candidates)
                    inst->m_lookup_table.set_cursor_pos_in_current_page (candidates->focused_candidate);
            }

            inst->update_lookup_table (inst->m_lookup_table);
        }
    }
}
Ejemplo n.º 2
0
void
StandardIMInstance::imm_update_aux_string      (const IME_InputContext   *ic,
                                                const IME_String         *string)
{
    if (ic && ic->id >= 0 && string) {
        StandardIMInstance *inst = __global->find_instance (ic->id);
        if (inst) {
            WideString str = inst->m_factory->convert_string (String (string->string));
            AttributeList attrs;
            if (string->nr_attributes > 0 && string->attributes) {
                for (int i = 0; i < string->nr_attributes; ++i)
                    attrs.push_back (convert_attribute (string->attributes [i]));
            }
            inst->update_aux_string (str, attrs);
        }
    }
}
Ejemplo n.º 3
0
void ReplayPlugin::replayActivity( std::shared_ptr<Activity> activity )
{

	printActivity(activity);

	stringstream str;
	try {
		char buff[40];
		siox_time_to_str( activity->time_start(), buff, false );


		activity->time_stop();
		activity->time_start();

		activity->aid();

		UniqueInterfaceID uid = sys_info->lookup_interface_of_activity( activity->ucaid() );

		sys_info->lookup_interface_name( uid );
		sys_info->lookup_interface_implementation( uid );


		// hold activity name to prevent multiple lookups

		int ucaid = activity->ucaid();

		if( ucaid == posix_open ) {
			// ###########################################################
			//wrapped_open(sub_activity->data);
			printf("'- open\n");

			
			std::stringstream ss;
			
			int ret = open(
					getActivityAttributeValueByName(activity, "POSIX", "descriptor/filename").str(),
					translateSIOXFlagsToPOSIX( getActivityAttributeValueByName(activity, "POSIX", "hints/openFlags").uint32() ),
					S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH // TODO: supply siox with rights flags converter
			);

			// open(POSIX/hints/openFlags=65, POSIX/descriptor/filename="test.tmp", POSIX/descriptor/filehandle=4) = 0 
			//int ret = open(
			//		getActivityAttributeValueByName(activity, "POSIX", "descriptor/filename").str(),
			//		translateSIOXFlagsToPOSIX( getActivityAttributeValueByName(activity, "POSIX", "hints/openFlags").uint32() ),
			//		S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IROTH // TODO: supply siox with rights flags converter
			//	);


			// 1) call from instrumentation:
			// vim build/tools/siox-skeleton-builder/layers/posix-deedless/siox-posix-deedless-dlsym.c:1799
			/*
			...
			siox_activity_set_attribute(sioxActivity, fileHandle, &ret);
			...
			*/


			// 2) within set_attribute
			// vim ./src/monitoring/low-level-c/siox-ll.cpp:767
			/*
				void siox_activity_set_attribute( siox_activity * activity, siox_attribute * attribute, const void * value )
				{
					assert( activity != nullptr );
					assert( attribute != nullptr );

					if( value == nullptr ) {
						return;       t
					}

					FUNCTION_BEGIN

					ActivityBuilder * ab = ActivityBuilder::getThreadInstance();
					OntologyAttribute oa = convertPtrToOntologyAttribute(attribute);
					Attribute attr( oa.aID, convert_attribute( oa, value ) );

					ab->setActivityAttribute( activity->activity, attr );

				}
			*/


			// 3) within activity builder
			// vim ./src/monitoring/activity_builder/ActivityBuilder.cpp:106
			/*
			void ActivityBuilder::setActivityAttribute( Activity * a, const Attribute & attribute )
			{
				assert( a != nullptr );

				a->attributeArray_.push_back( attribute );
			}
			*/




			Attribute attr( oa_fileHandle.aID, convert_attribute( oa_fileHandle, &ret ) );               
			activity->attributeArray_.push_back( attr );

			dump_fds();	
			//fds[getActivityAttributeValueByName(activity, "POSIX", "descriptor/filehandle").uint32()] = ret;
			dump_fds();	

			}

		else if( ucaid == posix_creat ) {
			//wrapped_creat(sub_activity->data);
			}

		else if( ucaid == posix_open64 ) {
			//wrapped_open64(sub_activity->data);
			}

		else if( ucaid == posix_creat64 ) {
			//wrapped_creat64(sub_activity->data);
			}

		else if( ucaid == posix_close ) {
			// ###########################################################
			//wrapped_close(sub_activity->data);
			printf("'- close\n");

			// close(POSIX/descriptor/filehandle=4) = 0
			int ret = close(
					fds[getActivityAttributeValueByName(activity, "POSIX", "descriptor/filehandle").uint32()]
				);
			}

		else if( ucaid == posix_dup ) {
			//wrapped_dup(sub_activity->data);
			}

		else if( ucaid == posix_dup2 ) {
			//wrapped_dup2(sub_activity->data);
			}

		else if( ucaid == posix_dup3 ) {
			//wrapped_dup3(sub_activity->data);
			}

		else if( ucaid == posix_sendfile ) {
			//wrapped_sendfile(sub_activity->data);
			}

		else if( ucaid == posix_write ) {
			// ###########################################################
			//wrapped_write(sub_activity->data);
			printf("'- write\n");
			
			// write(POSIX/quantity/BytesToWrite=3, POSIX/descriptor/filehandle=4, POSIX/data/MemoryAddress=4196057, POSIX/quantity/BytesWritten=3) = 0
			size_t count = getActivityAttributeValueByName(activity, "POSIX", "quantity/BytesToWrite").uint64();
			void * buf = (void *) getActivityAttributeValueByName(activity, "POSIX", "data/MemoryAddress").uint64();

			printf("buffer content: %s\n", (char*) buf);

			int ret = write(
					fds[getActivityAttributeValueByName(activity, "POSIX", "descriptor/filehandle").uint32()],
					shared_byte_buffer( size ),
					count
				);

			// TODO: assert(ret == expected);

			}

		else if( ucaid == posix_read ) {
			// ###########################################################
			//wrapped_read(sub_activity->data);
			printf("'- read\n");
			
			long size = getActivityAttributeValueByName(activity, "POSIX", "quantity/BytesToRead").uint64();
			int ret = read(
					fds[getActivityAttributeValueByName(activity, "POSIX", "descriptor/filehandle").uint32()],
					shared_byte_buffer( size ),
					size
				);

			}

		else if( ucaid == posix_writev ) {
			//wrapped_writev(sub_activity->data);
			}

		else if( ucaid == posix_readv ) {
			//wrapped_readv(sub_activity->data);
			}

		else if( ucaid == posix_pwrite ) {
			//wrapped_pwrite(sub_activity->data);
			}

		else if( ucaid == posix_pread ) {
			//wrapped_pread(sub_activity->data);
			}

		else if( ucaid == posix_pwrite64 ) {
			//wrapped_pwrite64(sub_activity->data);
			}

		else if( ucaid == posix_pread64 ) {
			//wrapped_pread64(sub_activity->data);
			}

		else if( ucaid == posix_pwritev ) {
			//wrapped_pwritev(sub_activity->data);
			}

		else if( ucaid == posix_preadv ) {
			//wrapped_preadv(sub_activity->data);
			}

		else if( ucaid == posix_pwritev64 ) {
			//wrapped_pwritev64(sub_activity->data);
			}

		else if( ucaid == posix_preadv64 ) {
			//wrapped_preadv64(sub_activity->data);
			}

		else if( ucaid == posix_sync ) {
			//wrapped_sync(sub_activity->data);
			}

		else if( ucaid == posix_fsync ) {
			//wrapped_fsync(sub_activity->data);
			}

		else if( ucaid == posix_fdatasync ) {
			//wrapped_fdatasync(sub_activity->data);
			}

		else if( ucaid == posix_lseek ) {
			// ###########################################################
			//wrapped_lseek(sub_activity->data);
			printf("'- lseek\n");
			
			// lseek(POSIX/descriptor/filehandle=4, POSIX/file/position=6)
			int ret = lseek(
					fds[getActivityAttributeValueByName(activity, "POSIX", "descriptor/filehandle").uint32()],
					getActivityAttributeValueByName(activity, "POSIX", "file/position").uint64(),
					SEEK_SET
				);

			// TODO: siox convert seeks flags? though siox is always taking the absolute position? => SEEK_SET
			
				

			}

		else if( ucaid == posix_posix_fadvise ) {
			//wrapped_posix_fadvise(sub_activity->data);
			}

		else if( ucaid == posix_remove ) {
			//wrapped_remove(sub_activity->data);
			}

		else if( ucaid == posix_rename ) {
			//wrapped_rename(sub_activity->data);
			}

		else if( ucaid == posix___xstat64 ) {
			//wrapped___xstat64(sub_activity->data);
			}

		else if( ucaid == posix___lxstat64 ) {
			//wrapped___lxstat64(sub_activity->data);
			}

		else if( ucaid == posix___fxstat64 ) {
			//wrapped___fxstat64(sub_activity->data);
			}

		else if( ucaid == posix___fxstat ) {
			//wrapped___fxstat(sub_activity->data);
			}

		else if( ucaid == posix_mmap ) {
			//wrapped_mmap(sub_activity->data);
			}

		else if( ucaid == posix_mmap64 ) {
			//wrapped_mmap64(sub_activity->data);
			}

		else if( ucaid == posix_fopen ) {
			// ###########################################################
			//wrapped_fopen(sub_activity->data);
			printf("'- fopen\n");
		



			// fopen(POSIX/descriptor/filename="test.tmp", POSIX/hints/openFlags=577, POSIX/descriptor/filehandle=4, POSIX/descriptor/FilePointer=32507344) = 0
			char mode[3];
			translatePOSIXFlagsToFILE( mode, getActivityAttributeValueByName(activity, "POSIX", "hints/openFlags").uint32() );

			FILE* ret = fopen(
					getActivityAttributeValueByName(activity, "POSIX", "descriptor/filename").str(),
					mode
				);

			dump_streams();	
			streams[getActivityAttributeValueByName(activity, "POSIX", "descriptor/FilePointer").uint64()] = ret;
			dump_streams();	


			}

		else if( ucaid == posix_fopen64 ) {
			//wrapped_fopen64(sub_activity->data);
			}

		else if( ucaid == posix_fdopen ) {
			//wrapped_fdopen(sub_activity->data);
			}

		else if( ucaid == posix_fileno ) {
			//wrapped_fileno(sub_activity->data);
			}

		else if( ucaid == posix_freopen ) {
			//wrapped_freopen(sub_activity->data);
			}

		else if( ucaid == posix_tmpfile ) {
			//wrapped_tmpfile(sub_activity->data);
			}

		else if( ucaid == posix_fclose ) {
			// ###########################################################
			//wrapped_fclose(sub_activity->data);
			printf("'- fclose\n");
			


/*
	// write to non existing file
	stream = fopen(file, "w");

	// everything ok? write and close
	if ( !stream ) {
		perror("fopen");
	}

	if ( !fwrite(buf, sizeof(char), 3, stream) ) { perror("fwrite"); }
	if ( !fseek(stream, 6, SEEK_SET) ) { perror("fseek"); }
	if ( !fwrite(buf+3, sizeof(char), 3, stream) ) { perror("fwrite"); }

	//fwrite(buf+3, sizeof(char), 3, stream);
	if (fclose(stream)) {
		perror("fclose");		
	}
*/

			}

		else if( ucaid == posix_fflush ) {
			//wrapped_fflush(sub_activity->data);
			}

		else if( ucaid == posix_fgetc ) {
			//wrapped_fgetc(sub_activity->data);
			}

		else if( ucaid == posix_getc ) {
			//wrapped_getc(sub_activity->data);
			}

		else if( ucaid == posix_fputc ) {
			//wrapped_fputc(sub_activity->data);
			}

		else if( ucaid == posix_putc ) {
			//wrapped_putc(sub_activity->data);
			}

		else if( ucaid == posix_fgets ) {
			//wrapped_fgets(sub_activity->data);
			}

		else if( ucaid == posix_fputs ) {
			//wrapped_fputs(sub_activity->data);
			}

		else if( ucaid == posix_fread ) {
			// ###########################################################
			//wrapped_fread(sub_activity->data);
			printf("'- fread\n");


/*
	// write to non existing file
	stream = fopen(file, "w");

	// everything ok? write and close
	if ( !stream ) {
		perror("fopen");
	}

	if ( !fwrite(buf, sizeof(char), 3, stream) ) { perror("fwrite"); }
	if ( !fseek(stream, 6, SEEK_SET) ) { perror("fseek"); }
	if ( !fwrite(buf+3, sizeof(char), 3, stream) ) { perror("fwrite"); }

	//fwrite(buf+3, sizeof(char), 3, stream);
	if (fclose(stream)) {
		perror("fclose");		
	}
*/

			long size = getActivityAttributeValueByName(activity, "POSIX", "quantity/BytesToRead").uint64();
			int ret = fread(
					shared_byte_buffer( size ),
					sizeof(char),
					size,
					streams[getActivityAttributeValueByName(activity, "POSIX", "descriptor/FilePointer").uint64()]
				);

			}

		else if( ucaid == posix_fwrite ) {
			// ###########################################################
			//wrapped_fwrite(sub_activity->data);
			printf("'- fwrite\n");
			
 
/*
	// write to non existing file
	stream = fopen(file, "w");

	// everything ok? write and close
	if ( !stream ) {
		perror("fopen");
	}

	if ( !fwrite(buf, sizeof(char), 3, stream) ) { perror("fwrite"); }
	if ( !fseek(stream, 6, SEEK_SET) ) { perror("fseek"); }
	if ( !fwrite(buf+3, sizeof(char), 3, stream) ) { perror("fwrite"); }

	//fwrite(buf+3, sizeof(char), 3, stream);
	if (fclose(stream)) {
		perror("fclose");		
	}
*/


			// fwrite(POSIX/quantity/BytesToWrite=3, POSIX/descriptor/FilePointer=32507344, POSIX/data/MemoryAddress=4196217, POSIX/quantity/BytesWritten=3) = 0
			long size = getActivityAttributeValueByName(activity, "POSIX", "quantity/BytesToWrite").uint64();
			int ret = fwrite(
					shared_byte_buffer( size ),
					sizeof(char),
					size,
					streams[getActivityAttributeValueByName(activity, "POSIX", "descriptor/FilePointer").uint64()]
				);


			}

		else if( ucaid == posix_fseeko ) {
			//wrapped_fseeko(sub_activity->data);
			}

		else if( ucaid == posix_fseek ) {
			// ###########################################################
			//wrapped_fseek(sub_activity->data);
			printf("'- fseek\n");

			// fseek(POSIX/descriptor/FilePointer=11331200, POSIX/file/position=6) = 0
			int ret = fseek(
					streams[getActivityAttributeValueByName(activity, "POSIX", "descriptor/FilePointer").uint64()],
					getActivityAttributeValueByName(activity, "POSIX", "file/position").uint64(),
					SEEK_SET
				);

			}

		else if( ucaid == posix_setbuf ) {
			//wrapped_setbuf(sub_activity->data);
			}

		else if( ucaid == posix_setvbuf ) {
			//wrapped_setvbuf(sub_activity->data);
			}

		else if( ucaid == posix_unlink ) {
			//wrapped_unlink(sub_activity->data);
			}

		else if( ucaid == posix_vfprintf ) { 
			//wrapped_vfprintf(sub_activity->data);
			}

		else if( ucaid == posix_vfscanf ) {
			//wrapped_vfscanf(sub_activity->data);
			}

		else if( ucaid == posix_fscanf ) {
			//wrapped_fscanf(sub_activity->data);
			}

		else if( ucaid == posix_fprintf ) {
			//wrapped_fprintf(sub_activity->data);
			}

		else if( ucaid == posix_aio_read ) {
			//wrapped_aio_read(sub_activity->data);
			}

		else if( ucaid == posix_aio_write ) {
			//wrapped_aio_write(sub_activity->data);
			}

		else if( ucaid == posix_lio_listio ) {
			//wrapped_lio_listio(sub_activity->data);
			}

		else if( ucaid == posix_aio_suspend ) {
			//wrapped_aio_suspend(sub_activity->data);
			}

		else if( ucaid == posix_aio_cancel ) {
			//wrapped_aio_cancel(sub_activity->data);
			}

		else if( ucaid == posix_fork ) {
			//wrapped_fork(sub_activity->data);
			}

		else if( ucaid == posix_lockf ) {
			//wrapped_lockf(sub_activity->data);
			}

		else if( ucaid == posix_flock ) {
			//wrapped_flock(sub_activity->data);
			}

		else if( ucaid == posix_socket ) {
			//wrapped_socket(sub_activity->data);
			}

		else if( ucaid == posix_setsockopt ) {
			//wrapped_setsockopt(sub_activity->data);
			}

		else if( ucaid == posix_pipe ) {
			//wrapped_pipe(sub_activity->data);
			}

		else if( ucaid == posix_pipe2 ) {
			//wrapped_pipe2(sub_activity->data);
			}

		else if( ucaid == posix_socketpair ) {
			//wrapped_socketpair(sub_activity->data);
			}

		else if( ucaid == posix_accept ) {
			//wrapped_accept(sub_activity->data);
			}

		else if( ucaid == posix_accept4 ) {
			//wrapped_accept4(sub_activity->data);
		}

		else {
        	// not found!
			printf("unknown type - nothing to replay");
		}
        

		/*
		for( auto itr = activity->attributeArray().begin() ; itr != activity->attributeArray().end(); itr++ ) {
			if( itr != activity->attributeArray().begin() ) {
				// new attribute (consider different handling)
			}

			const Attribute& attribute = *itr;
			//strattribute( *itr, str );
			OntologyAttributeFull oa = facade->lookup_attribute_by_ID( attribute.id );
			str << oa.domain << "/" << oa.name << "=";
			if( attribute.value.type() == VariableDatatype::Type::STRING){
				str << '"' << attribute.value << '"' ;
			}elsee
				str << attribute.value ;
			}



		}
		str << ")";
		str << " = " << activity->errorValue();

		if( activity->parentArray().begin() != activity->parentArray().end() ) {
			str << " ";
			for( auto itr = activity->parentArray().begin(); itr != activity->parentArray().end(); itr++ ) {
				if( itr != activity->parentArray().begin() ) {
					str << ", ";
				}
				str << *itr;
			}
		}


		*/

		cout << str.str() << endl;

	} catch( NotFoundError & e ) {
		cerr << "Error while parsing activity! Parsed so far: " << str.str() << endl;
	}


	printActivity(activity);
	printf("DONE \n\n");

}