Ejemplo n.º 1
0
def readFields(anEvent):
    byteOffset = 0  # force reloading next field

    for field in anEvent.getTraceFields():
        # list and string fields need to be aligned to 64 bit boundaries
        if (anEvent.isListField(field) or anEvent.getFieldType(field) == "string") and byteOffset != 0:
            print "recordStr.skipBytes(", str(8 - byteOffset), ");"
        if anEvent.isListField(field):
            _fieldName = anEvent.getFieldName(field) + "[i]"
            _fieldTypeSize = pemTypes.getTypeRawSize(anEvent.getFieldType(field), _fieldName)
            listLength = getListLength(anEvent, field)
            # byteOffset = (byteOffset + int(listLength)*int(_fieldTypeSize)) % 8
            # HACK!! assume lists are padded to 64 bits
            byteOffset = 0
            print "\t\t", anEvent.getFieldName(field), "= new", getJavaListFieldType(
                anEvent, field
            ), "[(int)", listLength, "];"
            print "\t\tfor(int i = 0; i <", listLength, "; i++)"
            print "\t\t\t", anEvent.getFieldName(field), "[i] =", string.join(
                ("recordStr.read", getJavaReaderType(anEvent, field), "()"), ""
            ), ";"

        else:
            _fieldName = anEvent.getFieldName(field)
            _fieldTypeSize = pemTypes.getTypeRawSize(anEvent.getFieldType(field), _fieldName)
            if anEvent.getFieldType(field) != "string":
                byteOffset = (byteOffset + int(_fieldTypeSize)) % 8
            print "\t\t", anEvent.getFieldName(field), "=", string.join(
                ("recordStr.read", getJavaReaderType(anEvent, field), "()"), ""
            ), ";"
Ejemplo n.º 2
0
def getTypeSize(anEvent, fieldName):
    if anEvent.isListField(fieldName):
        return string.join(('(', getListLength(anEvent, fieldName) ,') * ',
                            pemTypes.getTypeRawSize(anEvent.getFieldType(fieldName),
                                           fieldName)), \
                           '')
    else:
        return pemTypes.getTypeRawSize(anEvent.getFieldType(fieldName), fieldName)
Ejemplo n.º 3
0
def genWriteMethod(anEvent):
    print '\n\t/** serialization */'
    print '\tpublic void write(TraceOutputStream ostr) throws IOException {'
    print '\t\tsuper.write(ostr);'
    bytesWritten = 0  # keep track of the number of bytes written
    # before a list such that we can pad it to 8!
    # write all the records
    for field in anEvent.getTraceFields():
        if anEvent.isListField(field):
            if bytesWritten % 8 != 0:
                print '\t\tfor(int i =', str(bytesWritten), '; i < 8; i++)'
                print '\t\t\tostr.writeByte(0);'
            print '\t\tfor(int i = 0; i <', getListLength(anEvent, field), \
                  '; i++)'
            print '\t\t\t', string.join(('ostr.write', \
                                         getJavaReaderType(anEvent, field), \
                                         '(', anEvent.getFieldName(field), \
                                         '[i]);'), '')
        else:
            print '\t\t', string.join(('ostr.write', \
                                       getJavaReaderType(anEvent, field), \
                                       '(', anEvent.getFieldName(field), \
                                       ');'), '')
            if anEvent.getFieldType(field) != 'string':
                bytesWritten = bytesWritten + \
                               int(pemTypes.getTypeRawSize(anEvent.getFieldType(field),
                                                           field))

    print '\t}'
Ejemplo n.º 4
0
def genGeneratorConstructor(anEvent):
    print '\n'
    print '\t/** constructor for trace record generators */'
    print '\tpublic', anEvent.getClassName(), '(int timestamp__',

    # generate all arguments
    for field in anEvent._fieldSeq:
        print ',\n\t\t', getJavaFieldType(anEvent, field), \
              string.replace(anEvent.getFieldName(field), '_', '', 1),
    print ') {'

    # compute the record size
    recLen = '8'
    #    for field in anEvent._fieldSeq:
    #        recLen = recLen + '+' + getJavaTypeSize(anEvent, field)
    print '\t\tsuper(timestamp__,', anEvent.getQualifiedLayerId(), ',', \
          anEvent.getQualifiedClassId(), ',', anEvent.getQualifiedSpecifier(),\
          ', (', recLen, '));'
    # compute the record length
    print '\t\tint recLen = 0;'

    # write all the records
    for field in anEvent.getTraceFields():
        if anEvent.isListField(field):
            print '\t\t', anEvent.getFieldName(field), '= new ',\
                  getJavaListFieldType(anEvent, field), \
                  '[(int)', getListLength(anEvent, field), '];'
            print '\t\tfor(int i = 0; i <', getListLength(anEvent, field), \
                  '; i++) {'
            print '\t\t\t',  anEvent.getFieldName(field), '[i] = ',\
                  string.replace(anEvent.getFieldName(field), '_', '', 1),\
                  '[i];'
            print '\t\t\trecLen +=', \
                  pemTypes.getTypeRawSize(anEvent.getFieldType(field),field+"[i]"),';'
            print '\t\t}'
        else:
            print '\t\t',  anEvent.getFieldName(field), ' = ',\
                  string.replace(anEvent.getFieldName(field), '_', '', 1), \
                  ';'
            print '\t\trecLen +=', \
                  pemTypes.getTypeRawSize(anEvent.getFieldType(field), field), ';'
    print '\t\tif ((recLen % 8) != 0) recLen = recLen/8 + 1;'
    print '\t\telse recLen = recLen/8;'
    print '\t\tsetRecordLength(recLen+1);'
    print '\t}'
Ejemplo n.º 5
0
def genGeneratorConstructor(anEvent):
    print "\n"
    print "\t/** constructor for trace record generators */"
    print "\tpublic", anEvent.getClassName(), "(int timestamp__",

    # generate all arguments
    for field in anEvent._fieldSeq:
        print ",\n\t\t", getJavaFieldType(anEvent, field), string.replace(anEvent.getFieldName(field), "_", "", 1),
    print ") {"

    # compute the record size
    recLen = "8"
    #    for field in anEvent._fieldSeq:
    #        recLen = recLen + '+' + getJavaTypeSize(anEvent, field)
    print "\t\tsuper(timestamp__,", anEvent.getQualifiedLayerId(), ",", anEvent.getQualifiedClassId(), ",", anEvent.getQualifiedSpecifier(), ", (", recLen, "));"
    # compute the record length
    print "\t\tint recLen = 0;"

    # write all the records
    for field in anEvent.getTraceFields():
        if anEvent.isListField(field):
            print "\t\t", anEvent.getFieldName(field), "= new ", getJavaListFieldType(
                anEvent, field
            ), "[(int)", getListLength(anEvent, field), "];"
            print "\t\tfor(int i = 0; i <", getListLength(anEvent, field), "; i++) {"
            print "\t\t\t", anEvent.getFieldName(field), "[i] = ", string.replace(
                anEvent.getFieldName(field), "_", "", 1
            ), "[i];"
            print "\t\t\trecLen +=", pemTypes.getTypeRawSize(anEvent.getFieldType(field), field + "[i]"), ";"
            print "\t\t}"
        else:
            print "\t\t", anEvent.getFieldName(field), " = ", string.replace(
                anEvent.getFieldName(field), "_", "", 1
            ), ";"
            print "\t\trecLen +=", pemTypes.getTypeRawSize(anEvent.getFieldType(field), field), ";"
    print "\t\tif ((recLen % 8) != 0) recLen = recLen/8 + 1;"
    print "\t\telse recLen = recLen/8;"
    print "\t\tsetRecordLength(recLen+1);"
    print "\t}"
Ejemplo n.º 6
0
def readFields(anEvent):
    byteOffset = 0  # force reloading next field

    for field in anEvent.getTraceFields():
        # list and string fields need to be aligned to 64 bit boundaries
        if (anEvent.isListField(field) or \
     anEvent.getFieldType(field) == 'string') and \
     byteOffset != 0:
            print 'recordStr.skipBytes(', str(8 - byteOffset), ');'
        if anEvent.isListField(field):
            _fieldName = anEvent.getFieldName(field) + "[i]"
            _fieldTypeSize = pemTypes.getTypeRawSize(anEvent.getFieldType(field), \
                                                      _fieldName)
            listLength = getListLength(anEvent, field)
            # byteOffset = (byteOffset + int(listLength)*int(_fieldTypeSize)) % 8
            # HACK!! assume lists are padded to 64 bits
            byteOffset = 0
            print '\t\t', anEvent.getFieldName(field), '= new', \
                         getJavaListFieldType(anEvent, field), \
                         '[(int)', listLength, '];'
            print '\t\tfor(int i = 0; i <', listLength, '; i++)'
            print '\t\t\t', anEvent.getFieldName(field), '[i] =', \
                  string.join(('recordStr.read', \
                               getJavaReaderType(anEvent, field), \
                               '()'), ''), \
                               ';'

        else:
            _fieldName = anEvent.getFieldName(field)
            _fieldTypeSize = pemTypes.getTypeRawSize(anEvent.getFieldType(field), \
                                                     _fieldName)
            if anEvent.getFieldType(field) != 'string':
                byteOffset = (byteOffset + int(_fieldTypeSize)) % 8
            print '\t\t', anEvent.getFieldName(field), '=', \
                  string.join(('recordStr.read', \
                               getJavaReaderType(anEvent, field),'()'),''), \
                               ';'
Ejemplo n.º 7
0
def genWriteMethod(anEvent):
    print "\n\t/** serialization */"
    print "\tpublic void write(TraceOutputStream ostr) throws IOException {"
    print "\t\tsuper.write(ostr);"
    bytesWritten = 0  # keep track of the number of bytes written
    # before a list such that we can pad it to 8!
    # write all the records
    for field in anEvent.getTraceFields():
        if anEvent.isListField(field):
            if bytesWritten % 8 != 0:
                print "\t\tfor(int i =", str(bytesWritten), "; i < 8; i++)"
                print "\t\t\tostr.writeByte(0);"
            print "\t\tfor(int i = 0; i <", getListLength(anEvent, field), "; i++)"
            print "\t\t\t", string.join(
                ("ostr.write", getJavaReaderType(anEvent, field), "(", anEvent.getFieldName(field), "[i]);"), ""
            )
        else:
            print "\t\t", string.join(
                ("ostr.write", getJavaReaderType(anEvent, field), "(", anEvent.getFieldName(field), ");"), ""
            )
            if anEvent.getFieldType(field) != "string":
                bytesWritten = bytesWritten + int(pemTypes.getTypeRawSize(anEvent.getFieldType(field), field))

    print "\t}"
Ejemplo n.º 8
0
def genAIXMethodBody(anEvent, hasListFields):

    args = anEvent.packFields()
    sortedKeys = args.keys()
    sortedKeys.sort()
    stringsCount = anEvent.countStrings()

    # assume pemGlobals.dialect == 'AIX':
    print "\tif TRC_ISON(0) {"
    funcNamePrefix = "\tTRCGENT"
    castUint64 = 'unsigned long long'

    # for now treat all events as with ListFields, fill a temp buffer
    # with PEM event and write out as AIX generic event.
    # later change to use AIX macros for words 0,1,2,3,4 & 5, however
    # these write different bits for 32 vs 64 bit applications

    hasListFields = 1

    if hasListFields:
        # take the args and the list and pack it into an array of bytes
        print '\t\tunsigned char ___tmpBuffer[1024];'
        print '\t\tunsigned int ___listLength = 0;'
        if stringsCount > 0: print '\t\tunsigned int i;'
        currentKey = 0  # where are we with the other fields
        firstPacked = 0  # how many args are packed in this arg
        for f in anEvent.getTraceFields():
            if anEvent.isListField(f):
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),
                                                    f + "[i]")
                memcpy = '\t\tmemcpy(&___tmpBuffer[___listLength],'

                if anEvent.getFieldType(f) == 'string':
                    print '\t\tfor(i = 0; i <', anEvent.getListCount(f), \
                          '; i++) {'
                    print '\t', memcpy, f + "[i]", ",", fieldSize, ');'
                    print '\t\t\t ___listLength +=', fieldSize, ';\n\t\t}'
                else:
                    fieldSize = fieldSize + '*' + anEvent.getListCount(f)
                    print memcpy, '(char *)', f, ",", fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
            else:
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f), f)
                # if args[currentKey].count(f) == 1:
                if args[currentKey].count(
                        f) == 1 and anEvent.getFieldType(f) != 'string':
                    if firstPacked == 0:
                        # argument found as packed
                        print '\t\t*(', castUint64,\
                              '*)&___tmpBuffer[___listLength] =',\
                              args[currentKey], ';'
                        print '\t\t___listLength += 8;'
                        firstPacked = 1
                        byteSize = 0
                    byteSize = byteSize + int(fieldSize)
                    if byteSize == 8:
                        currentKey = currentKey + 1
                        firstPacked = 0
                else:
                    # argument has not been packed
                    print '\t\tmemcpy(&___tmpBuffer[___listLength],',
                    if anEvent.getFieldType(f) != 'string': print '(char *)&',
                    print f, ',', fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'

        # print "\t"+ funcNamePrefix +"Pre"+ str(len(args)-2) +"Bytes (",
        # print "\t"+ funcNamePrefix +"Bytes (",

        # arg1 = channel (always 0), arg2 = hookid, 32-bits HHH0SSSS
        # HHH = hooked, here the same for all PEM events
        # SSSS = 16 bit subid or 16 bit hookdata
        print "\t" + funcNamePrefix + "( 0, 0x02000000, \n\t\t\t",

        # emit code to generate PEM EventId ar arg3, the "data word"
        genNotifyEventId(anEvent)
        print ",\n\t\t\t___listLength, ___tmpBuffer);"

    elif len(args) < 8 and stringsCount == 0:
        print "\t" + funcNamePrefix + str(len(args)) + "(",
        genNotifyEventId(anEvent)
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"
    else:
        print "\t" + funcNamePrefix + "Generic(",
        genNotifyEventId(anEvent)
        print ",\n\t\t\t", str(len(args) - stringsCount), "/* word(s) */,",
        print str(stringsCount), "/* string(s) */",
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"

    print "\t}"
