Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* What make the directive run twice?
@ 2004-06-03  7:10 Jason Luo
  2004-06-03 20:44 ` Daniel Jacobowitz
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Luo @ 2004-06-03  7:10 UTC (permalink / raw)
  To: gdb

Hi all,

I use gdb 6.1 to debug Grub 0.94.When I debug the function check_device 
in lib/device.c,I found that the fopen directive was run twice.

[root@jason build]# gdb grub/grub
.........
(gdb) b device.c:617
Breakpoint 1 at 0x805dc29: file ../../lib/device.c, line 617.
(gdb) r
Starting program: /home/jason/sources/grub-0.94/build/grub/grub
Probing devices to guess BIOS drives. This may take a long time.

Breakpoint 1, init_device_map (map=0x806609c, map_file=0xbfffd350 "", 
floppy_disks=1)
     at ../../lib/device.c:617
617           get_ide_disk_name (name, i);
(gdb) n
618           if (check_device (name))
(gdb) s                             //here,I step in check_device
check_device (device=0xbfffd350 "/dev/hda") at ../../lib/device.c:321
321       if (*device == 0)
(gdb) p device
$1 = 0xbfffd350 "/dev/hda"
(gdb) n
324       fp = fopen (device, "r");
(gdb)
325       if (! fp)
(gdb)
346           return 0;             //return from here,but...
(gdb)
324       fp = fopen (device, "r");   //come to here!!!
(gdb) p device
$2 = 0x8073860 "\210$?"       //the parameter device was changed!!!!
(gdb) n
346           return 0;       //return from here,but
(gdb)
353       if (ioctl (fileno (fp), CDROM_GET_CAPABILITY, 0) >= 0)
(gdb)


When this section in gdb,the process is not correct and the device 
parameter of check_device function was changed.

what cause it?How can I do it?

My env is  gcc 3.3.1,glibc 2.3.2,Intel(R) Pentium(R) 4 CPU 2.60GHz with HT.

Jason


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

* Re: What make the directive run twice?
  2004-06-03  7:10 What make the directive run twice? Jason Luo
@ 2004-06-03 20:44 ` Daniel Jacobowitz
  2004-06-04  2:34   ` Jason Luo
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Jacobowitz @ 2004-06-03 20:44 UTC (permalink / raw)
  To: Jason Luo; +Cc: gdb

On Thu, Jun 03, 2004 at 03:07:59PM +0800, Jason Luo wrote:
> Hi all,
> 
> I use gdb 6.1 to debug Grub 0.94.When I debug the function check_device 
> in lib/device.c,I found that the fopen directive was run twice.

It wasn't run twice; it appears in the step output twice.  This is
common when debugging optimized code; part of the function call occurs
before the previous line and part after.

-- 
Daniel Jacobowitz


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

* Re: What make the directive run twice?
  2004-06-03 20:44 ` Daniel Jacobowitz
@ 2004-06-04  2:34   ` Jason Luo
  2004-06-04 12:11     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Luo @ 2004-06-04  2:34 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

> It wasn't run twice; it appears in the step output twice.  This is
> common when debugging optimized code; part of the function call occurs
> before the previous line and part after.

I disassemble the call function init_device_map,and the function 
check_device,I didn't find that you says.

init_device_map call check_deivce,then the control jump to the function 
check_device,then process continue.The process flow is correct  like the 
c source file's.

I guess you say is the binary code was optimized,isn't it? Counld you 
reference to me about the point?Thanks!


Best Regards
Jason



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

* Re: What make the directive run twice?
  2004-06-04  2:34   ` Jason Luo
@ 2004-06-04 12:11     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2004-06-04 12:11 UTC (permalink / raw)
  To: Jason Luo; +Cc: drow, gdb

> Date: Fri, 04 Jun 2004 10:30:32 +0800
> From: Jason Luo <jasonl@turbolinux.com.cn>
> 
> > It wasn't run twice; it appears in the step output twice.  This is
> > common when debugging optimized code; part of the function call occurs
> > before the previous line and part after.
> 
> I disassemble the call function init_device_map,and the function 
> check_device,I didn't find that you says.
> 
> init_device_map call check_deivce,then the control jump to the function 
> check_device,then process continue.The process flow is correct  like the 
> c source file's.

That's not the right way to analyze this.

When you type "next" in GDB, GDB needs to know how machine
instructions to run to land at the next source line.  So what you need
to do is to use a tool such as objdump to see what is the
correspondence between program code addresses and source lines.  That
is the information used by GDB during stepping.

My experience is consistent with what Daniel says: stepping through
optimized code quite often jumps between source lines like you saw.


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

end of thread, other threads:[~2004-06-04 12:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-03  7:10 What make the directive run twice? Jason Luo
2004-06-03 20:44 ` Daniel Jacobowitz
2004-06-04  2:34   ` Jason Luo
2004-06-04 12:11     ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox