public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [Patch]: Improve handling of DW_LNE_define_file
@ 2012-01-12 12:05 Tristan Gingold
  2012-01-16 22:16 ` Alan Modra
  2012-01-19 13:32 ` Michael Eager
  0 siblings, 2 replies; 6+ messages in thread
From: Tristan Gingold @ 2012-01-12 12:05 UTC (permalink / raw)
  To: binutils Development

Hi,

while investigating some issues on ia64 hp/ux, I made the following improvements to dwarf.c:

* hp/ux C compiler (at least the version I have) emit wrong length for DW_LNE_define_file opcode.  We can't fix that but detecting it is nice.

* objdump -WL crashed on DW_LNE_define_file and in fact incorrectly handled it.  This patch fixes this issue.

* objdump -WL generates 'UNKNOWN' messages for DW_LNE_set_discriminator and DW_LNE_HP_set_sequence opcodes.  After displaying the id of the opcode, I choose to ignore them.

No regression for x86 GNU Linux.

Ok for trunk ?

Tristan.

binutils/
2012-01-12  Tristan Gingold  <gingold@adacore.com>

	* dwarf.c (process_extended_line_op): Reindent define_file output.
	Detect define_file opcode length mismatch.
	(display_debug_lines_decoded): Add an entry in file_table for each
	define_file opcode.
	Ignore DW_LNE_set_discriminator and DW_LNE_HP_set_sequence.
	Display extended opcode for unhandle opcode.

index a775818..08f472f 100644
--- a/binutils/dwarf.c
+++ b/binutils/dwarf.c
@@ -247,6 +247,7 @@ process_extended_line_op (unsigned char *data, int is_stmt)
   unsigned int len;
   unsigned char *name;
   dwarf_vma adr;
+  unsigned char *orig_data = data;
 
   len = read_leb128 (data, & bytes_read, 0);
   data += bytes_read;
@@ -277,7 +278,7 @@ process_extended_line_op (unsigned char *data, int is_stmt)
       break;
 
     case DW_LNE_define_file:
-      printf (_("  define new File Table entry\n"));
+      printf (_("define new File Table entry\n"));
       printf (_("  Entry\tDir\tTime\tSize\tName\n"));
 
       printf ("   %d\t", ++state_machine_regs.last_file_entry);
@@ -288,7 +289,11 @@ process_extended_line_op (unsigned char *data, int is_stmt)
       printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
       data += bytes_read;
       printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
-      printf ("%s\n\n", name);
+      data += bytes_read;
+      printf ("%s", name);
+      if (data - orig_data != len)
+        printf (_(" [Bad opcode length]"));
+      printf ("\n\n");
       break;
 
     case DW_LNE_set_discriminator:
@@ -2800,7 +2805,9 @@ display_debug_lines_decoded (struct dwarf_section *section,
       int offset_size;
       int i;
       File_Entry *file_table = NULL;
+      unsigned int n_files = 0;
       unsigned char **directory_table = NULL;
+      unsigned int n_directories = 0;
 
       hdrptr = data;
 
@@ -2885,7 +2892,6 @@ display_debug_lines_decoded (struct dwarf_section *section,
       data = standard_opcodes + linfo.li_opcode_base - 1;
       if (*data != 0)
         {
-          unsigned int n_directories = 0;
           unsigned char *ptr_directory_table = data;
 
 	  while (*data != 0)
@@ -2912,7 +2918,6 @@ display_debug_lines_decoded (struct dwarf_section *section,
       /* Traverse the File Name table just to count the entries.  */
       if (*data != 0)
         {
-          unsigned int n_files = 0;
           unsigned char *ptr_file_name_table = data;
 
           while (*data != 0)
@@ -3044,21 +3049,36 @@ display_debug_lines_decoded (struct dwarf_section *section,
                     break;
                   case DW_LNE_define_file:
                     {
-                      unsigned int dir_index = 0;
+                      file_table = (File_Entry *)
+                        xmalloc ((n_files + 1) * sizeof (File_Entry));
 
                       ++state_machine_regs.last_file_entry;
+                      /* Source file name.  */
+                      file_table[n_files].name = op_code_data;
                       op_code_data += strlen ((char *) op_code_data) + 1;
-                      dir_index = read_leb128 (op_code_data, & bytes_read, 0);
+                      /* Directory index.  */
+                      file_table[n_files].directory_index =
+                        read_leb128 (op_code_data, & bytes_read, 0);
                       op_code_data += bytes_read;
-                      read_leb128 (op_code_data, & bytes_read, 0);
+                      /* Last modification time.  */
+                      file_table[n_files].modification_date =
+                        read_leb128 (op_code_data, & bytes_read, 0);
                       op_code_data += bytes_read;
-                      read_leb128 (op_code_data, & bytes_read, 0);
+                      /* File length.  */
+                      file_table[n_files].length =
+                        read_leb128 (op_code_data, & bytes_read, 0);
 
-                      printf ("%s:\n", directory_table[dir_index]);
+                      n_files++;
                       break;
                     }
+                  case DW_LNE_set_discriminator:
+                  case DW_LNE_HP_set_sequence:
+                    /* Simply ignored.  */
+                    break;
+
                   default:
-                    printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
+                    printf (_("UNKNOWN (%u): length %d\n"),
+                            ext_op_code, ext_op_code_len - bytes_read);
                     break;
                   }
                 data += ext_op_code_len;

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

* Re: [Patch]: Improve handling of DW_LNE_define_file
  2012-01-12 12:05 [Patch]: Improve handling of DW_LNE_define_file Tristan Gingold
@ 2012-01-16 22:16 ` Alan Modra
  2012-01-19 11:35   ` Tristan Gingold
  2012-01-19 13:32 ` Michael Eager
  1 sibling, 1 reply; 6+ messages in thread
From: Alan Modra @ 2012-01-16 22:16 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils Development

On Thu, Jan 12, 2012 at 01:05:15PM +0100, Tristan Gingold wrote:
>                    case DW_LNE_define_file:
>                      {
> -                      unsigned int dir_index = 0;
> +                      file_table = (File_Entry *)
> +                        xmalloc ((n_files + 1) * sizeof (File_Entry));

xrealloc.  Otherwise OK.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [Patch]: Improve handling of DW_LNE_define_file
  2012-01-16 22:16 ` Alan Modra
@ 2012-01-19 11:35   ` Tristan Gingold
  0 siblings, 0 replies; 6+ messages in thread
From: Tristan Gingold @ 2012-01-19 11:35 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils Development


On Jan 16, 2012, at 11:16 PM, Alan Modra wrote:

> On Thu, Jan 12, 2012 at 01:05:15PM +0100, Tristan Gingold wrote:
>>                   case DW_LNE_define_file:
>>                     {
>> -                      unsigned int dir_index = 0;
>> +                      file_table = (File_Entry *)
>> +                        xmalloc ((n_files + 1) * sizeof (File_Entry));
> 
> xrealloc.  Otherwise OK.

Argh, silly me.

Fixed, regtested and committed.

Thank you for catching that!

Tristan.

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

* Re: [Patch]: Improve handling of DW_LNE_define_file
  2012-01-12 12:05 [Patch]: Improve handling of DW_LNE_define_file Tristan Gingold
  2012-01-16 22:16 ` Alan Modra
@ 2012-01-19 13:32 ` Michael Eager
  2012-01-19 13:53   ` Tristan Gingold
  2012-01-19 13:59   ` Tristan Gingold
  1 sibling, 2 replies; 6+ messages in thread
From: Michael Eager @ 2012-01-19 13:32 UTC (permalink / raw)
  To: Tristan Gingold; +Cc: binutils Development

On 01/12/2012 04:05 AM, Tristan Gingold wrote:

> index a775818..08f472f 100644
> --- a/binutils/dwarf.c
> +++ b/binutils/dwarf.c

> @@ -288,7 +289,11 @@ process_extended_line_op (unsigned char *data, int is_stmt)
>         printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data,&  bytes_read, 0)));
>         data += bytes_read;
>         printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data,&  bytes_read, 0)));
> -      printf ("%s\n\n", name);
> +      data += bytes_read;
> +      printf ("%s", name);
> +      if (data - orig_data != len)

This should be
          if ((unsigned int) (data - orig_data) != len)
or change len to "int".

I prefer changing len.   I can check in obvious patch.


-- 
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

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

* Re: [Patch]: Improve handling of DW_LNE_define_file
  2012-01-19 13:32 ` Michael Eager
@ 2012-01-19 13:53   ` Tristan Gingold
  2012-01-19 13:59   ` Tristan Gingold
  1 sibling, 0 replies; 6+ messages in thread
From: Tristan Gingold @ 2012-01-19 13:53 UTC (permalink / raw)
  To: Michael Eager; +Cc: binutils Development


On Jan 19, 2012, at 2:32 PM, Michael Eager wrote:

> On 01/12/2012 04:05 AM, Tristan Gingold wrote:
> 
>> index a775818..08f472f 100644
>> --- a/binutils/dwarf.c
>> +++ b/binutils/dwarf.c
> 
>> @@ -288,7 +289,11 @@ process_extended_line_op (unsigned char *data, int is_stmt)
>>        printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data,&  bytes_read, 0)));
>>        data += bytes_read;
>>        printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data,&  bytes_read, 0)));
>> -      printf ("%s\n\n", name);
>> +      data += bytes_read;
>> +      printf ("%s", name);
>> +      if (data - orig_data != len)
> 
> This should be
>         if ((unsigned int) (data - orig_data) != len)
> or change len to "int".
> 
> I prefer changing len.   I can check in obvious patch.