Ejemplo n.º 9
0
def genMethodBody(anEvent, hasListFields):

    args = anEvent.packFields()
    sortedKeys = args.keys()
    sortedKeys.sort()
    stringsCount = anEvent.countStrings()

    if pemGlobals.dialect == 'K42':
        print "\tif(unlikely(kernelInfoLocal.traceInfo.mask & " + \
              pemEvent.getEventMaskMacro(anEvent.getClassId()) + ")) {"
        funcNamePrefix = "\ttraceDefault"
        castUint64 = 'uval64'
    else:
        funcNamePrefix = "notifyEvent"
        castUint64 = 'unsigned long long'

    if hasListFields:
        # take the args and the list and pack it into an array of bytes
        print '\t\tunsigned char ___tmpBuffer[1024];'
        print '\t\tunsigned int ___listLength = 0;'
        if stringsCount > 0: print '\t\tunsigned int i;'
        currentKey = 0  # where are we with the other fields
        firstPacked = 0  # how many args are packed in this arg
        for f in anEvent.getTraceFields():
            if anEvent.isListField(f):
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),
                                                    f + "[i]")
                memcpy = '\t\tmemcpy(&___tmpBuffer[___listLength],'

                if anEvent.getFieldType(f) == 'string':
                    print '\t\tfor(i = 0; i <', anEvent.getListCount(f), \
                          '; i++) {'
                    print '\t', memcpy, f + "[i]", ",", fieldSize, ');'
                    print '\t\t\t ___listLength +=', fieldSize, ';\n\t\t}'
                else:
                    fieldSize = fieldSize + '*' + anEvent.getListCount(f)
                    print memcpy, '(char *)', f, ",", fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
            else:
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f), f)
                if args[currentKey].count(f) == 1:
                    if firstPacked == 0:
                        # argument found as packed
                        print '\t\t*(', castUint64,\
                              '*)&___tmpBuffer[___listLength] =',\
                              args[currentKey], ';'
                        print '\t\t___listLength += 8;'
                        firstPacked = 1
                        byteSize = 0
                    byteSize = byteSize + int(fieldSize)
                    if byteSize == 8:
                        currentKey = currentKey + 1
                        firstPacked = 0
                else:
                    # argument has not been packed
                    print '\t\tmemcpy(&___tmpBuffer[___listLength],',
                    if anEvent.getFieldType(f) != 'string': print '(char *)&',
                    print f, ',', fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'

        # print "\t"+ funcNamePrefix +"Pre"+ str(len(args)-2) +"Bytes (",
        print "\t" + funcNamePrefix + "Bytes (",
        genNotifyEventId(anEvent)
        #for arg in sortedKeys:
        #    print ",\n\t\t\t" + args[arg],
        #print ");"
        print ",\n\t\t\t___listLength, ___tmpBuffer);"
    elif len(args) < 8 and stringsCount == 0:
        print "\t" + funcNamePrefix + str(len(args)) + "(",
        genNotifyEventId(anEvent)
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"
    else:
        print "\t" + funcNamePrefix + "Generic(",
        genNotifyEventId(anEvent)
        print ",\n\t\t\t", str(len(args) - stringsCount), "/* word(s) */,",
        print str(stringsCount), "/* string(s) */",
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"

    if pemGlobals.dialect == 'K42':
        print "\t}"
Ejemplo n.º 10
0
def genGeneratorConstructor(anEvent):
    print '\n'
    print '\t/** constructor for trace record generators */'
    print '\t', anEvent.getClassName(), '(int timestamp__',

    # generate the prototype
    # used to compute the record size
    recLen = '8'

    # get the trace layout of the arguments
    packedArgs = anEvent.packFields();

    # generate all filed arguments
    listFieldOrd = 0
    for field in anEvent._fieldSeq:
        if anEvent.isListField(field) and anEvent.getListCount(field) == None:
            print ',\n\t\tuint32', "listLengthInBytes" + str(listFieldOrd),
            listFieldOrd = listFieldOrd + 1
        print ',\n\t\t', getFieldType(anEvent, field), \
              anEvent.getFieldNameStripped(field),
    print ')',

    # compute the actual record length
    listFieldOrd = 0
    for field in packedArgs:
        fn = packedArgs[field]
        if anEvent.hasField(fn) and anEvent.isListField(fn):
            if anEvent.getFieldType(fn) == 'string':
                recLen = recLen + "+0"
                continue
            if anEvent.getListCount(fn) != None:
                recLen = recLen + "+(" +\
                         string.replace(anEvent.getListCount(fn),'_','',1)+\
                         "*" + \
                         pemTypes.getTypeRawSize(anEvent.getFieldType(fn),
                                                 fn) + ")"
            else:
                recLen = recLen + "+listLengthInBytes" + str(listFieldOrd)
            listFieldOrd = listFieldOrd + 1    
        elif anEvent.hasField(fn):
            recLen = recLen + "+" + \
                     pemTypes.getTypeRawSize(anEvent.getFieldType(fn),fn)
        else:
            recLen = recLen + "+8"

    # call parent constructor
    print ' :\n\t TraceRecord(',
    print 'timestamp__,', anEvent.getLayerId(), ',', \
          pemEvent.getEventMajorIdMacro(anEvent.getClassId()), ',' , \
          pemEvent.getEventSpecifierMacro(anEvent),', (',recLen,')) {'

    # if the event has no fields, just return
    if len(anEvent._fieldSeq) == 0:
        print '\t}'
        return

    # write all the records
    print '\t\t/* copy the arguments into the fields of the record, in case\n',
    print '\t\t *  the event gets used for anything else than dumping */'
    for field in anEvent._fieldSeq:
        argField = string.replace(anEvent.getFieldName(field), '_', '', 1)
        if anEvent.isListField(field):
            lenVar = "__" + anEvent.getFieldName(field) + "Len"
            print '\t\t', anEvent.getFieldName(field), '= new ',\
                  getListEltType(anEvent, field), \
                  '[', getListLength(anEvent, field), '];'
            if anEvent.getFieldType(field) == 'string':
                print "\t\tunsigned int " + lenVar + " = 0;"
            print '\t\tfor(unsigned int i = 0; i <', \
                  getListLength(anEvent, field), '; i++) {'
            if anEvent.getFieldType(field) == 'string':
                print '\t\t\t',  anEvent.getFieldName(field), \
                      '[i] = strdup(', argField, '[i]);'
                print '\t\t\t', lenVar, '+=', \
                      pemTypes.getTypeRawSize(anEvent.getFieldType(field),
                                              anEvent.getFieldName(field)+'[i]'), \
                      ';'
            else:
                print '\t\t\t',  anEvent.getFieldName(field), \
                      '[i] =', argField, '[i];'
            print '\t\t}'
            if anEvent.getFieldType(field) == 'string':
                print '\t\tsetRecordLength(getRecordLength() +', lenVar, '/8);'
        else:
            if anEvent.getFieldType(field) == 'string':
                lenVar = "__" + anEvent.getFieldName(field) + "Len"
                print '\t\tint', lenVar, '=', \
                      pemTypes.getTypeRawSize(anEvent.getFieldType(field),
                                              argField), ';'
                print '\t\t', anEvent.getFieldName(field),'= new char[', \
                      lenVar ,'];'
                print '\t\tmemcpy(', anEvent.getFieldName(field), ',', \
                      argField, ', strlen(', argField, ')+1);'
            else:
                print '\t\t',  anEvent.getFieldName(field), '=', \
                      argField, ';'

    print '\n\t\t/* write the fields into the payload */'
    sortedKeys = packedArgs.keys()
    sortedKeys.sort()
    declareTmp = 1
    for pArg in sortedKeys:
        field = packedArgs[pArg]
        if anEvent.hasField(field):
            if anEvent.isListField(field):
                # write a list of strings
                if anEvent.getFieldType(field) == 'string':
                    print '\t\tfor(unsigned i = 0; i <', \
                          getListLength(anEvent, field), '; i++) {'
                    lenVar = "__" + anEvent.getFieldName(field) + "Len"
                    print '\t\t\t', lenVar, '=', \
                      pemTypes.getTypeRawSize(anEvent.getFieldType(field),
                                              anEvent.getFieldName(field)+'[i]'), ';'
                    print '\t\t\twritePayload((char *)', \
                          anEvent.getFieldName(field), '[i],', lenVar, ');'
                    print '\t\t}'
                else: # write a list that's not of strings
                    lenVar = getTypeSize(anEvent, field)
                    print '\t\twritePayload((char *)', \
                          anEvent.getFieldName(field), ',', lenVar, ');'
            else:
                if anEvent.getFieldType(field) == 'string':
                    lenVar = "__" + anEvent.getFieldName(field) + "Len"
                    print '\t\twritePayload((char *)', \
                          anEvent.getFieldName(field), ',', lenVar, ');'
                else:
                    lenVar = getTypeSize(anEvent, field)
                    print '\t\twritePayload((char *)&', \
                          anEvent.getFieldName(field), ',', lenVar, ');'
        else:
            if declareTmp == 1:
                print '\t\tuint64 __tmp;'
                declareTmp = 0
            print '\t\t__tmp =', packedArgs[pArg], ';',
            print 'writePayload((char *)&__tmp, 8);'

    print '\t}'
Ejemplo n.º 11
0
def genRecordConstructor(anEvent):
    print '\npublic:'
    print '\t/** copy constructor for class readers */'
    print '\t', anEvent.getClassName(), \
          '(const TraceRecord &r, const char endianEnc)', \
          ': TraceRecord(r) {'

    # check that the record is of this class
    print '\t\tassert(r.getLayerId() ==', anEvent.getLayerId(), \
          '&& r.getClassId() ==', pemEvent.getEventMajorIdMacro(anEvent.getClassId()), \
          '&& r.getSpecifier() ==', pemEvent.getEventSpecifierMacro(anEvent),\
          ');'

    if len(anEvent._fieldSeq) > 0:
        print '\t\tuint32 __pos = 0;'
        
    # read the fields off the payload in chunks of 64 bytes.
    declareTmp = 1
    byteOffset = 0
    packedFields = anEvent.packFields()
    currentField = 0
    for field in anEvent.getTraceFields(): # anEvent._fieldSeq:
        if anEvent.isListField(field):
            listLength = getListLength(anEvent, field)
            # print '\t\tassert(', listLength, '< r.getPayloadLength());'
            print '\t\t', anEvent.getFieldName(field), '= new', \
                  getListEltType(anEvent, field), \
                  '[', listLength, '];'
            print '\t\tfor(unsigned int i = 0; i <', listLength, '; i++) {'
            _fieldName = anEvent.getFieldName(field) + "[i]"
            _fieldType = getListEltType(anEvent, field)
            _fieldTypeSize = pemTypes.getTypeRawSize(anEvent.getFieldType(field),
                                                     _fieldName)
            byteOffset = 0 # force reloading next field
            # retrieve the field
            if anEvent.getFieldType(field) == 'string':
                print '\t\t', _fieldName, '=', \
                      'strdup(r.getPayloadString(__pos));'
                print '\t\t__pos +=', _fieldTypeSize, ';'
            else:
                
                print '\t\tif( ((i*', _fieldTypeSize, ')& 0x7)==0) {'
                print '\t\t\tif((__pos >> 3) < r.getPayloadLength()) {'
                print '\t\t\t__tmp8bytes =',\
                      '*(uint64 *)r.getPayloadString(__pos, 8);'
                print '\t\t\t__tmp8bytes =TR2HO_8(__tmp8bytes, endianEnc);'
                print '\t\t\t__pos += 8;'
                print '\t\t} else { __tmp8bytes = 0; } // added fields '
                print '\t\t}'

                if _fieldTypeSize != '8':
                    print '\t\t', _fieldName, '= (', _fieldType, ')', \
                          '((__tmp8bytes >>', \
                          '((8-((i*',_fieldTypeSize,')&0x7)-',_fieldTypeSize, \
                          ')*8)) &', (str((1<<int(_fieldTypeSize)*8)-1)+'UL'),\
                          ');'
                else:
                    print '\t\t', _fieldName, '= __tmp8bytes;'

            print '\t\t}'


        else:
            _fieldName = anEvent.getFieldName(field)
            _fieldType = getFieldType(anEvent, field)
            _fieldTypeSize = pemTypes.getTypeRawSize(anEvent.getFieldType(field),
                                                     _fieldName)

            # retrieve the field
            if anEvent.getFieldType(field) == 'string':
                print '\t\t', _fieldName, '=', \
                      'strdup(r.getPayloadString(__pos));'
                print '\t\t__pos +=', _fieldTypeSize, ';'
                byteOffset = 0
            else:
                if declareTmp == 1:
                    print '\t\tuint64 __tmp8bytes;'
                    declareTmp = 0
                # if I cant find the current argument in the packed expr
                # it means that I need to move to the next 8 bytes
                if string.find(packedFields[currentField], field) == -1:
                    byteOffset = 0
                    currentField = currentField + 1
                if byteOffset == 0:
                    print '\t\tif((__pos >> 3) < r.getPayloadLength()) {'
                    print '\t\t\t__tmp8bytes =',\
                          '*(uint64 *)r.getPayloadString(__pos, 8);'
                    print '\t\t\t__tmp8bytes =TR2HO_8(__tmp8bytes, endianEnc);'
                    print '\t\t} else { __tmp8bytes = 0; } // added fields '
                    print '\t\t\t__pos += 8;'

                if _fieldTypeSize != '8':
                    print '\t\t', _fieldName, '= (', _fieldType, ')', \
                          '((__tmp8bytes >>', \
                          ((8-byteOffset-int(_fieldTypeSize))*8),\
                          ') &', (str((1<<int(_fieldTypeSize)*8)-1)+'UL') ,');'
                else:
                    print '\t\t', _fieldName, '= __tmp8bytes;'
                byteOffset = (byteOffset + int(_fieldTypeSize)) % 8


    print '\t}'
