top | item 17493467

(no title)

strong_silent_t | 7 years ago

I find it depends a lot on my level of understanding of the project I'm working on. If I wrote 20% or more of the code, or if I was involved in the design, etc., when there is a problem I know just where to look and can get there quickly.

For example, if I'm working on a Python script under 1000 lines I would never use a debugger. I might use wireshark or linux system tools if something was really wrong, but usually the trackback or program output is sufficient.

I've also tried to debug an Arduino project where I had a lot less knowledge of how the system works, and if I wasn't able to attach a debugger I don't want to know how long it would have taken me to find the problem (calling a null function pointer causes an interrupt that didn't have any handler).

I've also tried to debug other people's projects in high level languages, without a debugger where after taking about an hour to figure it out based on pure reason, realizing it would have been very quick and easy to find with a debugger.

I think if you look at what a program is doing, and at that point you can't form a testable hypothesis as to what is happening, at that point a debugger will certainly be faster if you know how to use it.

discuss

order

pmarreck|7 years ago

> I find it depends a lot on my level of understanding of the project I'm working on. If I wrote 20% or more of the code, or if I was involved in the design, etc., when there is a problem I know just where to look and can get there quickly.

Well, I mean... Ever wonder why that is? Your understanding of the various states the program can get into is fresh in your mind. Come back to it in a year after not looking at it all that time and suddenly you're relying hardcore on your unit test suite to contain that same knowledge in "automated proof" form... OR you start spending a lot of time in the debugger to "re-understand" the system, slowly and manually... Or both.

If you need to use a debugger, it's because you are in some unexpected state. With full understanding comes full control and in those cases, no, you need neither a debugger NOR a test suite, but since a test suite on well-written code already identifies many possible state failures, I've found that leaning on that instead of a debugger works out better in the end.

brokenmachine|7 years ago

How did you use a debugger on Arduino? I've been using Serial.print("WTF") more than I'd admit.

strong_silent_t|7 years ago

This is similar to what I did: https://learn.adafruit.com/proper-step-debugging-atsamd21-ar... . That is for that specific platform, not sure if there is something similar for the other versions.

I used the J-Link but I wanted to do it on Linux, so I used the JLink GDB Server along with the GDB build that comes with the Arduino IDE. It probably takes me a good 5 minutes to get everything set up, but the basic stuff works: breakpoints, stack trace, reading and writing memory locations.

The setup is a little convoluted, I'm not sure if there is a better way, but here are my notes:

    Procedure for running w/ debugger attached.
    
    1. disconnect debugger's usb
    2. connect device via usb
    3. arduino IDE program device
    4. identify elf, set up gdb with elf.
    5. plug in debugger
    6. run jlink gdb server
    7. attach gdb to jlink server "target remote:2331"
    8. "monitor reset", "continue" to re-run target from beginning.
    9. observe device is recognized by Arduino IDE
    10. open Arduino IDE serial monitor to interact with device.
    
    Now, Ctrl+C in GDB halts device, and stack etc. can be inspected, and
    then it can continue running with "cont".
    
    To rerun the device with the same program without redoing everything,
    go to step 8 and reset the device. and continue from there.
    
    To find .elf on linux:
    ==================================================
    find /tmp -name sketch_name.ino.elf 2>/dev/null
    

    gdb location:
    ==================================================
    /home/user/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gdb
    
    
    JLink setup command:
    ==================================================
    JLinkGDBServer -device ATSAMD21G18A -if SWD -speed 4000
    

    gdb attachment:
    ==================================================
    (gdb) target remote:2331