public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* How to use "frame addr" command in gdb?
@ 2014-11-19  5:46 Nan Xiao
  2014-11-19  6:49 ` Yao Qi
  0 siblings, 1 reply; 4+ messages in thread
From: Nan Xiao @ 2014-11-19  5:46 UTC (permalink / raw)
  To: gdb

Hi all,

I know there are 2 commands for selecting frame: "frame n" and "frame addr"(Selecting a Frame in gdb manual). And write a simple program to test the 2 commands.

The program is like this:

#include <stdio.h>

int func1(int a)
{
        return 2 * a;
}

int func2(int a)
{
        int c = 0;
        c = 2 * func1(a);
        return c;
}

int func3(int a)
{
        int c = 0;
        c = 2 * func2(a);
        return c;
}

int main(void)
{
        printf("%d\n", func3(10));
        return 0;
}

I use gdb to debug this program, and find 'frame n' command works OK:
(gdb) bt
#0  func1 (a=10) at a.c:5
#1  0x08050b67 in func2 (a=10) at a.c:11
#2  0x08050b89 in func3 (a=10) at a.c:18
#3  0x08050bb9 in main () at a.c:24
(gdb) frame 2
#2  0x08050b89 in func3 (a=10) at a.c:18

But when I want to use "frame addr" command, it seems not work well:

(gdb) frame 0x08050bb9
#0  0x00000000 in ?? ()
(gdb) frame 0x08050b89
#0  0x00000000 in ?? ()
(gdb) frame 0x08050b92
#0  0x00000000 in ?? ()

How to use "frame addr" command? Thanks very much in advance! I can't find other reference except the manual.

P.S. My gdb is 7.8.1, and works on Solaris X86 platform.

Best Regards
Nan Xiao

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

* Re: How to use "frame addr" command in gdb?
  2014-11-19  5:46 How to use "frame addr" command in gdb? Nan Xiao
@ 2014-11-19  6:49 ` Yao Qi
  2014-11-19  7:09   ` =?gb18030?B?TmFuIFhpYW8=?=
  2014-11-19  9:48   ` Pedro Alves
  0 siblings, 2 replies; 4+ messages in thread
From: Yao Qi @ 2014-11-19  6:49 UTC (permalink / raw)
  To: Nan Xiao; +Cc: gdb

Nan Xiao <xiaonan19830818@qq.com> writes:

> I use gdb to debug this program, and find 'frame n' command works OK:
> (gdb) bt
> #0  func1 (a=10) at a.c:5
> #1  0x08050b67 in func2 (a=10) at a.c:11
> #2  0x08050b89 in func3 (a=10) at a.c:18
> #3  0x08050bb9 in main () at a.c:24
> (gdb) frame 2
> #2  0x08050b89 in func3 (a=10) at a.c:18
>
> But when I want to use "frame addr" command, it seems not work well:
>
> (gdb) frame 0x08050bb9
> #0  0x00000000 in ?? ()
> (gdb) frame 0x08050b89
> #0  0x00000000 in ?? ()
> (gdb) frame 0x08050b92
> #0  0x00000000 in ?? ()
>
> How to use "frame addr" command? Thanks very much in advance! I can't
> find other reference except the manual.

You pass the wrong address to command "frame".  The addresses in the
output of "bt" command are the pc values in each frame.  They are not
the address of frames.

(gdb) help frame
Select and print a stack frame.
With no argument, print the selected stack frame.  (See also "info frame").
An argument specifies the frame to select.
It can be a stack frame number or the address of the frame.
                                  ^^^^^^^^^^^^^^^^^^^^^^^^
With argument, nothing is printed if input is coming from
a command file or a user-defined command.

We should pass "the address of the frame" to command "frame", and it can
be got from command "info frame".

(gdb) bt
#0  func1 (a=10) at 2.c:6
#1  0x08048452 in func2 (a=10) at 2.c:12
#2  0x08048474 in func3 (a=10) at 2.c:19
#3  0x08048493 in main () at 2.c:25
(gdb) info frame 2
Stack frame at 0xbfffee70:
               ^^^^^^^^^^ the address of the frame
 eip = 0x8048474 in func3 (2.c:19); saved eip = 0x8048493
 called by frame at 0xbfffee90, caller of frame at 0xbfffee54
 source language c.
 Arglist at 0xbfffee68, args: a=10
 Locals at 0xbfffee68, Previous frame's sp is 0xbfffee70
 Saved registers:
  ebp at 0xbfffee68, eip at 0xbfffee6c

