public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* c++ member arrays with variable size
@ 2007-11-04  1:52 D Haley
  2007-11-04  3:10 ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: D Haley @ 2007-11-04  1:52 UTC (permalink / raw)
  To: gdb

Hello,

I recently was doing some debugging, and came across
something new (to me). When debugging routines with
arrays that are declared with variable bounds i found
that GDB is not able to "see" them.

For example

#include <iostream>

void foo(unsigned int size);

int main()
{
	foo(3);
}

void foo(unsigned int size)
{
	char bar[size];
	int i=1;
	
	if(!size)
		return;

	std::cerr << bar[0] << std::endl;
}

upon placing a breakpoint on the std::cerr line, and
using "info locals" GDB wont show up the bar variable,
nor does trying to print bar work, it claims its not a
variable 'no symbol "bar" in current context'

Is it possible to identify these in GDB, or
alternatively how else can I view these arrays in the
debugger, short of rewriting it?

Thanks.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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

* Re: c++ member arrays with variable size
  2007-11-04  1:52 c++ member arrays with variable size D Haley
@ 2007-11-04  3:10 ` Daniel Jacobowitz
  2007-11-04 11:26   ` D Haley
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-11-04  3:10 UTC (permalink / raw)
  To: D Haley; +Cc: gdb

On Sat, Nov 03, 2007 at 06:52:51PM -0700, D Haley wrote:
> Is it possible to identify these in GDB, or
> alternatively how else can I view these arrays in the
> debugger, short of rewriting it?

Most of the time, if a variable does not show up in "info locals",
that means your compiler has not emitted debug info for it.  I tried
your example with G++ 4.2 on x86_64-linux, and did see the local
array.

-- 
Daniel Jacobowitz
CodeSourcery

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

* Re: c++ member arrays with variable size
  2007-11-04  3:10 ` Daniel Jacobowitz
@ 2007-11-04 11:26   ` D Haley
  2007-11-04 14:34     ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: D Haley @ 2007-11-04 11:26 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

Hi Daniel,

> Most of the time, if a variable does not show up in
> "info locals",
> that means your compiler has not emitted debug info
> for it.  I tried
> your example with G++ 4.2 on x86_64-linux, and did
> see the local
> array.

Hmm, I tried on another machine and yes, i can see it.
 For the record on the non-working version I am using
apple-darwin8-g++ (GCC) 4.0.1. Minus one point for
apple :( .

Thanks.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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

* Re: c++ member arrays with variable size
  2007-11-04 11:26   ` D Haley
@ 2007-11-04 14:34     ` Daniel Jacobowitz
  2007-11-05 18:55       ` Jim Ingham
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2007-11-04 14:34 UTC (permalink / raw)
  To: D Haley; +Cc: gdb

On Sun, Nov 04, 2007 at 03:26:50AM -0800, D Haley wrote:
> Hmm, I tried on another machine and yes, i can see it.
>  For the record on the non-working version I am using
> apple-darwin8-g++ (GCC) 4.0.1. Minus one point for
> apple :( .

This is probably because Apple's still using the older stabs debug
format.  I believe they either have switched, or are switching, to
DWARF-2; that will help a lot.

-- 
Daniel Jacobowitz
CodeSourcery

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

* Re: c++ member arrays with variable size
  2007-11-04 14:34     ` Daniel Jacobowitz
@ 2007-11-05 18:55       ` Jim Ingham
  2007-11-09  6:42         ` D Haley
  0 siblings, 1 reply; 6+ messages in thread
From: Jim Ingham @ 2007-11-05 18:55 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: D Haley, gdb

Daniel's right, gcc generated stabs (regardless of platform) omits  
debug records for variable length arrays.  DWARF reports them as  
arrays of 0 size.  We've actually supported DWARF for a while -  
starting with Xcode 2.4.  If you are on Tiger, you might want to  
download the latest tools - Xcode 2.5 from Apple's developer site.   
There aren't any tools hosted on Panther or earlier that work with  
DWARF, so if you're still on Panther, you will have to upgrade to Tiger.

Jim

On Nov 4, 2007, at 6:34 AM, Daniel Jacobowitz wrote:

> On Sun, Nov 04, 2007 at 03:26:50AM -0800, D Haley wrote:
>> Hmm, I tried on another machine and yes, i can see it.
>> For the record on the non-working version I am using
>> apple-darwin8-g++ (GCC) 4.0.1. Minus one point for
>> apple :( .
>
> This is probably because Apple's still using the older stabs debug
> format.  I believe they either have switched, or are switching, to
> DWARF-2; that will help a lot.
>
> -- 
> Daniel Jacobowitz
> CodeSourcery

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

* Re: c++ member arrays with variable size
  2007-11-05 18:55       ` Jim Ingham
@ 2007-11-09  6:42         ` D Haley
  0 siblings, 0 replies; 6+ messages in thread
From: D Haley @ 2007-11-09  6:42 UTC (permalink / raw)
  To: Jim Ingham, Daniel Jacobowitz; +Cc: gdb

Hi Jim,

Thanks for the heads up, I am using Xcode 2.4.1; I
will try that update later, last XCode update (hoping
for GCC's new OpenMP support) -- which I did a few
weeks ago -- was ~1GB! I'm using OSX 10.4, which I
believe is tiger (according to wikipedia).

Thankyou.


--- Jim Ingham <jingham@apple.com> wrote:

> Daniel's right, gcc generated stabs (regardless of
> platform) omits  
> debug records for variable length arrays.  DWARF
> reports them as  
> arrays of 0 size.  We've actually supported DWARF
> for a while -  
> starting with Xcode 2.4.  If you are on Tiger, you
> might want to  
> download the latest tools - Xcode 2.5 from Apple's
> developer site.   
> There aren't any tools hosted on Panther or earlier
> that work with  
> DWARF, so if you're still on Panther, you will have
> to upgrade to Tiger.
> 
> Jim
> 
> On Nov 4, 2007, at 6:34 AM, Daniel Jacobowitz wrote:
> 
> > On Sun, Nov 04, 2007 at 03:26:50AM -0800, D Haley
> wrote:
> >> Hmm, I tried on another machine and yes, i can
> see it.
> >> For the record on the non-working version I am
> using
> >> apple-darwin8-g++ (GCC) 4.0.1. Minus one point
> for
> >> apple :( .
> >
> > This is probably because Apple's still using the
> older stabs debug
> > format.  I believe they either have switched, or
> are switching, to
> > DWARF-2; that will help a lot.
> >
> > -- 
> > Daniel Jacobowitz
> > CodeSourcery
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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

end of thread, other threads:[~2007-11-09  6:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-04  1:52 c++ member arrays with variable size D Haley
2007-11-04  3:10 ` Daniel Jacobowitz
2007-11-04 11:26   ` D Haley
2007-11-04 14:34     ` Daniel Jacobowitz
2007-11-05 18:55       ` Jim Ingham
2007-11-09  6:42         ` D Haley

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