Groups > Microsoft > WinDbg > Re: need to print stack trace at every call to TlsAlloc()




need to print stack trace at every call to TlsAlloc()

need to print stack trace at every call to TlsAlloc()
Wed, 19 Mar 2008 12:43:53 -070
At every call to TlsAlloc() in the running app, I need to print stack
trace, to the console or to the logfile.

Which debugger or APIs can I use to do this ? Can debugger do this ?
I cannot stop the app at breakpoints interactively, need to leave it
freely running.

Or is there APIs that I can embed into app sources to
(1) hook to all calls to TlsAlloc(), and (2) print stacktrace ?


Thanks
Post Reply
Re: need to print stack trace at every call to TlsAlloc()
Wed, 19 Mar 2008 14:49:28 -070
You can set a stop-and-go breakpoint with a command to print the 
stack-trace.

0:01>.logopen tracefile.txt
0:01> bp  kernel32!TlsAlloc "kb;g"
0:01>g

-- 

-- 
This posting is provided "AS IS" with no warranties, and confers no
rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm


"Yakov" <iler.ml@gmail.com> wrote in message 
news:564739a0-887c-4645-8c19-637ad9734d45@p25g2000hsf.googlegroups.com...
> At every call to TlsAlloc() in the running app, I need to print stack
> trace, to the console or to the logfile.
>
> Which debugger or APIs can I use to do this ? Can debugger do this ?
> I cannot stop the app at breakpoints interactively, need to leave it
> freely running.
>
> Or is there APIs that I can embed into app sources to
> (1) hook to all calls to TlsAlloc(), and (2) print stacktrace ?
>
>
> Thanks
> Yakov 

Post Reply
Re: need to print stack trace at every call to TlsAlloc()
Wed, 19 Mar 2008 20:10:17 -000
In article
<564739a0-887c-4645-8c19-637ad9734d45@p25g2000hsf.googlegroups.com>,
Yakov  <iler.ml@gmail.com> wrote:
>Or is there APIs that I can embed into app sources to
>(1) hook to all calls to TlsAlloc(), and (2) print stacktrace ?

   Answering in reverse order, for stacktraces, look into projects
like http://www.codeproject.com/KB/threads/StackWalker.aspx As to the
hooking, f you have source code, then you can use the compiler to do
this for you. Do things like this: (1) do a search-and-replace to
change TlsAlloc() to something like TLS_ALLOC(). Then, (2), in a
header, insert a function like this:

inline DWORLD TLS_ALLOC(void)
{
  DumpStack();
  return TlsAlloc();
}

   You'll probably want to go further, wrapping the DumpStack() call
with something like a #ifndef FINAL or some other way to remove it
from the builds sent to end users.

Nathan Mates

--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/  
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
Post Reply
about | contact