Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 141540 | Differences between
and this patch

Collapse All | Expand All

(-)src-native/build/build_tptp_profiler.script (+4 lines)
Lines 48-50 Link Here
48
make -C ../src/ThreadProf -f Makefile $1
48
make -C ../src/ThreadProf -f Makefile $1
49
49
50
echo "----------------------------------------------"
50
echo "----------------------------------------------"
51
52
make -C ../src/ProbekitAgent -f Makefile $1
53
54
echo "----------------------------------------------"
(-)src-native/build/build_tptp_profiler.bat (+12 lines)
Lines 40-45 Link Here
40
set MAKE_CFG4=BuildHeapProf32 - Win32 %MAKE_MODE%
40
set MAKE_CFG4=BuildHeapProf32 - Win32 %MAKE_MODE%
41
set MAKE_FILE5=BuildThreadProf32.mak 
41
set MAKE_FILE5=BuildThreadProf32.mak 
42
set MAKE_CFG5=BuildThreadProf32 - Win32 %MAKE_MODE%
42
set MAKE_CFG5=BuildThreadProf32 - Win32 %MAKE_MODE%
43
set MAKE_FILE6=BuildProbekitAgent32.mak 
44
set MAKE_CFG6=BuildProbekitAgent32 - Win32 %MAKE_MODE%
43
goto make
45
goto make
44
46
45
:em64t
47
:em64t
Lines 123-128 Link Here
123
125
124
echo =============================================================
126
echo =============================================================
125
127
128
echo Executing: NMAKE /F %MAKE_FILE6% CFG="%MAKE_CFG6%" %MAKE_OPTIONS%
129
NMAKE /F %MAKE_FILE6% CFG="%MAKE_CFG6%" %MAKE_OPTIONS%
130
if %errorlevel% == 0 (
131
 	echo BUILD OK
132
) else (
133
	echo BUILD ERRORS
134
)
135
136
echo =============================================================
137
126
goto end
138
goto end
127
139
128
:error_acsdk_home
140
:error_acsdk_home
(-)src-native/build/tptp_profiler.dsw (+12 lines)
Lines 51-56 Link Here
51
51
52
###############################################################################
52
###############################################################################
53
53
54
Project: "BuildProbekitAgent32"=".\BuildProbekitAgent32.dsp" - Package Owner=<4>
55
56
Package=<5>
57
{{{
58
}}}
59
60
Package=<4>
61
{{{
62
}}}
63
64
###############################################################################
65
54
Project: "BuildThreadProf32"=".\BuildThreadProf32.dsp" - Package Owner=<4>
66
Project: "BuildThreadProf32"=".\BuildThreadProf32.dsp" - Package Owner=<4>
55
67
56
Package=<5>
68
Package=<5>
(-)src-native/src/ACCollector/ACCollector.cpp (-11 / +88 lines)
Lines 38-43 Link Here
38
    return ACCollector::GetInstance().SendVMAgentInitializedCommand();
38
    return ACCollector::GetInstance().SendVMAgentInitializedCommand();
39
}
39
}
40
40
41
/////////////////////////////////////////////////////////////////
42
43
// implementation util
44
45
// caller must free output name and value
46
static
47
void parseOption( const char* param_name, const char* param_value,
48
				  char*& name, char*& value )
49
{
50
	char NAME_START[] = "<name>";
51
    char NAME_END[] = "</name>";
52
    char VALUE_START[] = "<value>";
53
    char VALUE_END[] = "</value>";
54
            	
55
    #define SSIZE(str) (sizeof(str) - 1)            	
56
	#define BAD_OPTION(msg) { LOG_ERROR(msg); return; }
57
            	
58
    // reset output
59
    name = 0;
60
    value = 0;
61
            	
62
	// parse string            	
63
    int len = strlen(param_value);
64
    if( len < SSIZE(NAME_START) + SSIZE(NAME_END) + 
65
    		  SSIZE(VALUE_START) + SSIZE(VALUE_END) )
66
    	BAD_OPTION("value too short");
67
            		
68
	const char* ns = strstr( param_value, NAME_START);
69
    if( !ns ) BAD_OPTION("invalid syntax");  
70
    ns += SSIZE(NAME_START);
71
            	          		
72
	const char* ne = strstr( ns, NAME_END);
73
    if( !ne ) BAD_OPTION("invalid syntax");
74
            	
75
    const char* vs = strstr( ne, VALUE_START);
76
    if( !vs ) BAD_OPTION("invalid syntax");
77
    vs += SSIZE(VALUE_START);
78
            	
79
    /* string must end with </value> */
80
    const char* ve = param_value + len - SSIZE(VALUE_END); 
81
    if( ve <= vs ) BAD_OPTION("invalid syntax");
82
    if( strstr( ve, VALUE_END ) != ve  ) 
83
    	BAD_OPTION("invalid syntax: option doesn't end with \"</value>\"");
84
            	
85
    /* name */
86
    len = ne - ns;
87
    name = (char*)malloc( len + 1 );
88
	if( name == 0 )
89
		return;
90
    strncpy( name, ns, len );
91
    name[ len ] = 0;
92
            	
93
    /* value */
94
    len = ve - vs;
95
    value = (char*)malloc( len + 1 );
96
	if( value == 0 )
97
		return;
98
    strncpy( value, vs, len );
99
    value[ len ] = 0;
100
    
101
    return;
102
}
103
104
/////////////////////////////////////////////////////////////////
105
41
static char* profileName = "org.eclipse.tptp.jvmti";
106
static char* profileName = "org.eclipse.tptp.jvmti";
42
107
43
ACCollector::ACCollector() : BaseCollectorImpl(profileName), BaseAgentImpl(profileName)
108
ACCollector::ACCollector() : BaseCollectorImpl(profileName), BaseAgentImpl(profileName)
Lines 194-215 Link Here
194
//        }
259
//        }
195
            
260
            
196
    } else if (isEqualString(cmdName, "applyOptions")) {
261
    } else if (isEqualString(cmdName, "applyOptions")) {
197
        char name[250];
262
    	// TODO: this code doens't limit the option size; 
198
        char value[250];
263
    	// add some limitation for security purposes?
264
        m_dataListenerID = cmdBlock->getSourceID();
199
        tptp_list_t* paramList = cmdBlock->getParamList();
265
        tptp_list_t* paramList = cmdBlock->getParamList();
200
        _tptp_node_t* node = paramList->head;
266
        _tptp_node_t* node = paramList->head;
201
        for (int i = 0; i < paramList->count; i++) {
267
        for (int i = 0; i < paramList->count; i++) {
202
            tptp_param_t* param = (tptp_param_t*)(node->data);
268
            tptp_param_t* param = (tptp_param_t*)(node->data);
203
            node = node->next;
269
            node = node->next;
204
            if (strcmp("option", param->name) == 0) {
270
            
205
                if (sscanf(param->value, "<name>%250[^<]</name><value>%250[^<]</value>", name, value) == EOF) {
271
            if (param->name && param->value && 
206
                    //TODO
272
            	strcmp("option", param->name) == 0) {
207
                }
273
           		
208
                // TODO Add check for agg profiler options and iid
274
           		char* name;
209
                m_ACC_env->SetProfileOption(iid, name, value);
275
            	char* value;
210
                LOG_TRACE("Options: name=" << name << " value=" << value);
276
            	parseOption( param->name, param->value, name, value );
211
            }
277
            		            		
212
        }
278
            	// TODO Add check for agg profiler options and iid
279
            		
280
            	// name or value null means string not formed properly
281
            	if( name && value ) {            				
282
    				LOG_TRACE("Options: name='" << name 
283
    					<< "' value='" << value << "'" << std::endl);
284
    				m_ACC_env->SetProfileOption(iid, name, value);                               
285
            	}	
286
				free( name );
287
    			free( value ); 
288
			}
289
		}			                	
213
290
214
    } else if (isEqualString(cmdName, "AnalyseHeap")) {
291
    } else if (isEqualString(cmdName, "AnalyseHeap")) {
215
        m_ACC_env->AnalyseHeap();
292
        m_ACC_env->AnalyseHeap();
(-)src-native/include/JPIAgent/EC_Env.h (-1 / +6 lines)
Lines 94-99 Link Here
94
    bool (ECCALL *isControlled)(EC_Env* env);
94
    bool (ECCALL *isControlled)(EC_Env* env);
95
    bool (ECCALL *isEnabled)(EC_Env* env);
95
    bool (ECCALL *isEnabled)(EC_Env* env);
96
    bool (ECCALL *isAllocSitesSupported)(EC_Env* env);
96
    bool (ECCALL *isAllocSitesSupported)(EC_Env* env);
97
	const char*(ECCALL *getUnknownOptionByName)(EC_Env* env, const char* name);
97
98
98
    void (ECCALL *VMInitDone)(EC_Env* env);
99
    void (ECCALL *VMInitDone)(EC_Env* env);
99
};
100
};
Lines 228-234 Link Here
228
    bool isAllocSitesSupported() {
229
    bool isAllocSitesSupported() {
229
        return functions->isAllocSitesSupported(this);
230
        return functions->isAllocSitesSupported(this);
230
    }
231
    }
231
232
	
233
	const char* getUnknownOptionByName( const char* name ) {
234
		return functions->getUnknownOptionByName(this, name);
235
	}
236
		
232
    void VMInitDone() {
237
    void VMInitDone() {
233
        functions->VMInitDone(this);
238
        functions->VMInitDone(this);
234
    }
239
    }
(-)src-native/src/JPIAgent/Options.h (+2 lines)
Lines 143-148 Link Here
143
        bool isAllocSitesSupported() {
143
        bool isAllocSitesSupported() {
144
            return m_jvmtiAgent_Options.allocSites == 1;
144
            return m_jvmtiAgent_Options.allocSites == 1;
145
        }
145
        }
146
        
147
        const char* getUnknownOptionByName( const char* name );
146
148
147
    private:
149
    private:
148
        /**
150
        /**
(-)src-native/src/JPIAgent/Options.cpp (+13 lines)
Lines 570-572 Link Here
570
{
570
{
571
    return 0;
571
    return 0;
572
}
572
}
573
574
const char* 
575
COptions::getUnknownOptionByName( const char* name ) 
576
{
577
	generic_option* opt = m_jvmtiAgent_Options.unknowns;
578
    while( opt ) {
579
    	if( opt->key && STRICOLL( opt->key, name ) == 0 ) {
580
        	return opt->value;
581
		}
582
		opt = opt->next;
583
	}
584
    return 0;	
585
}
(-)src-native/src/JPIAgent/ECWrapper.cpp (+7 lines)
Lines 486-491 Link Here
486
    return ECWrapper::m_pCOptions->isAllocSitesSupported();
486
    return ECWrapper::m_pCOptions->isAllocSitesSupported();
487
}
487
}
488
488
489
EC_EXPORT const char* ECCALL
490
getUnknownOptionByName(EC_Env* env, const char* name)
491
{
492
    return ECWrapper::m_pCOptions->getUnknownOptionByName(name);
493
}
494
489
EC_EXPORT void ECCALL
495
EC_EXPORT void ECCALL
490
VMInitDone(EC_Env* env)
496
VMInitDone(EC_Env* env)
491
{
497
{
Lines 531-536 Link Here
531
    ECWrapper::m_ECFunctions.isControlled = &isControlled;
537
    ECWrapper::m_ECFunctions.isControlled = &isControlled;
532
    ECWrapper::m_ECFunctions.isEnabled = &isEnabled;
538
    ECWrapper::m_ECFunctions.isEnabled = &isEnabled;
533
    ECWrapper::m_ECFunctions.isAllocSitesSupported = &isAllocSitesSupported;
539
    ECWrapper::m_ECFunctions.isAllocSitesSupported = &isAllocSitesSupported;
540
    ECWrapper::m_ECFunctions.getUnknownOptionByName = &getUnknownOptionByName;
534
    ECWrapper::m_ECFunctions.VMInitDone = &VMInitDone;
541
    ECWrapper::m_ECFunctions.VMInitDone = &VMInitDone;
535
    ECWrapper::m_EC_Env.functions = &ECWrapper::m_ECFunctions;
542
    ECWrapper::m_EC_Env.functions = &ECWrapper::m_ECFunctions;
536
    *env = &ECWrapper::m_EC_Env;
543
    *env = &ECWrapper::m_EC_Env;
(-)src-native/src/ProbekitAgent/Instrumenter.cpp (+524 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#include "Instrumenter.h"
15
#include "Globals.h"
16
#include "ProbekitAgent.h"
17
#include "Util.h"
18
19
#include <stdio.h>
20
#include <assert.h>
21
22
#ifdef WIN32
23
#include <Winsock2.h> // for htons
24
#endif
25
26
#ifdef _UNIX_
27
#include <dlfcn.h> // for dlopen
28
#include <netinet/in.h> // for htons
29
#endif 
30
 
31
// Martini
32
#include <OSA.h>
33
#include "log.h"
34
35
using namespace Martini::OSA;
36
using namespace std;
37
38
// Old BCI
39
40
#define PROBESCRIPT_FILE_EXTENSION ".probescript"
41
#define PROBESCRIPT_CLASS_EXTENSION ".class"
42
43
#include <BCI/BCIEng/BCIEngInterface.h>
44
45
using namespace Martini::ProbekitAgent;
46
47
// BCI function types
48
typedef unsigned (*CreateBCIEngine_t)(pbcieng_t* o_eng);
49
typedef unsigned (*DestroyBCIEngine_t)(pbcieng_t i_eng);
50
typedef unsigned (*Initialize_t)(pbcieng_t i_pbcieng, const char* i_pchOptions, size_t i_cbOptions);
51
typedef unsigned (*SetAllocator_t)(pbcieng_t i_pbcieng, pfnMalloc_t i_pfnMalloc);
52
typedef unsigned (*SetCallback_t)(pbcieng_t i_pbcieng, pfnCallback_t i_pfnCallback, unsigned i_uFlags);
53
typedef unsigned (*Instrument_t)(pbcieng_t i_pbcieng, 
54
                                  const char* i_pInClass, size_t i_cbInClass, 
55
                                  char** o_ppOutClass, size_t* o_pcbOutClass);
56
                                       
57
// BCI functions
58
59
static CreateBCIEngine_t    CreateBCIEngine_fn;
60
static DestroyBCIEngine_t   DestroyBCIEngine_fn;
61
static Initialize_t         Initialize_fn;
62
static SetAllocator_t       SetAllocator_fn;
63
static SetCallback_t        SetCallback_fn;
64
static Instrument_t         Instrument_fn;
65
66
#define RESOLVE_FUNCTION(F) \
67
F##_fn = (F##_t)pLibrary->GetEntry(#F); \
68
if (F##_fn == NULL) { \
69
    LOG_ERROR("can't resolve " #F); \
70
    result = MRTE_ERROR_FAIL; \
71
    goto out; \
72
}
73
74
static pbcieng_t BCIEngine = NULL;
75
76
#define DEFAULT_BCI_LIBRARY "BCIEngProbe"
77
78
#define CMDLINE_PARAM_BCI "ext-pk-BCILibraryName"
79
#define CMDLINE_PARAM_PROBESCRIPT "ext-pk-probescript"
80
#define CMDLINE_PARAM_DUMP "ext-pk-dump"
81
82
/////////////////////////////////////////////////////////////////
83
84
static Martini::OSA::IThreadSync* lockBCI = Martini::OSA::CreateThreadSync();
85
86
static const char* logLocation = 0; // path to dump debug files
87
88
/////////////////////////////////////////////////////////////////
89
90
//
91
// Probe classes support
92
//
93
94
struct SDelayedClass {
95
	SDelayedClass( char* pname, // 0 terminated
96
				   char* pdata, // binary data
97
				   int plen )
98
		: name( strdup(pname) ), data( pdata ), len(plen), next( 0 )	
99
	{}
100
	
101
	~SDelayedClass()
102
	{
103
		free( (void*)name );
104
		free( (void*)data );
105
	}
106
	
107
	char* name;
108
	char* data;
109
	int len;
110
	
111
	SDelayedClass* next;
112
	
113
	static SDelayedClass* head;
114
	static SDelayedClass* tail;
115
	
116
	static void AddClass( SDelayedClass* newClass );
117
	static void FreeAllClasses();
118
119
};
120
121
SDelayedClass* SDelayedClass::head = 0;
122
SDelayedClass* SDelayedClass::tail = SDelayedClass::head;
123
124
// add new class in the list
125
void SDelayedClass::AddClass( SDelayedClass* newClass )
126
{
127
	if( SDelayedClass::head == 0 ) {
128
		SDelayedClass::head = newClass;
129
	}
130
	
131
	if( SDelayedClass::tail == 0 ) {
132
		SDelayedClass::tail = newClass;
133
	} else {
134
		SDelayedClass::tail->next = newClass;
135
		SDelayedClass::tail = newClass;
136
	}
137
}
138
139
// clear list
140
void SDelayedClass::FreeAllClasses() 
141
{	
142
	SDelayedClass* clsNext;
143
	SDelayedClass* cls = SDelayedClass::head;
144
	
145
	while( cls ) {
146
		clsNext = cls->next;
147
		delete cls;
148
		cls = clsNext;
149
	}
150
		
151
	SDelayedClass::head = 0;
152
	SDelayedClass::tail = 0;
153
}
154
155
//
156
// util
157
//
158
159
// Load shared library that implements BCI
160
static TResult LoadBCI(const char* options)
161
{
162
    TResult result = MRTE_RESULT_OK;
163
    char* BCIEngineName = Util::GetCmdlineOption( options, CMDLINE_PARAM_BCI );    
164
    if( BCIEngineName == NULL ) {
165
    	LOG_MESSAGE( PROFILER_NAME " BCI engine not defined, using default " 
166
    		DEFAULT_BCI_LIBRARY ); 
167
        BCIEngineName = strdup( DEFAULT_BCI_LIBRARY );
168
    }
169
    LOG_TRACE( PROFILER_NAME " BCIEngine=" << BCIEngineName );
170
    
171
    ILibraryLoader *pLibrary = CreateLibraryLoader( BCIEngineName, "", true );	
172
	        
173
    if (pLibrary == NULL) {
174
#ifdef __unix    	
175
    	LOG_ERROR( PROFILER_NAME " Instrumenter error: " << dlerror());
176
#endif    	
177
		LOG_ERROR( PROFILER_NAME "Could not load " << BCIEngineName ); 
178
		free( BCIEngineName );
179
        return MRTE_ERROR_FAIL;
180
    }    
181
182
    RESOLVE_FUNCTION(CreateBCIEngine);
183
    RESOLVE_FUNCTION(DestroyBCIEngine);
184
    RESOLVE_FUNCTION(Initialize);
185
    RESOLVE_FUNCTION(SetAllocator);
186
    RESOLVE_FUNCTION(SetCallback);
187
    RESOLVE_FUNCTION(Instrument);
188
        
189
    if( CreateBCIEngine_fn((pbcieng_t*)&BCIEngine) != 0 ) {
190
        LOG_ERROR( PROFILER_NAME " Can't initialize BCI engine implementation");
191
        result = MRTE_ERROR_FAIL;        
192
    }
193
    
194
out:        
195
    pLibrary->Destroy();    
196
    free( BCIEngineName );
197
    
198
    return result;
199
}
200
201
// send probescript to BCI
202
static TResult SendProbescriptToBCI( const char* probescript, int len )
203
{
204
	TResult result = MRTE_RESULT_OK;
205
	
206
	LOG_TRACE( PROFILER_NAME " content starts with " << (probescript ? probescript : "") );
207
    if( probescript ) {
208
    	int errCode = Initialize_fn(BCIEngine, probescript, len);
209
210
		if (errCode == 0) {
211
    		LOG_TRACE( PROFILER_NAME " probe script file processed successfully");
212
		} else {
213
        	LOG_ERROR( PROFILER_NAME " error processing probe script file");
214
            result = MRTE_ERROR_FAIL;
215
		}        
216
	}
217
	return result;
218
}
219
220
static TResult LoadProbeScriptFromOptions(const char* options)
221
{
222
	LOG_ASSERT(BCIEngine);
223
	TResult result = MRTE_RESULT_OK;
224
	
225
	char* probeScriptName = Util::GetCmdlineOption( options, CMDLINE_PARAM_PROBESCRIPT );
226
        
227
    if( probeScriptName ) {
228
    	
229
    	LOG_TRACE( PROFILER_NAME " probeScriptName=" << probeScriptName );
230
    
231
    	char* content;
232
    	int len;
233
    	Util::ReadFile( probeScriptName, content, len ); 
234
    	
235
    	result = SendProbescriptToBCI( content, len );
236
    	
237
    	free( content );
238
    	free( probeScriptName );
239
    }
240
    
241
    return result;
242
}
243
244
  
245
// BCI callback
246
int BCICallback(const char* i_pInfo, size_t i_cbInfo, unsigned i_wFlags)
247
{
248
    int result = 1;    
249
    
250
    if(!CGlobals::Instance()->m_VMInitSeen)
251
    {
252
        result = 0;
253
    }
254
    else if(i_wFlags == BCIENGINTERFACE_CALLBACK_MODULE)
255
    {
256
    	// let it instrument
257
    	// NOTE: is this is a probekit class, the condition above
258
    	// (m_VMInitSeen) disables its instrumentation
259
    }
260
    else if (
261
    	i_wFlags == BCIENGINTERFACE_CALLBACK_MODULE_INSTR ||
262
    	i_wFlags == BCIENGINTERFACE_CALLBACK_METHOD_INSTR ) {
263
    	
264
        /*
265
         * This is a report that this class or method was actually instrumented.
266
         * */      
267
#if defined(DEBUG) || defined(_DEBUG)         
268
		char* nameBuf = Util::StrNDup( i_pInfo, (int)i_cbInfo );  		
269
		if( nameBuf ) {
270
			LOG_TRACE( PROFILER_NAME " instrumented " << nameBuf );
271
			free( nameBuf );
272
		} else {
273
			LOG_ERROR( PROFILER_NAME " out of memory" );
274
		}
275
#endif        
276
    }
277
    
278
    return result;   
279
}
280
281
// process data sent by client - it's either probescript or .class
282
static 
283
TResult ProcessClientFile( const char* name, const char* data, int len )
284
{
285
	TResult retVal = MRTE_RESULT_OK;
286
		
287
	// name is either a class name or something.probescript
288
	if( strstr( name, PROBESCRIPT_FILE_EXTENSION ) ) {
289
		// probescript
290
		retVal = SendProbescriptToBCI( data, len );			
291
	} else if( const char* ext = strstr( name, PROBESCRIPT_CLASS_EXTENSION ) ) {
292
		// assume class
293
		char* nameBuf = Util::StrNDup( name, ext - name ); // strip extension		
294
		if( nameBuf == 0 ) {
295
			return MRTE_ERROR_FAIL;
296
		}
297
		char* dataBuf = Util::StrNDup( data, len );
298
		if( dataBuf == 0 ) {
299
			return MRTE_ERROR_FAIL;
300
		}
301
		SDelayedClass* delayedClass = new SDelayedClass( nameBuf, dataBuf, len );		
302
		SDelayedClass::AddClass( delayedClass );
303
		free( nameBuf );
304
	} else {
305
		LOG_ERROR( PROFILER_NAME " unsupported file " << name );
306
		retVal = MRTE_ERROR_FAIL;
307
	}	
308
	return retVal;
309
}
310
311
// read probekit settings from EC; return MRTE_RESULT_TRUE if such 
312
// settings found, MRTE_RESULT_FALSE if not found, an error code
313
// otherwise.	
314
static TResult ReadClientProbekitData()
315
{
316
	TResult retVal = MRTE_RESULT_FALSE;
317
	
318
   	// read probekit options
319
	CProbekitAgent* agent = CProbekitAgent::getInstance();
320
	
321
	// iterate and find all probekit options	
322
	for( int count = 0;; count++ ) {
323
		char optName[64];
324
		sprintf( optName, "PROBEKIT_DATA_%d", count );
325
		
326
    	const char* data = agent->getEC()->getUnknownOptionByName( optName );       
327
    
328
    	if( data == 0 ) {
329
    		break;
330
    	}    	    
331
    	
332
    	LOG_TRACE( PROFILER_NAME " " << optName << "=" << data	);
333
    	
334
    	int len = strlen( data );
335
    	LOG_TRACE( PROFILER_NAME " total len = " << len );
336
    	Util::DumpBuffer( logLocation, "base64", data, len );
337
    	
338
    	char* out = (char*)malloc( len+1 );    	
339
    	int decoded = Util::DecodeBuffer( data, len, out );     	
340
    	
341
    	// java is big-endian (i.e. network byte order)
342
    	int magic = ntohl(*(int*)out);
343
    	
344
    	char* ptr = out + sizeof(magic);
345
    	
346
    	LOG_TRACE( PROFILER_NAME " decoded " << decoded << 
347
    		" bytes, magic=" << magic);
348
    	    	
349
    	// ptr alignment may be inefficient
350
    	
351
    	while( ptr < out + decoded ) {
352
    	
353
    		int nameLen = ntohl(*(int*)ptr );    		
354
    		ptr += sizeof( nameLen );
355
    		
356
    		char* name = Util::StrNDup( ptr, nameLen ); 
357
			if( name == 0 ) {
358
				return MRTE_ERROR_FAIL;
359
			}
360
    		ptr += nameLen;
361
    		
362
    		int dataLen = ntohl(*(int*)ptr);
363
    		ptr += sizeof(dataLen);
364
    		
365
    		// read data
366
    		LOG_TRACE( PROFILER_NAME " nameLen=" << nameLen
367
    			<< " name = " << name
368
    			<< " dataLen = " << dataLen );
369
    			
370
    		retVal = ProcessClientFile( name, ptr, dataLen );
371
    		free( name );    		
372
    		if( MRTE_FAILED(retVal) ) {
373
				return retVal;    			
374
    		}
375
    		
376
    		ptr += dataLen;
377
    	}
378
    	 
379
    	free(out); 
380
    	
381
    	// read at least one option block
382
    	retVal = MRTE_RESULT_TRUE;    	
383
	} // for
384
    
385
    return retVal;
386
}
387
                                
388
//
389
// CBCIInstrumenter
390
//
391
392
393
CBCIInstrumenter::CBCIInstrumenter()
394
    : m_initialized(false)
395
{}
396
397
CBCIInstrumenter::~CBCIInstrumenter() 
398
{
399
    if( m_initialized && BCIEngine ) {
400
        DestroyBCIEngine_fn( BCIEngine );           
401
    }
402
}
403
404
TResult CBCIInstrumenter::Initialize(const char* options)
405
{
406
	TResult retVal = MRTE_RESULT_OK;
407
	
408
    LOG_TRACE( PROFILER_NAME " Initialize BCI Instrumenter, options=" << options);
409
            
410
    if( m_initialized ) {
411
    	LOG_MESSAGE( PROFILER_NAME " Instrumenter already initialized");
412
        return retVal;
413
    }        
414
                 
415
	// load BCI library                 
416
	retVal = LoadBCI(options);                 
417
    if( MRTE_FAILED( retVal ) ) {
418
        LOG_ERROR( PROFILER_NAME " Can't load BCI engine, error=" << retVal ); 
419
        return retVal;       
420
    } 
421
    
422
    SetCallback_fn(BCIEngine, BCICallback, 0xFFFF);
423
424
	logLocation = Util::GetCmdlineOption( options, CMDLINE_PARAM_DUMP );
425
    
426
    // read and process probekit settings from EC first
427
    retVal = ReadClientProbekitData();
428
    if( MRTE_FAILED(retVal) ) {
429
    	LOG_ERROR( PROFILER_NAME " Can't load probescript data from EC" ); 
430
        return retVal;    	
431
    }
432
    if( retVal == MRTE_RESULT_FALSE ) {
433
    	// didn't find probescript data in EC - read options     
434
    	retVal = LoadProbeScriptFromOptions(options);
435
    }
436
    if( MRTE_FAILED( retVal ) ) {
437
        LOG_ERROR( PROFILER_NAME " Can't load probescript from options" ); 
438
        return retVal;       
439
    }
440
    
441
    m_initialized = true;
442
    return retVal;    
443
}
444
445
TResult CBCIInstrumenter::Instrument(
446
    TMemoryAllocatorFunc memAllocFunc,
447
	const char* className,
448
    const char* inClass, size_t inClassLength, 
449
    char** outClass, size_t* outClassLength)
450
{
451
    TResult result = MRTE_RESULT_FALSE;
452
    
453
    if( !m_initialized ) {
454
        LOG_ERROR( PROFILER_NAME " BCI engine is not initialized" );
455
        return ( result = MRTE_ERROR_FAIL );
456
    }
457
    
458
    char* outClassTmp = 0;
459
    size_t outClassLengthTmp = 0;
460
    
461
    lockBCI->Enter(); // lock
462
    
463
    SetAllocator_fn( BCIEngine, memAllocFunc );
464
    Instrument_fn( BCIEngine, inClass, inClassLength, 
465
    	&outClassTmp, &outClassLengthTmp);
466
    SetAllocator_fn( BCIEngine, 0 );
467
    
468
    lockBCI->Leave(); // unlock
469
    
470
    if( outClassLengthTmp == inClassLength ) {
471
      ; // did nothing
472
    } else {   
473
        // instrumented        
474
475
		Util::DumpBuffer( logLocation, className,
476
			(const char*)outClassTmp, outClassLengthTmp );        
477
478
        *outClass = outClassTmp;
479
        *outClassLength = outClassLengthTmp; 
480
        
481
        result = MRTE_RESULT_TRUE;
482
    }         
483
484
    return result;
485
}                            
486
487
void CBCIInstrumenter::OnVMInit()
488
{
489
	JNIEnv *pEnv = 0;
490
    bool bAttached = false;
491
    
492
	LOG_TRACE( PROFILER_NAME " CBCIInstrumenter::OnVMInit" );
493
	
494
	TResult res = CGlobals::Instance()->pfnJPI_AttachCurrentThread(
495
        (JNIEnv**)&pEnv, &bAttached);
496
    if (MRTE_SUCCEEDED(res))
497
    {        	
498
		SDelayedClass* cls = SDelayedClass::head;
499
		while( cls ) {
500
	
501
			LOG_TRACE( PROFILER_NAME " process delayed class " << cls->name );
502
			
503
        	Util::DumpBuffer( logLocation, cls->name, cls->data, cls->len );
504
        	 
505
        	jclass c = pEnv->DefineClass(
506
        		cls->name, (jobject)NULL, (const jbyte*)cls->data, cls->len);
507
			LOG_TRACE( PROFILER_NAME " DefineClass returned " << (void*)c );        		
508
			if(c != 0 ) {
509
				pEnv->NewGlobalRef(c);
510
			}
511
			
512
			cls = cls->next;
513
			
514
		} // while
515
		
516
		SDelayedClass::FreeAllClasses();
517
				
518
		if (bAttached)
519
        {
520
            // Need to detach the thread from the JVM for proper cleanup
521
            CGlobals::Instance()->pfnJPI_DetachCurrentThread();
522
        }
523
    } // if		    
524
}        
(-)src-native/src/ProbekitAgent/ECStartEvent.h (+37 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#ifndef PROBEKIT_ECSTART_EVENT_H_
15
#define PROBEKIT_ECSTART_EVENT_H_
16
17
#include "MpiAPI.h"
18
19
namespace Martini { namespace ProbekitAgent {
20
21
    // CStartEvent - represents a Start event 
22
	class CECStartEvent : public MPI::IEcStartEventObserver
23
    {
24
    public:
25
        // Constructor
26
        CECStartEvent();
27
        // Destructor
28
        ~CECStartEvent();
29
        // Initialization - Register to event
30
        TResult Init(MPI::IMpi *pMpiApi, MPI::TId clientId);
31
        // Inherited methods
32
        void HandleEvent();
33
    };
34
35
} /*namespace Martini*/ } /*namespace ProbekitAgent*/
36
37
#endif // PROBEKIT_ECSTART_EVENT_H_
(-)src-native/src/ProbekitAgent/ClassFileLoadHookEvent.cpp (+72 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#include "ClassFileLoadHookEvent.h"
15
#include "InstrumenterFactory.h"
16
#include "Instrumenter.h"
17
18
using namespace Martini::ProbekitAgent;
19
using namespace Martini::MPI;
20
21
/*
22
 * CClassFileLoadHookEvent
23
 */ 
24
25
CClassFileLoadHookEvent::CClassFileLoadHookEvent(){}
26
27
CClassFileLoadHookEvent::~CClassFileLoadHookEvent(){}
28
29
/*
30
 * Init	- initializes internal data and registers event
31
 */
32
TResult CClassFileLoadHookEvent::Init(IMpi *pMpiApi, TId clientId)
33
{
34
	m_pMpiApi	=	pMpiApi;
35
	m_clientId	=	clientId;
36
37
	// Register event
38
	TResult res;
39
    res = m_pMpiApi->RegisterEvent(m_clientId, *this);
40
41
	return res;
42
}
43
44
/*
45
 * HandleEvent - callback function for Class File Load Hook event
46
 */
47
48
    // Here the agent can instrument the class.
49
    // Class data is stored in the 'data' argument.
50
51
    // If the agent instrumented the class, it needs to allocate a new buffer in
52
    // newClassData using memAllocFunc, and then set the new class data length in
53
    // newClassDataLength.
54
    
55
    // If the agent did not instrument the class, it should leave newClassData untouched,
56
57
void CClassFileLoadHookEvent::HandleEvent(SClassFileLoadHookEventData &data, 
58
                                          TMemoryAllocatorFunc memAllocFunc, 
59
                                          unsigned char **newClassData, 
60
                                          S32 *newClassDataLength)
61
{
62
	CInstrumenterFactory::getInstrumenter()->Instrument( 
63
			memAllocFunc,
64
			data.className,
65
			(const char*)data.classData, 
66
        	(size_t)data.classDataLength,
67
        	(char**)newClassData, 
68
        	(size_t*)newClassDataLength );
69
}
70
71
72
(-)src-native/src/ProbekitAgent/ECStopEvent.cpp (+42 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#include "ECStopEvent.h"
15
#include "Globals.h"
16
#include <log.h>
17
18
using namespace Martini;
19
using namespace Martini::MPI;
20
using namespace Martini::ProbekitAgent;
21
22
CECStopEvent::CECStopEvent(){}
23
CECStopEvent::~CECStopEvent(){}
24
25
/*
26
 * Init - initializes internal data and registers for Stop event    
27
 */
28
TResult 
29
CECStopEvent::Init(MPI::IMpi *pMpiApi, MPI::TId clientId)
30
{
31
    TResult res = pMpiApi->RegisterEvent(clientId, *this);
32
    return res;
33
}
34
35
/*
36
 * HandleEvent - callback function for Stop event    
37
 */
38
void 
39
CECStopEvent::HandleEvent()
40
{
41
	LOG_TRACE( PROFILER_NAME " EC Stop" );
42
}
(-)src-native/src/ProbekitAgent/ClassFileLoadHookEvent.h (+48 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#ifndef PROBEKIT_CLASS_FILE_LOAD_HOOK_EVENT_H
15
#define PROBEKIT_CLASS_FILE_LOAD_HOOK_EVENT_H
16
17
#include "MpiAPI.h"
18
19
namespace Martini { namespace ProbekitAgent {
20
21
	// CClassFileLoadHookEvent - represents a Class File Load Hook event
22
	class CClassFileLoadHookEvent : public MPI::IJavaClassFileLoadHookEventObserver
23
	{
24
	public:
25
		CClassFileLoadHookEvent();
26
		~CClassFileLoadHookEvent();
27
28
        // Initialization - Register to event
29
		TResult Init(MPI::IMpi *pMpiApi, MPI::TId clientId);
30
        
31
        // Event handler
32
        void HandleEvent(MPI::SClassFileLoadHookEventData &data,
33
                         TMemoryAllocatorFunc memAllocFunc,
34
                         unsigned char **newClassData,
35
                         S32 *newClassDataLength);
36
37
	private:
38
		// Pointer to the MPI implementation
39
        MPI::IMpi *m_pMpiApi;
40
41
        // Client id for MPI requests
42
	    MPI::TId m_clientId;
43
	};
44
45
} /*namespace Martini*/  } /*namespace ProbekitAgent*/
46
47
#endif	// PROBEKIT_CLASS_FILE_LOAD_HOOK_EVENT_H
48
(-)src-native/src/ProbekitAgent/InstrumenterFactory.h (+37 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#ifndef PROBEKIT_INSTRUMENTER_FACTORY_H
15
#define PROBEKIT_INSTRUMENTER_FACTORY_H
16
17
namespace Martini { namespace ProbekitAgent {
18
19
class IInstrumenter;    
20
    
21
class CInstrumenterFactory
22
{
23
public:
24
25
    static IInstrumenter* getInstrumenter();
26
    
27
private:
28
29
    CInstrumenterFactory();
30
    CInstrumenterFactory( const CInstrumenterFactory& );
31
    
32
    static IInstrumenter* m_instrumenter;            
33
};
34
35
} /*namespace Martini*/  } /*namespace ProbekitAgent*/
36
37
#endif // PROBEKIT_INSTRUMENTER_FACTORY_H
(-)src-native/src/ProbekitAgent/InstrumenterFactory.cpp (+28 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#include "InstrumenterFactory.h"
15
#include "Instrumenter.h"
16
17
using namespace Martini::ProbekitAgent;
18
19
IInstrumenter* CInstrumenterFactory::m_instrumenter = 0;
20
21
IInstrumenter* CInstrumenterFactory::getInstrumenter()
22
{
23
    if( m_instrumenter == 0 ) {
24
        m_instrumenter = new CBCIInstrumenter();
25
    }
26
    
27
    return m_instrumenter;   
28
}
(-)src-native/src/ProbekitAgent/ProbekitAgent.ver (+8 lines)
Added Link Here
1
{
2
    global:
3
        MPICL_Instantiate;
4
    local:
5
        *;
6
};
7
8
(-)src-native/src/ProbekitAgent/b64.c (+551 lines)
Added Link Here
1
/*********************************************************************\
2
3
MODULE NAME:    b64.c
4
5
AUTHOR:         Bob Trower 08/04/01
6
7
PROJECT:        Crypt Data Packaging
8
9
COPYRIGHT:      Copyright (c) Trantor Standard Systems Inc., 2001
10
11
NOTE:           This source code may be used as you wish, subject to
12
                the MIT license.  See the LICENCE section below.
13
14
DESCRIPTION:
15
                This little utility implements the Base64
16
                Content-Transfer-Encoding standard described in
17
                RFC1113 (http://www.faqs.org/rfcs/rfc1113.html).
18
19
                This is the coding scheme used by MIME to allow
20
                binary data to be transferred by SMTP mail.
21
22
                Groups of 3 bytes from a binary stream are coded as
23
                groups of 4 bytes in a text stream.
24
25
                The input stream is 'padded' with zeros to create
26
                an input that is an even multiple of 3.
27
28
                A special character ('=') is used to denote padding so
29
                that the stream can be decoded back to its exact size.
30
31
                Encoded output is formatted in lines which should
32
                be a maximum of 72 characters to conform to the
33
                specification.  This program defaults to 72 characters,
34
                but will allow more or less through the use of a
35
                switch.  The program enforces a minimum line size
36
                of 4 characters.
37
38
                Example encoding:
39
40
                The stream 'ABCD' is 32 bits long.  It is mapped as
41
                follows:
42
43
                ABCD
44
45
                 A (65)     B (66)     C (67)     D (68)   (None) (None)
46
                01000001   01000010   01000011   01000100
47
48
                16 (Q)  20 (U)  9 (J)   3 (D)    17 (R) 0 (A)  NA (=) NA (=)
49
                010000  010100  001001  000011   010001 000000 000000 000000
50
51
52
                QUJDRA==
53
54
                Decoding is the process in reverse.  A 'decode' lookup
55
                table has been created to avoid string scans.
56
57
DESIGN GOALS:	Specifically:
58
		Code is a stand-alone utility to perform base64 
59
		encoding/decoding. It should be genuinely useful 
60
		when the need arises and it meets a need that is 
61
		likely to occur for some users.  
62
		Code acts as sample code to show the author's 
63
		design and coding style.  
64
65
		Generally: 
66
		This program is designed to survive:
67
		Everything you need is in a single source file.
68
		It compiles cleanly using a vanilla ANSI C compiler.
69
		It does its job correctly with a minimum of fuss.  
70
		The code is not overly clever, not overly simplistic 
71
		and not overly verbose. 
72
		Access is 'cut and paste' from a web page.  
73
		Terms of use are reasonable.  
74
75
VALIDATION:     Non-trivial code is never without errors.  This
76
                file likely has some problems, since it has only
77
                been tested by the author.  It is expected with most
78
                source code that there is a period of 'burn-in' when
79
                problems are identified and corrected.  That being
80
                said, it is possible to have 'reasonably correct'
81
                code by following a regime of unit test that covers
82
                the most likely cases and regression testing prior
83
                to release.  This has been done with this code and
84
                it has a good probability of performing as expected.
85
86
                Unit Test Cases:
87
88
                case 0:empty file:
89
                    CASE0.DAT  ->  ->
90
                    (Zero length target file created
91
                    on both encode and decode.)
92
93
                case 1:One input character:
94
                    CASE1.DAT A -> QQ== -> A
95
96
                case 2:Two input characters:
97
                    CASE2.DAT AB -> QUJD -> AB
98
99
                case 3:Three input characters:
100
                    CASE3.DAT ABC -> QUJD -> ABC
101
102
                case 4:Four input characters:
103
                    case4.dat ABCD -> QUJDRA== -> ABCD
104
105
                case 5:All chars from 0 to ff, linesize set to 50:
106
107
                    AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIj
108
                    JCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZH
109
                    SElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWpr
110
                    bG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P
111
                    kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKz
112
                    tLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX
113
                    2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7
114
                    /P3+/w==
115
116
                case 6:Mime Block from e-mail:
117
                    (Data same as test case 5)
118
119
                case 7: Large files:
120
                    Tested 28 MB file in/out.
121
122
                case 8: Random Binary Integrity:
123
                    This binary program (b64.exe) was encoded to base64,
124
                    back to binary and then executed.
125
126
                case 9 Stress:
127
                    All files in a working directory encoded/decoded
128
                    and compared with file comparison utility to
129
                    ensure that multiple runs do not cause problems
130
                    such as exhausting file handles, tmp storage, etc.
131
132
                -------------
133
134
                Syntax, operation and failure:
135
                    All options/switches tested.  Performs as
136
                    expected.
137
138
                case 10:
139
                    No Args -- Shows Usage Screen
140
                    Return Code 1 (Invalid Syntax)
141
                case 11:
142
                    One Arg (invalid) -- Shows Usage Screen
143
                    Return Code 1 (Invalid Syntax)
144
                case 12:
145
                    One Arg Help (-?) -- Shows detailed Usage Screen.
146
                    Return Code 0 (Success -- help request is valid).
147
                case 13:
148
                    One Arg Help (-h) -- Shows detailed Usage Screen.
149
                    Return Code 0 (Success -- help request is valid).
150
                case 14:
151
                    One Arg (valid) -- Uses stdin/stdout (filter)
152
                    Return Code 0 (Sucess)
153
                case 15:
154
                    Two Args (invalid file) -- shows system error.
155
                    Return Code 2 (File Error)
156
                case 16:
157
                    Encode non-existent file -- shows system error.
158
                    Return Code 2 (File Error)
159
                case 17:
160
                    Out of disk space -- shows system error.
161
                    Return Code 3 (File I/O Error)
162
163
                -------------
164
165
                Compile/Regression test:
166
                    gcc compiled binary under Cygwin
167
                    Microsoft Visual Studio under Windows 2000
168
                    Microsoft Version 6.0 C under Windows 2000
169
170
DEPENDENCIES:   None
171
172
LICENCE:        Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc.
173
174
                Permission is hereby granted, free of charge, to any person
175
                obtaining a copy of this software and associated
176
                documentation files (the "Software"), to deal in the
177
                Software without restriction, including without limitation
178
                the rights to use, copy, modify, merge, publish, distribute,
179
                sublicense, and/or sell copies of the Software, and to
180
                permit persons to whom the Software is furnished to do so,
181
                subject to the following conditions:
182
183
                The above copyright notice and this permission notice shall
184
                be included in all copies or substantial portions of the
185
                Software.
186
187
                THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
188
                KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
189
                WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
190
                PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
191
                OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
192
                OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
193
                OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
194
                SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
195
196
VERSION HISTORY:
197
                Bob Trower 08/04/01 -- Create Version 0.00.00B
198
                vss 04/25/01 -- Added decode_buffer
199
200
\******************************************************************* */
201
202
#include <stdio.h>
203
#include <stdlib.h>
204
205
/*
206
** Translation Table as described in RFC1113
207
*/
208
static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
209
210
/*
211
** Translation Table to decode (created by author)
212
*/
213
static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
214
215
/*
216
** encodeblock
217
**
218
** encode 3 8-bit binary bytes as 4 '6-bit' characters
219
*/
220
void encodeblock( unsigned char in[3], unsigned char out[4], int len )
221
{
222
    out[0] = cb64[ in[0] >> 2 ];
223
    out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
224
    out[2] = (unsigned char) (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
225
    out[3] = (unsigned char) (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
226
}
227
228
/*
229
** encode
230
**
231
** base64 encode a stream adding padding and line breaks as per spec.
232
*/
233
void encode( FILE *infile, FILE *outfile, int linesize )
234
{
235
    unsigned char in[3], out[4];
236
    int i, len, blocksout = 0;
237
238
    while( !feof( infile ) ) {
239
        len = 0;
240
        for( i = 0; i < 3; i++ ) {
241
            in[i] = (unsigned char) getc( infile );
242
            if( !feof( infile ) ) {
243
                len++;
244
            }
245
            else {
246
                in[i] = 0;
247
            }
248
        }
249
        if( len ) {
250
            encodeblock( in, out, len );
251
            for( i = 0; i < 4; i++ ) {
252
                putc( out[i], outfile );
253
            }
254
            blocksout++;
255
        }
256
        if( blocksout >= (linesize/4) || feof( infile ) ) {
257
            if( blocksout ) {
258
                fprintf( outfile, "\r\n" );
259
            }
260
            blocksout = 0;
261
        }
262
    }
263
}
264
265
/*
266
** decodeblock
267
**
268
** decode 4 '6-bit' characters into 3 8-bit binary bytes
269
*/
270
void decodeblock( unsigned char in[4], unsigned char out[3] )
271
{   
272
    out[ 0 ] = (unsigned char ) (in[0] << 2 | in[1] >> 4);
273
    out[ 1 ] = (unsigned char ) (in[1] << 4 | in[2] >> 2);
274
    out[ 2 ] = (unsigned char ) (((in[2] << 6) & 0xc0) | in[3]);
275
}
276
277
/*
278
** decode
279
**
280
** decode a base64 encoded stream discarding padding, line breaks and noise
281
*/
282
void decode( FILE *infile, FILE *outfile )
283
{
284
    unsigned char in[4], out[3], v;
285
    int i, len;
286
287
    while( !feof( infile ) ) {
288
        for( len = 0, i = 0; i < 4 && !feof( infile ); i++ ) {
289
            v = 0;
290
            while( !feof( infile ) && v == 0 ) {
291
                v = (unsigned char) getc( infile );
292
                v = (unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]);
293
                if( v ) {
294
                    v = (unsigned char) ((v == '$') ? 0 : v - 61);
295
                }
296
            }
297
            if( !feof( infile ) ) {
298
                len++;
299
                if( v ) {
300
                    in[ i ] = (unsigned char) (v - 1);
301
                }
302
            }
303
            else {
304
                in[i] = 0;
305
            }
306
        }
307
        if( len ) {
308
            decodeblock( in, out );
309
            for( i = 0; i < len - 1; i++ ) {
310
                putc( out[i], outfile );
311
            }
312
        }
313
    }
314
}
315
316
// tmp
317
#ifdef __cplusplus
318
extern "C"
319
#endif
320
int decode_buffer( const char* inBuffer, int inLen, char* outBuffer)
321
{
322
    unsigned char in[4], out[3], v;
323
    int i, len;
324
    int inp = 0, outp = 0;
325
326
    while( inp < inLen ) {
327
        for( len = 0, i = 0; i < 4 && inp < inLen; i++ ) {
328
            v = 0;
329
            while( inp < inLen && v == 0 ) {
330
                v = (unsigned char) inBuffer[ inp++ ];
331
                v = (unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]);
332
                if( v ) {
333
                    v = (unsigned char) ((v == '$') ? 0 : v - 61);
334
                }
335
            }
336
            if( inp < inLen ) {
337
                len++;
338
                if( v ) {
339
                    in[ i ] = (unsigned char) (v - 1);
340
                }
341
            }
342
            else {
343
                in[i] = 0;
344
            }
345
        }
346
        if( len ) {
347
            decodeblock( in, out );
348
            for( i = 0; i < len - 1; i++ ) {
349
            	outBuffer[ outp++ ] = out[i];
350
            }
351
        }
352
    }
353
    return outp;
354
}
355
356
/*
357
** returnable errors
358
**
359
** Error codes returned to the operating system.
360
**
361
*/
362
#define B64_SYNTAX_ERROR        1
363
#define B64_FILE_ERROR          2
364
#define B64_FILE_IO_ERROR       3
365
#define B64_ERROR_OUT_CLOSE     4
366
#define B64_LINE_SIZE_TO_MIN    5
367
368
/*
369
** b64_message
370
**
371
** Gather text messages in one place.
372
**
373
*/
374
char *b64_message( int errcode )
375
{
376
    #define B64_MAX_MESSAGES 6
377
    char *msgs[ B64_MAX_MESSAGES ] = {
378
            "b64:000:Invalid Message Code.",
379
            "b64:001:Syntax Error -- check help for usage.",
380
            "b64:002:File Error Opening/Creating Files.",
381
            "b64:003:File I/O Error -- Note: output file not removed.",
382
            "b64:004:Error on output file close.",
383
            "b64:004:linesize set to minimum."
384
    };
385
    char *msg = msgs[ 0 ];
386
387
    if( errcode > 0 && errcode < B64_MAX_MESSAGES ) {
388
        msg = msgs[ errcode ];
389
    }
390
391
    return( msg );
392
}
393
394
/*
395
** b64
396
**
397
** 'engine' that opens streams and calls encode/decode
398
*/
399
400
int b64( int opt, char *infilename, char *outfilename, int linesize )
401
{
402
    FILE *infile;
403
    int retcode = B64_FILE_ERROR;
404
405
    if( !infilename ) {
406
        infile = stdin;
407
    }
408
    else {
409
        infile = fopen( infilename, "rb" );
410
    }
411
    if( !infile ) {
412
        perror( infilename );
413
    }
414
    else {
415
        FILE *outfile;
416
        if( !outfilename ) {
417
            outfile = stdout;
418
        }
419
        else {
420
            outfile = fopen( outfilename, "wb" );
421
        }
422
        if( !outfile ) {
423
            perror( outfilename );
424
        }
425
        else {
426
            if( opt == 'e' ) {
427
                encode( infile, outfile, linesize );
428
            }
429
            else {
430
                decode( infile, outfile );
431
            }
432
            if (ferror( infile ) || ferror( outfile )) {
433
                retcode = B64_FILE_IO_ERROR;
434
            }
435
            else {
436
                 retcode = 0;
437
            }
438
            if( outfile != stdout ) {
439
                if( fclose( outfile ) != 0 ) {
440
                    perror( b64_message( B64_ERROR_OUT_CLOSE ) );
441
                    retcode = B64_FILE_IO_ERROR;
442
                }
443
            }
444
        }
445
        if( infile != stdin ) {
446
            fclose( infile );
447
        }
448
    }
449
450
    return( retcode );
451
}
452
453
/*
454
** showuse
455
**
456
** display usage information, help, version info
457
*/
458
void showuse( int morehelp )
459
{
460
    {
461
        printf( "\n" );
462
        printf( "  b64      (Base64 Encode/Decode)      Bob Trower 08/03/01 \n" );
463
        printf( "           (C) Copr Bob Trower 1986-01.      Version 0.00B \n" );
464
        printf( "  Usage:   b64 -option  [ -l num ] [<FileIn> [<FileOut>]]  \n" );
465
        printf( "  Purpose: This program is a simple utility that implements\n" );
466
        printf( "           Base64 Content-Transfer-Encoding (RFC1113).     \n" );
467
    }
468
    if( !morehelp ) {
469
        printf( "           Use -h option for additional help.              \n" );
470
    }
471
    else {
472
        printf( "  Options: -e  encode to Base64   -h  This help text.      \n" );
473
        printf( "           -d  decode from Base64 -?  This help text.      \n" );
474
        printf( "  Note:    -l  use to change line size (from 72 characters)\n" );
475
        printf( "  Returns: 0 = success.  Non-zero is an error code.        \n" );
476
        printf( "  ErrCode: 1 = Bad Syntax, 2 = File Open, 3 = File I/O     \n" );
477
        printf( "  Example: b64 -e binfile b64file     <- Encode to b64     \n" );
478
        printf( "           b64 -d b64file binfile     <- Decode from b64   \n" );
479
        printf( "           b64 -e -l40 infile outfile <- Line Length of 40 \n" );
480
        printf( "  Note:    Will act as a filter, but this should only be   \n" );
481
        printf( "           used on text files due to translations made by  \n" );
482
        printf( "           operating systems.                              \n" );
483
        printf( "  Release: 0.00.00, Tue Aug 7   2:00:00 2001, ANSI-SOURCE C\n" );
484
    }
485
}
486
487
#define B64_DEF_LINE_SIZE   72
488
#define B64_MIN_LINE_SIZE    4
489
490
#define THIS_OPT(ac, av) (ac > 1 ? av[1][0] == '-' ? av[1][1] : 0 : 0)
491
492
/*
493
** main
494
**
495
** parse and validate arguments and call b64 engine or help
496
*/
497
498
#ifdef BASE64_MAIN
499
int main( int argc, char **argv )
500
{
501
    int opt = 0;
502
    int retcode = 0;
503
    int linesize = B64_DEF_LINE_SIZE;
504
    char *infilename = NULL, *outfilename = NULL;
505
506
    while( THIS_OPT( argc, argv ) ) {
507
        switch( THIS_OPT(argc, argv) ) {
508
            case 'l':
509
                    linesize = atoi( &(argv[1][2]) );
510
                    if( linesize < B64_MIN_LINE_SIZE ) {
511
                        linesize = B64_MIN_LINE_SIZE;
512
                        printf( "%s\n", b64_message( B64_LINE_SIZE_TO_MIN ) );
513
                    }
514
                    break;
515
            case '?':
516
            case 'h':
517
                    opt = 'h';
518
                    break;
519
            case 'e':
520
            case 'd':
521
                    opt = THIS_OPT(argc, argv);
522
                    break;
523
             default:
524
                    opt = 0;
525
                    break;
526
        }
527
        argv++;
528
        argc--;
529
    }
530
    switch( opt ) {
531
        case 'e':
532
        case 'd':
533
            infilename = argc > 1 ? argv[1] : NULL;
534
            outfilename = argc > 2 ? argv[2] : NULL;
535
            retcode = b64( opt, infilename, outfilename, linesize );
536
            break;
537
        case 0:
538
            retcode = B64_SYNTAX_ERROR;
539
        case 'h':
540
            showuse( opt );
541
            break;
542
543
    }
544
    if( retcode ) {
545
        printf( "%s\n", b64_message( retcode ) );
546
    }
547
548
    return( retcode );
549
}
550
551
#endif
(-)src-native/src/ProbekitAgent/Instrumenter.h (+65 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#ifndef PROBEKIT_INSTRUMENTER_H
15
#define PROBEKIT_INSTRUMENTER_H
16
17
#include <malloc.h>
18
#include <MRTEResults.h>
19
20
namespace Martini { namespace ProbekitAgent {
21
                                  
22
class IInstrumenter       
23
{
24
public:
25
26
    typedef void* (*TMemoryAllocatorFunc)(unsigned int);
27
28
    virtual ~IInstrumenter() {}
29
        
30
    virtual TResult Initialize(const char* options) = 0;
31
    
32
    virtual TResult Instrument(TMemoryAllocatorFunc memAllocFunc,
33
							   const char* className,
34
                   	           const char* inClass, size_t inClassLength, 
35
                               char** outClass, size_t* outClassLength) = 0;
36
                            
37
	virtual void OnVMInit() = 0;                            
38
};
39
40
class CBCIInstrumenter : public IInstrumenter     
41
{
42
    bool m_initialized;
43
        
44
public:
45
    
46
    CBCIInstrumenter();
47
    virtual ~CBCIInstrumenter();
48
    
49
    virtual TResult Initialize(const char* options);
50
    
51
    // Instrument returns MRTE_RESULT_TRUE if instrumented,
52
    // MRTE_RESULT_FALSE if not instrumented, an error code
53
    // otherwise.
54
    virtual TResult Instrument(TMemoryAllocatorFunc memAllocFunc,
55
							   const char* className,
56
                               const char* inClass, size_t inClassLength, 
57
                               char** outClass, size_t* outClassLength); 
58
                            
59
	virtual void OnVMInit();
60
};
61
62
63
} /*namespace Martini*/  } /*namespace ProbekitAgent*/
64
65
#endif // PROBEKIT_INSTRUMENTER_H
(-)src-native/src/ProbekitAgent/VMInitEvent.cpp (+51 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#include "VMInitEvent.h"
15
#include "Globals.h"
16
#include "InstrumenterFactory.h"
17
#include "Instrumenter.h"
18
#include <log.h>
19
20
using namespace Martini::ProbekitAgent;
21
using namespace Martini::MPI;
22
23
CVMInitEvent::CVMInitEvent()
24
{}
25
26
CVMInitEvent::~CVMInitEvent()
27
{}
28
29
/*
30
 * Init	- initializes internal data and registers for VM init event	
31
 */
32
TResult CVMInitEvent::Init(IMpi *pMpiApi, TId clientId)
33
{
34
	m_pMpiApi	=	pMpiApi;
35
	m_clientId	=	clientId;
36
37
	// register for VM init event
38
	TResult res = m_pMpiApi->RegisterEvent(m_clientId, *this);
39
	return res;
40
}
41
42
/*
43
 * HandleEvent - callback function for VM init event	
44
 */
45
void CVMInitEvent::HandleEvent(SVmInitEventData &data)
46
{
47
    LOG_TRACE( PROFILER_NAME " VM Init" );
48
    
49
    CInstrumenterFactory::getInstrumenter()->OnVMInit();    
50
    CGlobals::Instance()->m_VMInitSeen = true;
51
}
(-)src-native/build/BuildProbekitAgent32.mak (+275 lines)
Added Link Here
1
# Microsoft Developer Studio Generated NMAKE File, Based on BuildProbekitAgent32.dsp
2
!IF "$(CFG)" == ""
3
CFG=BuildProbekitAgent32 - Win32 Debug
4
!MESSAGE No configuration specified. Defaulting to BuildProbekitAgent32 - Win32 Debug.
5
!ENDIF 
6
7
!IF "$(CFG)" != "BuildProbekitAgent32 - Win32 Release" && "$(CFG)" != "BuildProbekitAgent32 - Win32 Debug"
8
!MESSAGE Invalid configuration "$(CFG)" specified.
9
!MESSAGE You can specify a configuration when running NMAKE
10
!MESSAGE by defining the macro CFG on the command line. For example:
11
!MESSAGE 
12
!MESSAGE NMAKE /f "BuildProbekitAgent32.mak" CFG="BuildProbekitAgent32 - Win32 Debug"
13
!MESSAGE 
14
!MESSAGE Possible choices for configuration are:
15
!MESSAGE 
16
!MESSAGE "BuildProbekitAgent32 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
17
!MESSAGE "BuildProbekitAgent32 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
18
!MESSAGE 
19
!ERROR An invalid configuration is specified.
20
!ENDIF 
21
22
!IF "$(OS)" == "Windows_NT"
23
NULL=
24
!ELSE 
25
NULL=nul
26
!ENDIF 
27
28
CPP=cl.exe
29
MTL=midl.exe
30
RSC=rc.exe
31
32
!IF  "$(CFG)" == "BuildProbekitAgent32 - Win32 Release"
33
34
OUTDIR=.\..\bin\windows\release\IA-32
35
INTDIR=.\release\IA-32\ProbekitAgent
36
# Begin Custom Macros
37
OutDir=.\..\bin\windows\release\IA-32
38
# End Custom Macros
39
40
ALL : "$(OUTDIR)\ProbekitAgent.dll"
41
42
43
CLEAN :
44
	-@erase "$(INTDIR)\b64.obj"
45
	-@erase "$(INTDIR)\ClassFileLoadHookEvent.obj"
46
	-@erase "$(INTDIR)\ECAttachEvent.obj"
47
	-@erase "$(INTDIR)\ECDetachEvent.obj"
48
	-@erase "$(INTDIR)\ECStartEvent.obj"
49
	-@erase "$(INTDIR)\ECStopEvent.obj"
50
	-@erase "$(INTDIR)\Globals.obj"
51
	-@erase "$(INTDIR)\Instrumenter.obj"
52
	-@erase "$(INTDIR)\InstrumenterFactory.obj"
53
	-@erase "$(INTDIR)\ProbekitAgent.obj"
54
	-@erase "$(INTDIR)\Util.obj"
55
	-@erase "$(INTDIR)\vc60.idb"
56
	-@erase "$(INTDIR)\VMInitEvent.obj"
57
	-@erase "$(OUTDIR)\ProbekitAgent.dll"
58
	-@erase "$(OUTDIR)\ProbekitAgent.exp"
59
	-@erase "$(OUTDIR)\ProbekitAgent.lib"
60
61
"$(OUTDIR)" :
62
    if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
63
64
"$(INTDIR)" :
65
    if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)"
66
67
CPP_PROJ=/nologo /MT /W3 /GX /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "./../src/Martini/Infrastructure/Include" /I "./../include/JPIAgent" /I "./../include/Martini" /I "./../src/BaseProf" /I "./../src/Martini/Include" /I "../../../org.eclipse.hyades.probekit/src-native" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BUILDPROBEKITAGENT32_EXPORTS" /D "IA32_ARCH" /Fp"$(INTDIR)\BuildProbekitAgent32.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c 
68
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32 
69
BSC32=bscmake.exe
70
BSC32_FLAGS=/nologo /o"$(OUTDIR)\BuildProbekitAgent32.bsc" 
71
BSC32_SBRS= \
72
	
73
LINK32=link.exe
74
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  Ws2_32.lib  LibraryLoader.lib /nologo /dll /incremental:no /pdb:"$(OUTDIR)\ProbekitAgent.pdb" /machine:I386 /out:"$(OUTDIR)\ProbekitAgent.dll" /implib:"$(OUTDIR)\ProbekitAgent.lib" /libpath:"..\bin\windows\release\IA-32" 
75
LINK32_OBJS= \
76
	"$(INTDIR)\VMInitEvent.obj" \
77
	"$(INTDIR)\Util.obj" \
78
	"$(INTDIR)\ProbekitAgent.obj" \
79
	"$(INTDIR)\InstrumenterFactory.obj" \
80
	"$(INTDIR)\Instrumenter.obj" \
81
	"$(INTDIR)\Globals.obj" \
82
	"$(INTDIR)\ClassFileLoadHookEvent.obj" \
83
	"$(INTDIR)\b64.obj" \
84
	"$(INTDIR)\ECStopEvent.obj" \
85
	"$(INTDIR)\ECStartEvent.obj" \
86
	"$(INTDIR)\ECAttachEvent.obj" \
87
	"$(INTDIR)\ECDetachEvent.obj"
88
89
"$(OUTDIR)\ProbekitAgent.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
90
    $(LINK32) @<<
91
  $(LINK32_FLAGS) $(LINK32_OBJS)
92
<<
93
94
!ELSEIF  "$(CFG)" == "BuildProbekitAgent32 - Win32 Debug"
95
96
OUTDIR=.\..\bin\windows\debug\IA-32
97
INTDIR=.\debug\IA-32\ProbekitAgent
98
# Begin Custom Macros
99
OutDir=.\..\bin\windows\debug\IA-32
100
# End Custom Macros
101
102
ALL : "$(OUTDIR)\ProbekitAgent.dll"
103
104
105
CLEAN :
106
	-@erase "$(INTDIR)\b64.obj"
107
	-@erase "$(INTDIR)\ClassFileLoadHookEvent.obj"
108
	-@erase "$(INTDIR)\ECAttachEvent.obj"
109
	-@erase "$(INTDIR)\ECDetachEvent.obj"
110
	-@erase "$(INTDIR)\ECStartEvent.obj"
111
	-@erase "$(INTDIR)\ECStopEvent.obj"
112
	-@erase "$(INTDIR)\Globals.obj"
113
	-@erase "$(INTDIR)\Instrumenter.obj"
114
	-@erase "$(INTDIR)\InstrumenterFactory.obj"
115
	-@erase "$(INTDIR)\ProbekitAgent.obj"
116
	-@erase "$(INTDIR)\Util.obj"
117
	-@erase "$(INTDIR)\vc60.idb"
118
	-@erase "$(INTDIR)\vc60.pdb"
119
	-@erase "$(INTDIR)\VMInitEvent.obj"
120
	-@erase "$(OUTDIR)\ProbekitAgent.dll"
121
	-@erase "$(OUTDIR)\ProbekitAgent.exp"
122
	-@erase "$(OUTDIR)\ProbekitAgent.lib"
123
	-@erase "$(OUTDIR)\ProbekitAgent.pdb"
124
125
"$(OUTDIR)" :
126
    if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
127
128
"$(INTDIR)" :
129
    if not exist "$(INTDIR)/$(NULL)" mkdir "$(INTDIR)"
130
131
CPP_PROJ=/nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "./../src/Martini/Infrastructure/Include" /I "./../include/JPIAgent" /I "./../include/Martini" /I "./../src/BaseProf" /I "./../src/Martini/Include" /I "../../../org.eclipse.hyades.probekit/src-native" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "IA32_ARCH" /Fp"$(INTDIR)\BuildProbekitAgent32.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c 
132
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32 
133
BSC32=bscmake.exe
134
BSC32_FLAGS=/nologo /o"$(OUTDIR)\BuildProbekitAgent32.bsc" 
135
BSC32_SBRS= \
136
	
137
LINK32=link.exe
138
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib MartiniOSA.lib Ws2_32.lib LibraryLoader.lib /nologo /dll /incremental:no /pdb:"$(OUTDIR)\ProbekitAgent.pdb" /debug /machine:I386 /out:"$(OUTDIR)\ProbekitAgent.dll" /implib:"$(OUTDIR)\ProbekitAgent.lib" /pdbtype:sept /libpath:"..\bin\windows\debug\IA-32" 
139
LINK32_OBJS= \
140
	"$(INTDIR)\VMInitEvent.obj" \
141
	"$(INTDIR)\Util.obj" \
142
	"$(INTDIR)\ProbekitAgent.obj" \
143
	"$(INTDIR)\InstrumenterFactory.obj" \
144
	"$(INTDIR)\Instrumenter.obj" \
145
	"$(INTDIR)\Globals.obj" \
146
	"$(INTDIR)\ClassFileLoadHookEvent.obj" \
147
	"$(INTDIR)\b64.obj" \
148
	"$(INTDIR)\ECStopEvent.obj" \
149
	"$(INTDIR)\ECStartEvent.obj" \
150
	"$(INTDIR)\ECAttachEvent.obj" \
151
	"$(INTDIR)\ECDetachEvent.obj"
152
153
"$(OUTDIR)\ProbekitAgent.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
154
    $(LINK32) @<<
155
  $(LINK32_FLAGS) $(LINK32_OBJS)
156
<<
157
158
!ENDIF 
159
160
.c{$(INTDIR)}.obj::
161
   $(CPP) @<<
162
   $(CPP_PROJ) $< 
163
<<
164
165
.cpp{$(INTDIR)}.obj::
166
   $(CPP) @<<
167
   $(CPP_PROJ) $< 
168
<<
169
170
.cxx{$(INTDIR)}.obj::
171
   $(CPP) @<<
172
   $(CPP_PROJ) $< 
173
<<
174
175
.c{$(INTDIR)}.sbr::
176
   $(CPP) @<<
177
   $(CPP_PROJ) $< 
178
<<
179
180
.cpp{$(INTDIR)}.sbr::
181
   $(CPP) @<<
182
   $(CPP_PROJ) $< 
183
<<
184
185
.cxx{$(INTDIR)}.sbr::
186
   $(CPP) @<<
187
   $(CPP_PROJ) $< 
188
<<
189
190
191
!IF "$(NO_EXTERNAL_DEPS)" != "1"
192
!IF EXISTS("BuildProbekitAgent32.dep")
193
!INCLUDE "BuildProbekitAgent32.dep"
194
!ELSE 
195
!MESSAGE Warning: cannot find "BuildProbekitAgent32.dep"
196
!ENDIF 
197
!ENDIF 
198
199
200
!IF "$(CFG)" == "BuildProbekitAgent32 - Win32 Release" || "$(CFG)" == "BuildProbekitAgent32 - Win32 Debug"
201
SOURCE=..\src\ProbekitAgent\b64.c
202
203
"$(INTDIR)\b64.obj" : $(SOURCE) "$(INTDIR)"
204
	$(CPP) $(CPP_PROJ) $(SOURCE)
205
206
207
SOURCE=..\src\ProbekitAgent\ClassFileLoadHookEvent.cpp
208
209
"$(INTDIR)\ClassFileLoadHookEvent.obj" : $(SOURCE) "$(INTDIR)"
210
	$(CPP) $(CPP_PROJ) $(SOURCE)
211
212
213
SOURCE=..\src\ProbekitAgent\ECAttachEvent.cpp
214
215
"$(INTDIR)\ECAttachEvent.obj" : $(SOURCE) "$(INTDIR)"
216
	$(CPP) $(CPP_PROJ) $(SOURCE)
217
218
219
SOURCE=..\src\ProbekitAgent\ECDetachEvent.cpp
220
221
"$(INTDIR)\ECDetachEvent.obj" : $(SOURCE) "$(INTDIR)"
222
	$(CPP) $(CPP_PROJ) $(SOURCE)
223
224
225
SOURCE=..\src\ProbekitAgent\ECStartEvent.cpp
226
227
"$(INTDIR)\ECStartEvent.obj" : $(SOURCE) "$(INTDIR)"
228
	$(CPP) $(CPP_PROJ) $(SOURCE)
229
230
231
SOURCE=..\src\ProbekitAgent\ECStopEvent.cpp
232
233
"$(INTDIR)\ECStopEvent.obj" : $(SOURCE) "$(INTDIR)"
234
	$(CPP) $(CPP_PROJ) $(SOURCE)
235
236
237
SOURCE=..\src\ProbekitAgent\Globals.cpp
238
239
"$(INTDIR)\Globals.obj" : $(SOURCE) "$(INTDIR)"
240
	$(CPP) $(CPP_PROJ) $(SOURCE)
241
242
243
SOURCE=..\src\ProbekitAgent\Instrumenter.cpp
244
245
"$(INTDIR)\Instrumenter.obj" : $(SOURCE) "$(INTDIR)"
246
	$(CPP) $(CPP_PROJ) $(SOURCE)
247
248
249
SOURCE=..\src\ProbekitAgent\InstrumenterFactory.cpp
250
251
"$(INTDIR)\InstrumenterFactory.obj" : $(SOURCE) "$(INTDIR)"
252
	$(CPP) $(CPP_PROJ) $(SOURCE)
253
254
255
SOURCE=..\src\ProbekitAgent\ProbekitAgent.cpp
256
257
"$(INTDIR)\ProbekitAgent.obj" : $(SOURCE) "$(INTDIR)"
258
	$(CPP) $(CPP_PROJ) $(SOURCE)
259
260
261
SOURCE=..\src\ProbekitAgent\Util.cpp
262
263
"$(INTDIR)\Util.obj" : $(SOURCE) "$(INTDIR)"
264
	$(CPP) $(CPP_PROJ) $(SOURCE)
265
266
267
SOURCE=..\src\ProbekitAgent\VMInitEvent.cpp
268
269
"$(INTDIR)\VMInitEvent.obj" : $(SOURCE) "$(INTDIR)"
270
	$(CPP) $(CPP_PROJ) $(SOURCE)
271
272
273
274
!ENDIF 
275
(-)src-native/src/ProbekitAgent/b64test.cpp (+41 lines)
Added Link Here
1
#include "tptp/TPTPUtils.h"
2
#include <stdio.h>
3
#include <string.h>
4
#include <malloc.h>
5
#include <assert.h>
6
7
char buff[] = 
8
"3srswAAAAA1tLnByb2Jlc2NyaXB0AAAAblJFTSB1bm5hbWVkX3Byb2JlClBST0JFClJVTEUgKiBK\n"
9
"VGVzdCAqICogaW5jbHVkZQpSVUxFICogKiAqICogZXhjbHVkZQpSRUYgT05FTlRSWSBtX3Byb2Jl\n"
10
"JFByb2JlXzAgX2VudHJ5ICgpViAKAAAAB21fcHJvYmUAAAD+yv66vgAAADEAEQoAAwANBwAOBwAP\n"
11
"BwAQAQAHUHJvYmVfMAEADElubmVyQ2xhc3NlcwEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5l\n"
12
"TnVtYmVyVGFibGUBAApTb3VyY2VGaWxlAQAMbV9wcm9iZS5qYXZhDAAHAAgBAAdtX3Byb2JlAQAQ\n"
13
"amF2YS9sYW5nL09iamVjdAEAD21fcHJvYmUkUHJvYmVfMAAgAAIAAwAAAAAAAQAAAAcACAABAAkA\n"
14
"AAAhAAEAAQAAAAUqtwABsQAAAAEACgAAAAoAAgAAAAcABAAJAAIACwAAAAIADAAGAAAACgABAAQA\n"
15
"AgAFAAkAAAAPbV9wcm9iZSRQcm9iZV8wAAAB0cr+ur4AAAAxACAKAAYADgkADwAQCAARCgASABMH\n"
16
"ABUHABgBAAY8aW5pdD4BAAMoKVYBAARDb2RlAQAPTGluZU51bWJlclRhYmxlAQAGX2VudHJ5AQAK\n"
17
"U291cmNlRmlsZQEADG1fcHJvYmUuamF2YQwABwAIBwAZDAAaABsBABJIZWxsbyBmcm9tIHByb2Jl\n"
18
"IQoHABwMAB0AHgcAHwEAD21fcHJvYmUkUHJvYmVfMAEAB1Byb2JlXzABAAxJbm5lckNsYXNzZXMB\n"
19
"ABBqYXZhL2xhbmcvT2JqZWN0AQAQamF2YS9sYW5nL1N5c3RlbQEAA291dAEAFUxqYXZhL2lvL1By\n"
20
"aW50U3RyZWFtOwEAE2phdmEvaW8vUHJpbnRTdHJlYW0BAAdwcmludGxuAQAVKExqYXZhL2xhbmcv\n"
21
"U3RyaW5nOylWAQAHbV9wcm9iZQAhAAUABgAAAAAAAgABAAcACAABAAkAAAAdAAEAAQAAAAUqtwAB\n"
22
"sQAAAAEACgAAAAYAAQAAAAkACQALAAgAAQAJAAAAJQACAAAAAAAJsgACEgO2AASxAAAAAQAKAAAA\n"
23
"CgACAAAADgAIABAAAgAMAAAAAgANABcAAAAKAAEABQAUABYACQ==";
24
25
26
int main()
27
{
28
	int len = strlen( buff );
29
	
30
	char* out = (char*)malloc( len );
31
	int decoded = 
32
		tptp_decodeBase64( (tptp_string*)buff, len, (unsigned char*)out, len );
33
		
34
	printf("base64 len = %d, decoded: %d\n", len, decoded );
35
		
36
	assert( decoded == 892 );
37
	//fwrite( out, decoded, 1, stdout );
38
	
39
	return 0;		
40
	
41
}
(-)src-native/src/ProbekitAgent/Util.cpp (+137 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#include "Util.h"
15
#include "ProbekitAgent.h"
16
17
#include <log.h>
18
19
#ifdef _UNIX_
20
#define FILE_SEPARATOR '/'
21
#else
22
#define FILE_SEPARATOR '\\'
23
#endif
24
25
// tmp - use b64.c until tptp_decodeBase64() starts working
26
extern "C" int decode_buffer( const char* inBuffer, int inLen, char* outBuffer);
27
28
namespace Martini { namespace ProbekitAgent { namespace Util {
29
30
void DumpBuffer( const char* dir, const char* fileName, 
31
				 const char* buffer, int len )
32
{
33
	if( dir ) {
34
		char* fileNameClean = strdup( fileName );
35
		
36
		// replace all slashes
37
		char* p = fileNameClean;
38
		while( *p ) {
39
			if( *p == FILE_SEPARATOR ) *p = '_';
40
			p++;
41
		}
42
		
43
		char* path = (char*)malloc( strlen(dir) + strlen(fileName) + 16 );
44
		sprintf( path, "%s%c%s.dump", dir, FILE_SEPARATOR, fileNameClean );
45
    
46
    	FILE* handle = fopen( path, "wb+" );    	
47
    	if( handle == 0 ) {
48
     		LOG_ERROR( PROFILER_NAME " can't create dump file " << path );
49
     		free( path );
50
     		return;   
51
		}
52
    	fwrite( buffer, len, 1, handle );
53
	    fclose( handle );
54
	    
55
	    free( fileNameClean );
56
	    free( path );	    
57
	}
58
}
59
60
// caller must free result
61
void ReadFile( const char* fname, char*& result, int& resultLen )
62
{
63
	resultLen = 0;
64
	
65
	FILE* handle = fopen( fname, "r" );
66
	if( handle == 0 ) {
67
		LOG_ERROR( PROFILER_NAME " can't open " << fname );
68
		return;
69
	}
70
	
71
	fseek(handle, 0L, SEEK_END);
72
	long len = ftell( handle );
73
	LOG_TRACE( PROFILER_NAME " length of probescript file is " << len ); 
74
    if( len < 1 ) {
75
    	fclose( handle );
76
		return;
77
    }	
78
    fseek(handle, 0L, SEEK_SET);
79
    
80
    result = (char*)malloc( len + 1 );
81
    resultLen = fread( result, 1, len, handle );
82
    LOG_TRACE( PROFILER_NAME " read " << resultLen );
83
    result[ resultLen ] = 0;
84
85
	// remove     
86
    char* ptr = result;
87
    while( *ptr ) {
88
		if( *ptr == '\n') {
89
			*ptr = 0;
90
		}
91
		ptr++;
92
	}
93
    
94
    fclose( handle );
95
    return;
96
}
97
98
99
#define CMDLINE_PARAM_NAME_SEPARATOR '='
100
#define CMDLINE_PARAM_SEPARATOR ','
101
102
// caller must free result
103
char* GetCmdlineOption( const char* options, const char* name )
104
{
105
	char* result = NULL;
106
	const char* p0 = strstr( options, name );
107
	if(	p0 ) {
108
		p0 = strchr( p0, CMDLINE_PARAM_NAME_SEPARATOR );
109
		if( p0 && *(++p0) ) {
110
			const char* p1 = strchr( p0, CMDLINE_PARAM_SEPARATOR );
111
			int len = p1 ? (p1 - p0) : strlen(p0);
112
			result = (char*)malloc( len + 1 );
113
			strncpy( result, p0, len );
114
			result[ len ] = 0;
115
		}
116
	}
117
	
118
	return result;
119
}
120
// tmp - use b64.c until tptp_decodeBase64() starts working
121
int DecodeBuffer( const char* inBuffer, int inLen, char* outBuffer)
122
{
123
	return decode_buffer( inBuffer, inLen, outBuffer );
124
}
125
126
char* StrNDup( const char* src, int len )
127
{
128
	char* dst = (char*)malloc( len + 1 );
129
	if( dst == 0 ) {
130
		return 0;
131
	}
132
	memcpy( dst, src, len );
133
    dst[ len ] = 0;
134
	return dst;
135
}	
136
137
} /*namespace Martini*/  } /*namespace ProbekitAgent*/ } /*namespace Util*/
(-)src-native/src/ProbekitAgent/ProbekitAgent.cpp (+219 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#include "ProbekitAgent.h"
15
#include "InstrumenterFactory.h"
16
#include "Instrumenter.h"
17
18
// Martini
19
#include "LibraryLoader.h"
20
#include "log.h"
21
22
using namespace Martini;
23
using namespace Martini::MPI;
24
using namespace Martini::OSA;
25
using namespace Martini::JPIAgent;
26
using namespace Martini::ProbekitAgent;
27
28
using namespace std;
29
30
static Martini::ProbekitAgent::CProbekitAgent probekitAgent;
31
32
/////////////////////////////////////////////////////////////////
33
34
Martini::OSA::IThreadSync* lockObject = Martini::OSA::CreateThreadSync();
35
36
/////////////////////////////////////////////////////////////////
37
38
39
/*
40
 *    MPICL_Instantiate - The profiler initialization method. 
41
 *    The profiler initializes itself and registers for MPI events 
42
 */
43
extern "C" API_EXPORT TResult 
44
MPICL_Instantiate(IMpi *pMpiApi, TId clientId, const char *szOptions)
45
{
46
    LOG_TRACE(PROFILER_NAME " MPICL_Instantiate");
47
       
48
    LOG_ASSERT(pMpiApi != 0);
49
    LOG_ASSERT(clientId != 0);
50
        
51
    TResult retVal = probekitAgent.Init(pMpiApi, clientId, szOptions);
52
    if (MRTE_FAILED(retVal))
53
    {
54
        return MRTE_ERROR_FAIL;
55
    }
56
    
57
    IInstrumenter* instrumenter =
58
    	CInstrumenterFactory::getInstrumenter();
59
	if( instrumenter ) {
60
    	retVal = instrumenter->Initialize(szOptions);        
61
	} else {
62
		            
63
        LOG_ERROR( "Can't create instrumenter" );
64
        retVal = MRTE_ERROR_FAIL;
65
           
66
    } 
67
    LOG_TRACE(PROFILER_NAME " MPICL_Instantiate done");
68
    return retVal;
69
}
70
71
//=======================================================================================
72
73
CProbekitAgent* CProbekitAgent::getInstance()
74
{
75
	return &probekitAgent;
76
}
77
78
CProbekitAgent::CProbekitAgent()
79
  : ec_env( NULL )
80
{
81
}
82
83
CProbekitAgent::~CProbekitAgent()
84
{
85
}
86
87
/*
88
 * InitEvents - initialize object event - register events
89
 */
90
91
TResult CProbekitAgent::Init(MPI::IMpi *pMpiApi, MPI::TId clientId, 
92
                             const char *szOptions)
93
{
94
    TResult retVal;    
95
96
    m_pMpiApi   =   pMpiApi;
97
    m_clientId  =   clientId;
98
99
	retVal = InitEC();
100
    if (MRTE_FAILED(retVal))
101
    {
102
    	LOG_ERROR( PROFILER_NAME " error initializing EC");
103
        return retVal;
104
    }
105
    
106
    retVal = InitEvents();
107
    if (MRTE_FAILED(retVal))
108
    {
109
    	LOG_ERROR( PROFILER_NAME " error registering events");
110
        return retVal;
111
    }
112
        
113
    retVal = BindJpiFunctions();
114
    if (MRTE_FAILED(retVal))
115
    {
116
    	LOG_ERROR( PROFILER_NAME " failed to bind JPI exported functions");
117
    }    
118
119
    return retVal;                               
120
}
121
122
/*
123
 * InitEvents - initialize object event - register events
124
 */
125
TResult CProbekitAgent::InitEvents()
126
{
127
    TResult retVal;    
128
129
	// EC stop event; Martini RT will sleep
130
	// in this event initialization
131
	retVal = m_ECAttachHandler.Init(m_pMpiApi, m_clientId);
132
    if (MRTE_FAILED(retVal))
133
    {
134
        return retVal;
135
    }
136
	
137
	retVal = m_ECDetachHandler.Init(m_pMpiApi, m_clientId);
138
    if (MRTE_FAILED(retVal))
139
    {
140
        return retVal;
141
    }
142
	
143
	retVal = m_ECStartHandler.Init(m_pMpiApi, m_clientId);
144
    if (MRTE_FAILED(retVal))
145
    {
146
        return retVal;
147
    }
148
149
	retVal = m_ECStopHandler.Init(m_pMpiApi, m_clientId);
150
    if (MRTE_FAILED(retVal))
151
    {
152
        return retVal;
153
    }
154
155
    retVal = m_ClassFileLoadHookHandler.Init(m_pMpiApi, m_clientId);
156
    if (MRTE_FAILED(retVal))
157
    {
158
        return retVal;
159
    }
160
161
    retVal = m_VMInitHandler.Init(m_pMpiApi, m_clientId);
162
    if (MRTE_FAILED(retVal))
163
    {
164
        return retVal;
165
    }
166
                       
167
    return MRTE_RESULT_OK;
168
}
169
170
/*
171
 * BindJpiFunctions - bind required exported JPI functions
172
 */
173
TResult CProbekitAgent::BindJpiFunctions()
174
{
175
    ILibraryLoader *pJpiLoader = LoadBistroLibrary("JPI");
176
    if (!pJpiLoader)
177
    {
178
        return MRTE_ERROR_FAIL;
179
    }
180
181
    CGlobals::Instance()->pfnJPI_AttachCurrentThread = 
182
        (TJpiAttachCurrentThread)pJpiLoader->GetEntry("JPI_AttachCurrentThread");
183
    if (!CGlobals::Instance()->pfnJPI_AttachCurrentThread)
184
    {
185
        return MRTE_ERROR_FAIL;
186
    }
187
188
    CGlobals::Instance()->pfnJPI_DetachCurrentThread = 
189
        (TJpiDetachCurrentThread)pJpiLoader->GetEntry("JPI_DetachCurrentThread");
190
    if (!CGlobals::Instance()->pfnJPI_DetachCurrentThread)
191
    {
192
        return MRTE_ERROR_FAIL;
193
    }
194
    
195
    pJpiLoader->Destroy();
196
197
    return MRTE_RESULT_OK;
198
}
199
200
TResult CProbekitAgent::InitEC()
201
{
202
  	LOG_TRACE( PROFILER_NAME " InitEC");
203
204
    Martini::OSA::ILibraryLoader* libraryLoader;
205
    libraryLoader = CreateLibraryLoader("JPIAgent", 0);
206
    if (libraryLoader == 0) {
207
        return MRTE_ERROR_OSA_FAILURE;
208
    }
209
    GetEC_Env_t ecpEnv = (GetEC_Env_t)(libraryLoader->GetEntry("GetEC_Env"));
210
    if (ecpEnv == 0) {
211
        return MRTE_ERROR_OSA_FAILURE;
212
    }
213
    
214
    (*ecpEnv)(PROFILER_NAME, &ec_env);       
215
216
	libraryLoader->Destroy();
217
    
218
    return MRTE_RESULT_OK;
219
}
(-)src-native/build/BuildProbekitAgent32.dsp (+195 lines)
Added Link Here
1
# Microsoft Developer Studio Project File - Name="BuildProbekitAgent32" - Package Owner=<4>
2
# Microsoft Developer Studio Generated Build File, Format Version 6.00
3
# ** DO NOT EDIT **
4
5
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
6
7
CFG=BuildProbekitAgent32 - Win32 Debug
8
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
9
!MESSAGE use the Export Makefile command and run
10
!MESSAGE 
11
!MESSAGE NMAKE /f "BuildProbekitAgent32.mak".
12
!MESSAGE 
13
!MESSAGE You can specify a configuration when running NMAKE
14
!MESSAGE by defining the macro CFG on the command line. For example:
15
!MESSAGE 
16
!MESSAGE NMAKE /f "BuildProbekitAgent32.mak" CFG="BuildProbekitAgent32 - Win32 Debug"
17
!MESSAGE 
18
!MESSAGE Possible choices for configuration are:
19
!MESSAGE 
20
!MESSAGE "BuildProbekitAgent32 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
21
!MESSAGE "BuildProbekitAgent32 - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
22
!MESSAGE 
23
24
# Begin Project
25
# PROP AllowPerConfigDependencies 0
26
# PROP Scc_ProjName ""
27
# PROP Scc_LocalPath ""
28
CPP=cl.exe
29
MTL=midl.exe
30
RSC=rc.exe
31
32
!IF  "$(CFG)" == "BuildProbekitAgent32 - Win32 Release"
33
34
# PROP BASE Use_MFC 0
35
# PROP BASE Use_Debug_Libraries 0
36
# PROP BASE Output_Dir "Release"
37
# PROP BASE Intermediate_Dir "Release"
38
# PROP BASE Target_Dir ""
39
# PROP Use_MFC 0
40
# PROP Use_Debug_Libraries 0
41
# PROP Output_Dir "..\bin\windows\release\IA-32"
42
# PROP Intermediate_Dir "release\IA-32\ProbekitAgent"
43
# PROP Ignore_Export_Lib 0
44
# PROP Target_Dir ""
45
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BUILDPROBEKITAGENT32_EXPORTS" /YX /FD /c
46
# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "./../src/Martini/Infrastructure/Include" /I "./../include/JPIAgent" /I "./../include/Martini" /I "./../src/BaseProf" /I "./../src/Martini/Include" /I "../../../org.eclipse.hyades.probekit/src-native" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BUILDPROBEKITAGENT32_EXPORTS" /D "IA32_ARCH" /YX /FD /c
47
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
48
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
49
# ADD BASE RSC /l 0x409 /d "NDEBUG"
50
# ADD RSC /l 0x409 /d "NDEBUG"
51
BSC32=bscmake.exe
52
# ADD BASE BSC32 /nologo
53
# ADD BSC32 /nologo
54
LINK32=link.exe
55
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
56
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib  Ws2_32.lib  LibraryLoader.lib /nologo /dll /machine:I386 /out:"..\bin\windows\release\IA-32\ProbekitAgent.dll" /libpath:"..\bin\windows\release\IA-32"
57
58
!ELSEIF  "$(CFG)" == "BuildProbekitAgent32 - Win32 Debug"
59
60
# PROP BASE Use_MFC 0
61
# PROP BASE Use_Debug_Libraries 1
62
# PROP BASE Output_Dir "BuildProbekitAgent32___Win32_Debug"
63
# PROP BASE Intermediate_Dir "BuildProbekitAgent32___Win32_Debug"
64
# PROP BASE Target_Dir ""
65
# PROP Use_MFC 0
66
# PROP Use_Debug_Libraries 1
67
# PROP Output_Dir "..\bin\windows\debug\IA-32"
68
# PROP Intermediate_Dir "debug\IA-32\ProbekitAgent"
69
# PROP Ignore_Export_Lib 0
70
# PROP Target_Dir ""
71
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BUILDPROBEKITAGENT32_EXPORTS" /YX /FD /GZ /c
72
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_HOME)\include" /I "$(JAVA_HOME)\include\win32" /I "./../src/Martini/Infrastructure/Include" /I "./../include/JPIAgent" /I "./../include/Martini" /I "./../src/BaseProf" /I "./../src/Martini/Include" /I "../../../org.eclipse.hyades.probekit/src-native" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "IA32_ARCH" /YX /FD /GZ /c
73
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
74
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
75
# ADD BASE RSC /l 0x409 /d "_DEBUG"
76
# ADD RSC /l 0x409 /d "_DEBUG"
77
BSC32=bscmake.exe
78
# ADD BASE BSC32 /nologo
79
# ADD BSC32 /nologo
80
LINK32=link.exe
81
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
82
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib MartiniOSA.lib Ws2_32.lib LibraryLoader.lib /nologo /dll /incremental:no /debug /machine:I386 /out:"..\bin\windows\debug\IA-32\ProbekitAgent.dll" /pdbtype:sept /libpath:"..\bin\windows\debug\IA-32"
83
84
!ENDIF 
85
86
# Begin Target
87
88
# Name "BuildProbekitAgent32 - Win32 Release"
89
# Name "BuildProbekitAgent32 - Win32 Debug"
90
# Begin Group "Source Files"
91
92
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
93
# Begin Source File
94
95
SOURCE=..\src\ProbekitAgent\b64.c
96
# End Source File
97
# Begin Source File
98
99
SOURCE=..\src\ProbekitAgent\ClassFileLoadHookEvent.cpp
100
# End Source File
101
# Begin Source File
102
103
SOURCE=..\src\ProbekitAgent\ECAttachEvent.cpp
104
# End Source File
105
# Begin Source File
106
107
SOURCE=..\src\ProbekitAgent\ECDetachEvent.cpp
108
# End Source File
109
# Begin Source File
110
111
SOURCE=..\src\ProbekitAgent\ECStartEvent.cpp
112
# End Source File
113
# Begin Source File
114
115
SOURCE=..\src\ProbekitAgent\ECStopEvent.cpp
116
# End Source File
117
# Begin Source File
118
119
SOURCE=..\src\ProbekitAgent\Globals.cpp
120
# End Source File
121
# Begin Source File
122
123
SOURCE=..\src\ProbekitAgent\Instrumenter.cpp
124
# End Source File
125
# Begin Source File
126
127
SOURCE=..\src\ProbekitAgent\InstrumenterFactory.cpp
128
# End Source File
129
# Begin Source File
130
131
SOURCE=..\src\ProbekitAgent\ProbekitAgent.cpp
132
# End Source File
133
# Begin Source File
134
135
SOURCE=..\src\ProbekitAgent\Util.cpp
136
# End Source File
137
# Begin Source File
138
139
SOURCE=..\src\ProbekitAgent\VMInitEvent.cpp
140
# End Source File
141
# End Group
142
# Begin Group "Header Files"
143
144
# PROP Default_Filter "h;hpp;hxx;hm;inl"
145
# Begin Source File
146
147
SOURCE=..\src\ProbekitAgent\ClassFileLoadHookEvent.h
148
# End Source File
149
# Begin Source File
150
151
SOURCE=..\src\ProbekitAgent\ECAttachEvent.h
152
# End Source File
153
# Begin Source File
154
155
SOURCE=..\src\ProbekitAgent\ECDetachEvent.h
156
# End Source File
157
# Begin Source File
158
159
SOURCE=..\src\ProbekitAgent\ECStartEvent.h
160
# End Source File
161
# Begin Source File
162
163
SOURCE=..\src\ProbekitAgent\ECStopEvent.h
164
# End Source File
165
# Begin Source File
166
167
SOURCE=..\src\ProbekitAgent\Globals.h
168
# End Source File
169
# Begin Source File
170
171
SOURCE=..\src\ProbekitAgent\Instrumenter.h
172
# End Source File
173
# Begin Source File
174
175
SOURCE=..\src\ProbekitAgent\InstrumenterFactory.h
176
# End Source File
177
# Begin Source File
178
179
SOURCE=..\src\ProbekitAgent\ProbekitAgent.h
180
# End Source File
181
# Begin Source File
182
183
SOURCE=..\src\ProbekitAgent\Util.h
184
# End Source File
185
# Begin Source File
186
187
SOURCE=..\src\ProbekitAgent\VMInitEvent.h
188
# End Source File
189
# End Group
190
# Begin Group "Resource Files"
191
192
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
193
# End Group
194
# End Target
195
# End Project
(-)src-native/src/ProbekitAgent/Makefile (+62 lines)
Added Link Here
1
#/************************************************************************
2
# * Copyright (c) 2007 OC Systems Inc.
3
# * All rights reserved. This program and the accompanying materials
4
# * are made available under the terms of the Eclipse Public License v1.0
5
# * which accompanies this distribution, and is available at
6
# * http://www.eclipse.org/legal/epl-v10.html
7
# *
8
# * Contributors:
9
# *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
# *
11
# * $Id:$ 
12
# ************************************************************************/
13
 
14
ROOTDIR = ../..
15
16
include $(ROOTDIR)/src/makefile.inc
17
18
INCLUDES = -I ../../include/JPIAgent \
19
	-I ../../include/Martini \
20
	-I ../../src/BaseProf \
21
	-I ../../src/Martini/Include \
22
	-I ../../src/Martini/Infrastructure/Include \
23
	-I ../../../../org.eclipse.hyades.probekit/src-native \
24
	-I $(TPTP_ACSDK_HOME)/include \
25
	-I $(JAVA_HOME)/include -I $(JAVA_HOME)/include/linux
26
27
OBJS = 	\
28
	$(OBJDIR)/b64.o \
29
	$(OBJDIR)/ProbekitAgent.o \
30
	$(OBJDIR)/InstrumenterFactory.o \
31
	$(OBJDIR)/Instrumenter.o \
32
	$(OBJDIR)/ClassFileLoadHookEvent.o \
33
	$(OBJDIR)/VMInitEvent.o \
34
	$(OBJDIR)/Globals.o \
35
	$(OBJDIR)/ECAttachEvent.o \
36
	$(OBJDIR)/ECDetachEvent.o \
37
	$(OBJDIR)/ECStartEvent.o \
38
	$(OBJDIR)/ECStopEvent.o \
39
	$(OBJDIR)/Util.o
40
41
LIB = libProbekitAgent.so
42
43
VER_FILE = ProbekitAgent.ver
44
45
all: release
46
47
release: $(OBJDIR) $(OUTDIR)/$(LIB)
48
49
$(OBJDIR): 
50
	mkdir -p $(OBJDIR) ; mkdir -p $(OUTDIR)
51
52
clean: 
53
	rm -rf $(OBJS) $(OUTDIR)/$(LIB)
54
55
include ./Makefile.dep
56
57
$(OUTDIR)/$(LIB): $(OBJS)
58
	$(CPP_LINK) $(OBJS) -Wall -o $@ -L../../bin/linux/release/IA-32 -L$(OUTDIR) -lMartiniOSA \
59
	../../bin/linux/release/IA-32/LibraryLoader.a \
60
	-L $(TPTP_ACSDK_HOME)/lib -ltptpUtils \
61
 	-lpthread -ldl $(STD_LIBS) $(VER_SCR)
62
(-)src-native/src/ProbekitAgent/VMInitEvent.h (+45 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#ifndef PROBEKIT_VM_INIT_H
15
#define PROBEKIT_VM_INIT_H
16
17
#include "MpiAPI.h"
18
19
namespace Martini { namespace ProbekitAgent {
20
21
	// CVMInitEvent - represents a VM init event 
22
	class CVMInitEvent : public MPI::IVmInitEventObserver
23
	{
24
	public:
25
		CVMInitEvent();
26
		~CVMInitEvent();
27
28
        // Initialization - Register to event
29
		TResult Init(MPI::IMpi *pMpiApi, MPI::TId clientId);
30
        
31
        // Event handler
32
        void HandleEvent(MPI::SVmInitEventData &data);
33
34
	private:
35
		// Pointer to the MPI implementation
36
        MPI::IMpi *m_pMpiApi;
37
38
        // Client id for MPI requests
39
	    MPI::TId m_clientId;
40
	};
41
42
} /*namespace Martini*/  } /*namespace ProbekitAgent*/
43
44
#endif	// PROBEKIT_VM_INIT_H
45
(-)src-native/src/ProbekitAgent/Globals.cpp (+16 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#include "Globals.h"
15
16
Martini::ProbekitAgent::CGlobals* Martini::ProbekitAgent::CGlobals::s_pInstance = 0;
(-)src-native/src/ProbekitAgent/ECStopEvent.h (+38 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#ifndef PROBEKIT_ECStop_EVENT_H_
15
#define PROBEKIT_ECStop_EVENT_H_
16
17
#include "MpiAPI.h"
18
19
namespace Martini { namespace ProbekitAgent {
20
21
    // CStopEvent - represents a Stop event 
22
	class CECStopEvent : public MPI::IEcStopEventObserver
23
    {
24
    public:
25
        // Constructor
26
        CECStopEvent();
27
        // Destructor
28
        ~CECStopEvent();
29
        
30
        // Initialization - Register to event
31
        TResult Init(MPI::IMpi *pMpiApi, MPI::TId clientId);
32
        // Inherited methods
33
        void HandleEvent();
34
    };
35
36
} /*namespace Martini*/ } /*namespace ProbekitAgent*/
37
38
#endif // PROBEKIT_ECStop_EVENT_H_
(-)src-native/src/ProbekitAgent/README (+24 lines)
Added Link Here
1
ProbekitAgent implements load-time instrumentation using the old
2
TPTP BCI engine.
3
4
Invocation: 
5
6
#java -cp ".;C:\Documents and Settings\Vsevolod\Desktop\tptp\probe"  "-agentlib:JPIBootLoader=JPIAgent:server=standalone;ProbekitAgent:ext-pk-BCILibraryName=BCIEngProbe,ext-pk-probescript=..\..\probe\m.probescript"  JTest
7
8
#java "-agentlib:JPIBootLoader=JPIAgent:server=controlled;ProbekitAgent"  JTest
9
 
10
Command line parameters:
11
12
ext-pk-BCILibraryName
13
	optional; specifies base name of BCI library,
14
	default value "BCIEngProbe"
15
ext-pk-probescript
16
	optional; standalone mode; specifies  
17
	.probescript file
18
ext-pk-dump
19
	optional; specifies location to write temporary dump files
20
	
21
Built and tested on linux x86 and windows ia32.
22
 
23
24
(-)src-native/src/ProbekitAgent/Util.h (+40 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#ifndef _PROBEKIT_UTIL_H
15
#define _PROBEKIT_UTIL_H
16
17
#define PROFILER_NAME "PROBEKIT"
18
19
namespace Martini { namespace ProbekitAgent { namespace Util {
20
		
21
	// Dump buffer to location specified by dir;
22
	// Do nothing if the location is null.
23
	void DumpBuffer( const char* dir, const char* fileName, 
24
				     const char* buffer, int len );
25
26
	// Read file into a buffer; caller must free result
27
	void ReadFile( const char* fname, char*& result, int& resultLen );
28
29
	// parse options, look for specified name
30
	char* GetCmdlineOption( const char* options, const char* name );	
31
	
32
	// return decoded length	
33
	int DecodeBuffer( const char* inBuffer, int inLen, char* outBuffer);
34
	
35
	// malloc a new string, strcpy len bytes, add zero
36
	char* StrNDup( const char* src, int len );
37
			
38
} /*namespace Martini*/  } /*namespace ProbekitAgent*/ } /*namespace Util*/
39
40
#endif // _PROBEKIT_UTIL_H
(-)src-native/src/ProbekitAgent/Globals.h (+51 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#ifndef PROBEKIT_GLOBALS_H
15
#define PROBEKIT_GLOBALS_H
16
17
#include "JPI.H"
18
19
#define PROFILER_NAME "PROBEKIT"
20
21
namespace Martini { namespace ProbekitAgent {
22
23
    class CGlobals
24
    {
25
    public:
26
        static CGlobals* Instance() 
27
        {
28
            if (0 == s_pInstance)
29
            {
30
                s_pInstance = new CGlobals();
31
            }
32
            return s_pInstance;
33
        }
34
35
        TJpiAttachCurrentThread pfnJPI_AttachCurrentThread;
36
        TJpiDetachCurrentThread pfnJPI_DetachCurrentThread;
37
        
38
        bool m_VMInitSeen;
39
40
    protected:
41
        static CGlobals* s_pInstance;
42
43
        CGlobals(): 
44
            pfnJPI_AttachCurrentThread(0), pfnJPI_DetachCurrentThread(0),
45
            m_VMInitSeen(false)
46
            {}
47
48
    };
49
}}
50
#endif // PROBEKIT_GLOBALS_H
51
(-)src-native/src/ProbekitAgent/ECDetachEvent.cpp (+37 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#include "ECDetachEvent.h"
15
#include "Globals.h"
16
#include <log.h>
17
18
using namespace Martini::ProbekitAgent;
19
using namespace Martini::MPI;
20
21
CECDetachEvent::CECDetachEvent(){}
22
23
CECDetachEvent::~CECDetachEvent(){}
24
25
TResult CECDetachEvent::Init(IMpi *pMpiApi, TId clientId)
26
{    
27
    TResult res = pMpiApi->RegisterEvent(clientId, *this);
28
    return res;
29
}
30
31
/*
32
 * HandleEvent - callback function 
33
 */
34
void CECDetachEvent::HandleEvent()
35
{
36
	LOG_TRACE( PROFILER_NAME " EC Detach" );
37
}
(-)src-native/src/ProbekitAgent/ECAttachEvent.cpp (+40 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#include "ECAttachEvent.h"
15
#include "Globals.h"
16
#include <log.h>
17
18
using namespace Martini::ProbekitAgent;
19
using namespace Martini::MPI;
20
21
CECAttachEvent::CECAttachEvent(){}
22
23
CECAttachEvent::~CECAttachEvent(){}
24
25
/*
26
 * Init	- initializes internal data and registers for VM init event	
27
 */
28
TResult CECAttachEvent::Init(IMpi *pMpiApi, TId clientId)
29
{ 
30
	TResult res = pMpiApi->RegisterEvent(clientId, *this);
31
	return res;
32
}
33
34
/*
35
 * HandleEvent - callback function 
36
 */
37
void CECAttachEvent::HandleEvent()
38
{
39
	LOG_TRACE( PROFILER_NAME " EC Attach" );
40
}
(-)src-native/src/ProbekitAgent/ProbekitAgent.h (+84 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
 
14
#ifndef _PROBEKIT_AGENT_H
15
#define _PROBEKIT_AGENT_H
16
17
#include "MpiAPI.h"
18
#include "OSA.h"
19
#include "MRTEResults.h"
20
21
#include "VMInitEvent.h"
22
#include "ECAttachEvent.h"
23
#include "ECDetachEvent.h"
24
#include "ECStartEvent.h"
25
#include "ECStopEvent.h"
26
#include "ClassFileLoadHookEvent.h"
27
#include "Globals.h"
28
#include "EC_Env.h"
29
30
namespace Martini { namespace ProbekitAgent {
31
32
    class CProbekitAgent //: public BaseProf::CBaseProfiler
33
    {            
34
    public:
35
        CProbekitAgent();
36
        virtual ~CProbekitAgent();
37
        
38
        static CProbekitAgent* getInstance();
39
        
40
        TResult Init(MPI::IMpi *pMpiApi, MPI::TId clientId, const char *szOptions);                
41
        
42
        JPIAgent::EC_Env* getEC() 
43
        { return ec_env; }
44
45
	private:
46
47
		// Initializes internal data and registers for VM shutdown event
48
        TResult InitEvents();
49
        
50
        // Bind required JPI exported functions
51
        TResult BindJpiFunctions();
52
        
53
        // Initialize EC environment	        
54
		TResult InitEC();
55
	        
56
    private:
57
        
58
        // VM init event object
59
        CVMInitEvent m_VMInitHandler;
60
61
		// the agent doesn't use EC events but they seem
62
		// necessary to make Martini RT sleep in controlled mode.
63
64
		CECAttachEvent m_ECAttachHandler;
65
		CECDetachEvent m_ECDetachHandler;
66
		CECStartEvent m_ECStartHandler;
67
		CECStopEvent m_ECStopHandler;
68
69
        // Class File Load Hook event object
70
        CClassFileLoadHookEvent m_ClassFileLoadHookHandler;
71
72
        // EC environment
73
        JPIAgent::EC_Env* ec_env;
74
        
75
        // Pointer to the MPI implementation
76
        MPI::IMpi* m_pMpiApi;
77
78
        // Client id for MPI requests
79
        MPI::TId m_clientId;
80
    };
81
82
} /*namespace Martini*/  } /*namespace ProbekitAgent*/
83
84
#endif // _PROBEKIT_AGENT_H
(-)src-native/src/ProbekitAgent/ECAttachEvent.h (+37 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#ifndef PROBEKIT_EC_ATTACH_EVENT_H
15
#define PROBEKIT_EC_ATTACH_EVENT_H
16
17
#include "MpiAPI.h"
18
19
namespace Martini { namespace ProbekitAgent {
20
21
	class CECAttachEvent : public MPI::IEcAttachEventObserver
22
	{
23
	public:
24
		CECAttachEvent();
25
		~CECAttachEvent();
26
27
      // Initialization - Register to event
28
		TResult Init(MPI::IMpi *pMpiApi, MPI::TId clientId);
29
30
		virtual void HandleEvent();
31
32
	};
33
34
} /*namespace Martini*/  } /*namespace ProbekitAgent*/
35
36
#endif	// PROBEKIT_EC_ATTACH_EVENT_H
37
(-)src-native/src/ProbekitAgent/Makefile.dep (+35 lines)
Added Link Here
1
$(OBJDIR)/ProbekitAgent.o: ProbekitAgent.cpp
2
	$(CPP_COMPILE)
3
4
$(OBJDIR)/Instrumenter.o: Instrumenter.cpp
5
	$(CPP_COMPILE)
6
7
$(OBJDIR)/InstrumenterFactory.o: InstrumenterFactory.cpp
8
	$(CPP_COMPILE)
9
10
$(OBJDIR)/ClassFileLoadHookEvent.o: ClassFileLoadHookEvent.cpp
11
	$(CPP_COMPILE)
12
13
$(OBJDIR)/VMInitEvent.o: VMInitEvent.cpp
14
	$(CPP_COMPILE)
15
16
$(OBJDIR)/Globals.o: Globals.cpp
17
	$(CPP_COMPILE)
18
19
$(OBJDIR)/ECAttachEvent.o: ECAttachEvent.cpp
20
	$(CPP_COMPILE)
21
22
$(OBJDIR)/ECDetachEvent.o: ECDetachEvent.cpp
23
	$(CPP_COMPILE)
24
25
$(OBJDIR)/ECStartEvent.o: ECStartEvent.cpp
26
	$(CPP_COMPILE)
27
28
$(OBJDIR)/ECStopEvent.o: ECStopEvent.cpp
29
	$(CPP_COMPILE)
30
	
31
$(OBJDIR)/Util.o: Util.cpp
32
	$(CPP_COMPILE)	
33
34
$(OBJDIR)/b64.o: b64.c
35
	$(CPP_COMPILE)
(-)src-native/src/ProbekitAgent/ECStartEvent.cpp (+42 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#include "ECStartEvent.h"
15
#include "Globals.h"
16
#include <log.h>
17
18
using namespace Martini;
19
using namespace Martini::MPI;
20
using namespace Martini::ProbekitAgent;
21
22
CECStartEvent::CECStartEvent(){}
23
CECStartEvent::~CECStartEvent(){}
24
25
/*
26
 * Init - initializes internal data and registers for Start event    
27
 */
28
TResult 
29
CECStartEvent::Init(MPI::IMpi *pMpiApi, MPI::TId clientId)
30
{
31
    TResult res = pMpiApi->RegisterEvent(clientId, *this);
32
    return res;
33
}
34
35
/*
36
 * HandleEvent - callback function for Start event    
37
 */
38
void 
39
CECStartEvent::HandleEvent()
40
{
41
	LOG_TRACE( PROFILER_NAME " EC Start" );
42
}
(-)src-native/src/ProbekitAgent/ECDetachEvent.h (+37 lines)
Added Link Here
1
/************************************************************************
2
 * Copyright (c) 2007 OC Systems Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Vsevolod Sandomirskiy, OC Systems - Probekit support
10
 *
11
 * $Id:$ 
12
 ************************************************************************/
13
14
#ifndef PROBEKIT_EC_DETACH_EVENT_H
15
#define PROBEKIT_EC_DETACH_EVENT_H
16
17
#include "MpiAPI.h"
18
19
namespace Martini { namespace ProbekitAgent {
20
21
	class CECDetachEvent : public MPI::IEcDetachEventObserver
22
	{
23
	public:
24
		CECDetachEvent();
25
		~CECDetachEvent();
26
27
		// Initialization - Register to event
28
		TResult Init(MPI::IMpi *pMpiApi, MPI::TId clientId);
29
30
		virtual void HandleEvent();
31
32
	};
33
34
} /*namespace Martini*/  } /*namespace ProbekitAgent*/
35
36
#endif	// PROBEKIT_EC_DETACH_EVENT_H
37

Return to bug 141540