Ejemplo n.º 12
0
def genAIXMethodBody(anEvent, hasListFields):

    args = anEvent.packFields()
    sortedKeys = args.keys()
    sortedKeys.sort()
    stringsCount = anEvent.countStrings()

    # assume pemGlobals.dialect == 'AIX':
    print "\tif TRC_ISON(0) {"
    funcNamePrefix = "\tTRCGENT"
    castUint64 = 'unsigned long long'

    # for now treat all events as with ListFields, fill a temp buffer
    # with PEM event and write out as AIX generic event.
    # later change to use AIX macros for words 0,1,2,3,4 & 5, however
    # these write different bits for 32 vs 64 bit applications

    hasListFields = 1

    if hasListFields:
        # take the args and the list and pack it into an array of bytes
        print '\t\tunsigned char ___tmpBuffer[1024];'
        print '\t\tunsigned int ___listLength = 0;'
        if stringsCount > 0: print '\t\tunsigned int i;'
        currentKey = 0          # where are we with the other fields
        firstPacked = 0         # how many args are packed in this arg
        for f in anEvent.getTraceFields():
            if anEvent.isListField(f):
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),
                                                    f+"[i]")
                memcpy = '\t\tmemcpy(&___tmpBuffer[___listLength],'

                if anEvent.getFieldType(f) == 'string':
                    print '\t\tfor(i = 0; i <', anEvent.getListCount(f), \
                          '; i++) {'
                    print '\t', memcpy, f + "[i]", ",", fieldSize, ');'
                    print '\t\t\t ___listLength +=', fieldSize, ';\n\t\t}'
                else:
                    fieldSize = fieldSize + '*' + anEvent.getListCount(f)
                    print memcpy, '(char *)', f, ",", fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
            else:
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),f)
                # if args[currentKey].count(f) == 1:
                if args[currentKey].count(f) == 1 and anEvent.getFieldType(f) != 'string':
                    if firstPacked == 0:
                        # argument found as packed
                        print '\t\t*(', castUint64,\
                              '*)&___tmpBuffer[___listLength] =',\
                              args[currentKey], ';'
                        print '\t\t___listLength += 8;'
                        firstPacked = 1
                        byteSize = 0
                    byteSize = byteSize + int(fieldSize)
                    if byteSize == 8:
                        currentKey = currentKey + 1
                        firstPacked = 0
                else:
                    # argument has not been packed
                    print '\t\tmemcpy(&___tmpBuffer[___listLength],',
                    if anEvent.getFieldType(f) != 'string': print '(char *)&',
                    print f, ',', fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'

        # print "\t"+ funcNamePrefix +"Pre"+ str(len(args)-2) +"Bytes (",
        # print "\t"+ funcNamePrefix +"Bytes (",

        # arg1 = channel (always 0), arg2 = hookid, 32-bits HHH0SSSS
        # HHH = hooked, here the same for all PEM events
        # SSSS = 16 bit subid or 16 bit hookdata
        print "\t"+ funcNamePrefix +"( 0, 0x02000000, \n\t\t\t",

        # emit code to generate PEM EventId ar arg3, the "data word"
        genNotifyEventId(anEvent)
        print ",\n\t\t\t___listLength, ___tmpBuffer);"

    elif len(args) < 8 and stringsCount == 0:
        print "\t" + funcNamePrefix + str(len(args)) + "(",
        genNotifyEventId(anEvent)
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"
    else:
        print "\t" + funcNamePrefix + "Generic(",
        genNotifyEventId(anEvent)
        print ",\n\t\t\t",str(len(args)-stringsCount),"/* word(s) */,",
        print str(stringsCount), "/* string(s) */",
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"

    print "\t}"
Ejemplo n.º 13
0
def genMethodBody(anEvent, hasListFields):            

    args = anEvent.packFields()
    sortedKeys = args.keys()
    sortedKeys.sort()
    stringsCount = anEvent.countStrings()
        
    if pemGlobals.dialect == 'K42':
        print "\tif(unlikely(kernelInfoLocal.traceInfo.mask & " + \
              pemEvent.getEventMaskMacro(anEvent.getClassId()) + ")) {"
        funcNamePrefix = "\ttraceDefault"
        castUint64 = 'uval64'
    else:
        funcNamePrefix = "notifyEvent"
        castUint64 = 'unsigned long long'
    
    if hasListFields:
        # take the args and the list and pack it into an array of bytes
        print '\t\tunsigned char ___tmpBuffer[1024];'
        print '\t\tunsigned int ___listLength = 0;'
        if stringsCount > 0: print '\t\tunsigned int i;'
        currentKey = 0          # where are we with the other fields
        firstPacked = 0         # how many args are packed in this arg
        for f in anEvent.getTraceFields():
            if anEvent.isListField(f):
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),
                                                    f+"[i]")
                memcpy = '\t\tmemcpy(&___tmpBuffer[___listLength],'

                if anEvent.getFieldType(f) == 'string':
                    print '\t\tfor(i = 0; i <', anEvent.getListCount(f), \
                          '; i++) {'
                    print '\t', memcpy, f + "[i]", ",", fieldSize, ');'
                    print '\t\t\t ___listLength +=', fieldSize, ';\n\t\t}'
                else:
                    fieldSize = fieldSize + '*' + anEvent.getListCount(f)
                    print memcpy, '(char *)', f, ",", fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
            else:
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),f)
                if args[currentKey].count(f) == 1:
                    if firstPacked == 0:
                        # argument found as packed
                        print '\t\t*(', castUint64,\
                              '*)&___tmpBuffer[___listLength] =',\
                              args[currentKey], ';'
                        print '\t\t___listLength += 8;'
                        firstPacked = 1
                        byteSize = 0
                    byteSize = byteSize + int(fieldSize)
                    if byteSize == 8:
                        currentKey = currentKey + 1
                        firstPacked = 0
                else:
                    # argument has not been packed
                    print '\t\tmemcpy(&___tmpBuffer[___listLength],',
                    if anEvent.getFieldType(f) != 'string': print '(char *)&',
                    print f, ',', fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
                
        # print "\t"+ funcNamePrefix +"Pre"+ str(len(args)-2) +"Bytes (",
        print "\t"+ funcNamePrefix +"Bytes (",
        genNotifyEventId(anEvent)
        #for arg in sortedKeys:
        #    print ",\n\t\t\t" + args[arg],
        #print ");"
        print ",\n\t\t\t___listLength, ___tmpBuffer);"
    elif len(args) < 8 and stringsCount == 0:
        print "\t" + funcNamePrefix + str(len(args)) + "(",
        genNotifyEventId(anEvent)
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"
    else:
        print "\t" + funcNamePrefix + "Generic(",
        genNotifyEventId(anEvent)
        print ",\n\t\t\t",str(len(args)-stringsCount),"/* word(s) */,",
        print str(stringsCount), "/* string(s) */",
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"

    if pemGlobals.dialect == 'K42':
        print "\t}"