(gdb) frame 0xbfffee70
#2  0x08048474 in func3 (a=10) at 2.c:19
19              c = 2 * func2(a);

-- 
Yao (齐尧)

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

* Re:  How to use "frame addr" command in gdb?
  2014-11-19  6:49 ` Yao Qi
@ 2014-11-19  7:09   ` =?gb18030?B?TmFuIFhpYW8=?=
  2014-11-19  9:48   ` Pedro Alves
  1 sibling, 0 replies; 4+ messages in thread
From: =?gb18030?B?TmFuIFhpYW8=?= @ 2014-11-19  7:09 UTC (permalink / raw)
  To: =?gb18030?B?WWFvIFFp?=; +Cc: =?gb18030?B?Z2Ri?=

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain;	charset="gb18030", Size: 2331 bytes --]

Hi Yao,

    Got it! Thanks very much for your clarifying of it!

Best Regards
Nan Xiao
------------------ Original ------------------
From:  "Yao Qi";<yao@codesourcery.com>;
Date:  Wed, Nov 19, 2014 02:49 PM
To:  "Nan Xiao"<xiaonan19830818@qq.com>;
Cc:  "gdb"<gdb@sourceware.org>;
Subject:  Re: How to use "frame addr" command in gdb?

Nan Xiao <xiaonan19830818@qq.com> writes:

> I use gdb to debug this program, and find 'frame n' command works OK:
> (gdb) bt
> #0  func1 (a=10) at a.c:5
> #1  0x08050b67 in func2 (a=10) at a.c:11
> #2  0x08050b89 in func3 (a=10) at a.c:18
> #3  0x08050bb9 in main () at a.c:24
> (gdb) frame 2
> #2  0x08050b89 in func3 (a=10) at a.c:18
>
> But when I want to use "frame addr" command, it seems not work well:
>
> (gdb) frame 0x08050bb9
> #0  0x00000000 in ?? ()
> (gdb) frame 0x08050b89
> #0  0x00000000 in ?? ()
> (gdb) frame 0x08050b92
> #0  0x00000000 in ?? ()
>
> How to use "frame addr" command? Thanks very much in advance! I can't
> find other reference except the manual.

You pass the wrong address to command "frame".  The addresses in the
output of "bt" command are the pc values in each frame.  They are not
the address of frames.

(gdb) help frame
Select and print a stack frame.
With no argument, print the selected stack frame.  (See also "info frame").
An argument specifies the frame to select.
It can be a stack frame number or the address of the frame.
                                  ^^^^^^^^^^^^^^^^^^^^^^^^
With argument, nothing is printed if input is coming from
a command file or a user-defined command.

We should pass "the address of the frame" to command "frame", and it can
be got from command "info frame".

(gdb) bt
#0  func1 (a=10) at 2.c:6
#1  0x08048452 in func2 (a=10) at 2.c:12
#2  0x08048474 in func3 (a=10) at 2.c:19
#3  0x08048493 in main () at 2.c:25
(gdb) info frame 2
Stack frame at 0xbfffee70:
               ^^^^^^^^^^ the address of the frame
 eip = 0x8048474 in func3 (2.c:19); saved eip = 0x8048493
 called by frame at 0xbfffee90, caller of frame at 0xbfffee54
 source language c.
 Arglist at 0xbfffee68, args: a=10
 Locals at 0xbfffee68, Previous frame's sp is 0xbfffee70
 Saved registers:
  ebp at 0xbfffee68, eip at 0xbfffee6c

(gdb) frame 0xbfffee70
#2  0x08048474 in func3 (a=10) at 2.c:19
19              c = 2 * func2(a);

-- 
Yao (ÆëÒ¢)

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

* Re: How to use "frame addr" command in gdb?
  2014-11-19  6:49 ` Yao Qi
  2014-11-19  7:09   ` =?gb18030?B?TmFuIFhpYW8=?=
@ 2014-11-19  9:48   ` Pedro Alves
  1 sibling, 0 replies; 4+ messages in thread
From: Pedro Alves @ 2014-11-19  9:48 UTC (permalink / raw)
  To: Yao Qi, Nan Xiao; +Cc: gdb

BTW,

I think I've argued before that "frame NUMBER" shouldn't fallback to
creating a frame chain starting at NUMBER if no frame number
NUMBER, nor a frame at adderss NUMBER is found in the frame chain.
If I haven't, I'll do that now.  :-)  That's highly misleading, because the
user is more likely to be trying to select a frame by number, like:

(top-gdb) bt
#0  gdb_main (args=0x7fffffffd810) at src/gdb/main.c:1157
#1  0x00000000004638e7 in main (argc=1, argv=0x7fffffffd918) at src/gdb/gdb.c:32
(top-gdb) frame 0
#0  gdb_main (args=0x7fffffffd810) at src/gdb/main.c:1157
1157      catch_errors (captured_main, args, "", RETURN_MASK_ALL);
(top-gdb) frame 1
#1  0x00000000004638e7 in main (argc=1, argv=0x7fffffffd918) at src/gdb/gdb.c:32
32        return gdb_main (&args);
(top-gdb) frame 2
#0  0x0000000000000000 in ?? ()
(top-gdb)

For the "frame 2" above, I'd much rather that gdb complained
with "no frame number 2".

For the OP's case, I'd rather that gdb complained with "no frame at ADDR".
For the use case of actually telling GDB to inspect a frame at some
address not on the unwound frame chain, the user would need to ask that
from GDB explicitly.  That would mean we'd have something like:

(gdb) frame number NUM
(gdb) frame NUM  (alias for "frame number")
(gdb) frame address ADDR
(gdb) frame create ADDR  /  frame address -create ADDR

Thanks,
Pedro Alves

On 11/19/2014 06:49 AM, Yao Qi wrote:
> Nan Xiao <xiaonan19830818@qq.com> writes:
> 
>> I use gdb to debug this program, and find 'frame n' command works OK:
>> (gdb) bt
>> #0  func1 (a=10) at a.c:5
>> #1  0x08050b67 in func2 (a=10) at a.c:11
>> #2  0x08050b89 in func3 (a=10) at a.c:18
>> #3  0x08050bb9 in main () at a.c:24
>> (gdb) frame 2
>> #2  0x08050b89 in func3 (a=10) at a.c:18
>>
>> But when I want to use "frame addr" command, it seems not work well:
>>
>> (gdb) frame 0x08050bb9
>> #0  0x00000000 in ?? ()
>> (gdb) frame 0x08050b89
>> #0  0x00000000 in ?? ()
>> (gdb) frame 0x08050b92
>> #0  0x00000000 in ?? ()
>>
>> How to use "frame addr" command? Thanks very much in advance! I can't
>> find other reference except the manual.
> 
> You pass the wrong address to command "frame".  The addresses in the
> output of "bt" command are the pc values in each frame.  They are not
> the address of frames.
> 
> (gdb) help frame
> Select and print a stack frame.
> With no argument, print the selected stack frame.  (See also "info frame").
> An argument specifies the frame to select.
> It can be a stack frame number or the address of the frame.
>                                   ^^^^^^^^^^^^^^^^^^^^^^^^
> With argument, nothing is printed if input is coming from
> a command file or a user-defined command.
> 
> We should pass "the address of the frame" to command "frame", and it can
> be got from command "info frame".
> 
> (gdb) bt
> #0  func1 (a=10) at 2.c:6
> #1  0x08048452 in func2 (a=10) at 2.c:12
> #2  0x08048474 in func3 (a=10) at 2.c:19
> #3  0x08048493 in main () at 2.c:25
> (gdb) info frame 2
> Stack frame at 0xbfffee70:
>                ^^^^^^^^^^ the address of the frame
>  eip = 0x8048474 in func3 (2.c:19); saved eip = 0x8048493
>  called by frame at 0xbfffee90, caller of frame at 0xbfffee54
>  source language c.
>  Arglist at 0xbfffee68, args: a=10
>  Locals at 0xbfffee68, Previous frame's sp is 0xbfffee70
>  Saved registers:
>   ebp at 0xbfffee68, eip at 0xbfffee6c
> 
> (gdb) frame 0xbfffee70
> #2  0x08048474 in func3 (a=10) at 2.c:19
> 19              c = 2 * func2(a);
> 

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

end of thread, other threads:[~2014-11-19  9:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-19  5:46 How to use "frame addr" command in gdb? Nan Xiao
2014-11-19  6:49 ` Yao Qi
2014-11-19  7:09   ` =?gb18030?B?TmFuIFhpYW8=?=
2014-11-19  9:48   ` Pedro Alves

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).