public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* The step-Over (next) command seems repetitively displaying same statement execution
@ 2015-12-22 12:03 Jitendra Pawar
  2015-12-22 16:21 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Jitendra Pawar @ 2015-12-22 12:03 UTC (permalink / raw)
  To: gdb

Hello,

While using gdb some time I saw that the step-over(next) command
repeats whatever display in last step.
This mostly observed while stepping over the system calls. For example-

Below is my sample code snippet-
------------------------------------------------------------------------
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    char *c;

    c = (char*) malloc (12);

    memcpy(c, "Hello World", 12);

    printf("%s\n", c);
}
------------------------------------------------------------------------


While debugging this code I found that the malloc statement execution
repeats as shown below-


------------------------------------------------------------------------
$ gdb -q a.out
Reading symbols from /home/jitendra/work/roughwork/a.out...done.
(gdb) br main
Breakpoint 1 at 0x40054c: file hello.c, line 9.
(gdb) run
Starting program: /home/itendrap/work/roughwork/a.out
warning: no loadable sections found in added symbol-file
system-supplied DSO at 0x7ffff7ffa000

Breakpoint 1, main () at t.c:9
9        c = (char*) malloc (12);
(gdb) n
9        c = (char*) malloc (12);
(gdb) n
11        memcpy(c, "Hello World", 12);
(gdb) n
13        printf("%s\n", c);
(gdb) n
Hello World
14    }
(gdb)
------------------------------------------------------------------------

Can anyone please explain whats going wrong here? Why the malloc
statement 'c = (char*) malloc (12);' gets repeated?

Thanks in advance,
- Jitendra Pawar

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: The step-Over (next) command seems repetitively displaying same statement execution
  2015-12-22 12:03 The step-Over (next) command seems repetitively displaying same statement execution Jitendra Pawar
@ 2015-12-22 16:21 ` Eli Zaretskii
  2015-12-23  3:23   ` Jitendra Pawar
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2015-12-22 16:21 UTC (permalink / raw)
  To: Jitendra Pawar; +Cc: gdb

> Date: Tue, 22 Dec 2015 17:33:16 +0530
> From: Jitendra Pawar <jitendrap@ryussi.com>
> 
> $ gdb -q a.out
> Reading symbols from /home/jitendra/work/roughwork/a.out...done.
> (gdb) br main
> Breakpoint 1 at 0x40054c: file hello.c, line 9.
> (gdb) run
> Starting program: /home/itendrap/work/roughwork/a.out
> warning: no loadable sections found in added symbol-file
> system-supplied DSO at 0x7ffff7ffa000
> 
> Breakpoint 1, main () at t.c:9
> 9        c = (char*) malloc (12);
> (gdb) n
> 9        c = (char*) malloc (12);
> (gdb) n
> 11        memcpy(c, "Hello World", 12);
> (gdb) n
> 13        printf("%s\n", c);
> (gdb) n
> Hello World
> 14    }
> (gdb)
> ------------------------------------------------------------------------
> 
> Can anyone please explain whats going wrong here? Why the malloc
> statement 'c = (char*) malloc (12);' gets repeated?

What compilation command and switches did you use to compile this
program?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: The step-Over (next) command seems repetitively displaying same statement execution
  2015-12-22 16:21 ` Eli Zaretskii
@ 2015-12-23  3:23   ` Jitendra Pawar
  0 siblings, 0 replies; 3+ messages in thread
From: Jitendra Pawar @ 2015-12-23  3:23 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb

Hello Eli,

I am sorry, I forgot to mention that.

Compilation command is: " gcc hello.c -g " thats it.
gcc version is: 4.6.3
gdb version is: GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04

Thanks,
- Jitendra Pawar

On Tue, Dec 22, 2015 at 9:51 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> Date: Tue, 22 Dec 2015 17:33:16 +0530
>> From: Jitendra Pawar <jitendrap@ryussi.com>
>>
>> $ gdb -q a.out
>> Reading symbols from /home/jitendra/work/roughwork/a.out...done.
>> (gdb) br main
>> Breakpoint 1 at 0x40054c: file hello.c, line 9.
>> (gdb) run
>> Starting program: /home/itendrap/work/roughwork/a.out
>> warning: no loadable sections found in added symbol-file
>> system-supplied DSO at 0x7ffff7ffa000
>>
>> Breakpoint 1, main () at t.c:9
>> 9        c = (char*) malloc (12);
>> (gdb) n
>> 9        c = (char*) malloc (12);
>> (gdb) n
>> 11        memcpy(c, "Hello World", 12);
>> (gdb) n
>> 13        printf("%s\n", c);
>> (gdb) n
>> Hello World
>> 14    }
>> (gdb)
>> ------------------------------------------------------------------------
>>
>> Can anyone please explain whats going wrong here? Why the malloc
>> statement 'c = (char*) malloc (12);' gets repeated?
>
> What compilation command and switches did you use to compile this
> program?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-23  3:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-22 12:03 The step-Over (next) command seems repetitively displaying same statement execution Jitendra Pawar
2015-12-22 16:21 ` Eli Zaretskii
2015-12-23  3:23   ` Jitendra Pawar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).