Esempio n. 1
0
void InstructionTrace(INS ins, void* v)
{
	// check if we just received a snapshot request
	bool snapshotStatus = CheckSnapshotEvent();
	if (snapshotStatus)
	{
		// We just detected a monitoring change! Take a memory snapshot now
		TakeSnapshot();

		// reset the event
		DisableSnapshotEvent();
	}

	// check the monitoring event if we should still be monitoring or not 
	bool monitoringStatus = CheckMonitoringEvent();
	if (!monitoringStatus)
	{
		return;
	}

	instruction_trace trace;
	trace.tid = PIN_GetTid();
	trace.address = INS_Address(ins);

	memset(trace.library_name, 0, 260);
	std::string libraryName;
	if (CHECK_LIBRARY_NAMES && GetLibraryName(trace.address, libraryName))
	{
		snprintf(trace.library_name, sizeof(trace.library_name), "%s", libraryName.c_str());
	}
	

	if (INS_IsCall(ins) == true)
	{
		trace.execution_depth = executionDepth++;
	}
	else if (INS_IsRet(ins) == true)
	{
		trace.execution_depth = executionDepth--;
	}
	else
		trace.execution_depth = executionDepth;

	trace.instruction_count = instructionCount++;
	
#ifdef TARGET_WINDOWS
	trace.execution_time = WINDOWS::GetTickCount();
#else
	timeval time;
	gettimeofday(&time, NULL);
	unsigned long millis = (time.tv_sec * 1000) + (time.tv_usec / 1000);
	trace.execution_time = millis;
#endif

	LogStruct(trace);
}
Esempio n. 2
0
static int LogField(d_String* str, adbus_Iterator* i)
{
    const adbus_Bool*     b;
    const uint8_t*        u8;
    const int16_t*        i16;
    const uint16_t*       u16;
    const int32_t*        i32;
    const uint32_t*       u32;
    const int64_t*        i64;
    const uint64_t*       u64;
    const double*         d;
    const char*     string;
    size_t          size;

    switch (*i->sig)
    {
    case ADBUS_BOOLEAN:
        if (adbus_iter_bool(i, &b))
            return -1;
        ds_cat_f(str, "%s", *b ? "true" : "false");
        break;
    case ADBUS_UINT8:
        if (adbus_iter_u8(i, &u8))
            return -1;
        ds_cat_f(str, "%d", (int) *u8);
        break;
    case ADBUS_INT16:
        if (adbus_iter_i16(i, &i16))
            return -1;
        ds_cat_f(str, "%d", (int) *i16);
        break;
    case ADBUS_UINT16:
        if (adbus_iter_u16(i, &u16))
            return -1;
        ds_cat_f(str, "%d", (int) *u16);
        break;
    case ADBUS_INT32:
        if (adbus_iter_i32(i, &i32))
            return -1;
        ds_cat_f(str, "%d", (int) *i32);
        break;
    case ADBUS_UINT32:
        if (adbus_iter_u32(i, &u32))
            return -1;
        ds_cat_f(str, "%u", (unsigned int) *u32);
        break;
    case ADBUS_INT64:
        if (adbus_iter_i64(i, &i64))
            return -1;
        ds_cat_f(str, "%lld", (long long int) *i64);
        break;
    case ADBUS_UINT64:
        if (adbus_iter_u64(i, &u64))
            return -1;
        ds_cat_f(str, "%llu", (long long unsigned int) *u64);
        break;
    case ADBUS_DOUBLE:
        if (adbus_iter_double(i, &d))
            return -1;
        ds_cat_f(str, "%.15g", *d);
        break;
    case ADBUS_STRING:
        if (adbus_iter_string(i, &string, &size))
            return -1;
        ds_cat_f(str, "\"%*s\"", size, string);
        break;
    case ADBUS_OBJECT_PATH:
        if (adbus_iter_objectpath(i, &string, &size))
            return -1;
        ds_cat_f(str, "\"%*s\"", size, string);
        break;
    case ADBUS_SIGNATURE:
        if (adbus_iter_signature(i, &string, &size))
            return -1;
        ds_cat_f(str, "\"%*s\"", size, string);
        break;
    case ADBUS_DICTENTRY_BEGIN:
        if (LogField(str, i))
            return -1;
        ds_cat_f(str, " = ");
        if (LogField(str, i))
            return -1;
        if (*i->sig != ADBUS_DICTENTRY_END)
            return -1;
        break;
    case ADBUS_ARRAY_BEGIN:
        return LogArray(str, i);
    case ADBUS_STRUCT_BEGIN:
        return LogStruct(str, i);
    case ADBUS_VARIANT_BEGIN:
        return LogVariant(str, i);
    default:
        assert(0);
        return -1;
    }
    return 0;
}