public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Still cannot print variable
@ 2005-04-15  9:09 JS
  2005-04-15  9:20 ` Konstantin Karganov
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: JS @ 2005-04-15  9:09 UTC (permalink / raw)
  To: gdb

I am still have problems printing a variable. I have this code in a file
called test.:

int main()
{

        int d = 119;

        return(0);

}

I then compile it like this:

        gcc -g -Wall -o test test.c

(I have also tried with option -O0 but that changes nothing).

I run "gdb test" followed by "print d" and then I get this error:

No symbol "d" in current context.

Why is it not possible to see the contents of "d" when debugging?


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

* Re: Still cannot print variable
  2005-04-15  9:09 Still cannot print variable JS
@ 2005-04-15  9:20 ` Konstantin Karganov
  2005-04-15 10:02   ` JS
  2005-04-15  9:27 ` Joakim Hove
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Konstantin Karganov @ 2005-04-15  9:20 UTC (permalink / raw)
  To: JS; +Cc: gdb

Hello JS,

> I run "gdb test" followed by "print d" and then I get this error:

> No symbol "d" in current context.

> Why is it not possible to see the contents of "d" when debugging?

Because you are not yet debugging!
As described above, you started the debugger but not started the
program being debugged.
Try this:
 gdb test
 break main            // to stop your program run
 run
 print d

-- 
Best regards,
 Konstantin 



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

* Re: Still cannot print variable
  2005-04-15  9:09 Still cannot print variable JS
  2005-04-15  9:20 ` Konstantin Karganov
@ 2005-04-15  9:27 ` Joakim Hove
  2005-04-15  9:30 ` Eli Zaretskii
  2005-04-15 11:55 ` Bob Rossi
  3 siblings, 0 replies; 10+ messages in thread
From: Joakim Hove @ 2005-04-15  9:27 UTC (permalink / raw)
  To: fedevaps; +Cc: gdb

JS <fedevaps@yahoo.dk> writes:


> I run "gdb test" followed by "print d" and then I get this error:

You must explicitly start test with the run command from gdb:

bash% gdb test
<...>
(gdb) run


However, that is also not enough because the current program will
immediately complete, and hence when you get back to the (gdb) prompt
the context of the (no longer) running program is void. Hence you must
set a breakpoint to halt the execution:


bash% gdb test
<...>
(gdb) break test.c:5    # Break at line 5 in file test.c
(gdb) run
(gdb) print d



HTH - Joakim

-- 
Joakim Hove
hove AT ift uib no                 /    
Tlf: +47 (55 5)8 27 90            /     Stabburveien 18		 
Fax: +47 (55 5)8 94 40           /      N-5231 Paradis		 
http://www.ift.uib.no/~hove/    /      	55 91 28 18 / 92 68 57 04

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

* Re: Still cannot print variable
  2005-04-15  9:09 Still cannot print variable JS
  2005-04-15  9:20 ` Konstantin Karganov
  2005-04-15  9:27 ` Joakim Hove
@ 2005-04-15  9:30 ` Eli Zaretskii
  2005-04-15 11:55 ` Bob Rossi
  3 siblings, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2005-04-15  9:30 UTC (permalink / raw)
  To: fedevaps; +Cc: gdb

> From: JS <fedevaps@yahoo.dk>
> Date: Fri, 15 Apr 2005 11:09:09 +0200
> 
> I am still have problems printing a variable. I have this code in a file
> called test.:
> 
> int main()
> {
> 
>         int d = 119;
> 
>         return(0);
> 
> }
> 
> I then compile it like this:
> 
>         gcc -g -Wall -o test test.c
> 
> (I have also tried with option -O0 but that changes nothing).
> 
> I run "gdb test" followed by "print d" and then I get this error:
> 
> No symbol "d" in current context.

You need to get to the main function, since "d" is a local variable.
After you do get to main, step one line to get past the assignment of
119 to "d", and then print its value.

When I do this, I get the value of "d" printed as I'd expect.

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

* Re: Still cannot print variable
  2005-04-15  9:20 ` Konstantin Karganov
@ 2005-04-15 10:02   ` JS
  2005-04-15 10:11     ` Re[2]: " Konstantin Karganov
  0 siblings, 1 reply; 10+ messages in thread
From: JS @ 2005-04-15 10:02 UTC (permalink / raw)
  To: gdb

Konstantin Karganov wrote:

> Hello JS,
> 
>> I run "gdb test" followed by "print d" and then I get this error:
> 
>> No symbol "d" in current context.
> 
>> Why is it not possible to see the contents of "d" when debugging?
> 
> Because you are not yet debugging!
> As described above, you started the debugger but not started the
> program being debugged.
> Try this:
>  gdb test
>  break main            // to stop your program run
>  run
>  print d
> 


Ok now it work but when I write "print d" I get:

$1 = 134513410

But I declared d to be 119.

I have tried the different print arguments:

x
d
u
o
etc. but nothig seems to print 119.

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

* Re[2]: Still cannot print variable
  2005-04-15 10:02   ` JS
