Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Handling corner case in building symbol table when "debug_line" includes  compilation directory
@ 2007-03-15  1:55 Maxim Grigoriev
  2007-03-15  2:27 ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Maxim Grigoriev @ 2007-03-15  1:55 UTC (permalink / raw)
  To: gdb-patches

Hello All,

Tensilica compiler seems to provide a unique approach in building DWARF
line tables. It confuses GDB algorithms being used to build symbol tables.

First in DW_TAG_compile_unit entry

   DW_AT_name        is a source file name as it was used in a command line;
   DW_AT_comp_dir    is a full path name to a compilation directory;    

Then in the statement program prologue, the directory table includes at
least one entry, which is again the compilation directory. And, there is
a corresponding file table entry referencing to this directory.

Assuming that this combination of the names of the directories and files
does not contradict DWARF standard, I think GDB has to handle this 
situation.

I suggest the following patch to fix this problem:

2007-03-15 Maxim Grigoriev <maxim2405@gmail.com>

    * buildsym.c (start_subfile): Add handling missing case while
    building symbol table for a compilation unit.


Index: gdb/buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.47
diff -u -r1.47 buildsym.c
--- gdb/buildsym.c    27 Feb 2007 22:57:42 -0000    1.47
+++ gdb/buildsym.c    15 Mar 2007 01:14:14 -0000
@@ -549,7 +549,18 @@
 
   for (subfile = subfiles; subfile; subfile = subfile->next)
     {
-      if (FILENAME_CMP (subfile->name, name) == 0)
+      char *subfile_name;
+      if (IS_ABSOLUTE_PATH(name) && !IS_ABSOLUTE_PATH (subfile->name))
+    {
+      subfile_name = concat (dirname, SLASH_STRING,
+                 subfile->name, (char *)NULL);
+      make_cleanup (xfree, subfile_name);
+    }
+      else
+    {
+      subfile_name = subfile->name;
+    }
+      if (FILENAME_CMP (subfile_name, name) == 0)
     {
       current_subfile = subfile;
       return;


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

* Re: Handling corner case in building symbol table when  "debug_line" includes  compilation directory
  2007-03-15  1:55 Handling corner case in building symbol table when "debug_line" includes compilation directory Maxim Grigoriev
@ 2007-03-15  2:27 ` Daniel Jacobowitz
  2007-03-15  4:30   ` Maxim Grigoriev
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2007-03-15  2:27 UTC (permalink / raw)
  To: Maxim Grigoriev; +Cc: gdb-patches

On Wed, Mar 14, 2007 at 06:54:57PM -0700, Maxim Grigoriev wrote:
> Hello All,

> Tensilica compiler seems to provide a unique approach in building DWARF
> line tables. It confuses GDB algorithms being used to build symbol tables.

> First in DW_TAG_compile_unit entry

>   DW_AT_name        is a source file name as it was used in a command line;
>   DW_AT_comp_dir    is a full path name to a compilation directory;    
> Then in the statement program prologue, the directory table includes at
> least one entry, which is again the compilation directory. And, there is
> a corresponding file table entry referencing to this directory.

> Assuming that this combination of the names of the directories and files
> does not contradict DWARF standard, I think GDB has to handle this situation.

> I suggest the following patch to fix this problem:

First of all, your mailer ate whitespace in the patch again - very
hard to read.

Unfortunately, I do not understand your description.  Could you show
me an example?

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: Handling corner case in building symbol table when "debug_line"  includes  compilation directory
  2007-03-15  2:27 ` Daniel Jacobowitz
@ 2007-03-15  4:30   ` Maxim Grigoriev
  2007-04-10 21:03     ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Maxim Grigoriev @ 2007-03-15  4:30 UTC (permalink / raw)
  To: Maxim Grigoriev, gdb-patches

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

I've attached the patch separately. Now, it should be fine. Sorry for 
inconvenience.

1) test case
extern int printf(const char *fmt,...);

int main()
{
printf("Hello, World !\n");
printf("Let's make DWARF consistent across all the tools !\n");
}

2) output from "readelf --debug-dump"

The section .debug_info contains:

Compilation Unit @ 0:
Length: 241
Version: 2
Abbrev Offset: 0
Pointer Size: 4
<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
DW_AT_name : test.c
DW_AT_comp_dir : /home/maxim/W/BadgerPass/PR_14999
DW_AT_producer : xt-xcc for 7.1.2-development -O0 
-OPT:align_instructions=32 -g2
DW_AT_language : 1 (ANSI C)
DW_AT_identifier_case: 0 (case_sensitive)
DW_AT_stmt_list : 0
[ . . . . . ]
Dump of debug contents of section .debug_line:

Length: 101
DWARF Version: 2
Prologue Length: 65
[ . . . . .]

