如何跟踪调用堆栈 [英] How to trace call stack

查看:92
本文介绍了如何跟踪调用堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Turbo C 3.0上看到了一个简单的调用堆栈

但是我正在为一个简单的调用堆栈而徘徊.我正在开发一个多线程应用程序,但查询中出现错误,因此当我运行它时,它陷入了某些功能.那么我想看看那个坏男孩用不正确的查询调用了那个单独的函数.我知道如果我仔细调试,我会找到那个单独的功能.但我想在调用堆栈上看到它,有人指导我:)

附注:这个问题可以比这个短,但我无法做到. :(

I saw a simple calling stack on Turbo C 3.0

But I am wandering for a that simple calling stack. I am working on a multi-threading application and I am having a error in the query, so when I run it stuck in certain function. then I want to see the bad boy who called that individual function with improper query. I know if i debug carefully i will find that individual function. but i want to see it on the calling stack, someone guide me :)

p.s.: The question can be shorter than this, but I could not make it. :(

推荐答案

虽然这对计时问题无济于事,但您可以记录谁在打电话以及参数是什么.如果您可以在每次调用之前刷新日志,然后知道是谁在进行废话调用以及参数是什么.如果将其包装在宏中,以这种方式检测代码应该不会太难(我知道,我不必这样做... :-)).

如果有多个线程调用有问题的项,那么您将必须为每个线程创建一个日志,但希望它只是一个线程弄乱了.

另一种选择是将有问题的函数包装在另一个函数中,该函数执行参数验证并在传递某些狡猾时调用DebugBreak.然后,如果在调试器上运行它,它将在获取不可靠的数据时中断,您可以检查调用堆栈,找到有问题的调用方,然后查看当时的状态.

狡猾的英语警报!
While this won''t help if it''s a timing issue you could log who''s making the call and what the parameters are. If you flush the log before each call you know who''s making the crap call AND what the parameters are. If you wrap the lot up in a macro it shouldn''t be too hard to instrument your code this way (I know, I don''t have to do it... :-) ).

If more than one thread calls the offending item then you''ll have to create a log for each thread but hopefully it''s just one thread messing up.

Another option would be to wrap your offending function in another one that does parameter validation and calls DebugBreak when something dodgy is passed. Then if you run it under a debugger it''ll break when it gets the dodgy data, you can examine the call stack, find the offending caller AND see what its state is at the time.

Dodgy English Alert!!


请参见 http: //win32.mvps.org/misc/stackwalk.html [ ^ ]
另外 http://www.cygnus-software.com/papers/release_debugging.html [ ^ ]
您可能希望为每个.dll附带一个.pdb文件.

这些文章引用了VC6,但是Windows API仍然存在.

希望这会有所帮助,

巴勃罗.
See http://win32.mvps.org/misc/stackwalk.html[^]
Also http://www.cygnus-software.com/papers/release_debugging.html[^]
You may want to ship a .pdb file for each .dll.

The articles refer to VC6, but the Windows API is still there.

Hope this helps,

Pablo.


这篇关于如何跟踪调用堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