Sponsored Content
Top Forums Programming Why does gdb stop at a different line than “i b” shows while returning from function? Post 302679737 by ijustneeda on Tuesday 31st of July 2012 02:24:48 PM
Old 07-31-2012
Why does gdb stop at a different line than “i b” shows while returning from function?

Here is the program I am trying to debug:

Code:
#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 Peter's gdb Tutorial: Stepping And Resuming. Here is the problem:

Code:
(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?
 

10 More Discussions You Might Find Interesting

1. Programming

string returning function

I have two string returning function in ESQL/C char *segment_name(lbuffer) char *lbuffer; {..... and char *get_bpdvalue(f_name) char *f_name; {...... both declared above main() char *get_bpdvalue(); char *segment_name(); my problem is segment_name works on sprintf and strcpy... (5 Replies)
Discussion started by: jisc
5 Replies

2. Programming

create a thread from a returning function

hi all, my requirement is to create a thread by calling another function. i.e i dont call pthread_create directly from main, but by calling another function (createThd - below ), from main. Example: void *thread_function(void *arg) { /* thread function */ int i; rc =... (3 Replies)
Discussion started by: wolwy_pete
3 Replies

3. Shell Programming and Scripting

returning from a function

Hi all, I am very new to BASH shell programming. I need to return an integer from a function to the caller function. I did this: but it keeps giving me wrong return: Can someone help me out here, please? Thanks (2 Replies)
Discussion started by: alirezan
2 Replies

4. Programming

execl function at GDB

Hi, we would appreciate if any one answer the below query. void main() { printf(“ I am in main\n”); execl(“/HOME/source/file2”,” /HOME/source/file2”,1,0); printf(“after execl\n”); } How to step the file2 source code in GDB. (2 Replies)
Discussion started by: RAMESHPRABUDASS
2 Replies

5. Programming

returning multiple values from a function in C

hi how can I return multiple values from a C function. I tried the following: #include <stdio.h> void foo(int id, char *first_name, char *last_name) { /* this is just an example to illustrate my problem... real code makes use of the "id" parameter. */ first_name = (char... (8 Replies)
Discussion started by: Andrewkl
8 Replies

6. Shell Programming and Scripting

Returning the name of function used

Hi All In my script, I can call on several functions. I have a logging function that is called by any of these functions. What I would like is some way of identifying which function I am using and pass this to the log function as some parameter. Is there some built in command or way of... (3 Replies)
Discussion started by: kingpin2502
3 Replies

7. Programming

Function Returning Value w/o return stmt

I am working on a C/Unix application from last 2 years which communicates with other systems using proprietary format of my client. We have a function written in C which returns integer, which is response from other system to the request message initiated by my system. This return value is then... (1 Reply)
Discussion started by: dpmore
1 Replies

8. Programming

Function Returning Pointer

Hi guys. how a functions such fdopen, ... can return pointer? are these functions use static memory(variables)? (6 Replies)
Discussion started by: majid.merkava
6 Replies

9. Programming

How to step in one function after the function be executed in gdb?

In gdb, I can call one function with command "call", but how can I step in the function? I don't want to restart the program, but the function had been executed, gdb will execute next statement, and I don't know how to recall the function. (4 Replies)
Discussion started by: 915086731
4 Replies

10. Programming

Malloc function returning NULL

Hi All, I am using malloc function for allocating dynamic memory. When I am using below code on Linux server its working fine, but When I am trying the same code on HP UNIX server its returning NULL. below is a fragment of code in which it is giving problem. tmp = (format_tree... (4 Replies)
Discussion started by: Taher Saifuddin
4 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. --font=desc Set the font description. Default is Monospace 12. --rtl Do rtl layout. --paper ps Choose paper size. Known paper sizes are legal, letter, a4. Default is A4. --bottom-margin=bm Set bottom margin in postscript points (1/72 inch). Default is 36. --top-margin=tm Set top margin. Default is 36. --left-margin=lm Set left margin. Default is 36. --right-margin=rm Set right margin. Default is 36. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --encoding=ENCODING Assume the documentation encoding is ENCODING. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 08:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy