Does anyone have suggestions for a good way to find out what (local) pointers are pointing at what items on the heap? I have a bug in a program that's almost certainly caused by two pointers pointing to the same object when they should be pointing to separate ones. Treat this as a 'newbie' question. The answer might be a debugger, but I haven't had a bug serious enough to use a debugger in four years - one of the benefits of using c++ - so I've forgotten how to use one. I usually just print variables to stdandard output. -- JDL Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
Treat this as a 'newbie' question. The answer might be a debugger, but I haven't had a bug serious enough to use a debugger in four years - one of the benefits of using c++ - so I've forgotten how to use one. I usually just print variables to stdandard output.
I can't believe someone is saying this. If you haven't had the need for a debugger in 4 years, then you must not be doing serious programming! I would take my time and get familar with gdb and ddd. It would take a few days but you would not regret it. If you ever have read the book "Debugging Applications" by John Robbins, you would first learn how to use a debugger before you even touch programming. At work it surprises me how many engineers are actually afraid of using a debugger. When they encounter a problem, they open the code in the editor and trying to guess what the code is doing. Being very fluent in all the different debugging environments (Visual C++, gdb/ddd), I prefer to put breakpoints here and there and step thru it to see whats happening. I would say it again. The time that you spend learning how to use a debugger will never go into waste. Period. Salman
On Sun, 01 Jun 2003 17:57:50 +0100 John Lamb <J.D.Lamb@btinternet.com> wrote:
Does anyone have suggestions for a good way to find out what (local) pointers are pointing at what items on the heap?
I have a bug in a program that's almost certainly caused by two pointers pointing to the same object when they should be pointing to separate ones.
Treat this as a 'newbie' question. The answer might be a debugger, but I haven't had a bug serious enough to use a debugger in four years - one of the benefits of using c++ - so I've forgotten how to use one. I
usually just print variables to stdandard output. In addition to Salman's excellent response, you might also want to look at Valgrind. But, DDD can give you a very graphical description of your pointers and objects. With GDB and DDD you should be able to isolate when the pointers are set.
-- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Jerry Feldman wrote:
In addition to Salman's excellent response, you might also want to look at Valgrind. But, DDD can give you a very graphical description of your pointers and objects. With GDB and DDD you should be able to isolate when the pointers are set.
Thanks. The data displays in DDD were just what I needed and it obviously just uses gdb underneath, which is what I used to use all the time. -- JDL Non enim propter gloriam, diuicias aut honores pugnamus set propter libertatem solummodo quam Nemo bonus nisi simul cum vita amittit.
participants (3)
-
Jerry Feldman
-
John Lamb
-
Salman Khilji