Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Igor Khavkine <igor.kh@gmail.com>
To: gdb@sourceware.org, Daniel Jacobowitz <drow@false.org>
Subject: Re: C99 variable length arrays
Date: Fri, 27 Jan 2006 08:15:00 -0000	[thread overview]
Message-ID: <ab2dc45b0601261647g4f3c7feo9d47031fd7fb285e@mail.gmail.com> (raw)
In-Reply-To: <20060126233311.GA21429@nevyn.them.org>

[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]

On 1/26/06, Daniel Jacobowitz <drow@false.org> wrote:
> On Thu, Jan 26, 2006 at 06:30:56PM -0500, Igor Khavkine wrote:
> > On 1/26/06, Daniel Jacobowitz <drow@false.org> wrote:

> > > The first thing to do is to write a small testcase, and post the
> > > testcase along with the debugging output that your GCC generates
> > > for it.
> >
> > There is a test case already in the GDB bug database (PR 1796, as I
> > mentioned in my first message). What kind of debugging output should I
> > post? Is there an option to make gcc dump the debugging info in human
> > readable form?
>
> Not really - but you can run readelf -wi on the resulting object file.
> I recommend you do this after linking to make sure relocations are
> resolved.

OK. I'm attaching a small test case, vla-bug.c. I compiled the object
with `gcc -g -c vla-bug.c' and the executable with `gcc -g -o vla-bug
vla-bug.c'. I then ran `readelf -wi' on the .o and the executable. I'm
attaching all the relevant files.

Note that I call the function test() with argument 3. This means that
the local variable length array will have size 3. However, when run
under GDB, GDB will think the array is only of size 2 (that's the size
it always seems to assume for VLA's). Unfortunately, I can glimpse
next to nothing from the readelf output. Can you tell whether GCC puts
enough debugging info into the compiled code for GDB to get the size
right at runtime?

Thanks in advance.

Igor

[-- Attachment #2: vla-bug.c --]
[-- Type: text/x-csrc, Size: 91 bytes --]

void test (int x)
{
	int arr[x];
	arr[0] = 1;
}

int main (void)
{
	test (3);
	return 0;
}

[-- Attachment #3: vla-bug.o.elf --]
[-- Type: application/octet-stream, Size: 2334 bytes --]

The section .debug_info contains:

  Compilation Unit @ 0:
   Length:        215
   Version:       2
   Abbrev Offset: 0
   Pointer Size:  4
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_stmt_list   : 0	
     DW_AT_high_pc     : 0x4c	
     DW_AT_low_pc      : 0	
     DW_AT_name        : vla-bug.c	
     DW_AT_comp_dir    : /home/igor/c/gdb-bug	
     DW_AT_producer    : GNU C 3.3.5 (Debian 1:3.3.5-13)	
     DW_AT_language    : 1	(ANSI C)
 <1><58>: Abbrev Number: 2 (DW_TAG_subprogram)
     DW_AT_sibling     : <93>	
     DW_AT_external    : 1	
     DW_AT_name        : test	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 2	
     DW_AT_prototyped  : 1	
     DW_AT_low_pc      : 0	
     DW_AT_high_pc     : 0x29	
     DW_AT_frame_base  : 1 byte block: 55 	(DW_OP_reg5)
 <2><70>: Abbrev Number: 3 (DW_TAG_formal_parameter)
     DW_AT_name        : x	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 1	
     DW_AT_type        : <93>	
     DW_AT_location    : 2 byte block: 91 8 	(DW_OP_fbreg: 8)
 <2><7c>: Abbrev Number: 4 (DW_TAG_variable)
     DW_AT_artificial  : 1	
     DW_AT_type        : <bd>	
     DW_AT_location    : 1 byte block: 50 	(DW_OP_reg0)
 <2><84>: Abbrev Number: 5 (DW_TAG_variable)
     DW_AT_name        : arr	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 3	
     DW_AT_type        : <9a>	
     DW_AT_location    : 2 byte block: 70 0 	(DW_OP_breg0: 0)
 <1><93>: Abbrev Number: 6 (DW_TAG_base_type)
     DW_AT_name        : int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 5	(signed)
 <1><9a>: Abbrev Number: 7 (DW_TAG_array_type)
     DW_AT_sibling     : <ad>	
     DW_AT_type        : <93>	
 <2><a3>: Abbrev Number: 8 (DW_TAG_subrange_type)
     DW_AT_type        : <ad>	
     DW_AT_upper_bound : <7c>	
 <1><ad>: Abbrev Number: 6 (DW_TAG_base_type)
     DW_AT_name        : unsigned int	
     DW_AT_byte_size   : 4	
     DW_AT_encoding    : 7	(unsigned)
 <1><bd>: Abbrev Number: 9 (DW_TAG_const_type)
     DW_AT_type        : <93>	
 <1><c2>: Abbrev Number: 10 (DW_TAG_subprogram)
     DW_AT_external    : 1	
     DW_AT_name        : main	
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 8	
     DW_AT_prototyped  : 1	
     DW_AT_type        : <93>	
     DW_AT_low_pc      : 0x29	
     DW_AT_high_pc     : 0x4c	
     DW_AT_frame_base  : 1 byte block: 55 	(DW_OP_reg5)


[-- Attachment #4: vla-bug.elf.gz --]
[-- Type: application/x-gzip, Size: 5196 bytes --]

      reply	other threads:[~2006-01-27  0:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-26 13:49 Igor Khavkine
2006-01-26 15:08 ` Daniel Jacobowitz
2006-01-26 23:33   ` Igor Khavkine
2006-01-27  0:02     ` Daniel Jacobowitz
2006-01-27  8:15       ` Igor Khavkine [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ab2dc45b0601261647g4f3c7feo9d47031fd7fb285e@mail.gmail.com \
    --to=igor.kh@gmail.com \
    --cc=drow@false.org \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox