views:

171

answers:

2

I'd like to change the way some types are displayed using either 'dt' or '??' in a manner similar to how you can do that with autoexp.dat. Is there a way to do this?

For example, I have a structure something like this:


struct Foo
{
    union Bar
    {
       int a;
       void *p;
    } b;
};

And I've got an array of a few hundred of these, all of which I know point to a structure Bar. Is there any way to tell cdb that, in this expression anyway, that 'p' is a pointer to Bar? This is the kind of thing you could do with autoexp. (The concrete example here is that I've got a stashtable that can have keys of any type, but I know they keys are strings. the implementation stores them as void pointers).

Thanks in advance!

+1  A: 

You can say du or da to have it dump memory as unicode or ascii strings.

jeffamaphone
if I have an array that has an element pointing to a string that is somewhere else in memory can I invoke 'da' on that pointer's address as part of printing the array?
aaron
If you know the start address of the array, you should be able to calculate the offset from the start address to the element you want (sizeof(struct) * i) and then add the offset of the (DWORD aligned) element inside the struct. You can also do dt -r on the struct's address to have the debugger recursively dump all the members.
jeffamaphone
+1  A: 

I don't think there's anything as simple as autoexp.dat.

You have a couple potential options - you can write a simple script file with the debugger commands to dump the data structure in the way you want and use the "$<filename" command (or one of its variants). Combined with user aliases you can get this to be pretty easy and natural to use.

The second option is quite a bit more involved, but with it comes much more power - write an extension DLL that dumps your data structure. For something like what you're talking about this is probably overkill. But you have immense power with debugger extensions (in fact, much of the power that comes in the Debugging tools package is implemented this way). The SDK is packaged with the debugger, so it's easy to determine if this is what you might need.

Michael Burr