


What Good Linux Debuggers Are There? 69
David Weekly asks: "I'm programming for a small software company that's got a fair bit of C++ code; we've been using gdb whilst on Linux, but have been a little frustrated by its shortcomings with multithreaded applications and its fumbling multiple inheritance issues. I poked around on the Net and, other than gdb, I was only able to find Etnus' TotalView as a modern, actively-developed Linux debugger. Are there really only two Linux debuggers (that one can take seriously)? How, for instance, do folks who code up Apache modules test them in multithreaded mode? (i.e., not just using '-X'.) I'd love to hear answers more substantive than 'use printf()' and/or 'just use ____, my favorite gdb frontend'."
Re:printf (Score:1)
So that isn't an answer, but it may be that developing a test suite (unit tests, plus assertions), may obviate the need for a debugger even on existing projects.
Well, shoot me quick, Rufus! (Score:1)
Personally, I debug as I go, function by function, sometimes line-by-line. Others whip up a pile of code and then try to figure out what the hell's wrong with it _this_ time. Still others run it through a program to make some other programmer tell them what the hell's wrong _this_ time (debuggers.)
Search freshmeat using the word "bug" and see what comes up. Here's what I found:
Search on "bug" - 335 entries returned.
Search on "debug" - 199 entries returned.
Search on "debugger" - 78 entries returned.
Go for it, dude!
A little refinement (Score:2)
I'd love to know, too, since gdb falls short on this.
The best I can offer is that the debugger that comes with Intel's free (for non-commerical use) compiler for linux probably works well, but I haven't installed it on my computer since I'm too lazy to install rpm on my machine and get it set up so that it won't scream when the installer runs rpm.
To that end, I was able to find a debugger called <A HREF=http://www.concerto.demon.co.uk/UPS/>UPS</a&
More useful may be <A HREF=http://hegel.ittc.ukans.edu/projects/smartgd
Hope that helps. . .
Re:Well, shoot me quick, Rufus! (Score:2)
Dynamic Display Debugger (Score:1, Redundant)
Nice try (Score:2)
As we all know, DDD is just a frontend for GDB, and does
tkgdb (Score:1, Redundant)
Re:tkgdb (Score:2)
Re:tkgdb (Score:1)
Also he needs to compile with gcc 3.1.1 to get better support of c++.
Also I think there are no other debugger for linux because nobody wants to make one when gsb is there and it is the best one period.
Re:tkgdb (Score:2)
There are other debuggers for Linux, it's just that no one on Slashdot knows of them, as usual.
Aaron
You forgot a choice... (Score:1, Funny)
Oh right, it's Ask Slashdot, not Polls.
Multiple inheritance (Score:3, Flamebait)
What I've ended up doing in hard cases (where printf will not help) is create local pointers to the parent classes and examine them from gdb. Once the problem is solved, the extra variables are gone, too.
Example:
Base1 *b1 = dynamic_cast[Base1*](this);
Base2 *b2 = dynamic_cast[Base2*](this);
(change [] to less-than and greater-than).
Of course, this will not help when your hierarchy is more than a couple of levels deep and things get even more complicated when the parent class is actually a template argument.
I hope, however, that this is just a very-hard-to-fix bug in gdb, as opposed to an even deeper design problem (as I think is the case with threaded code). So there might still be hope.
Re:Multiple inheritance (Score:2, Insightful)
For more details, have a look at Andrei Alexandrescu's Modern C++ design. This book is an absolute eye-opener and it has done exactly that for a large part of the C++ community.
Re:Multiple inheritance (Score:2)
Just because implementations are possibly redundant does not mean that they are actually redundant. And just because C++ has warts (or what you call abominations) doesn't mean object-oriented systems all have the same warts.
Three bad things about them: (Score:3, Insightful)
2) You have to dive through the code to remove them and then recompile on every iteration of the debugging process if you don't want to keep getting info for finding bugs you've already fixed every time you run the program.
3) They clutter up your code and make it much less readable and maintainable.
and as a super extra bonus for everyone
4) The only workaround for problems (1) and (2) is fancy use of the preprocessor, which has the unwanted side effect of making (3) even worse!
Re:Three bad things about them: (Score:5, Interesting)
You can log against any backend source you feel like, flat files, syslog, databases, etc. You can remove the logging module entirely at runtime, without paying a performance hit for the debug statements. This saves a lot of jumping back and forth when you're trying to package up a release. If you're stuck without the fund$ for a top-end debugger it's the next best thing. It's for java, but I don't see any reason why the concept couldn't be ported to C++.
Re:Three bad things about them: (Score:2)
Additionally, I thought the log4j 'compiling out' was just taking advantage of a Java language feature where dead code is not executed, but you still had to incur a (small) runtime penalty of 1-2ms. Is this no longer true?
Re:Three bad things about them: (Score:2)
Re:Three bad things about them: (Score:1)
>It's for java, but I don't see any reason why the
>concept couldn't be ported to C++.
It has [sourceforge.net] been. Several times.
http://log4c.sourceforge.net/
http://sourcefor
http://log4cplus.sourcef
It's also been ported to a number of other languages.
(See the 'ports to other languages' section.)
http://jakarta.apache.org/log4j/docs/d
My goodness, You are all illiterate! (Score:3, Interesting)
Please read an entire post before replying.
Finally, what do I use for multithreaded application debugging? I don't have a tool for once I've cut the code but if you define your system using Finite State Processes then you can use the LTS Analyser [ic.ac.uk] to check for deadlocks etc and you can step through a concurrent system generating whatever event you like. It is worth a look, although matching your code to your model is still tricky. And of course you need to learn FSP, but the website above teaches you.
Re:Intel compiler/debugger (Score:1)
Free 30-day evaluation [intel.com]
Vince Harron
Using perf analysis for debugging? (Score:2, Informative)
http://www.intel.com/software/products/index.htm [intel.com]
I can't speak for the debugger, but when we switched our simulator from gcc to icc with profiling, we gained 25-30% performance. Needless to say, that was way cool. The other threading and vtune items might provide some useful insights to your code.
I hate to say it, but all the stuff I work on is generally so small, it's not worth the overhead to attach a debugger to it, so I'm not much of an expert in this area
- Mike
Intel's Debugger (Score:5, Informative)
Visual C++ has a great debugger (Score:1, Troll)
oh, wait a minute.. Linux? then nevermind. Linus says debuggers are for wimps anyway, dontcha know?
Re:Visual C++ has a great debugger (Score:1)
Choices (Score:2, Informative)
2.) printf()
3.) gdb
4.) lint
5.) the proprietary debugger you mentioned.
6.) modify the thread library. (a niceties of open source/free software)
7.) modify your OS. (look into UML [user-mode-linux.org]
Generally some combination of these should allow you to solve any programming problem on linux.
I find it amusing that a poster above calls everyone else illiterate for not reading the original post and then provides a link to a Transition System Analyzer for JAVA (the original poster is using C++)
Re:hey! (Score:2)
Re:hey! (Score:1)
ups (Score:3, Informative)
(The only real downside is its user interface, which isn't too great.)
if nothing works... (Score:1)
Speaking of which... what exactly is it in gdb that needs fixing (thread stuff? what specifically??).. I use it fine with multithreaded apps all the time (a absolutely massive C program generally).
craz
Sorry, No Good Linux Debuggers (Score:4, Interesting)
We develop software for Linux and PS2 but all of our code builds on Windows and we spend most of our time working there. I strongly recommend you use a Windows XP/2000 and Visual C++ as your main development environment and port to Linux periodically. You'll save yourself countless hours of misery.
Good luck,
Vince Harron
Re:Sorry, No Good Linux Debuggers (Score:2)
Yeah, given the itch scratching nature of open source I'm stumped by the shortage of Linux debuggers and how little they've progressed since I graduated from college four years ago. I would have honestly expected Linux to have the cream-of-the-crop of debugging tools by now.
In addition to VC++/.NET don't forgot the seriously powerful lower-level debuggers like windbg, cdb, and the NT kernel debugger [microsoft.com] (all free). I couldn't imagine developing a serious app without these kinds of tools.
Re:Sorry, No Good Linux Debuggers (Score:3, Informative)
Asking the wrong question? (Score:3, Insightful)
It seems that the choices for debuggers under Linux are a bit lacking.
I hate to remember how many hours I've spend using source debuggers - chasing down long call stacks, getting confused about just what was gong on.
Now however, I haven't used a debugger at all in the last 10 years, under either Windows or Linux. The difference? - Modern software engineering practice.
Although there are doubtless legitimate cases where a debugger is very useful; my opinion is that for any decient sized C++ codes, the application of a handful of coding techniques is a much better substitute.
If you're chasing memory problems, use a suitable (zero cost) templated smart pointer implementation - so you can't even compile code that would corrupt memory. Similarly, apropriate abstraction classes for synchonization can also provide all the logging information you'll need to chase down synchnonization issues in parallel codes - and will help avoiding many of them in the first place (research has come a long way since the days of using error-prone primitive semaphores in high-level code).
I suggest also liberal use of assertions (preconditions, postconditions, invariances) and multi-level logging.
In my experience, with these tools, bad code that would cause memory corruptions or synthronization deadlocks or race-conditions will just not compile. Any that aren't caught are usually easily seen with the logging output or assertions.
Hope my suggestions help - even though I didn't address your question. If you want to read more, pickup some books on modern generic programming in C++ and a couple software engineering texts.
why wasn't this modded up? (Score:2)
Re:Asking the wrong question? (Score:3, Interesting)
I had a witty response all planned, but let me just be blunt: Are you a masochist? Either that or you're not doing serious C++ development, or you're a manager that doesn't write code.
My team uses everything you mention, with the addition of some other stuff like automatic memory leak detection and OS-level hooks to detect heap corruption, invalid handle usage, etc. [microsoft.com] I'm not even sure how your smart pointer template library would detect or prevent all heap corruption bugs, as they aren't always caused by dangling pointers...
While these techniques and tools are great, even with great programming practices there's no way you can eliminate all bugs this way. People make mistakes.
So when you're in the initial stages of development you're meaning to tell me that neither you nor anybody on your team makes a mistake where you end up dereferencing a NULL pointer? Or do you try to track it down from the logging instead of taking three seconds to get a call stack with symbols and line number information in a debugger? What about when another component or library crashes or returns an unexpected result; don't you investigate? What about subtle logic flaws that become readily apparent when stepping through the code with a debugger? You can't log everything.
Re:Asking the wrong question? (Score:1)
Re:Asking the wrong question? (Score:3, Interesting)
Yes, I've been doing serious C++ programming for years (of varying degrees of seriousness :). I am not a manager.
My team uses everything you mention, with the addition of some other stuff like automatic memory leak detection and OS-level hooks to detectI...
You won't need automatic memory leak detection if you make it *impossible* to program.
While these techniques and tools are great, even with great programming practices there's no way you can eliminate all bugs this way. People make mistakes.
Yes, people make mistakes - that is what the compiler is for (for the most part - of course I'm not claiming it can get *everything*)
So when you're in the initial stages of development you're meaning to tell me that neither you nor anybody on your team makes a mistake where you end up dereferencing a NULL pointer?
Correct. The smart-ptr class we use doesn't allow any such thing. Why on earth would you want to allow the concept of pointing to nothing? - it doesn't even make sense. Change your smart-ptr class to not allow initialization or assigmnent from anything but another smart-ptr. The constructor can construct new instances too, so it is impossible to have a pointer point to anything but a valid object. Our smart-ptr also checks the validity of the address with our memory management system before any dereference too - just in case it gets corrupted via some other mechanism - but that is very very rare.
What about when another component or library crashes or returns an unexpected result; don't you investigate? What about subtle logic flaws that become readily apparent when stepping through the code with a debugger? You can't log everything.
I admit we typically either have developed all the code in the system (save OS calls), or have control over the source of other libraries - so we can apply the same techniques to them. Not everyone can have that control.
Check out Andrei Alexandrescu's book on modern C++ design for a half-decient smart-ptr class to use as a starting point.
Re:Asking the wrong question? (Score:2)
The only way you can statically detect memory leaks is by severely restricting the kinds of data structures that you are allowed to create; i.e., by throwing away a huge amount of solution space.
What kind of tradeoff is that?
Re:Asking the wrong question? (Score:1)
Memory leaks are *not* generally statically detectable. That is, you cannot detect them at compile time.
But you *can* make it impossible to write code that leaks - at compile time.
Your compiler can enforce correct use of a smart-ptr - one which also manages storage either by reporting memory that was not manually reclaimed, or just automatically reclaiming it (garbage collection) - or both. If you use a garbage collector (either to reclaim all storage or just to get what you missed) then your code will not leak unless there is a bug in the collector or smart-ptr code.
There are also garbage collection techniques for C++ that work fine with C pointers and malloc/free - although I don't use them. They typically don't provide all the other type safety benefits of the smart-ptr approach.
Re:Asking the wrong question? (Score:1)
PS: You are right though - that if you don't use a garbage collector, if a smart-ptr is just reporting leaks - they are still leaks. That is why I use a garbage collector.
Re:Asking the wrong question? (Score:2)
However, my original point is that it is highly misleading to claim that using a static language construct can prevent memory leaks. What you seem to have meant is that language constructs can allow you to *detect* leaks at runtime, or that runtime support can allow garbage collection.
Your original post made it sound like "if the compiler doesn't complain, the code doesn't leak." Which is simply not possible, except under exceedingly restrictive conditions on the data structures the language supports.
Re:Asking the wrong question? (Score:1, Informative)
http://www.moderncppdesign.com/
but you have to give an e-mail address to read it.
Re:Asking the wrong question? (Score:2)
Kylix? (Score:2)
Well, I haven't tried it, but what about Borland Kylix [borland.com]? The new version 3 claims to support ANSI/ISO C++ on Linux. And if you read the feature PDF [borland.com] on page 4 they mention many of the features you seek.
It might be worth taking a look.
Totalview, and other options (Score:2)
In fact, I have found it to work in many places gdb fails. (e.g. I can get a nonsensical stack trace in g++ compiled code under gdb that totalview can still make sense of.)
Apart from that, there are the memory checking tools that are incredibly useful, often far more so than a debugger since they tell you when something went wrong, not when the problem escalated into a full segfault. I wish purify were available for linux -- I hope valgrind is good, and hope to try it out soon, but haven't yet. There is also something called zerofault, but I doubt it is available for linux.
Sadly, your best course of action may be to run on other platforms (irix, win32, solaris) where there are different tools available more to your liking. I know that's a bit hard for some projects, but different platforms often make different bugs appear. (For example, some hardware/software IRIX combinations instantly bus error on null pointer dereferences, other IRIXes happily ignore them until they cause worse problems.)
Metrowerks (Score:1)
The experts say: (Score:2)
Brian Kernighan and Rob Pike in The Practice of Programming say:
They go on to say that debuggers are valuable, and not to be overlooked. However they don't use them very much.
These are also well respected programers. I would recomend you follow their example unless you know a good reason not to.
P.S. typos in the above quote are my fault.
Try GVD (Score:2, Informative)
Does this count? (Score:1)
It's not quite a debugger I suppose
Multiple Processor : same interface and features for dozens of processors
Fully Interactive : you work with the disassembler and forget about tedious multiple passes.
High Level Constructs, such as unions, structures, variable size structures and enumerated types.
Stack Variables keep track of your local variables, Local Variables.
Program Navigator Toolbar
Fully dynamic Global and Local Labels.
Low Level Constructs such as bitfields
Interactive Register Renaming makes RISC processors easy.
Auto-commenting : you can even define and use your own comments base.
Versatility : loads and disassemble virtually any file. Visit our gallery for a small subset.
Graphing : through a VCG Port. Graphing as it stands in version 4.21
Two that i can think of (Score:2)
Useful if you're sent to the pen... (Score:1)
With the life sentences soon to be handed out to "hackers" who "endanger life" [it'll be interesting to see how far the lawyers stretch that], a good debuggerer could come in handy!
linux debugger (Score:1)
From http://www.etnus.com/Products/TotalView/platforms/ index.html --
You can also use TotalView to debug programs that you have created using compilers provided by Lahey, KAI, and PGI. Gnu compilers are also supported. Your programs can be written in Fortran, C, C++, or assembler.
Parallel environments that TotalView supports include MPICH, OpenMP, PVM, and SHMEM.
It's not all GDBs fault (Score:1)