The Directory Table:
/home/maxim/W/BadgerPass/PR_14999

The File Name Table:
Entry Dir Time Size Name
1 1 1173897037 152 test.c

* * * * *

So the compilation directory is listed in the directory table. And, there is
a reference from the file table pointing to this directory.

Normally, we wouldn't see a compilation directory in a line table prologue.
With my native GCC on the same test case I have:

<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
DW_AT_stmt_list : 0
DW_AT_high_pc : 0x80483b6
DW_AT_low_pc : 0x8048384
DW_AT_producer : GNU C 4.1.1 20060525 (Red Hat 4.1.1-1)
DW_AT_language : 1 (ANSI C)
DW_AT_name : test.c
DW_AT_comp_dir : /home/maxim/W/BadgerPass/PR_14999
[ . . . . ]
The Directory Table is empty.

The File Name Table:
Entry Dir Time Size Name
1 0 0 0 test.c

So the compilation directory gets always described and referenced 
explicitly.
Thanks for looking into this.

2007-03-15 Maxim Grigoriev <maxim2405@gmail.com>

* buildsym.c (start_subfile): Add handling missing case while
building symbol table for a compilation unit.

< Patch is attached >

Daniel Jacobowitz wrote:
> On Wed, Mar 14, 2007 at 06:54:57PM -0700, Maxim Grigoriev wrote:
>   
>> Hello All,
>>     
>
>   
>> Tensilica compiler seems to provide a unique approach in building DWARF
>> line tables. It confuses GDB algorithms being used to build symbol tables.
>>     
>
>   
>> First in DW_TAG_compile_unit entry
>>     
>
>   
>>   DW_AT_name        is a source file name as it was used in a command line;
>>   DW_AT_comp_dir    is a full path name to a compilation directory;    
>> Then in the statement program prologue, the directory table includes at
>> least one entry, which is again the compilation directory. And, there is
>> a corresponding file table entry referencing to this directory.
>>     
>
>   
>> Assuming that this combination of the names of the directories and files
>> does not contradict DWARF standard, I think GDB has to handle this situation.
>>     
>
>   
>> I suggest the following patch to fix this problem:
>>     
>
> First of all, your mailer ate whitespace in the patch again - very
> hard to read.
>
> Unfortunately, I do not understand your description.  Could you show
> me an example?
>
>   


