|
This probe injects a C++ exception.
test.cpp:
--------
#include <iostream>
#include <stdexcept>
using namespace std;
void report_error( const char* msg )
{
throw runtime_error( msg );
}
void print_msg( const char* msg )
{
cout << "msg: " << string(msg) << endl;
}
void test( int p )
{
if ( p == 0 )
{
report_error( "test: bad parameter" );
}
}
int main()
{
print_msg( "from main");
try
{
test( 0 );
}
catch( const exception& e )
{
cout << "Caught:" << e.what() << endl;
}
return 0;
}
apc:
---
#include <unistd.h>
probe thread
{
probe extern:"::test(int)"
{
on_entry
{
log( "OK ", $p );
sleep(10);
$print_msg( "from probe" );
$report_error( "fault injection" );
}
}
} |