cd $APROBE/demo/Aprobe/C make or make -f Makefile.gccIf "make" isn't in your path, use "/usr/ccs/bin/make". If errors are encountered, check that Aprobe is set up properly as described in $APROBE/demo/Aprobe/README.
The demo program, demo.c, is a small program that does a few memory allocations. There is nothing special about demo.c; it could be any program.
aprobe -u trace demo.exe
apformat demo | more
aprobe -u profile demo.exe
apformat demo | more
aprobe -u memwatch -p -g demo.exe 2
apformat demo | more
If you ran into any problems, please contact support@ocsystems.com (or call us at +1 703 359 8160).
The predefined probes are:
The steps above led through all of these except for statprof and coverage. The statprof probe does statistical profiling for which this trivial demo program is too quick. The coverage probe is demonstrated below, where we will run a small "custom" probe in combination with this predefined line coverage probe to get 100% test coverage.
Each predefined probe has a similar interface. Where substantial configuration is available, the user can request a Java GUI with which to specify the configuration. The configuration is defined in a readable file with an extension of ".cfg", and you can directly edit that file to change options if you decide not to use the GUI. However, each probe has a good set of defaults to allow you to use it "out-of-the-box", as we did above.
These predefined probes are just the beginning -- you can write your own custom probes, as described in the next section.
Examine the file "demo.apc", reproduced below.
//
// This apc file will force the malloc call to return a NULL value
// (indicating no more memory available) after malloc is called five
// times from within AllocateOne.
//
int count = 0;
probe thread
{
probe extern:"AllocateOne()"
{
probe extern:"malloc()" in "libc.a(shr.o)"
{
on_entry
count++;
on_exit
if (count > 5)
$return = NULL;
}
}
}
The aprobe patching language is C, with a few extra keywords added (probe, on_entry, on_exit and on_line). The "patches", or probes, that are defined in demo.apc were compiled when you ran "make" above, producing demo.ual. These probes cause malloc to return a 0 after it is called the fifth time from within the routine AllocateOne. In the demo, this will cause a different path to be executed, so we can test that path.
To run the demo with this probe (demo.ual), so just as we did above, but using "demo":
aprobe -u demo demo.exeWe see that it displays "out of memory" because our custom probe modified the address returned by "malloc()" to be NULL. (There's no need to run apformat since it doesn't log any data.)
aprobe -u coverage demo.exe
apformat demo
Now let's run it again for the "Out of memory" case. To do this we run the line coverage probe again, but this time we add the demo UAL, so both the demo and coverage probes are applied. (One can use many different probes at the same time!)
aprobe -u coverage -u demo demo.exe
apformat demo
Aprobe provides a mechanism to merge these results to get a combined report: see $APROBE/examples/learn/test_coverage.
Of course, custom probes can do much more than this demo shows. If you want to get an idea of what they can do, we suggest that you try the examples in the directories under $APROBE/examples/.
For other information, including white papers, visit www.aprobe.com or contact sales@ocsystems.com.