[-- Attachment #2: PATCH.diff --]
[-- Type: text/x-patch, Size: 807 bytes --]

Index: gdb/buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.47
diff -u -r1.47 buildsym.c
--- gdb/buildsym.c	27 Feb 2007 22:57:42 -0000	1.47
+++ gdb/buildsym.c	15 Mar 2007 01:14:14 -0000
@@ -549,7 +549,18 @@
 
   for (subfile = subfiles; subfile; subfile = subfile->next)
     {
-      if (FILENAME_CMP (subfile->name, name) == 0)
+      char *subfile_name;
+      if (IS_ABSOLUTE_PATH(name) && !IS_ABSOLUTE_PATH (subfile->name))
+	{
+	  subfile_name = concat (dirname, SLASH_STRING,
+				 subfile->name, (char *)NULL);
+	  make_cleanup (xfree, subfile_name);
+	}
+      else
+	{
+	  subfile_name = subfile->name;
+	}
+      if (FILENAME_CMP (subfile_name, name) == 0)
 	{
 	  current_subfile = subfile;
 	  return;

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

* Re: Handling corner case in building symbol table when "debug_line"  includes  compilation directory
  2007-03-15  4:30   ` Maxim Grigoriev
@ 2007-04-10 21:03     ` Daniel Jacobowitz
  2007-04-10 23:34       ` Maxim Grigoriev
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2007-04-10 21:03 UTC (permalink / raw)
  To: Maxim Grigoriev; +Cc: gdb-patches

On Wed, Mar 14, 2007 at 09:30:23PM -0700, Maxim Grigoriev wrote:
> I've attached the patch separately. Now, it should be fine. Sorry for 
> inconvenience.

Actually, I apologize - looks like it was my mailer to blame...

> So the compilation directory is listed in the directory table. And, there is
> a reference from the file table pointing to this directory.
> 
> Normally, we wouldn't see a compilation directory in a line table prologue.

Right.  Now I understand.

This stuff is all quite fragile; we don't keep good track of what
dirname is which.  I think I puzzled it out, but...

> +      char *subfile_name;
> +      if (IS_ABSOLUTE_PATH(name) && !IS_ABSOLUTE_PATH (subfile->name))
> +	{
> +	  subfile_name = concat (dirname, SLASH_STRING,
> +				 subfile->name, (char *)NULL);

Isn't that the wrong DIRNAME?  That's supposed to be a prefix to NAME,
but SUBFILE might be in a different directory.  You need
subfile->dirname (if it's not NULL).

As for the patch, watch out for your formatting.  Spaces around
parentheses and you don't need braces around a single statement.
Also, creating a cleanup in a function that doesn't call do_cleanups
is bad.  It would be better to free it immediately when we're done
with it.

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: Handling corner case in building symbol table when "debug_line"  includes  compilation directory
  2007-04-10 21:03     ` Daniel Jacobowitz
@ 2007-04-10 23:34       ` Maxim Grigoriev
  2007-04-11  2:06         ` Maxim Grigoriev
  0 siblings, 1 reply; 8+ messages in thread
From: Maxim Grigoriev @ 2007-04-10 23:34 UTC (permalink / raw)
  To: Maxim Grigoriev, gdb-patches, Daniel Jacobowitz

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

Daniel Jacobowitz wrote:

. . . . . .
>> +      char *subfile_name;
>> +      if (IS_ABSOLUTE_PATH(name) && !IS_ABSOLUTE_PATH (subfile->name))
>> +	{
>> +	  subfile_name = concat (dirname, SLASH_STRING,
>> +				 subfile->name, (char *)NULL);
>>     
>
> Isn't that the wrong DIRNAME?  That's supposed to be a prefix to NAME,
> but SUBFILE might be in a different directory.  You need
> subfile->dirname (if it's not NULL).
>
> As for the patch, watch out for your formatting.  Spaces around
> parentheses and you don't need braces around a single statement.
> Also, creating a cleanup in a function that doesn't call do_cleanups
> is bad.  It would be better to free it immediately when we're done
> with it
I didn't manage to create a test case when "subfile->dirname"
is different from "dirname". But, I think your comment is
correct. I followed all your suggestions and attached new
patch. Thanks for looking into this.

2007-04-10 Maxim Grigoriev <maxim2405@gmail.com>

* buildsym.c (start_subfile): Add handling missing case while
building symbol table for a compilation unit.



[-- Attachment #2: PATCH2.diff --]
[-- Type: text/x-patch, Size: 869 bytes --]

Index: gdb/buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.47
diff -u -r1.47 buildsym.c
--- gdb/buildsym.c	27 Feb 2007 22:57:42 -0000	1.47
+++ gdb/buildsym.c	10 Apr 2007 23:22:49 -0000
@@ -549,9 +549,19 @@
 
   for (subfile = subfiles; subfile; subfile = subfile->next)
     {
-      if (FILENAME_CMP (subfile->name, name) == 0)
+      char *subfile_name;
+      if (IS_ABSOLUTE_PATH(name) &&
+	  !IS_ABSOLUTE_PATH (subfile->name) &&
+	  (subfile->dirname != NULL))
+	subfile_name = concat (subfile->dirname, SLASH_STRING,
+			       subfile->name, NULL);
+      else
+	subfile_name = subfile->name;
+      if (FILENAME_CMP (subfile_name, name) == 0)
 	{
 	  current_subfile = subfile;
+	  if (subfile_name != subfile->name)
+	    xfree (subfile_name);
 	  return;
 	}
     }

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

* Re: Handling corner case in building symbol table when "debug_line"  includes  compilation directory
  2007-04-10 23:34       ` Maxim Grigoriev
@ 2007-04-11  2:06         ` Maxim Grigoriev
  2007-05-14 14:11           ` Daniel Jacobowitz
  0 siblings, 1 reply; 8+ messages in thread
From: Maxim Grigoriev @ 2007-04-11  2:06 UTC (permalink / raw)
  To: Maxim Grigoriev; +Cc: gdb-patches, Daniel Jacobowitz

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

I think I missed one important detail in my patch.
Here is an improved version:

2007-04-10 Maxim Grigoriev <maxim2405@gmail.com>

        * buildsym.c (start_subfile): Add handling missing case while
        building symbol table for a compilation unit.


[-- Attachment #2: PATCH3.diff --]
[-- Type: text/x-patch, Size: 1007 bytes --]

Index: gdb/buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.47
diff -u -r1.47 buildsym.c
--- gdb/buildsym.c	27 Feb 2007 22:57:42 -0000	1.47
+++ gdb/buildsym.c	11 Apr 2007 02:02:37 -0000
@@ -549,11 +549,23 @@
 
   for (subfile = subfiles; subfile; subfile = subfile->next)
     {
-      if (FILENAME_CMP (subfile->name, name) == 0)
+      char *subfile_name;
+      if (IS_ABSOLUTE_PATH(name) &&
+	  !IS_ABSOLUTE_PATH (subfile->name) &&
+	  (subfile->dirname != NULL))
+	subfile_name = concat (subfile->dirname, SLASH_STRING,
+			       subfile->name, NULL);
+      else
+	subfile_name = subfile->name;
+      if (FILENAME_CMP (subfile_name, name) == 0)
 	{
 	  current_subfile = subfile;
+	  if (subfile_name != subfile->name)
+	    xfree (subfile_name);
 	  return;
 	}
+      if (subfile_name != subfile->name)
+	xfree (subfile_name);
     }
 
   /* This subfile is not known.  Add an entry for it. Make an entry

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

* Re: Handling corner case in building symbol table when  "debug_line" includes  compilation directory
  2007-04-11  2:06         ` Maxim Grigoriev
@ 2007-05-14 14:11           ` Daniel Jacobowitz
  2007-05-14 19:01             ` Maxim Grigoriev
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2007-05-14 14:11 UTC (permalink / raw)
  To: Maxim Grigoriev; +Cc: gdb-patches

On Tue, Apr 10, 2007 at 07:06:37PM -0700, Maxim Grigoriev wrote:
> I think I missed one important detail in my patch.
> Here is an improved version:
> 
> 2007-04-10 Maxim Grigoriev <maxim2405@gmail.com>
> 
>        * buildsym.c (start_subfile): Add handling missing case while
>        building symbol table for a compilation unit.

Sorry I didn't get back to you about this.  The patch is fine, but
still had some formatting issues.  I've applied this version - please
let me know if it does not work for you.

-- 
Daniel Jacobowitz
CodeSourcery

2007-05-14  Maxim Grigoriev  <maxim2405@gmail.com>

	* buildsym.c (start_subfile): Handle absolute pathnames
	while comparing subfile names.

Index: buildsym.c
===================================================================
RCS file: /cvs/src/src/gdb/buildsym.c,v
retrieving revision 1.47
diff -u -p -r1.47 buildsym.c
--- buildsym.c	27 Feb 2007 22:57:42 -0000	1.47
+++ buildsym.c	14 May 2007 13:37:19 -0000
@@ -549,11 +549,27 @@ start_subfile (char *name, char *dirname
 
   for (subfile = subfiles; subfile; subfile = subfile->next)
     {
-      if (FILENAME_CMP (subfile->name, name) == 0)
+      char *subfile_name;
+
+      /* If NAME is an absolute path, and this subfile is not, then
+	 attempt to create an absolute path to compare.  */
+      if (IS_ABSOLUTE_PATH (name)
+	  && !IS_ABSOLUTE_PATH (subfile->name)
+	  && subfile->dirname != NULL)
+	subfile_name = concat (subfile->dirname, SLASH_STRING,
+			       subfile->name, NULL);
+      else
+	subfile_name = subfile->name;
+
+      if (FILENAME_CMP (subfile_name, name) == 0)
 	{
 	  current_subfile = subfile;
+	  if (subfile_name != subfile->name)
+	    xfree (subfile_name);
 	  return;
 	}
+      if (subfile_name != subfile->name)
+	xfree (subfile_name);
     }
 
   /* This subfile is not known.  Add an entry for it. Make an entry


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

* Re: Handling corner case in building symbol table when "debug_line"  includes  compilation directory
  2007-05-14 14:11           ` Daniel Jacobowitz
@ 2007-05-14 19:01             ` Maxim Grigoriev
  0 siblings, 0 replies; 8+ messages in thread
From: Maxim Grigoriev @ 2007-05-14 19:01 UTC (permalink / raw)
  To: gdb-patches, Daniel Jacobowitz

Everything works fine.

Thanks much for looking into this and fixing formatting issues.

-- Maxim


Daniel Jacobowitz wrote:
> On Tue, Apr 10, 2007 at 07:06:37PM -0700, Maxim Grigoriev wrote:
>   
>> I think I missed one important detail in my patch.
>> Here is an improved version:
>>
>> 2007-04-10 Maxim Grigoriev <maxim2405@gmail.com>
>>
>>        * buildsym.c (start_subfile): Add handling missing case while
>>        building symbol table for a compilation unit.
>>     
>
> Sorry I didn't get back to you about this.  The patch is fine, but
> still had some formatting issues.  I've applied this version - please
> let me know if it does not work for you.
>
>   


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

end of thread, other threads:[~2007-05-14 19:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-15  1:55 Handling corner case in building symbol table when "debug_line" includes compilation directory Maxim Grigoriev
2007-03-15  2:27 ` Daniel Jacobowitz
2007-03-15  4:30   ` Maxim Grigoriev
2007-04-10 21:03     ` Daniel Jacobowitz
2007-04-10 23:34       ` Maxim Grigoriev
2007-04-11  2:06         ` Maxim Grigoriev
2007-05-14 14:11           ` Daniel Jacobowitz
2007-05-14 19:01             ` Maxim Grigoriev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox