views:

161

answers:

2

Do you know how to read another process stack in delphi ??

+8  A: 

Yes.

You can enumerate threads with Toolhelp functions; get the context with GetThreadContext(); and read the stack memory (i.e. using ESP from the context) with ReadProcessMemory(). The stack grows downwards in memory, so reading memory locations after ESP is going down the stack.

Barry Kelly
And use dbghelp api's to get names from the symbols could be the next step.
Remko
+1  A: 

You could take a look at the "TThreadSampler.MakeStackDump" procedure of the following unit of my sampling profiler: http://code.google.com/p/asmprofiler/source/browse/trunk/Sampling/mcThreadSampler.pas

This function can read from the same thread, or same process or different process (each with it's own optimized function).

Btw: my Sampling Profiler reads Delphi debug symbols (.map, .jdbg, etc) because there is still no good Delphi to Pdb debug symbol converter (so you can view the stack of a Delphi program in Windows debugger or Process Explorer, Visual Studio etc). You can also use my sampling profiler for view the current stack of any process! http://code.google.com/p/asmprofiler/wiki/AsmProfilerSamplingMode

André