How to convert other types to char* or string with dtrace
In using dtrace, if other types can be converted to character types, then you can easily perform comparison operations, so the logic is much easier to write. But why I didn't find a good way to convert type, usually report error l type conversion failed, such as convert ustack(2) or usym(ucaller) to string type, please ask if there is a good way or suggestion, I will be very grateful!
Thank you so much for your question. It is great to hear from users.
D (the language implemented by DTrace to write tracing scripts in) provides comparison operations for various types, but it also has a pretty strict interpretation of type compatibility. It also uses a specific 'string' type that isn't quite the same as C's 'char *'. The general idea for value comparison in DTrace is really based on making use of the type information that is available.
Now, the examples you provide (ustack(2) and usym(caller)) ar both special cases. While they appear to be functions, they are actually 'D actions' which means that they cannot be used in expressions. They generate trace output that is stored in the trace buffer rather than returning a value. It is therefore not possible to cast to any other type because there is no return value.
There is an outstanding bug that stack() and usym() (and similar actions) should be able to occur in pseudo-expression context as part of aggregation or associative array keys. But that is a very special case that again does not allow any casting (and doing so would be pointless because you cannot assign it to anything).
Does that answer your question?
well, thanks for your answer! Is there a way to filter out user functions and sieve out system library (non-kernel level) symbols, I was thinking of doing it by character traits, but it doesn't seem to support type conversion.