Groups > Microsoft > WinDbg > Re: DBGHelp.dll -- getting value of symbols




DBGHelp.dll -- getting value of symbols

DBGHelp.dll -- getting value of symbols
Wed, 12 Mar 2008 08:00:00 -070
Hi, I am trying to write a function which will spit out the function 
parameters of its parent function.  I have tried to implement this using 
DBGHelp.dll.  Not easy considering the minimal documentation! However, I am 
very close to making it work. 

I can walk the stack and find the stackframe for the function I am 
interested in.  I then enumerate the symbols and I can see the symbol names 
in PSYMBOL_INFO.  However I cannot seem to get any other detailed information 
from the symbols. Nearly all my calls to SymGetTypeInfo  with various 
IMAGEHLP_SYMBOL_TYPE_INFO fail with an error code of 1.  The only one that 
succeeds is TI_GET_BASETYPE. I am interested in getting the name, type, and 
the value for each of the symbols. Below is my call to SymGetTypeInfo. My gut 
feeling is that I am missing some minor little detail, or that I am somehow 
not initializing something properly. 

Any advice would be great. Thanks,
Adam






BOOL CALLBACK SymEnumSymbolsCallback( PSYMBOL_INFO pSymInfo, ULONG 
SymbolSize, PVOID UserContext)
{
int symbolType=0;
if (!SymGetTypeInfo(GetCurrentProcess(),pSymInfo->ModBase, 
pSymInfo->TypeIndex, TI_GET_TYPE,&symbolType))
{
DWORD ErrCode = GetLastError(); 
if( ErrCode == 1 ) 
std::cout<<"Error: SymGetTypeInfo() failed. Property not 
supported"<<std::endl;
else 
std::cout<<"Error: SymGetTypeInfo() failed. Error 
code:"<<::GetLastError()<<std::endl;
}

Post Reply
Re: DBGHelp.dll -- getting value of symbols
Thu, 13 Mar 2008 03:46:11 -070
On Mar 12, 3:00 pm, neojava <neoj...@discussions.microsoft.com> wrote:
> Hi, I am trying to write a function which will spit out the function
> parameters of its parent function.  I have tried to implement this using
> DBGHelp.dll.  Not easy considering the minimal documentation! However, I
am
> very close to making it work.
>
> I can walk the stack and find the stackframe for the function I am
> interested in.  I then enumerate the symbols and I can see the symbol
names
> in PSYMBOL_INFO.  However I cannot seem to get any other detailed
information
> from the symbols. Nearly all my calls to SymGetTypeInfo  with various
> IMAGEHLP_SYMBOL_TYPE_INFO fail with an error code of 1.  The only one that
> succeeds is TI_GET_BASETYPE. I am interested in getting the name, type,
and
> the value for each of the symbols. Below is my call to SymGetTypeInfo. My
gut
> feeling is that I am missing some minor little detail, or that I am
somehow
> not initializing something properly.

Start with:-

    enum SymTagEnum tag = (enum SymTagEnum)0;
    SymGetTypeInfo( GetCurrentProcess(), pSymInfo->ModBase, pSymInfo-
>TypeIndex, TI_GET_SYMTAG, &tag );

Then switch on the various tag values...

Most simple variables will be "SymTagBaseType".

For this tag type you can call TI_GET_BASETYPE.
Look in cvconst.h for the various btXxx values in the BasicType enum

TI_GET_SYMNAME gets you the name of the type (which you seem to need
to LocalFree).
TI_GET_LENGTH gets you the # bytes

Regards,
Post Reply
Re: DBGHelp.dll -- getting value of symbols
Thu, 13 Mar 2008 08:28:04 -070
Roger, 
Thanks, the suggestion was illuminating.  I had previously been looking at 
the Tag returned from the PSYM_INFO in the EnumSymbolsCallback function.  It 
was always returned SymTagData. 

Following your direction
SymGetTypeInfo( GetCurrentProcess(), pSymInfo->ModBase, pSymInfo, TypeIndex,

TI_GET_SYMTAG, &tag );

now allows me to see the following two types:
SymTagBaseType 
SymTagPointerType.

However when I try to get the SymTag for a symbol that is a class or struct 
I end up with SymTagNull.   I suspect that I have either somehow not properly 
loaded the symbols or that I need to drill down into the child symbols to get 
the information. I tried checking to see if the Symbol had children via 
SymGetTypeInfo  but I get back 0. 

Any ideas?

Thanks Again,
Adam

"roger.orr@gmail.com" wrote:

> On Mar 12, 3:00 pm, neojava <neoj...@discussions.microsoft.com>
wrote:
> > Hi, I am trying to write a function which will spit out the function
> > parameters of its parent function.  I have tried to implement this
using
> > DBGHelp.dll.  Not easy considering the minimal documentation! However,
I am
> > very close to making it work.
> >
> > I can walk the stack and find the stackframe for the function I am
> > interested in.  I then enumerate the symbols and I can see the symbol
names
> > in PSYMBOL_INFO.  However I cannot seem to get any other detailed
information
> > from the symbols. Nearly all my calls to SymGetTypeInfo  with various
> > IMAGEHLP_SYMBOL_TYPE_INFO fail with an error code of 1.  The only one
that
> > succeeds is TI_GET_BASETYPE. I am interested in getting the name,
type, and
> > the value for each of the symbols. Below is my call to SymGetTypeInfo.
My gut
> > feeling is that I am missing some minor little detail, or that I am
somehow
> > not initializing something properly.
> 
> Start with:-
> 
>     enum SymTagEnum tag = (enum SymTagEnum)0;
>     SymGetTypeInfo( GetCurrentProcess(), pSymInfo->ModBase, pSymInfo-
> >TypeIndex, TI_GET_SYMTAG, &tag );
> 
> Then switch on the various tag values...
> 
> Most simple variables will be "SymTagBaseType".
> 
> For this tag type you can call TI_GET_BASETYPE.
> Look in cvconst.h for the various btXxx values in the BasicType enum
> 
> TI_GET_SYMNAME gets you the name of the type (which you seem to need
> to LocalFree).
> TI_GET_LENGTH gets you the # bytes
> 
> Regards,
> Roger.
Post Reply
Re: DBGHelp.dll -- getting value of symbols
Thu, 13 Mar 2008 11:31:01 -070
It turns out that I was using the wrong version of the DLL.   I was using the 
DLL in the Windows/system32.  I copied the most recent version of the DLL to 
my executable's directory and suddenly everything started to work.  

If anyone else encounters strange issues with DBGhelp where absolutely 
nothing seems to make sense the first thing to check would be that you are 
using the most recent DLL.

http://blogs.msdn.com/matt_pietrek/archive/2005/02/04/367494.aspx


"neojava" wrote:

> Roger, 
> Thanks, the suggestion was illuminating.  I had previously been looking at

> the Tag returned from the PSYM_INFO in the EnumSymbolsCallback function. 
It 
> was always returned SymTagData. 
> 
> Following your direction
> SymGetTypeInfo( GetCurrentProcess(), pSymInfo->ModBase, pSymInfo,
TypeIndex, 
> TI_GET_SYMTAG, &tag );
> 
> now allows me to see the following two types:
> SymTagBaseType 
> SymTagPointerType.
> 
> However when I try to get the SymTag for a symbol that is a class or struct

> I end up with SymTagNull.   I suspect that I have either somehow not
properly 
> loaded the symbols or that I need to drill down into the child symbols to
get 
> the information. I tried checking to see if the Symbol had children via 
> SymGetTypeInfo  but I get back 0. 
> 
> Any ideas?
> 
> Thanks Again,
> Adam
> 
> "roger.orr@gmail.com" wrote:
> 
> > On Mar 12, 3:00 pm, neojava <neoj...@discussions.microsoft.com>
wrote:
> > > Hi, I am trying to write a function which will spit out the
function
> > > parameters of its parent function.  I have tried to implement
this using
> > > DBGHelp.dll.  Not easy considering the minimal documentation!
However, I am
> > > very close to making it work.
> > >
> > > I can walk the stack and find the stackframe for the function I
am
> > > interested in.  I then enumerate the symbols and I can see the
symbol names
> > > in PSYMBOL_INFO.  However I cannot seem to get any other detailed
information
> > > from the symbols. Nearly all my calls to SymGetTypeInfo  with
various
> > > IMAGEHLP_SYMBOL_TYPE_INFO fail with an error code of 1.  The only
one that
> > > succeeds is TI_GET_BASETYPE. I am interested in getting the name,
type, and
> > > the value for each of the symbols. Below is my call to
SymGetTypeInfo. My gut
> > > feeling is that I am missing some minor little detail, or that I
am somehow
> > > not initializing something properly.
> > 
> > Start with:-
> > 
> >     enum SymTagEnum tag = (enum SymTagEnum)0;
> >     SymGetTypeInfo( GetCurrentProcess(), pSymInfo->ModBase,
pSymInfo-
> > >TypeIndex, TI_GET_SYMTAG, &tag );
> > 
> > Then switch on the various tag values...
> > 
> > Most simple variables will be "SymTagBaseType".
> > 
> > For this tag type you can call TI_GET_BASETYPE.
> > Look in cvconst.h for the various btXxx values in the BasicType enum
> > 
> > TI_GET_SYMNAME gets you the name of the type (which you seem to need
> > to LocalFree).
> > TI_GET_LENGTH gets you the # bytes
> > 
> > Regards,
> > Roger.
Post Reply
Re: DBGHelp.dll -- getting value of symbols
Tue, 18 Mar 2008 15:10:22 -070
Hi Adam,

Sorry to off the newsgroup...

On Mar 13, 2:31 pm, neojava <neoj...@discussions.microsoft.com> wrote:
> It turns out that I was using the wrong version of the DLL. I was using
the
> DLL in the Windows/system32.
It burned me also. I make it a point to call load library on
DbgHelp.dll (even though I am statically linked) to verify the version
info on DbgHelp. I think this is the only time I have ever checked a
file version at runtime.

> I copied the most recent version of the DLL to my executable's directory
> and suddenly everything started to work.
And Windows File Protection won't allow us to drop a newer version
into \System32...

Post Reply
<< Previous 1 2 Next >>
( Page 1 of 2 )
about | contact