I think the cast is cleaner as 'len' was already used as unsigned.
I will commit the fix.

Sorry for not having seen that.

Tristan.

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

* Re: [Patch]: Improve handling of DW_LNE_define_file
  2012-01-19 13:32 ` Michael Eager
  2012-01-19 13:53   ` Tristan Gingold
@ 2012-01-19 13:59   ` Tristan Gingold
  1 sibling, 0 replies; 6+ messages in thread
From: Tristan Gingold @ 2012-01-19 13:59 UTC (permalink / raw)
  To: Michael Eager; +Cc: binutils Development


On Jan 19, 2012, at 2:32 PM, Michael Eager wrote:

> On 01/12/2012 04:05 AM, Tristan Gingold wrote:
> 
>> index a775818..08f472f 100644
>> --- a/binutils/dwarf.c
>> +++ b/binutils/dwarf.c
> 
>> @@ -288,7 +289,11 @@ process_extended_line_op (unsigned char *data, int is_stmt)
>>        printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data,&  bytes_read, 0)));
>>        data += bytes_read;
>>        printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data,&  bytes_read, 0)));
>> -      printf ("%s\n\n", name);
>> +      data += bytes_read;
>> +      printf ("%s", name);
>> +      if (data - orig_data != len)
> 
> This should be
>         if ((unsigned int) (data - orig_data) != len)
> or change len to "int".
> 
> I prefer changing len.   I can check in obvious patch.

I committed this:

Thank you for noticing this.

Tristan.

2012-01-19  Tristan Gingold  <gingold@adacore.com>

	* dwarf.c (process_extended_line_op): Add a cast to silent a
	warning.

RCS file: /cvs/src/src/binutils/dwarf.c,v
retrieving revision 1.106
diff -c -r1.106 dwarf.c
*** dwarf.c	19 Jan 2012 11:34:44 -0000	1.106
--- dwarf.c	19 Jan 2012 13:57:55 -0000
***************
*** 291,297 ****
        printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
        data += bytes_read;
        printf ("%s", name);
!       if (data - orig_data != len)
          printf (_(" [Bad opcode length]"));
        printf ("\n\n");
        break;
--- 291,297 ----
        printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
        data += bytes_read;
        printf ("%s", name);
!       if ((unsigned int) (data - orig_data) != len)
          printf (_(" [Bad opcode length]"));
        printf ("\n\n");
        break;

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

end of thread, other threads:[~2012-01-19 13:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-12 12:05 [Patch]: Improve handling of DW_LNE_define_file Tristan Gingold
2012-01-16 22:16 ` Alan Modra
2012-01-19 11:35   ` Tristan Gingold
2012-01-19 13:32 ` Michael Eager
2012-01-19 13:53   ` Tristan Gingold
2012-01-19 13:59   ` Tristan Gingold

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