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

  • Home
  • SEARCH
  • 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 8353825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:22:33+00:00 2026-06-09T09:22:33+00:00

Here is the program I am trying to debug: #include <stdio.h> int i =

  • 0

Here is the program I am trying to debug:

#include <stdio.h>
int i = 5;

int main(void)
{
    int x = 3;

    display(x);
    return 0;
}


void display(int x)
{
for ( i=0; i<x; ++i ) {
    printf("i is %d.\n", i);
}
}

This code is coming from here http://www.dirac.org/linux/gdb/05-Stepping_And_Resuming.php#breakpointsandwatchpoints. Here is the problem:

(gdb) break display 
Breakpoint 1 at 0x40051e: file try5.c, line 15.
(gdb) run
Starting program: /home/ja/gdb/learning/try5 

Breakpoint 1, display (x=3) at try5.c:15
(gdb) frame 1
#1  0x000000000040050c in main () at try5.c:8
(gdb) break 
Breakpoint 2 at 0x40050c: file try5.c, line 8.
(gdb) c
Continuing.
i is 0.
i is 1.
i is 2.

Breakpoint 2, main () at try5.c:9
(gdb) i b
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000000000040051e in display at try5.c:15
    breakpoint already hit 1 time
2       breakpoint     keep y   0x000000000040050c in main at try5.c:8
    breakpoint already hit 1 time
(gdb) c
Continuing.

Program exited normally.
(gdb) q

Debugger finished

It was supposed to stop at line 8 in main() but it stopped at line 9 it main(). For me it’s misleading. I think it should stop at line 9, because this is what ‘break’ commands does – sets a break point at the very next instruction. But why “info breakpoints” said that the break point was set at line 8?

  • 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-06-09T09:22:35+00:00Added an answer on June 9, 2026 at 9:22 am

    The breakpoint is placed at the right place, as you saw, because it did break after returning from the function. If you do a disassemble, you’ll also see that the breakpoint is placed at the right instruction (in this example at 0x00401192):

    b display
    r
    f 1
    b
    disassemble $pc
    ...
       0x0040118d <+29>:    call   0x401199 <display>
    => 0x00401192 <+34>:    mov    $0x0,%eax
       0x00401197 <+39>:    leave
    
    i b
    ...
    2       breakpoint     keep y   0x00401192 in main at try5.c:8
    

    But it shows the wrong line number. First I thought it might be related to function return, so I added extra instructions after the display call, but it still shows the wrong line.

    This looks a bug to me.

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

Sidebar

Related Questions

So here I am trying to debug this issue where the program takes forever
Here's my program so far: int main() { char choice = 'D'; string inputString;
I am trying to debug my program using NSZombie. The debugger did return me
I trying to debug code on my first Android program. I started using the
Similar to this problem here: Old Question about C# debugging I'm trying to debug
Here is the entirety of my code, I am trying to debug it, but
I am trying to launch a program from another program. Here is the code
I'm trying to build a hello-world program here to check my android kit installation.
I am trying to send mail using SmtpClient() within my Winforms VB.Net program Here
Here's the deal: I'm trying, as a learning experience, to convert a C program

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.