1

My objective is to store the class name of the object called this found in a frame's locals. When you look at this sequence of commands, am I falling foul of some Windbg syntax rules that mean the as command doesn't seem to throw any error, but also doesn't set the alias as I would like?

This confuses me a bit because the alias was demonstrably set in the isolated .foreach command I used earlier and now I am just nesting that (although I'd also tried as /c coupled with a .printf) further along...

0:133> ad /q *
0:133> al
No aliases
0:133> .foreach /pS 1 /ps 4 (Token {dv /t this}) { as myClass Token }
0:133> al
  Alias            Value  
 -------          ------- 
 myClass          foo  
0:133> ad /q *
0:133> al
No aliases
0:133> !for_each_local .if ($spat ("@#Local","this") == 1) { .foreach /pS 1 /ps 4 (Token { dv /t this }) { .printf "${Token}\n" } }
foo
0:133> !for_each_local .if ($spat ("@#Local","this") == 1) { .foreach /pS 1 /ps 4 (Token { dv /t this }) { as myClass Token } }
0:133> al
No aliases
0:133> !for_each_local .if ($spat ("@#Local","this") == 1) { .foreach /pS 1 /ps 4 (Token { dv /t this }) { as /c myClass .printf "${Token}" } }
0:133> al
No aliases

It seems like an intricacy of as, I can use .echo ${Token} happily too, but I can't use as with ${Token}. I've tried combinations of aS and semicolons to no avail and I'm sure it's just a syntax question and this is documented but I can no longer see the wood for the trees.

Last attempt, I tried - !for_each_local .if ($spat ("@#Local","this") == 1) { .foreach /pS 1 /ps 4 (Token { dv /t this }) { as /c myClass .echo ${Token} } } - bah!!!

Hippogriff
  • 295
  • 1
  • 4
  • 18

1 Answers1

1

The extension commands (!-commands; bang-commands) do not work well with aliases in general.

You can try that with a simplified command:

0:000> al
No aliases
0:000> !for_each_module as x y
0:000> al
No aliases

You can try to bypass this limitation by letting the command output its result to the console and then process this output with a non-extension command.

For the simplified example:

0:000> ad *
0:000> al
No aliases
0:000> .foreach (Token {!for_each_module .echo y}) {;as x Token}
0:000> al
  Alias            Value  
 -------          ------- 
 x                y 
 y                y 

Note how the alias got expanded on the second expansion. You might try to avoid that with some more /ps parameters.

Your command may become as ugly as:

.foreach /ps 1000 (result { !for_each_local .if ($spat ("@#Local","this") == 1) { .foreach /pS 1 /ps 4 (Token { dv /t this }) { .printf "${Token}\n" } }}) {;as myClass result}
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222