Thread: How to use breakpoints

  1. #1
    Registered User
    Join Date
    Feb 2019
    Posts
    70

    How to use breakpoints

    Hi everyone,

    I am trying to learn the basics of debugging using SEGGER. I am using a very simple blinky example to start learning debugging.
    I have declare and initialize two variables x & y. When I run the debugger and use the "watch" window to monitor the value of each variable, I can see the y variable but neither the x or i variables.. It sais "symbol not found" as shown on screenshot_69

    How to use breakpoints-screenshot_69-jpg

    The strange thing is that if I initialize x=0 then I can see the x variable on "watch" window as shown on screenshot_70. But again I cannot see the i variable.

    How to use breakpoints-screenshot_70-jpg

    Moreover if I delete both x and y variables then I can monitor i variable while debugging as shown in screenshot_71.

    How to use breakpoints-screenshot_71-jpg


    I cannot figure out what I am doing wrong with the breakpoints.. Any help?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,626
    How are you compiling the code?

    Which compiler are you using?

    Unless you specifically compile with debug enabled (say gcc -g) and no optimisations (say gcc -O0), then some things might not actually exist in the code any more.

    So for example, if the compiler keeps a particular 'variable' always in a register, then you might never see it's value in the debugger.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    70
    Hi Salem and thank you for your answer!!

    Quote Originally Posted by Salem View Post
    Which compiler are you using?
    I am using the GCC compiler with SEGGER IDE.

    Quote Originally Posted by Salem View Post
    How are you compiling the code?

    Unless you specifically compile with debug enabled (say gcc -g) and no optimisations (say gcc -O0), then some things might not actually exist in the code any more.
    You're right (that's why I love forums!!!), I was compiling in release mode, that's why I wasn't reading particular variables.. After compiling into debugging mode I was able to read every variable.

    I lost two hours of searching yesterday but that was I good lesson since now I have a clearer view of release and debugging modes.

    So in general while developing a firmware you have to compile in debugging mode and as soon as you're ready to flash the firmware to the target you have to compile into release mode for optimization right?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,626
    Ordinarily, I would suggest creating yourself a little mock environment of your embedded target that allows you to test say 90% of your code before you even flash the device.

    SEGGER also offer their own simulations.
    Simulation | SEGGER - The Embedded Experts

    Whilst in theory there is no difference between debug and release (except for speed and size), aggressive optimisation levels will flush out bad assumptions in your code which debug will just gloss over. So you do at least need to test your release builds every so often.

    But while you have the memory space on the target, stick to flashing debug builds if you want to do any on target investigations.

    You can use the debugger with release builds, but you need to be mindful that what is being run is not quite what it seems in the source code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gdb breakpoints
    By atlantis43 in forum C Programming
    Replies: 6
    Last Post: 06-07-2015, 02:10 AM
  2. GDB help with setting breakpoints
    By shredderr in forum C Programming
    Replies: 5
    Last Post: 04-19-2011, 08:47 AM
  3. C::B breakpoints problem
    By Kayl669 in forum C Programming
    Replies: 4
    Last Post: 02-18-2010, 11:31 AM
  4. Hardware Breakpoints
    By Hawkin in forum C Programming
    Replies: 14
    Last Post: 02-24-2008, 09:24 PM
  5. Breakpoints in VC7.1
    By nidhimathew in forum C++ Programming
    Replies: 1
    Last Post: 08-10-2004, 05:10 PM

Tags for this Thread