Customized probe library
Occasionally, it is necessary to create your own customized probe library. As installed, the system has a probe library facility but it may be too general for your needs. This facility, which is available on the Launcher->Debug menu, enables the user to store probes in a file and later load those probes.
However, there may be situations where you would like the probe library to be maintained by source code control. The process of doing this is pretty simple.
- Remove all probes from the system.
- Create your special probes using the probe editor.
- Save your probes to a file using Debug->Probe Library->Save…
- Create a method to return probe save string, as follows;
probeSaveString ^'FileBrowser>>text CRC: 1512475320 Probes: 1 ProbeType: CodeProbe CharacterPosition: 124 LabelString: ''Break in FileBrowser>>text at 124'' Variables: 0 TestExpr: ''Transcript show: ''''foo'''';cr. ^false'' '
5. Now create a method to install the probes as follows;
installMyProbes
ProbeCompiledMethod probeMethodsFrom: self probeSaveString readStream.
Because of the difficulty in properly quoting strings in a method it is better to let the system do it for you. In a workspace do a printIt, using a similar expression as below, and copy the resulting string into your method;
'probLibTest.prb' asFilename readStream contents
One other thing you need to be aware of is that if your method changes and you attempt to load a probe library, the load will fail. Detection of the method change is done by comparing the CRC value.
Comments
Question
[Boris] September 27, 2005 16:42:59.451
Terry,
Could you elaborate a bit on the usefulness of such approach? While I don't argue with the power of probes in particular, it seems that there is inherent brittleness in the fact that such meta information is disconnected from the method in question when stored as a string somewhere else (be it file or another method). Do you have a good practical example of when you would go this route?
Why probe libraries
[ Terry] September 27, 2005 18:04:43.917
Comment by Terry
Boris
I created the probe library because it was requested by a customer. They use a library to instrument their code. Recently, someone else wanted to "modify" code under test so it would generate an error condition, but they did not want to permanently modify their code. So, using a probe seems like a good solution.
In the case of generating an error, to test error handling, one can use the conditional expression to raise an exception and set the initial search context to be the context the code was called from. This would make it appear that the exception was raised in the application code rather than a probe.
Another situation is when you are using multiple processes and the processes have error handler to prevent them from dying when an exception occurs. With these handlers in place you don't get an unhandled exception that you can debug. So, what you do is you put a breakpoint in the exception handler. Using a probe library is an easy way to automatically insert the probes where they are needed.
Re: Customized probe library
[ anonymous] September 27, 2005 18:31:54.854
Comment by anonymous
Terry,
Oh I think I have a pretty good idea about the probes and their value. My question has more to do with the fact that storing probe definitions in files or code introduces brittleness into the system. In provided scenario, should someone go and modify FileBrowser>>text, chances are the probe will fail to install on the next test run forcing you to go back and update probe definition stored somewhere else. Perhaps use method's meta information to save/update probes ala pragmas? Comments?
-Boris
Why use files
[ Terry] September 27, 2005 19:34:42.043
Comment by Terry
Boris
Well, it uses files because that was what the customer asked for at the time, this was probably in VW 2.5. If you notice my message shows you how to use your own method as a library instead. The problem is some people will want to version the library into Store while others may not want it to save itself into a method. So, this way I figure it is easy to save the probes to a file then open it and put the string into a method or whatever the user would like.