This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: patch for bfd/dwarf2.c, support for 16-bit addresses in DWARF-2


Hi Nick,

> [...]
> This would probably be simpler to code as a switch statement, like
> this:
> 
>   switch (unit->addr_size)
>     {
>     case 8:
>       return bfd_get_64 (unit->abfd, (bfd_byte *) buf);
>     case 4:
>       return bfd_get_32 (unit->abfd, (bfd_byte *) buf);
>     case 2:
>       return bfd_get_16 (unit->abfd, (bfd_byte *) buf);
>     default:
>       abort ();
>     }
> 
> This also prevents the function from silently doing the wrong thing.

Ok, but there is a check already in parse_comp_unit().
Looks better anyway! New patch at the end.

> There is code in _bfd_dwarf2_find_nearest_line () that also checks to
> see if addr_size is 4 or 8.  Why have you not patched this function
> as well ?
> 
Because it is correct.

There is a confusion in bfd and gdb about addr_size.

In _bfd_dwarf2_find_nearest_line(), the 'addr_size' corresponds to the
ELF format size: 4 for ELF32 and 8 for ELF64. It is used to represent
size/offset/index within the ELF sections.

This 'addr_size' has nothing to do with the address size of the target 
specified by the DW_AT_address_class. It should better be named
'elf_addr_size'
or something like this.

Note that the DWARF 2 spec does not deal with ELF64... I understand
this is issue http://www.eagercon.com/dwarf/issues/991102-1.htm for
the next DWARF standard.

	Stephane

2000-02-23  Stephane Carrez  <stcarrez@worldnet.fr>

	* dwarf2read.c (dwarf2_build_psymtabs_hard): Use
	bfd_arch_bits_per_address to get the size of addresses.
	(read_address): Read 16-bits addresses.
--- /src/gnu/cygnus/binutils/bfd/dwarf2.c	Wed Jul 14 10:49:38 1999
+++ bfd/dwarf2.c	Wed Feb 23 22:27:17 2000
@@ -336,15 +336,17 @@ read_address (unit, buf)
      struct comp_unit* unit;
      char *buf;
 {
-  bfd_vma retval = 0;
-
-  if (unit->addr_size == 4)
+  switch (unit->addr_size)
     {
-      retval = bfd_get_32 (unit->abfd, (bfd_byte *) buf);
-    } else {
-      retval = bfd_get_64 (unit->abfd, (bfd_byte *) buf);
+    case 8:
+      return bfd_get_64 (unit->abfd, (bfd_byte *) buf);
+    case 4:
+      return bfd_get_32 (unit->abfd, (bfd_byte *) buf);
+    case 2:
+      return bfd_get_16 (unit->abfd, (bfd_byte *) buf);
+    default:
+      abort ();
     }
-  return retval;
 }
 
 
@@ -1277,9 +1279,9 @@ parse_comp_unit (abfd, info_ptr, end_ptr
       return 0;
     }
 
-  if (addr_size != 4 && addr_size != 8)
+  if (addr_size != 4 && addr_size != 8 && addr_size != 2)
     {
-      (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '4' and '8'.", addr_size );
+      (*_bfd_error_handler) ("Dwarf Error: found address size '%u', this reader can only handle address sizes '2' '4' and '8'.", addr_size );
       bfd_set_error (bfd_error_bad_value);
       return 0;
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]