Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6974991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:18:35+00:00 2026-05-27T17:18:35+00:00

I’m debugging some ANSI C code with gcc44 and gdb, on a 64bit Linux

  • 0

I’m debugging some ANSI C code with gcc44 and gdb, on a 64bit Linux CentOS 5.7 server.

Around the middle of one of my functions, I have a for loop that loops 192 times (there are 2 lines of code in the loop). If I setup gdb with a breakpoint at the start of the for loop, I can step through the for loop all 192 times and it exits the for loop and continues into the next line of code after the for loop. This is all stepping through the code in gdb using "s" or "n". Everything works fine.

Now, instead of stepping through the for loop using "s" or "n" to get to the next line of code after the for loop, I start gdb and then set a breakpoint at the line just after the end of the for loop. If I then press "c" in gdb, it gives me "Program exited normally". I expected gdb to stop at this breakpoint located on the line of code just after the for loop. (!?)

As another experiment, I learned that gdb DOES successfully stop on any breakpoint set on any line after the line of code immediately following the for loop.

Maybe others have had this experience judging by questions such as this (there are 2 additional references therein):

gdb error "Program exited normally"

It’s repeatable in gdb. Without digging into the code in question, anyone seen this behavior before and/or have any idea what I could check?

EDIT 1

If I include a printf("\n"); on the breakpoint line that gives problems above, moving what used to be on that line to one line below this printf code, then everything works fine (e.g. gdb stops on the printf line).

I can even set a breakpoint successfully on the previously-problematic line of code in question, which is now the next line after the printf line. Weird!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:18:36+00:00Added an answer on May 27, 2026 at 5:18 pm

    Your compiler is playing tricks on you.

    Well, not really, but it’s not doing exactly what you suspect.

    A first principals concept of the compiler would be to sequentially turn every line of C into one or more assembly instructions, and execute the assembly in the same order as the C code.

    In reality the compiler will reorganize things to optimize for speed or space. If an instruction is deemed to have no net effect on the program state it could be removed completely. Thus when you tell GDB to break on that line, well.. there is no assembly instruction with debugging information pointing to that line of C.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.