Discussions

News: Debugger Tips

  1. Debugger Tips (15 messages)

    The blogger Kasia brought up the point that a lot of people aren't using debuggers. Cedric Beust then noted that there isn't a lot of material on good practices for using your debugger, so he posted a couple of good ones including: using conditional breakpoints, using break conditions for println, and running a method until it exits.

    Read Kasia in Why use a debugger?

    Read Cedric's Debugger Tips

    Threaded Messages (15)

  2. More Debugger Tips[ Go to top ]

    This post
    http://www.oracle.com/technology/products/jdev/howtos/10g/dbg_tips/debugger_tips1.html
    has some cool tricks that the JDeveloper debugger can do, like stepping back in time, and tracking memory allocation.
  3. Linus had posted this message a while back about debuggers. Even though the message is about kernel debuggers, I think there is wisdom in it for debugger use in general.

    Enjoy,

    >
    > very nice monologue, thanks. It would be great to know Linus' opinion. I
    > mean, I knew Linus' opinion of some years' ago but perhaps it changed? He
    > is a living being and not some set of rules written in stone so perhaps
    > current stability/highquality of kdb suggests to Linus that it may be
    > (just maybe) acceptable into official tree?

    I don't like debuggers. Never have, probably never will. I use gdb all the time, but I tend to use it not as a debugger, but as a disassembler on steroids that you can program.

    None of the arguments for a kernel debugger has touched me in the least. And trust me, over the years I've heard quite a lot of them. In the end, they tend to boil down to basically:

     - it would be so much easier to do development, and we'd be able to add new things faster.

    And quite frankly, I don't care. I don't think kernel development should be "easy". I do not condone single-stepping through code to find the bug. I do not think that extra visibility into the system is necessarily a good
    thing.

    Apparently, if you follow the arguments, not having a kernel debugger leads to various maladies:
     - you crash when something goes wrong, and you fsck and it takes forever and you get frustrated.
     - people have given up on Linux kernel programming because it's too hard and too time-consuming
     - it takes longer to create new features.

    And nobody has explained to me why these are _bad_ things.

    To me, it's not a bug, it's a feature. Not only is it documented, but it's _good_, so it obviously cannot be a bug.

    "Takes longer to create new features" - this one in particular is not a very strong argument for having a debugger. It's not as if lack of features or new code would be a problem for Linux, or, in fact, for the software industry as a whole. Quite the reverse. My biggest job is to say "no" to new features, not trying to find them.

    Oh. And sure, when things crash and you fsck and you didn't even get a clue about what went wrong, you get frustrated. Tough. There are two kinds of reactions to that: you start being careful, or you start whining about a kernel debugger.

    Quite frankly, I'd rather weed out the people who don't start being careful early rather than late. That sounds callous, and by God, it _is_ callous. But it's not the kind of "if you can't stand the heat, get out the the kitchen" kind of remark that some people take it for. No, it's something much more deeper: I'd rather not work with people who aren't careful. It's darwinism in software development.

    It's a cold, callous argument that says that there are two kinds of people, and I'd rather not work with the second kind. Live with it.

    I'm a bastard. I have absolutely no clue why people can ever think otherwise. Yet they do. People think I'm a nice guy, and the fact is that I'm a scheming, conniving bastard who doesn't care for any hurt feelings or lost hours of work if it just results in what I consider to be a better system.

    And I'm not just saying that. I'm really not a very nice person. I can say "I don't care" with a straight face, and really mean it.

    I happen to believe that not having a kernel debugger forces people to think about their problem on a different level than with a debugger. I think that without a debugger, you don't get into that mindset where you know how it behaves, and then you fix it from there. Without a debugger, you tend to think about problems another way. You want to understand
    things on a different _level_.

    It's partly "source vs binary", but it's more than that. It's not that you have to look at the sources (of course you have to - and any good debugger will make that _easy_). It's that you have to look at the level _above_ sources. At the meaning of things. Without a debugger, you basically have
    to go the next step: understand what the program does. Not just that particular line.

    And quite frankly, for most of the real problems (as opposed to the stupid bugs - of which there are many, as the latest crap with "truncate()" has shown us) a debugger doesn't much help. And the real problems are what I worry about. The rest is just details. It will get fixed eventually.

    I do realize that others disagree. And I'm not your Mom. You can use a kernel debugger if you want to, and I won't give you the cold shoulder because you have "sullied" yourself. But I'm not going to help you use one, and I wuld frankly prefer people not to use kernel debuggers that much. So I don't make it part of the standard distribution, and if the
    existing debuggers aren't very well known I won't shed a tear over it.

    Because I'm a bastard, and proud of it!

    Linus
  4. Linus had posted this message a while back about debuggers. Even though the message is about kernel debuggers, I think there is wisdom in it for debugger use in general.

    Why not avoid the usual development cycle at all? Just figure out the program in your mind with maybe the mildly scorned off use of some scratch paper and avoiding mundane things like development tools (intellisense, debuggers, IDE, etc..). Avoid tests too because there is no need of them, having already thought off all the possibile scenarios and side-effects. Finally just compile it and deploy.
  5. Let me paraphrase Linus:

    I hate stupid people. Stupid people have no business making me aware of their existence, much less contributing to the Linux kernel. Debuggers help stupid people find trivial bugs. Finding trivial bugs makes them think that they are not stupid, and consequently they make me aware of their existence and commit the atrocity of trying to commit to the kernel. Also, I don't find debuggers particularly usefule. Therefore, I don't like debuggers. However, if you are an intelligent person, I don't care whether or not you use a debugger. I don't care if you climbed a mountain and God himself told you how to fix the code. All I care about whether you've come up with an intelligent solution to a non-trivial problem, and therefore are not wasting my time.

    -----------------------------------

    Two Points:
    1. I completely agree with Linus's stance on stupid people, even though I suspect he would put me in that group if I submitted a kernel patch.

    2. The rest of us mere mortals have to be concerned with those trivial errors that debuggers help us find - and must of us don't enjoy tracking them down so we want to spend as little time on it as possible.

    Debuggers are a tool. Most of the anti-debugger posts amount to "I know a lot of stupid programmers who use debuggers. If they didn't have debuggers, maybe they would not longer be able to be programmers and therefore would be unable to cause me headaches. Therefore, I hate debuggers."

    Don't bash the tool, bash the people. They're the ones being annoying.
  6. Kasia is a women ;)[ Go to top ]

    It sound a bit strange "The blogger Kasia...". Kasia is not a nick (I thik). Kasia is popular girl's name in central Europe (just Catrin). Seems that Kasia has Polish roots thus a bit difficult name and surname. Just FYI.

    Artur
  7. Debuggers are slow[ Go to top ]

    Although debuggers do help out in certain situations, I would avoid them if I can. Primarily because they slow you down. I'd rather figure out how to test the "non-framework" code using a JUnit test rather than letting it go through the debugger. Failing that I'll see if I can assign the task of creating the test framework to someone else who can program better than myself.

    The debugger would still be useful if you suspect something to be wrong in the framework and cannot easily validate using a sanity test against the framework.

    Of course this assumes that you are not developing the framework at the same time you are developing your application. If you are its best that you split the work into two groups, one for the framework and one for the application and make sure that application developers do not actually go directly into the framework internals (if possible).

    BTW, you can do this without removing Collective Code Ownership. Just allow an application developer to switch to framework developer and vice versa on occassion, but they should not be working on both the framework and the application on the same workspace at the same time.
  8. Debuggers are slow[ Go to top ]

    Although debuggers do help out in certain situations, I would avoid them if I can.

    How do you know if you can?

    --
    Cedric
    http://beust.com/weblog
  9. Debuggers are slow[ Go to top ]

    I'd rather figure out how to test the "non-framework" code using a JUnit test rather than letting it go through the debugger.

    You appear to confuse discovering bugs with locating and fixing them.
  10. Debuggers are slow[ Go to top ]

    This was a really good joke.....thou i dont quite understand every bit of it :)))

    First of all, u r confusing between testing and debugging. Testing and debugging are not substitues. When ur test case fails, u debug unless its pretty evident whats wrong.

    Also i dont see why debugging slows u down.

    Although debuggers do help out in certain situations, I would avoid them if I can. Primarily because they slow you down. I'd rather figure out how to test the "non-framework" code using a JUnit test rather than letting it go through the debugger. Failing that I'll see if I can assign the task of creating the test framework to someone else who can program better than myself.The debugger would still be useful if you suspect something to be wrong in the framework and cannot easily validate using a sanity test against the framework.Of course this assumes that you are not developing the framework at the same time you are developing your application. If you are its best that you split the work into two groups, one for the framework and one for the application and make sure that application developers do not actually go directly into the framework internals (if possible).BTW, you can do this without removing Collective Code Ownership. Just allow an application developer to switch to framework developer and vice versa on occassion, but they should not be working on both the framework and the application on the same workspace at the same time.
  11. Debuggers are slow[ Go to top ]

    Although debuggers do help out in certain situations, I would avoid them if I can. Primarily because they slow you down.

    I dunno.. maybe I'm a bit old school, but I'm influenced by Steve McConnell author of Writing Solid Code and Debugging the Software Development process who suggests that you should step through all your code in the debugger before checking it in.

    The rational is that freshly written code most likely has bugs in it, you might as well do the stepping sooner than later then (since repairing the bug sooner is cheaper than later). I'm not sure Unit tests change this.

    Since maintenance is a higher cost than initial development, maybe Steve McConnell is right?
  12. Debuggers are slow[ Go to top ]

    Thou it may be tough to get into this habit, i think it definitely makes sense...
    Although debuggers do help out in certain situations, I would avoid them if I can. Primarily because they slow you down.
    I dunno.. maybe I'm a bit old school, but I'm influenced by Steve McConnell author of Writing Solid Code and Debugging the Software Development process who suggests that you should step through all your code in the debugger before checking it in. The rational is that freshly written code most likely has bugs in it, you might as well do the stepping sooner than later then (since repairing the bug sooner is cheaper than later). I'm not sure Unit tests change this.Since maintenance is a higher cost than initial development, maybe Steve McConnell is right?
  13. Use debuggers even for new code[ Go to top ]

    I dunno.. maybe I'm a bit old school, but I'm influenced by Steve McConnell author of Writing Solid Code and Debugging the Software Development process who suggests that you should step through all your code in the debugger before checking it in.

    Yes!

    This is such an important statement that I wrote another blog entry about it:

    http://beust.com/weblog/archives/000202.html

    Let me know what you think.

    --
    Cedric
  14. Before you even write new code....[ Go to top ]

    I dunno.. maybe I'm a bit old school, but I'm influenced by Steve McConnell author of Writing Solid Code and Debugging the Software Development process who suggests that you should step through all your code in the debugger before checking it in.
    Yes!This is such an important statement that I wrote another blog entry about it: http://beust.com/weblog/archives/000202.htmlLet me know what you think.-- Cedric

    You can go one step further with hotswap and full speed debugging and not event write the code before you hit the breakpoint:

    http://www.orablogs.com/gdavison/archives/000146.html

    That way you have a full understanding of the parameters as you build up the method. It can be quite usefull in certain cases where the API you are using is unfamiliar. Definitely much faster than having to rebuild.
  15. Bugseeker2 from Karmira...[ Go to top ]

    I quite liked Bugseeker2 from Karmira, but the company pretty much dropped off the face of the placent a couple of years ago. Anyone know what happened to them?

    http://www.karmira.com

    Then again, since moving over to unit testing, I haven't had nearly the need to step through my applications...
  16. Bugseeker2 from Karmira...[ Go to top ]

    Then again, since moving over to unit testing, I haven't had nearly the need to step through my applications...

    i dont know if u read my post above, but i fail to understand why u r trying to compare unit testing with debugging. what happens when ur unit test fails. dont u have to fix it. i agree that there are many problems which are evident and u dont need to step thru ur code to narrow down to the problem. but what abt the tougher problems. unless u r working with simple code, i dont see why a debugger wont help u. i am not saying that a debugger is mandatory but it will definitely decrease the amount of time spent in narrowing down on the problem and fixing it.