[lldb-dev] Cast SBValue?
Greg Clayton
gclayton at apple.com
Thu Sep 23 14:16:44 PDT 2010
It currently isn't in there, though it could easily be added. We should probably add it as:
class SBValue {
...
SBValue Cast (SBType type);
};
You would need to check the SBValue object that is returned to make sure the casting happened correctly since we couldn't cast a "struct foo" to a "int *".
Then we would need to be add a FindTypes to SBModule for a lookup in a specific module, and to SBTarget for a lookup in all modules in a target:
class SBModule {
...
// Lookup a type in this modules
SBTypeList FindTypes (const char *type_name, uint32_t max_num_matches);
};
class SBTarget {
...
// Lookup a type in all modules within a target
SBTypeList FindTypes (const char *type_name, uint32_t max_num_matches);
};
We need to have the extra "uint32_t max_num_matches" to work around the GCC one definition rule where you might get a type defined in each compile unit in your binary and if you lookup say "size_t", you might get thousands of matches. If you specify "max_num_matches = 1", then you can stop as soon as you find just one match.
The final code would look something like:
SBValue void_ptr_value (...);
SBModule module (frame.GetModule());
SBTypeList type_list (module.FindTypes ("MyType *", 1));
if (type_list.GetSize())
{
// We were able to find a type that matches
SBValue casted_value (void_ptr_value.Cast (type_list.GetTypeAtIndex (0)));
// Now check cast to make sure it worked
if (casted_value.IsValid())
{
// The cast worked!!
}
}
This isn't in the public API just yet, but it can easily be added.
Greg Clayton
On Sep 23, 2010, at 3:04 AM, arvid.picciani at nokia.com wrote:
> Hi,
>
> I see no way of casting an SBValue to a different type. quite often you have void pointers flying around, that are actually pointers to a class instance.
> Casting inside an expression is not an option, since we'd prefer having it work on coredumps.
> Is there some API i missed?
> _______________________________________________
> lldb-dev mailing list
> lldb-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/lldb-dev
More information about the lldb-dev
mailing list