你怎么调试? [英] How do you debug?

查看:51
本文介绍了你怎么调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编写代码时,我会使用很多:


std :: cout<< TEST1 \ n;;


....

....

< some code> < br $> b $ b ....

....


std :: cout<< TEST2 \ n;





但是有没有更好的方法来进行这种调试(可能还有一些

预处理器命令)?

我知道我可以使用gdb调试器但通常我更喜欢上面的

程序。 />

When I write code I use a lot of:

std::cout << "TEST1\n";

....
....
<some code>
....
....

std::cout << "TEST2\n";

etc.

But is there some better way do this kind of debugging (maybe with some
preprocessor commands)?

I know that I could use the gdb debugger but often I prefer the above
procedure.

推荐答案



您可以尝试查看assert()函数 - 请参阅此处了解介绍
http://www.codeguru.com/forum/showthread.php?t = 315371


10月2日下午4:55,桌面< f ... @ sss.comwrote:

You could try looking at the assert() function - see here for an intro
http://www.codeguru.com/forum/showthread.php?t=315371

On Oct 2, 4:55 pm, desktop <f...@sss.comwrote:

当我编写代码时,我会使用很多:


std :: cout<< TEST1 \ n;


...

...

< some code>

...

...


std :: cout<< TEST2 \ n;





但是有没有更好的方法来进行这种调试(可能还有一些

预处理器命令)?

我知道我可以使用gdb调试器但通常我更喜欢上面的

程序。
When I write code I use a lot of:

std::cout << "TEST1\n";

...
...
<some code>
...
...

std::cout << "TEST2\n";

etc.

But is there some better way do this kind of debugging (maybe with some
preprocessor commands)?

I know that I could use the gdb debugger but often I prefer the above
procedure.



Michael DOUBEZ写道:
Michael DOUBEZ wrote:

实际上,在发布中保留断言代码(即不使用NDEBUG)

a好主意;就像在你学会了如何驾驶之后戴上安全带一样。
Actually, keeping asserts in the release code (i.e. not using NDEBUG) is
a good idea; just like wearing a safety belt after you have learned how
to drive.



这取决于您需要的效率水平。例如,在许多

库中,保持_NDEBUG保留对所有容器的边界检查,

并且这不仅是可取的。这就是为什么我建议为发布检查创建自己的

断言。我同意,如果可以的话,保持断言

可能是一件好事(即使失败的断言使程序崩溃

无论如何)。

It depends on the efficiency level that you need. For example, in many
libraries keeping _NDEBUG retains boundary checks on all the containers,
and that''s not only desirable. That''s why I suggested to create his own
asserts for release checks. I agree that, if you can, keeping asserts
may be a good thing (even though a failed assert makes the program crash
anyway).


除了作为事后分析之外,我很少使用调试器;我的单元测试

通常就足够了。
I rarely use the debugger except as post mortem analysis; my unit tests
are usually sufficient.



那么调试单元测试呢?


问候,


Zeppe

And what about debugging unit tests?

Regards,

Zeppe


Zeppe写道:
Zeppe wrote:

Michael DOUBEZ写道:
Michael DOUBEZ wrote:

>实际上,在发布代码中保留断言(即不使用NDEBUG)
是一个好主意;就像在学会了如何驾驶之后戴上安全带一样。
>Actually, keeping asserts in the release code (i.e. not using NDEBUG)
is a good idea; just like wearing a safety belt after you have learned
how to drive.



这取决于您需要的效率水平。例如,在许多

库中,保持_NDEBUG保留对所有容器的边界检查,

并且这不仅是可取的。这就是为什么我建议为发布检查创建自己的

断言。我同意,如果可以的话,保持断言

可能是一件好事(即使失败的断言使程序崩溃

无论如何)。


It depends on the efficiency level that you need. For example, in many
libraries keeping _NDEBUG retains boundary checks on all the containers,
and that''s not only desirable. That''s why I suggested to create his own
asserts for release checks. I agree that, if you can, keeping asserts
may be a good thing (even though a failed assert makes the program crash
anyway).


>除了作为事后分析之外,我很少使用调试器;我的单位
测试通常就足够了。
>I rarely use the debugger except as post mortem analysis; my unit
tests are usually sufficient.



那么调试单元测试呢?


And what about debugging unit tests?



调试单元测试的最佳方法是撤消最后编辑!


-

Ian Collins。

The best way to debug unit tests is to undo the last edit!

--
Ian Collins.


这篇关于你怎么调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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