@ 2005-04-15 10:11     ` Konstantin Karganov
  2005-04-15 10:22       ` JS
  0 siblings, 1 reply; 10+ messages in thread
From: Konstantin Karganov @ 2005-04-15 10:11 UTC (permalink / raw)
  To: JS; +Cc: gdb

Hello JS,

>> Try this:
>>  gdb test
>>  break main            // to stop your program run
>>  run
>>  print d
>> 
> Ok now it work but when I write "print d" I get:

> $1 = 134513410

> But I declared d to be 119.
Sure! Because you stand before the initialization.
Try to do "step" or "next" and after that you'll see your variable
initialized.

-- 
Best regards,
 Konstantin 



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

* Re: Re[2]: Still cannot print variable
  2005-04-15 10:11     ` Re[2]: " Konstantin Karganov
@ 2005-04-15 10:22       ` JS
  0 siblings, 0 replies; 10+ messages in thread
From: JS @ 2005-04-15 10:22 UTC (permalink / raw)
  To: gdb

Konstantin Karganov wrote:

> Hello JS,
> 
>>> Try this:
>>>  gdb test
>>>  break main            // to stop your program run
>>>  run
>>>  print d
>>> 
>> Ok now it work but when I write "print d" I get:
> 
>> $1 = 134513410
> 
>> But I declared d to be 119.
> Sure! Because you stand before the initialization.
> Try to do "step" or "next" and after that you'll see your variable
> initialized.
> 

Yes I just read Elis reply...should have done that before posting :-)

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

* Re: Still cannot print variable
  2005-04-15  9:09 Still cannot print variable JS
                   ` (2 preceding siblings ...)
  2005-04-15  9:30 ` Eli Zaretskii
@ 2005-04-15 11:55 ` Bob Rossi
  2005-04-15 12:01   ` Dave Korn
  2005-04-15 12:06   ` Daniel Jacobowitz
  3 siblings, 2 replies; 10+ messages in thread
From: Bob Rossi @ 2005-04-15 11:55 UTC (permalink / raw)
  To: JS; +Cc: gdb

On Fri, Apr 15, 2005 at 11:09:09AM +0200, JS wrote:
> I am still have problems printing a variable. I have this code in a file
> called test.:
> 
> int main()
> {
> 
>         int d = 119;
> 
>         return(0);
> 
> }
> 
> I then compile it like this:
> 
>         gcc -g -Wall -o test test.c
> 
> (I have also tried with option -O0 but that changes nothing).
> 
> I run "gdb test" followed by "print d" and then I get this error:

You know, I just realized it's kind of odd that GDB doesn't look on the
users PATH to figure out which program to debug. For instance, it must
first look in the . directory, which is why this works in the first
place. I'd expect GDB to start debugging /usr/bin/test, as if he'd run
'test' on the command line.

Bob Rossi

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

* RE: Still cannot print variable
  2005-04-15 11:55 ` Bob Rossi
@ 2005-04-15 12:01   ` Dave Korn
  2005-04-15 12:06   ` Daniel Jacobowitz
  1 sibling, 0 replies; 10+ messages in thread
From: Dave Korn @ 2005-04-15 12:01 UTC (permalink / raw)
  To: 'Bob Rossi', 'JS'; +Cc: gdb

----Original Message----
>From: Bob Rossi
>Sent: 15 April 2005 12:55


> You know, I just realized it's kind of odd that GDB doesn't look on the
> users PATH to figure out which program to debug. For instance, it must
> first look in the . directory, which is why this works in the first
> place. I'd expect GDB to start debugging /usr/bin/test, as if he'd run
> 'test' on the command line.


  Perhaps gdb *does* look in $PATH, and JS has the current directory ('.')
in his $PATH settings?

  I just tried 'gdb yes' and it WFM....

    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

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

* Re: Still cannot print variable
  2005-04-15 11:55 ` Bob Rossi
  2005-04-15 12:01   ` Dave Korn
@ 2005-04-15 12:06   ` Daniel Jacobowitz
  1 sibling, 0 replies; 10+ messages in thread
From: Daniel Jacobowitz @ 2005-04-15 12:06 UTC (permalink / raw)
  To: gdb

On Fri, Apr 15, 2005 at 07:54:54AM -0400, Bob Rossi wrote:
> You know, I just realized it's kind of odd that GDB doesn't look on the
> users PATH to figure out which program to debug. For instance, it must
> first look in the . directory, which is why this works in the first
> place. I'd expect GDB to start debugging /usr/bin/test, as if he'd run
> 'test' on the command line.

It does search $PATH.  However, it searches the current directory
first, because it's more like a program taking a file argument than it
is like a command.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-15  9:09 Still cannot print variable JS
2005-04-15  9:20 ` Konstantin Karganov
2005-04-15 10:02   ` JS
2005-04-15 10:11     ` Re[2]: " Konstantin Karganov
2005-04-15 10:22       ` JS
2005-04-15  9:27 ` Joakim Hove
2005-04-15  9:30 ` Eli Zaretskii
2005-04-15 11:55 ` Bob Rossi
2005-04-15 12:01   ` Dave Korn
2005-04-15 12:06   ` Daniel Jacobowitz

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