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
XmbDrawString(3X11)						  XLIB FUNCTIONS					       XmbDrawString(3X11)

NAME
XmbDrawString, XwcDrawString, Xutf8DrawString - draw text using a single font set SYNTAX
void XmbDrawString(display, d, font_set, gc, x, y, string, num_bytes) Display *display; Drawable d; XFontSet font_set; GC gc; int x, y; char *string; int num_bytes; void XwcDrawString(display, d, font_set, gc, x, y, string, num_wchars) Display *display; Drawable d; XFontSet font_set; GC gc; int x, y; wchar_t *string; int num_wchars; void Xutf8DrawString(display, d, font_set, gc, x, y, string, num_bytes) Display *display; Drawable d; XFontSet font_set; GC gc; int x, y; char *string; int num_bytes; ARGUMENTS
d Specifies the drawable. display Specifies the connection to the X server. font_set Specifies the font set. gc Specifies the GC. num_bytes Specifies the number of bytes in the string argument. num_wchars Specifies the number of characters in the string argument. string Specifies the character string. x y Specify the x and y coordinates. DESCRIPTION
The XmbDrawString, XwcDrawString and Xutf8DrawString functions draw the specified text with the foreground pixel. When the XFontSet has missing charsets, each unavailable character is drawn with the default string returned by XCreateFontSet. The behavior for an invalid codepoint is undefined. The function Xutf8DrawString is an XFree86 extension introduced in XFree86 4.0.2. Its presence is indicated by the macro X_HAVE_UTF8_STRING. SEE ALSO
XDrawImageString(3X11), XDrawString(3X11), XDrawText(3X11), XmbDrawImageString(3X11), XmbDrawText(3X11) Xlib - C Language X Interface X Version 11 Release 6.6 XmbDrawString(3X11)
All times are GMT -4. The time now is 07:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy