From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16329 invoked by alias); 25 Feb 2011 10:40:26 -0000 Received: (qmail 16320 invoked by uid 22791); 25 Feb 2011 10:40:22 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT,TW_SV,TW_TM X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.156) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 25 Feb 2011 10:40:14 +0000 Received: from md1.u-strasbg.fr (md1.u-strasbg.fr [IPv6:2001:660:2402::186]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id p1PAe6g0009544 ; Fri, 25 Feb 2011 11:40:06 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms4.u-strasbg.fr [130.79.204.13]) by md1.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p1PAe6Y6022199 ; Fri, 25 Feb 2011 11:40:06 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from E6510Muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.4/jtpda-5.5pre1) with ESMTP id p1PAe5Vv003181 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) ; Fri, 25 Feb 2011 11:40:06 +0100 (CET) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: "'H.J. Lu'" Cc: "'Kai Tietz'" , "'Binutils'" References: <-8460070221060995487@unknownmsgid> <-6930711422310680743@unknownmsgid> <4D63D49D.90101@redhat.com> <-2339605939192327273@unknownmsgid> <-3886800211494155692@unknownmsgid> <1561346207520594884@unknownmsgid> In-Reply-To: Subject: [RFC] Use only dwarf_vma types in dwarf code (was RE: [RFC patch]: Adjust the use of 'long' type in dwarf2.h header) Date: Fri, 25 Feb 2011 10:40:00 -0000 Message-ID: <00c101cbd4d8$5d9b62c0$18d22840$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00305.txt.bz2 This patch RFC is follow up of the thread concerning problems with the act that readelf defines BFD64 under other conditions=20 than dwarf.c leading to potential problems. The idea is to completely remove bfd_vma and dwarf_signed_vma=20 from dwarf.h and dwarf.c sources. The patch is pretty mechanical, but there are several=20 points that probably needs discussion: 1) This basically makes use of 8-byte for dwarf_vma and dwarf_signed_vma for almost all modern machines/compilers. It could still impact performance for system where int64 computation is slow, I have no idea if this can really be a problem or not. 2) I also tried to remove (long) and (unsigned long) types whenever they seemed to me to be used for something that could be a target address or offset and replaced it by a dwarf_{signed_}vma type. (This is also related to the Mingw64 target issue for which 'long' is 4-byte whereas 'void *' is 8-byte). But I might not have caught all occurrences and might have misunderstood some other cases. An example is the address field of the Machine_State_Registers, I don't know if this relates really to a target address... Another important point is that I have no machine that can run the testsuite on my patch, so that it might very well introduce regression that I am unaware of. Anyhow, I will be pleased to get comments on this patch. Pierre Muller GDB pascal language maintainer 2011-02-25 Pierre Muller Replace bfd_vma type and analog types by dwarf_vma and analogs. Use dwarf specific print functions to display these type values. * dwarf.h (dwarf_signed_vma): New type; (DWARF2_External_LineInfo): Replace bfd_vma by dwarf_vma. (DWARF2_External_PubNames): Likewise. (DWARF2_External_CompUnit): Likewise. (DWARF2_External_ARange): Likewise. (read_leb128): Change return type to dwarf_vma. * dwarf.c (print_dwarf_vma): Check byte_size values. (dwarf_vmatoa): Change parameter type to dwarf_vma. (dwarf_svmatoa): New static function. (read_leb128): Change return type to dwarf_vma. (read_sleb128): New static function. (struct State_Machine_Registers): Change address field type to dwarf_vma. (process_extended_line_op): Adapt to type changes. (fetch_indirect_string): Likewise. (idisplay_block): Likewise. (decode_location_expression): Likewise. (read_and_display_attr_value): Likewise. (process_debug_info): Likewise. (display_debug_lines_raw): Likewise. (display_debug_lines_decoded): Likewise. (SLEB macro): Use new read_sleb128 function. Index: binutils/dwarf.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/binutils/dwarf.c,v retrieving revision 1.84 diff -u -p -r1.84 dwarf.c --- binutils/dwarf.c 23 Feb 2011 08:52:33 -0000 1.84 +++ binutils/dwarf.c 25 Feb 2011 10:12:30 -0000 @@ -106,6 +106,7 @@ static void print_dwarf_vma (dwarf_vma val, unsigned byte_size) { static char buff[18]; + int offset; =20 /* Printf does not have a way of specifiying a maximum field width for an integer value, so we print the full value into a buffer and then select @@ -120,11 +121,29 @@ print_dwarf_vma (dwarf_vma val, unsigned snprintf (buff, sizeof (buff), "%16.16lx ", val); #endif =20 - fputs (buff + (byte_size =3D=3D 4 ? 8 : 0), stdout); + if (byte_size =3D=3D 0) + offset =3D 0; + else + if (byte_size > 0 && byte_size <=3D8) + offset =3D 16 - 2 * byte_size; + else + error("Wrong size in print_dwarf_vma"); + + fputs (buff + offset, stdout); } =20 +#if __STDC_VERSION__ >=3D 199901L || (defined(__GNUC__) && __GNUC__ >=3D 2) +#ifndef __MSVCRT__ +#define DWARF_VMA_FMT "ll" +#else +#define DWARF_VMA_FMT "I64" +#endif +#else +#define DWARF_VMA_FMT "l" +#endif + static const char * -dwarf_vmatoa (const char *fmtch, bfd_vma value) +dwarf_vmatoa (const char *fmtch, dwarf_vma value) { /* As dwarf_vmatoa is used more then once in a printf call for output, we are cycling through an fixed array of pointers @@ -136,7 +155,7 @@ dwarf_vmatoa (const char *fmtch, bfd_vma char fmt[32]; char *ret; =20 - sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch); + sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); =20 ret =3D buf[buf_pos++].place; buf_pos %=3D ARRAY_SIZE(buf); @@ -146,10 +165,33 @@ dwarf_vmatoa (const char *fmtch, bfd_vma return ret; } =20 -bfd_vma +static char * +dwarf_svmatoa (const char *fmtch, dwarf_signed_vma value) +{ + /* As dwarf_vmatoa is used more then once in a printf call + for output, we are cycling through an fixed array of pointers + for return address. */ + static int buf_pos =3D 0; + static struct dwarf_vmatoa_buf { + char place[64]; + } buf[16]; + char fmt[32]; + char *ret; + + sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); + + ret =3D buf[buf_pos++].place; + buf_pos %=3D ARRAY_SIZE(buf); + + snprintf (ret, sizeof (buf[0].place), fmt, value); + + return ret; +} + +dwarf_vma read_leb128 (unsigned char *data, unsigned int *length_return, int sign) { - bfd_vma result =3D 0; + dwarf_vma result =3D 0; unsigned int num_read =3D 0; unsigned int shift =3D 0; unsigned char byte; @@ -159,7 +201,7 @@ read_leb128 (unsigned char *data, unsign byte =3D *data++; num_read++; =20 - result |=3D ((bfd_vma) (byte & 0x7f)) << shift; + result |=3D ((dwarf_vma) (byte & 0x7f)) << shift; =20 shift +=3D 7; =20 @@ -175,9 +217,16 @@ read_leb128 (unsigned char *data, unsign return result; } =20 -typedef struct State_Machine_Registers +/* Create a signed version to avoid painful typecasts. */ +static dwarf_signed_vma +read_sleb128 (unsigned char *data, unsigned int *length_return) +{ + return (dwarf_signed_vma) read_leb128 (data, length_return, 1); +} + + typedef struct State_Machine_Registers { - unsigned long address; + dwarf_vma address; unsigned int file; unsigned int line; unsigned int column; @@ -216,7 +265,7 @@ process_extended_line_op (unsigned char=20 unsigned int bytes_read; unsigned int len; unsigned char *name; - bfd_vma adr; + dwarf_vma adr; =20 len =3D read_leb128 (data, & bytes_read, 0); data +=3D bytes_read; @@ -253,19 +302,17 @@ process_extended_line_op (unsigned char=20 printf (" %d\t", ++state_machine_regs.last_file_entry); name =3D data; data +=3D strlen ((char *) data) + 1; - printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0)); + printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); data +=3D bytes_read; - printf ("%" BFD_VMA_FMT "u\t", - read_leb128 (data, & bytes_read, 0)); + printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); data +=3D bytes_read; - printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0)); + printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); printf ("%s\n\n", name); break; =20 case DW_LNE_set_discriminator: printf (_("set Discriminator to %s\n"), - dwarf_vmatoa ("u", - read_leb128 (data, & bytes_read, 0))); + dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); break; =20 /* HP extensions. */ @@ -316,7 +363,7 @@ process_extended_line_op (unsigned char=20 } =20 static const char * -fetch_indirect_string (bfd_vma offset) +fetch_indirect_string (dwarf_vma offset) { struct dwarf_section *section =3D &debug_displays [str].section; =20 @@ -327,7 +374,8 @@ fetch_indirect_string (bfd_vma offset) offset -=3D section->address; if (offset > section->size) { - warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset); + warn (_("DW_FORM_strp offset too big: %s\n"), + dwarf_vmatoa ("x", offset)); return _(""); } =20 @@ -615,9 +663,9 @@ get_FORM_name (unsigned long form) } =20 static unsigned char * -display_block (unsigned char *data, unsigned long length) +display_block (unsigned char *data, dwarf_vma length) { - printf (_(" %lu byte block: "), length); + printf (_(" %s byte block: "), dwarf_vmatoa ("u", length)); =20 while (length --) printf ("%lx ", (unsigned long) byte_get (data++, 1)); @@ -630,13 +678,13 @@ decode_location_expression (unsigned cha unsigned int pointer_size, unsigned int offset_size, int dwarf_version, - bfd_vma length, - bfd_vma cu_offset, + dwarf_vma length, + dwarf_vma cu_offset, struct dwarf_section * section) { unsigned op; unsigned int bytes_read; - bfd_vma uvalue; + dwarf_vma uvalue; unsigned char *end =3D data + length; int need_frame_base =3D 0; =20 @@ -687,13 +735,13 @@ decode_location_expression (unsigned cha data +=3D 8; break; case DW_OP_constu: - printf ("DW_OP_constu: %" BFD_VMA_FMT "u", - read_leb128 (data, &bytes_read, 0)); + printf ("DW_OP_constu: %s", + dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); data +=3D bytes_read; break; case DW_OP_consts: - printf ("DW_OP_consts: %" BFD_VMA_FMT "d", - read_leb128 (data, &bytes_read, 1)); + printf ("DW_OP_consts: %s", + dwarf_svmatoa ("d", read_sleb128 (data, &bytes_read))); data +=3D bytes_read; break; case DW_OP_dup: @@ -748,8 +796,8 @@ decode_location_expression (unsigned cha printf ("DW_OP_plus"); break; case DW_OP_plus_uconst: - printf ("DW_OP_plus_uconst: %" BFD_VMA_FMT "u", - read_leb128 (data, &bytes_read, 0)); + printf ("DW_OP_plus_uconst: %s", + dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); data +=3D bytes_read; break; case DW_OP_shl: @@ -894,36 +942,37 @@ decode_location_expression (unsigned cha case DW_OP_breg29: case DW_OP_breg30: case DW_OP_breg31: - printf ("DW_OP_breg%d (%s): %" BFD_VMA_FMT "d", + printf ("DW_OP_breg%d (%s): %s", op - DW_OP_breg0, regname (op - DW_OP_breg0, 1), - read_leb128 (data, &bytes_read, 1)); + dwarf_svmatoa ("d", (dwarf_signed_vma)=20 + read_leb128 (data, &bytes_read, 1))); data +=3D bytes_read; break; =20 case DW_OP_regx: uvalue =3D read_leb128 (data, &bytes_read, 0); data +=3D bytes_read; - printf ("DW_OP_regx: %" BFD_VMA_FMT "u (%s)", - uvalue, regname (uvalue, 1)); + printf ("DW_OP_regx: %s (%s)", + dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); break; case DW_OP_fbreg: need_frame_base =3D 1; - printf ("DW_OP_fbreg: %" BFD_VMA_FMT "d", - read_leb128 (data, &bytes_read, 1)); + printf ("DW_OP_fbreg: %s", + dwarf_svmatoa ("d", read_sleb128 (data, &bytes_read))); data +=3D bytes_read; break; case DW_OP_bregx: uvalue =3D read_leb128 (data, &bytes_read, 0); data +=3D bytes_read; - printf ("DW_OP_bregx: %" BFD_VMA_FMT "u (%s) %" BFD_VMA_FMT "d", - uvalue, regname (uvalue, 1), - read_leb128 (data, &bytes_read, 1)); + printf ("DW_OP_bregx: %s (%s) %s", + dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), + dwarf_svmatoa ("d", read_sleb128 (data, &bytes_read))); data +=3D bytes_read; break; case DW_OP_piece: - printf ("DW_OP_piece: %" BFD_VMA_FMT "u", - read_leb128 (data, &bytes_read, 0)); + printf ("DW_OP_piece: %s", + dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); data +=3D bytes_read; break; case DW_OP_deref_size: @@ -943,15 +992,17 @@ decode_location_expression (unsigned cha case DW_OP_call2: /* XXX: Strictly speaking for 64-bit DWARF3 files this ought to be an 8-byte wide computation. */ - printf ("DW_OP_call2: <0x%" BFD_VMA_FMT "x>", - (bfd_signed_vma) byte_get (data, 2) + cu_offset); + printf ("DW_OP_call2: <0x%s>", + dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2) + + cu_offset)); data +=3D 2; break; case DW_OP_call4: /* XXX: Strictly speaking for 64-bit DWARF3 files this ought to be an 8-byte wide computation. */ - printf ("DW_OP_call4: <0x%" BFD_VMA_FMT "x>", - (bfd_signed_vma) byte_get (data, 4) + cu_offset); + printf ("DW_OP_call4: <0x%s>", + dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4) + + cu_offset)); data +=3D 4; break; case DW_OP_call_ref: @@ -965,14 +1016,14 @@ decode_location_expression (unsigned cha } if (dwarf_version =3D=3D 2) { - printf ("DW_OP_call_ref: <0x%lx>", - (long) byte_get (data, pointer_size)); + printf ("DW_OP_call_ref: <0x%s>", + dwarf_vmatoa ("x", byte_get (data, pointer_size))); data +=3D pointer_size; } else { - printf ("DW_OP_call_ref: <0x%lx>", - (long) byte_get (data, offset_size)); + printf ("DW_OP_call_ref: <0x%s>", + dwarf_vmatoa ("x", byte_get (data, offset_size))); data +=3D offset_size; } break; @@ -984,11 +1035,11 @@ decode_location_expression (unsigned cha break; case DW_OP_bit_piece: printf ("DW_OP_bit_piece: "); - printf ("size: %" BFD_VMA_FMT "u ", - read_leb128 (data, &bytes_read, 0)); + printf ("size: %s ", + dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); data +=3D bytes_read; - printf ("offset: %" BFD_VMA_FMT "u ", - read_leb128 (data, &bytes_read, 0)); + printf ("offset: %s ", + dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0))); data +=3D bytes_read; break; =20 @@ -1037,20 +1088,18 @@ decode_location_expression (unsigned cha } if (dwarf_version =3D=3D 2) { - printf ("DW_OP_GNU_implicit_pointer: " - "<0x%" BFD_VMA_FMT "x> %" BFD_VMA_FMT "d", - (bfd_vma) byte_get (data, pointer_size), - (bfd_signed_vma) read_leb128 (data + pointer_size, - &bytes_read, 1)); + printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", + dwarf_vmatoa ("x", byte_get (data, pointer_size)), + dwarf_svmatoa ("d", read_sleb128 (data + pointer_size, + &bytes_read))); data +=3D pointer_size + bytes_read; } else { - printf ("DW_OP_GNU_implicit_pointer: " - "<0x%" BFD_VMA_FMT "x> %" BFD_VMA_FMT "d", - (bfd_vma) byte_get (data, offset_size), - (bfd_signed_vma) read_leb128 (data + offset_size, - &bytes_read, 1)); + printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", + dwarf_vmatoa ("x", byte_get (data, offset_size)), + dwarf_svmatoa ("d", read_sleb128 (data + offset_size, + &bytes_read))); data +=3D offset_size + bytes_read; } break; @@ -1112,15 +1161,15 @@ static unsigned char * read_and_display_attr_value (unsigned long attribute, unsigned long form, unsigned char * data, - bfd_vma cu_offset, - bfd_vma pointer_size, - bfd_vma offset_size, + dwarf_vma cu_offset, + dwarf_vma pointer_size, + dwarf_vma offset_size, int dwarf_version, debug_info * debug_info_p, int do_loc, struct dwarf_section * section) { - bfd_vma uvalue =3D 0; + dwarf_vma uvalue =3D 0; unsigned char *block_start =3D NULL; unsigned char * orig_data =3D data; unsigned int bytes_read; @@ -1207,7 +1256,7 @@ read_and_display_attr_value (unsigned lo { case DW_FORM_ref_addr: if (!do_loc) - printf (" <0x%" BFD_VMA_FMT "x>", uvalue); + printf (" <0x%s>", dwarf_vmatoa ("x",uvalue)); break; =20 case DW_FORM_ref1: @@ -1215,14 +1264,14 @@ read_and_display_attr_value (unsigned lo case DW_FORM_ref4: case DW_FORM_ref_udata: if (!do_loc) - printf (" <0x%" BFD_VMA_FMT "x>", uvalue + cu_offset); + printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset)); break; =20 case DW_FORM_data4: case DW_FORM_addr: case DW_FORM_sec_offset: if (!do_loc) - printf (" 0x%" BFD_VMA_FMT "x", uvalue); + printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); break; =20 case DW_FORM_flag_present: @@ -1232,7 +1281,7 @@ read_and_display_attr_value (unsigned lo case DW_FORM_sdata: case DW_FORM_udata: if (!do_loc) - printf (" %" BFD_VMA_FMT "d", uvalue); + printf (" %s", dwarf_vmatoa ("d", uvalue)); break; =20 case DW_FORM_ref8: @@ -1240,7 +1289,7 @@ read_and_display_attr_value (unsigned lo if (!do_loc) { uvalue =3D byte_get (data, 4); - printf (" 0x%" BFD_VMA_FMT "x", uvalue); + printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4)); } if ((do_loc || do_debug_loc || do_debug_ranges) @@ -1249,7 +1298,7 @@ read_and_display_attr_value (unsigned lo if (sizeof (uvalue) =3D=3D 8) uvalue =3D byte_get (data, 8); else - error (_("DW_FORM_data8 is unsupported when sizeof (bfd_vma) !=3D 8\n")); + error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) !=3D 8\n")); } data +=3D 8; break; @@ -1354,7 +1403,7 @@ read_and_display_attr_value (unsigned lo if (lmax =3D=3D 0 || num >=3D lmax) { lmax +=3D 1024; - debug_info_p->loc_offsets =3D (bfd_vma *) + debug_info_p->loc_offsets =3D (dwarf_vma *) xcrealloc (debug_info_p->loc_offsets, lmax, sizeof (*debug_info_p->loc_offsets)); debug_info_p->have_frame_base =3D (int *) @@ -1385,7 +1434,7 @@ read_and_display_attr_value (unsigned lo if (lmax =3D=3D 0 || num >=3D lmax) { lmax +=3D 1024; - debug_info_p->range_lists =3D (bfd_vma *) + debug_info_p->range_lists =3D (dwarf_vma *) xcrealloc (debug_info_p->range_lists, lmax, sizeof (*debug_info_p->range_lists)); debug_info_p->max_range_lists =3D lmax; @@ -1463,9 +1512,10 @@ read_and_display_attr_value (unsigned lo case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; default: if (uvalue >=3D DW_LANG_lo_user && uvalue <=3D DW_LANG_hi_user) - printf ("(implementation defined: %" BFD_VMA_FMT "x)", uvalue); + printf ("(implementation defined: %s)",=20 + dwarf_vmatoa ("x", uvalue)); else - printf ("(Unknown: %" BFD_VMA_FMT "x)", uvalue); + printf ("(Unknown: %s)", dwarf_vmatoa("x", uvalue)); break; } break; @@ -1829,9 +1879,9 @@ static unsigned char * read_and_display_attr (unsigned long attribute, unsigned long form, unsigned char * data, - bfd_vma cu_offset, - bfd_vma pointer_size, - bfd_vma offset_size, + dwarf_vma cu_offset, + dwarf_vma pointer_size, + dwarf_vma offset_size, int dwarf_version, debug_info * debug_info_p, int do_loc, @@ -1943,7 +1993,7 @@ process_debug_info (struct dwarf_section unsigned char *hdrptr; unsigned char *tags; int level; - bfd_vma cu_offset; + dwarf_vma cu_offset; int offset_size; int initial_length_size; unsigned char signature[8] =3D { 0 }; @@ -2378,14 +2428,14 @@ display_debug_lines_raw (struct dwarf_se =20 data +=3D strlen ((char *) data) + 1; =20 - printf ("%" BFD_VMA_FMT "u\t", - read_leb128 (data, & bytes_read, 0)); + printf ("%s\t", + dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); data +=3D bytes_read; - printf ("%" BFD_VMA_FMT "u\t", - read_leb128 (data, & bytes_read, 0)); + printf ("%s\t", + dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); data +=3D bytes_read; - printf ("%" BFD_VMA_FMT "u\t", - read_leb128 (data, & bytes_read, 0)); + printf ("%s\t", + dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0))); data +=3D bytes_read; printf ("%s\n", name); } @@ -2400,8 +2450,8 @@ display_debug_lines_raw (struct dwarf_se while (data < end_of_sequence) { unsigned char op_code; - int adv; - unsigned long int uladv; + dwarf_signed_vma adv; + dwarf_vma uladv; unsigned int bytes_read; =20 op_code =3D *data++; @@ -2414,8 +2464,10 @@ display_debug_lines_raw (struct dwarf_se { uladv *=3D linfo.li_min_insn_length; state_machine_regs.address +=3D uladv; - printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"), - op_code, uladv, state_machine_regs.address); + printf (_(" Special opcode %d: " + "advance Address by %s to 0x%s"), + op_code, dwarf_vmatoa ("u", uladv), + dwarf_vmatoa ("x", state_machine_regs.address)); } else { @@ -2426,14 +2478,16 @@ display_debug_lines_raw (struct dwarf_se state_machine_regs.op_index =3D (state_machine_regs.op_index + uladv) % linfo.li_max_ops_per_insn; - printf (_(" Special opcode %d: advance Address by %lu to 0x%lx[%d]"), - op_code, uladv, state_machine_regs.address, + printf (_(" Special opcode %d: " + "advance Address by %s to 0x%s[%d]"), + op_code, dwarf_vmatoa ("u", uladv), + dwarf_vmatoa ("x", state_machine_regs.address), state_machine_regs.op_index); } adv =3D (op_code % linfo.li_line_range) + linfo.li_line_base; state_machine_regs.line +=3D adv; - printf (_(" and Line by %d to %d\n"), - adv, state_machine_regs.line); + printf (_(" and Line by %s to %d\n"), + dwarf_vmatoa ("d", adv), state_machine_regs.line); } else switch (op_code) { @@ -2452,8 +2506,9 @@ display_debug_lines_raw (struct dwarf_se { uladv *=3D linfo.li_min_insn_length; state_machine_regs.address +=3D uladv; - printf (_(" Advance PC by %lu to 0x%lx\n"), uladv, - state_machine_regs.address); + printf (_(" Advance PC by %s to 0x%s\n"), + dwarf_vmatoa ("u", uladv), + dwarf_vmatoa ("x", state_machine_regs.address)); } else { @@ -2464,39 +2519,42 @@ display_debug_lines_raw (struct dwarf_se state_machine_regs.op_index =3D (state_machine_regs.op_index + uladv) % linfo.li_max_ops_per_insn; - printf (_(" Advance PC by %lu to 0x%lx[%d]\n"), uladv, - state_machine_regs.address, + printf (_(" Advance PC by %s to 0x%s[%d]\n"), + dwarf_vmatoa ("u", uladv), + dwarf_vmatoa ("x", state_machine_regs.address), state_machine_regs.op_index); } break; =20 case DW_LNS_advance_line: - adv =3D read_leb128 (data, & bytes_read, 1); + adv =3D read_sleb128 (data, & bytes_read); data +=3D bytes_read; state_machine_regs.line +=3D adv; - printf (_(" Advance Line by %d to %d\n"), adv, - state_machine_regs.line); + printf (_(" Advance Line by %s to %d\n"), + dwarf_svmatoa ("d", adv), + state_machine_regs.line); break; =20 case DW_LNS_set_file: adv =3D read_leb128 (data, & bytes_read, 0); data +=3D bytes_read; - printf (_(" Set File Name to entry %d in the File Name Table\n"), - adv); + printf (_(" Set File Name to entry %s in the File Name Table\n"), + dwarf_svmatoa ("d", adv)); state_machine_regs.file =3D adv; break; =20 case DW_LNS_set_column: uladv =3D read_leb128 (data, & bytes_read, 0); data +=3D bytes_read; - printf (_(" Set column to %lu\n"), uladv); + printf (_(" Set column to %s\n"),=20 + dwarf_vmatoa ("u", uladv)); state_machine_regs.column =3D uladv; break; =20 case DW_LNS_negate_stmt: adv =3D state_machine_regs.is_stmt; adv =3D ! adv; - printf (_(" Set is_stmt to %d\n"), adv); + printf (_(" Set is_stmt to %s\n"), dwarf_svmatoa("d", adv)); state_machine_regs.is_stmt =3D adv; break; =20 @@ -2511,8 +2569,9 @@ display_debug_lines_raw (struct dwarf_se { uladv *=3D linfo.li_min_insn_length; state_machine_regs.address +=3D uladv; - printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv, - state_machine_regs.address); + printf (_(" Advance PC by constant %s to 0x%s\n"), + dwarf_vmatoa ("u", uladv), + dwarf_vmatoa ("x", state_machine_regs.address)); } else { @@ -2523,8 +2582,9 @@ display_debug_lines_raw (struct dwarf_se state_machine_regs.op_index =3D (state_machine_regs.op_index + uladv) % linfo.li_max_ops_per_insn; - printf (_(" Advance PC by constant %lu to 0x%lx[%d]\n"), - uladv, state_machine_regs.address, + printf (_(" Advance PC by constant %s to 0x%s[%d]\n"), + dwarf_vmatoa ("u", uladv),=20 + dwarf_vmatoa ("x", state_machine_regs.address), state_machine_regs.op_index); } break; @@ -2534,8 +2594,9 @@ display_debug_lines_raw (struct dwarf_se data +=3D 2; state_machine_regs.address +=3D uladv; state_machine_regs.op_index =3D 0; - printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"), - uladv, state_machine_regs.address); + printf (_(" Advance PC by fixed size amount %s to 0x%s\n"), + dwarf_vmatoa ("u", uladv),=20 + dwarf_vmatoa ("x", state_machine_regs.address)); break; =20 case DW_LNS_set_prologue_end: @@ -2549,7 +2610,7 @@ display_debug_lines_raw (struct dwarf_se case DW_LNS_set_isa: uladv =3D read_leb128 (data, & bytes_read, 0); data +=3D bytes_read; - printf (_(" Set ISA to %lu\n"), uladv); + printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv)); break; =20 default: @@ -2557,8 +2618,8 @@ display_debug_lines_raw (struct dwarf_se =20 for (i =3D standard_opcodes[op_code - 1]; i > 0 ; --i) { - printf ("0x%" BFD_VMA_FMT "x%s", - read_leb128 (data, &bytes_read, 0), + printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data, + &bytes_read, 0)), i =3D=3D 1 ? "" : ", "); data +=3D bytes_read; } @@ -2888,7 +2949,7 @@ display_debug_lines_decoded (struct dwar break; =20 case DW_LNS_advance_line: - adv =3D read_leb128 (data, & bytes_read, 1); + adv =3D read_sleb128 (data, & bytes_read); data +=3D bytes_read; state_machine_regs.line +=3D adv; break; @@ -2971,8 +3032,8 @@ display_debug_lines_decoded (struct dwar =20 for (i =3D standard_opcodes[op_code - 1]; i > 0 ; --i) { - printf ("0x%" BFD_VMA_FMT "x%s", - read_leb128 (data, &bytes_read, 0), + printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data, + &bytes_read, 0)), i =3D=3D 1 ? "" : ", "); data +=3D bytes_read; } @@ -3007,24 +3068,24 @@ display_debug_lines_decoded (struct dwar if (!do_wide || (fileNameLength <=3D MAX_FILENAME_LENGTH)) { if (linfo.li_max_ops_per_insn =3D=3D 1) - printf ("%-35s %11d %#18lx\n", newFileName, - state_machine_regs.line, + printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n", + newFileName, state_machine_regs.line, state_machine_regs.address); else - printf ("%-35s %11d %#18lx[%d]\n", newFileName, - state_machine_regs.line, + printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n", + newFileName, state_machine_regs.line, state_machine_regs.address, state_machine_regs.op_index); } else { if (linfo.li_max_ops_per_insn =3D=3D 1) - printf ("%s %11d %#18lx\n", newFileName, - state_machine_regs.line, + printf ("%s %11d %#18" DWARF_VMA_FMT "x\n", + newFileName, state_machine_regs.line, state_machine_regs.address); else - printf ("%s %11d %#18lx[%d]\n", newFileName, - state_machine_regs.line, + printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n", + newFileName, state_machine_regs.line, state_machine_regs.address, state_machine_regs.op_index); } @@ -4110,7 +4171,7 @@ frame_display_row (Frame_Chunk *fc, int=20 =20 #define GET(N) byte_get (start, N); start +=3D N #define LEB() read_leb128 (start, & length_return, 0); start +=3D length_return -#define SLEB() read_leb128 (start, & length_return, 1); start +=3D length_return +#define SLEB() read_sleb128 (start, & length_return); start +=3D length_return =20 static int display_debug_frames (struct dwarf_section *section, Index: binutils/dwarf.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/binutils/dwarf.h,v retrieving revision 1.21 diff -u -p -r1.21 dwarf.h --- binutils/dwarf.h 23 Feb 2011 08:52:33 -0000 1.21 +++ binutils/dwarf.h 25 Feb 2011 10:12:30 -0000 @@ -20,6 +20,7 @@ MA 02110-1301, USA. */ =20 typedef unsigned HOST_WIDEST_INT dwarf_vma; +typedef HOST_WIDEST_INT dwarf_signed_vma; typedef unsigned HOST_WIDEST_INT dwarf_size_type; =20 /* Structure found in the .debug_line section. */ @@ -38,7 +39,7 @@ DWARF2_External_LineInfo; =20 typedef struct { - bfd_vma li_length; + dwarf_vma li_length; unsigned short li_version; unsigned int li_prologue_length; unsigned char li_min_insn_length; @@ -62,10 +63,10 @@ DWARF2_External_PubNames; =20 typedef struct { - bfd_vma pn_length; + dwarf_vma pn_length; unsigned short pn_version; - bfd_vma pn_offset; - bfd_vma pn_size; + dwarf_vma pn_offset; + dwarf_vma pn_size; } DWARF2_Internal_PubNames; =20 @@ -81,9 +82,9 @@ DWARF2_External_CompUnit; =20 typedef struct { - bfd_vma cu_length; + dwarf_vma cu_length; unsigned short cu_version; - bfd_vma cu_abbrev_offset; + dwarf_vma cu_abbrev_offset; unsigned char cu_pointer_size; } DWARF2_Internal_CompUnit; @@ -100,9 +101,9 @@ DWARF2_External_ARange; =20 typedef struct { - bfd_vma ar_length; + dwarf_vma ar_length; unsigned short ar_version; - bfd_vma ar_info_offset; + dwarf_vma ar_info_offset; unsigned char ar_pointer_size; unsigned char ar_segment_size; } @@ -165,15 +166,15 @@ typedef struct unsigned int pointer_size; unsigned int offset_size; int dwarf_version; - bfd_vma cu_offset; - bfd_vma base_address; + dwarf_vma cu_offset; + dwarf_vma base_address; /* This is an array of offsets to the location list table. */ - bfd_vma *loc_offsets; + dwarf_vma *loc_offsets; int *have_frame_base; unsigned int num_loc_offsets; unsigned int max_loc_offsets; /* List of .debug_ranges offsets seen in this .debug_info. */ - bfd_vma *range_lists; + dwarf_vma *range_lists; unsigned int num_range_lists; unsigned int max_range_lists; } @@ -217,5 +218,5 @@ void *cmalloc (size_t, size_t); void *xcmalloc (size_t, size_t); void *xcrealloc (void *, size_t, size_t); =20 -bfd_vma read_leb128 (unsigned char *data, +dwarf_vma read_leb128 (unsigned char *data, unsigned int *length_return, int sign); > -----Message d'origine----- > De=A0: binutils-owner@sourceware.org [mailto:binutils- > owner@sourceware.org] De la part de H.J. Lu > Envoy=E9=A0: jeudi 24 f=E9vrier 2011 14:51 > =C0=A0: Pierre Muller > Cc=A0: Kai Tietz; Binutils > Objet=A0: Re: [RFC patch]: Adjust the use of 'long' type in dwarf2.h > header >=20 > On Thu, Feb 24, 2011 at 3:33 AM, Pierre Muller > wrote: > >> #if __GNUC__ >=3D 2 > >> /* Define BFD64 here, even if our default architecture is 32 bit ELF > >> =A0 =A0as this will allow us to read in and parse 64bit and 32bit ELF > >> files. > >> =A0 =A0Only do this if we believe that the compiler can support a 64 b= it > >> =A0 =A0data type. =A0For now we only rely on GCC being able to do this. > =A0*/ > >> #define BFD64 > >> #endif > >> > >> .... > >> #include "dwarf.h" > >> --- > >> > >> dwarf_vma should be the same inside and outside of readelf.c. > > > > > > =A0This means, if I understand this correctly that > > if I compile a 32 bit readelf executable > > bfd_vma will be a 64-bit integer inside readelf.c, > > but a 32-bit integer in dwarf.c. > > > > =A0dwarf.c still mainly uses bfd_vma > > and has dwarf_vma only for one function > > get_encoded_value... > > > > =A0Should read_leb128 (and maybe other functions within > > dwarf.c) also be changed to use > > dwarf_vma rather than bfd_vma in that case? > > >=20 > Probably since readelf.c has >=20 > static unsigned long > read_uleb128 (unsigned char *data, unsigned int *length_return) > { > return read_leb128 (data, length_return, 0); > } >=20 >=20 >=20 > -- > H.J.