Search code examples
printfaliaswindbgaliases

Windbg .printf string alias from as /c


Hopefully this is a simple question, but if I define an alias a1 as an expression 1+1 with as /x a1 1+1 then I can display that via .echo a1 or .printf "a1 = %d", a1.

Is it possible to do the same with .printf if I define an alias a2 as a CommandString with as /c a2 dv /t this?

I can certainly .echo it, but trying something like .printf "a2 = %ma", a2 gives a Couldn't resolve error at error, like:

.printf "a2 = %ma", a2
class Blah:Blah:Blah * this = 0x00000000194dacf0
 = Couldn't resolve error at 'class Blah::Blah::Blah * this = 0x00000000194dacf0
'

This is the same if a2 is defined with as /c a2 .printf "hello". I couldn't find examples of .printf being used to display string aliases otherwise I could just crib that... I thought it strange, unless I'm missing something obvious.


Solution

  • 0:000> dv /t this
    class Student * this = 0x000000c5`d6f6f910
    0:000> as /c foo dv /t this
    0:000> al
      Alias            Value  
     -------          ------- 
     foo              class Student * this = 0x000000c5`d6f6f910
    
    0:000> .printf "${foo}"
    class Student * this = 0x000000c5`d6f6f910
    

    you accepted this but I was going to ask you this question in comment instead edited the answer

    I answered the query but why are you trying to use %ma ?? it is supposed to print an ascii string in target virtual address space like

    0:000> .printf "%ma\n" , poi(poi(this)+8)
    dave
    

    edit usage of alias interpreter

    0:000> .printf "to check if an alias is defined use ${/v:foo} ${/n:foo} == 1 \n" 
    to check if an alias is defined use ${/v:foo} foo == 1 
    
    0:000> .printf "to expand an alias  ${/n:foo} use ${/v:foo} == ${foo} " 
    to expand an alias  foo use ${/v:foo} == class Student * this = 0x000000c5`d6f6f910