public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix for the gdb.base/macscp.exp testcase failure with split dwarf.
@ 2021-11-19  6:56 Achra, Nitika
  2021-11-19 18:55 ` Keith Seitz
  0 siblings, 1 reply; 7+ messages in thread
From: Achra, Nitika @ 2021-11-19  6:56 UTC (permalink / raw)
  To: gdb-patches; +Cc: George, Jini Susan

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

[AMD Official Use Only]

Requesting to please review the attached patch.

Command used: make check RUNTESTFLAGS='CC_FOR_TARGET="clang -gdwarf-5 -gsplit-dwarf -fdebug-macro"'
                                         TESTS="gdb.base/macscp.exp"

Before the patch:
Number of expected passes            234
Number of unexpected failures        65
Number of known failures             40

After the patch:
Number of expected passes            315
Number of unexpected failures        1
Number of known failures             23

Compiler used: clang 12.0.0

Regards,
Nitika

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


[-- Attachment #2: 0001-Fix-for-the-gdb.base-macscp.exp-testcase-failure-wit.patch --]
[-- Type: application/octet-stream, Size: 30206 bytes --]

From d8460a4f4a8924a427fb8ec193ab5d932135060c Mon Sep 17 00:00:00 2001
From: nitachra <Nitika.Achra@amd.com>
Date: Fri, 1 Oct 2021 01:11:24 +0530
Subject: [PATCH] Fix for the gdb.base/macscp.exp testcase failure with split
 dwarf.

Command used: make check RUNTESTFLAGS='CC_FOR_TARGET="clang -gdwarf-5 -gsplit-dwarf -fdebug-macro"'
			 TESTS="gdb.base/macscp.exp"

Before the patch:
Number of expected passes            234
Number of unexpected failures        65
Number of known failures             40

After the patch:
Number of expected passes            315
Number of unexpected failures        1
Number of known failures             23

Compiler used: clang 12.0.0

gdb/ChangeLog:

	* dwarf2/line-header.c (add_include_dir): Handle .debug_line.dwo
	  include directories table entries.
	* (add_file_name): Handle .debug_line.dwo file names entries.
	* (file_file_name): Read the file name from .debug_line.dwo or
	  .debug_line sections.
	* (read_formatted_entries): Handle the .debug_line.dwo section.
	* (dwarf_decode_line_header): Read both .debug_line and
	   .debug_line.dwo headers.
	* dwarf2/line-header.h (include_dir): Handle the .debug_line.dwo
	  section entries.
	* (add_include_dir): Add an entry to the m_include_dirs vector or
	  to m_dwo_include_dirs vector if reading .debug_line.dwo
	  section.
	* (add_file_name): Add an entry to the m_file_names vector or to
	  the m_dwo_file_names vector if reading dwo section.
	* (include_dir_at): Return the include dir from m_include_dirs or
	  from the m_dwo_include_dirs.
	* (is_valid_dwo_file_index): Added this new function which will
	  check if the index is valid index in file_names table in
	  .debug_line.dwo.
	* (file_name_at): Return the file name from m_file_names or
	  from m_dwo_file_names vector.
	* (m_dwo_file_names): Return the file names vector containg the
	   .debug_line.dwo section file names entries.
	* (struct line_header): Added .debug_line.dwo header fields.
	* (m_dwo_include_dirs): New vector to contain include directories
	  of .debug_line.dwo.
	* (m_dwo_file_names): New vector to contain file names entries of
	  .debug_line.dwo section.
	* dwarf2/read.c (compute_include_file_name): Added a parameter
	  to check if the dwo is true.
	* (dw2_get_file_names_reader): Handle the file names entries from
	  .debug_line.dwo section.
	* (dwarf_decode_line_header): Read both .debug_line and
	  .debug_line.dwo section. If the CU type is debug_types, read
	  only the .debug_line.dwo section.
	* (compute_include_file_name). Handle the dwo section.
	* (class lnp_state_machine): For state machine, always read the
	  .debug_line section because line table is present only in the primary
	  file.
	* (handle_set_file): Likewise.
	* (dwarf_decode_lines_1): Likewise.
	* (new_symbol): Add a parameter in file_name_at function to
	   handle the dwo unit.
	* gdb/macrotab.c (compare_locations): Compare the file names
	  instaed of macro source file pointers because there are duplicate file
	  names in .debug_line and .debug_line.dwo sections. So, the pointers may
	  not match even if the files are same.
---
 gdb/dwarf2/line-header.c | 159 +++++++++++++++++++++++++--------------
 gdb/dwarf2/line-header.h |  89 ++++++++++++++++------
 gdb/dwarf2/read.c        | 106 +++++++++++++++++++++-----
 gdb/macrotab.c           |   4 +-
 4 files changed, 260 insertions(+), 98 deletions(-)

diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c
index 15195764c89..deeb28f361e 100644
--- a/gdb/dwarf2/line-header.c
+++ b/gdb/dwarf2/line-header.c
@@ -26,58 +26,69 @@
 #include "filenames.h"
 
 void
-line_header::add_include_dir (const char *include_dir)
+line_header::add_include_dir (const char *include_dir, bool is_dwo)
 {
   if (dwarf_line_debug >= 2)
     {
       size_t new_size;
+      int include_dir_size = is_dwo ? m_dwo_include_dirs.size ():
+			     m_include_dirs.size ();
       if (version >= 5)
-	new_size = m_include_dirs.size ();
+	new_size = include_dir_size;
       else
-	new_size = m_include_dirs.size () + 1;
+	new_size = include_dir_size + 1;
       fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
 			  new_size, include_dir);
     }
-  m_include_dirs.push_back (include_dir);
+
+    if (is_dwo)
+      m_dwo_include_dirs.push_back (include_dir);
+    else
+      m_include_dirs.push_back (include_dir);
 }
 
 void
 line_header::add_file_name (const char *name,
 			    dir_index d_index,
 			    unsigned int mod_time,
-			    unsigned int length)
+			    unsigned int length,
+			    bool is_dwo)
 {
   if (dwarf_line_debug >= 2)
     {
       size_t new_size;
+      bool file_name_size = is_dwo ? dwo_file_names_size ():
+			     file_names_size ();
       if (version >= 5)
-	new_size = file_names_size ();
+	new_size = file_name_size;
       else
-	new_size = file_names_size () + 1;
+	new_size = file_name_size + 1;
       fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n",
 			  new_size, name);
     }
-  m_file_names.emplace_back (name, d_index, mod_time, length);
+
+    if (is_dwo)
+      m_dwo_file_names.emplace_back (name, d_index, mod_time, length);
+    else
+      m_file_names.emplace_back (name, d_index, mod_time, length);
 }
 
 gdb::unique_xmalloc_ptr<char>
 line_header::file_file_name (int file) const
 {
   /* Is the file number a valid index into the line header's file name
-     table?  Remember that file numbers start with one, not zero.  */
-  if (is_valid_file_index (file))
+     table?  First check in the .debug_line.dwo file table and then in
+     .debug_line table. Remember that file numbers start with one in
+     DWARFv4 and with zero in DWARFv5.  */
+  if (is_valid_dwo_file_index (file))
     {
-      const file_entry *fe = file_name_at (file);
-
-      if (!IS_ABSOLUTE_PATH (fe->name))
-	{
-	  const char *dir = fe->include_dir (this);
-	  if (dir != NULL)
-	    return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
-							  fe->name,
-							  (char *) NULL));
-	}
-      return make_unique_xstrdup (fe->name);
+      const file_entry *fe = file_name_at (file, true);
+      return make_unique_xstrdup (fe->symtab->filename);
+    }
+  else if (is_valid_file_index (file))
+    {
+      const file_entry *fe = file_name_at (file, false);
+      return make_unique_xstrdup (fe->symtab->filename);
     }
   else
     {
@@ -137,12 +148,13 @@ read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
 static void
 read_formatted_entries (dwarf2_per_objfile *per_objfile, bfd *abfd,
 			const gdb_byte **bufp, struct line_header *lh,
-			const struct comp_unit_head *cu_header,
+			const struct comp_unit_head *cu_header, bool is_dwo,
 			void (*callback) (struct line_header *lh,
 					  const char *name,
 					  dir_index d_index,
 					  unsigned int mod_time,
-					  unsigned int length))
+					  unsigned int length,
+					  bool is_dwo_file))
 {
   gdb_byte format_count, formati;
   ULONGEST data_count, datai;
@@ -254,7 +266,7 @@ read_formatted_entries (dwarf2_per_objfile *per_objfile, bfd *abfd,
 	    }
 	}
 
-      callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length);
+      callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length, is_dwo);
     }
 
   *bufp = buf;
@@ -262,11 +274,12 @@ read_formatted_entries (dwarf2_per_objfile *per_objfile, bfd *abfd,
 
 /* See line-header.h.  */
 
-line_header_up
+void
 dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
 			   dwarf2_per_objfile *per_objfile,
 			   struct dwarf2_section_info *section,
-			   const struct comp_unit_head *cu_header)
+			   const struct comp_unit_head *cu_header,
+			   line_header_up& lh, bool is_dwo)
 {
   const gdb_byte *line_ptr;
   unsigned int bytes_read, offset_size;
@@ -280,38 +293,47 @@ dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
   if (to_underlying (sect_off) + 4 >= section->size)
     {
       dwarf2_statement_list_fits_in_line_number_section_complaint ();
-      return 0;
+      return;
     }
 
-  line_header_up lh (new line_header ());
-
   lh->sect_off = sect_off;
   lh->offset_in_dwz = is_dwz;
 
   line_ptr = section->buffer + to_underlying (sect_off);
 
   /* Read in the header.  */
-  lh->total_length =
+  unsigned int total_length = 0;
+  total_length =
     read_checked_initial_length_and_offset (abfd, line_ptr, cu_header,
-					    &bytes_read, &offset_size);
-  line_ptr += bytes_read;
+                                            &bytes_read, &offset_size);
+  if (is_dwo)
+    lh->dwo_total_length = total_length;
+  else
+    lh->total_length = total_length;
 
-  const gdb_byte *start_here = line_ptr;
+  line_ptr += bytes_read;
 
-  if (line_ptr + lh->total_length > (section->buffer + section->size))
+  if (line_ptr + total_length > (section->buffer + section->size))
     {
       dwarf2_statement_list_fits_in_line_number_section_complaint ();
-      return 0;
+      return;
     }
-  lh->statement_program_end = start_here + lh->total_length;
+
+   if (!is_dwo)
+   {
+     const gdb_byte *start_here = line_ptr;
+     lh->statement_program_end = start_here + lh->total_length;
+   }
+
   lh->version = read_2_bytes (abfd, line_ptr);
   line_ptr += 2;
+
   if (lh->version > 5)
     {
       /* This is a version we don't understand.  The format could have
 	 changed in ways we don't handle properly so just punt.  */
       complaint (_("unsupported version in .debug_line section"));
-      return NULL;
+      return;
     }
   if (lh->version >= 5)
     {
@@ -328,12 +350,22 @@ dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
 	  complaint (_("unsupported segment selector size %u "
 		       "in .debug_line section"),
 		     segment_selector_size);
-	  return NULL;
+	  return;
 	}
     }
-  lh->header_length = read_offset (abfd, line_ptr, offset_size);
+
+  unsigned int header_length = 0;
+  header_length = read_offset (abfd, line_ptr, offset_size);
   line_ptr += offset_size;
-  lh->statement_program_start = line_ptr + lh->header_length;
+
+  if (is_dwo)
+    lh->dwo_header_length = header_length;
+  else
+    lh->header_length = header_length;
+
+   if (!is_dwo)
+     lh->statement_program_start = line_ptr + lh->header_length;
+
   lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
   line_ptr += 1;
   if (lh->version >= 4)
@@ -357,46 +389,65 @@ dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
   line_ptr += 1;
   lh->line_range = read_1_byte (abfd, line_ptr);
   line_ptr += 1;
-  lh->opcode_base = read_1_byte (abfd, line_ptr);
+
+  unsigned char opcode_base;
+  opcode_base = read_1_byte (abfd, line_ptr);
   line_ptr += 1;
-  lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]);
 
-  lh->standard_opcode_lengths[0] = 1;  /* This should never be used anyway.  */
-  for (i = 1; i < lh->opcode_base; ++i)
+  if (is_dwo)
+  {
+    lh->dwo_opcode_base = opcode_base;
+    lh->dwo_standard_opcode_lengths.reset (new unsigned char[lh->dwo_opcode_base]);
+
+    lh->dwo_standard_opcode_lengths[0] = 1;  /* This should never be used anyway.  */
+    for (i = 1; i < lh->dwo_opcode_base; ++i)
+    {
+      lh->dwo_standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
+      line_ptr += 1;
+    }
+  }
+  else
+  {
+    lh->opcode_base = opcode_base;
+    lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]);
+
+    lh->standard_opcode_lengths[0] = 1;  /* This should never be used anyway.  */
+    for (i = 1; i < lh->opcode_base; ++i)
     {
       lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
       line_ptr += 1;
     }
+   }
 
   if (lh->version >= 5)
     {
       /* Read directory table.  */
       read_formatted_entries (per_objfile, abfd, &line_ptr, lh.get (),
-			      cu_header,
+			      cu_header, is_dwo,
 			      [] (struct line_header *header, const char *name,
 				  dir_index d_index, unsigned int mod_time,
-				  unsigned int length)
+				  unsigned int length, bool is_dwo_section)
 	{
-	  header->add_include_dir (name);
+	  header->add_include_dir (name, is_dwo_section);
 	});
 
       /* Read file name table.  */
       read_formatted_entries (per_objfile, abfd, &line_ptr, lh.get (),
-			      cu_header,
+			      cu_header, is_dwo,
 			      [] (struct line_header *header, const char *name,
 				  dir_index d_index, unsigned int mod_time,
-				  unsigned int length)
+				  unsigned int length, bool is_dwo_section)
 	{
-	  header->add_file_name (name, d_index, mod_time, length);
+	  header->add_file_name (name, d_index, mod_time, length, is_dwo_section);
 	});
     }
   else
     {
       /* Read directory table.  */
       while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
-	{
+        {
 	  line_ptr += bytes_read;
-	  lh->add_include_dir (cur_dir);
+	  lh->add_include_dir (cur_dir, is_dwo);
 	}
       line_ptr += bytes_read;
 
@@ -414,7 +465,7 @@ dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
 	  length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
 	  line_ptr += bytes_read;
 
-	  lh->add_file_name (cur_file, d_index, mod_time, length);
+	  lh->add_file_name (cur_file, d_index, mod_time, length, is_dwo);
 	}
       line_ptr += bytes_read;
     }
@@ -422,6 +473,4 @@ dwarf_decode_line_header  (sect_offset sect_off, bool is_dwz,
   if (line_ptr > (section->buffer + section->size))
     complaint (_("line number info header doesn't "
 		 "fit in `.debug_line' section"));
-
-  return lh;
 }
diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h
index 4cacb8ca344..ee586e8b65d 100644
--- a/gdb/dwarf2/line-header.h
+++ b/gdb/dwarf2/line-header.h
@@ -44,9 +44,12 @@ struct file_entry
       length (length_)
   {}
 
-  /* Return the include directory at D_INDEX stored in LH.  Returns
-     NULL if D_INDEX is out of bounds.  */
-  const char *include_dir (const line_header *lh) const;
+  /* Return the include directory at D_INDEX stored in m_include_dirs vector
+     in LH or in m_dwo_include_dirs vector in LH if IS_DWO is true. m_dwo_
+     include_dirs contains the include_directories entries of .debug_line.dwo
+     section whereas m_include_dirs contains the include_directories array
+     entries of .debug_line section. Returns NULL if D_INDEX is out of bounds.  */
+  const char *include_dir (const line_header *lh, bool is_dwo) const;
 
   /* The file name.  Note this is an observing pointer.  The memory is
      owned by debug_line_buffer.  */
@@ -75,25 +78,33 @@ struct line_header
     : offset_in_dwz {}
   {}
 
-  /* Add an entry to the include directory table.  */
-  void add_include_dir (const char *include_dir);
+  /* Add an entry to the m_include_dirs vector or to m_dwo_include_dirs vector
+     if IS_DWO is true.  */
+  void add_include_dir (const char *include_dir, bool is_dwo);
 
-  /* Add an entry to the file name table.  */
+  /* Add an entry to the m_file_names vector or to the m_dwo_file_names vector
+     if IS_DWO is true. m_dwo_file_names vector contains the file_names entries of
+     .debug_line.dwo section whereas m_file_names contains the file_names array
+     entries of .debug_line section.  */
   void add_file_name (const char *name, dir_index d_index,
-		      unsigned int mod_time, unsigned int length);
+		      unsigned int mod_time, unsigned int length, bool is_dwo);
 
-  /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
+  /* Return the include dir from m_include_dirs or from the m_dwo_include_dirs
+     if IS_DWO is true at INDEX (0-based in DWARF 5 and 1-based before).
      Returns NULL if INDEX is out of bounds.  */
-  const char *include_dir_at (dir_index index) const
+  const char *include_dir_at (dir_index index, bool is_dwo) const
   {
     int vec_index;
     if (version >= 5)
       vec_index = index;
     else
       vec_index = index - 1;
-    if (vec_index < 0 || vec_index >= m_include_dirs.size ())
+    int include_dirs_size = is_dwo ? m_dwo_include_dirs.size () :
+			    m_include_dirs.size ();
+    if (vec_index < 0 || vec_index >= include_dirs_size)
       return NULL;
-    return m_include_dirs[vec_index];
+    return is_dwo ? m_dwo_include_dirs[vec_index] :
+		    m_include_dirs[vec_index];
   }
 
   bool is_valid_file_index (int file_index) const
@@ -103,25 +114,36 @@ struct line_header
     return 1 <= file_index && file_index <= file_names_size ();
   }
 
-  /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
+  bool is_valid_dwo_file_index (int file_index) const
+  {
+    if (version >= 5)
+      return 0 <= file_index && file_index < dwo_file_names_size ();
+    return 1 <= file_index && file_index <= dwo_file_names_size ();
+
+  }
+
+  /* Return the file name from m_file_names or from m_dwo_file_names vector
+     if IS_DWO is true at INDEX (0-based in DWARF 5 and 1-based before).
      Returns NULL if INDEX is out of bounds.  */
-  file_entry *file_name_at (file_name_index index)
+  file_entry *file_name_at (file_name_index index, bool is_dwo)
   {
     int vec_index;
     if (version >= 5)
       vec_index = index;
     else
       vec_index = index - 1;
-    if (vec_index < 0 || vec_index >= m_file_names.size ())
+    int file_names_size = is_dwo ? m_dwo_file_names.size ():
+			  m_file_names.size ();
+    if (vec_index < 0 || vec_index >= file_names_size)
       return NULL;
-    return &m_file_names[vec_index];
+    return is_dwo ? &m_dwo_file_names[vec_index] : &m_file_names[vec_index];
   }
 
   /* A const overload of the same.  */
-  const file_entry *file_name_at (file_name_index index) const
+  const file_entry *file_name_at (file_name_index index, bool is_dwo) const
   {
     line_header *lh = const_cast<line_header *> (this);
-    return lh->file_name_at (index);
+    return lh->file_name_at (index, is_dwo);
   }
 
   /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
@@ -133,6 +155,12 @@ struct line_header
   const std::vector<file_entry> &file_names () const
   { return m_file_names; }
 
+  std::vector<file_entry> &dwo_file_names ()
+  { return m_dwo_file_names; }
+  /* A const overload of the same.  */
+  const std::vector<file_entry> &dwo_file_names () const
+  { return m_dwo_file_names; }
+
   /* Offset of line number information in .debug_line section.  */
   sect_offset sect_off {};
 
@@ -140,14 +168,17 @@ struct line_header
   unsigned offset_in_dwz : 1; /* Can't initialize bitfields in-class.  */
 
   unsigned int total_length {};
+  unsigned int dwo_total_length {};
   unsigned short version {};
   unsigned int header_length {};
+  unsigned int dwo_header_length {};
   unsigned char minimum_instruction_length {};
   unsigned char maximum_ops_per_instruction {};
   unsigned char default_is_stmt {};
   int line_base {};
   unsigned char line_range {};
   unsigned char opcode_base {};
+  unsigned char dwo_opcode_base {};
 
   /* standard_opcode_lengths[i] is the number of operands for the
      standard opcode whose value is i.  This means that
@@ -155,9 +186,18 @@ struct line_header
      element is standard_opcode_lengths[opcode_base - 1].  */
   std::unique_ptr<unsigned char[]> standard_opcode_lengths;
 
+  /* dwo_standard_opcode_lengths[i] is the number of operands for the
+     standard opcode whose value is i.  This means that
+     dwo_standard_opcode_lengths[0] is unused, and the last meaningful
+     element is dwo_standard_opcode_lengths[dwo_opcode_base - 1].  */
+  std::unique_ptr<unsigned char[]> dwo_standard_opcode_lengths;
+
   int file_names_size () const
   { return m_file_names.size(); }
 
+  int dwo_file_names_size () const
+  { return m_dwo_file_names.size (); }
+
   /* The start and end of the statement program following this
      header.  These point into dwarf2_per_objfile->line_buffer.  */
   const gdb_byte *statement_program_start {}, *statement_program_end {};
@@ -173,19 +213,25 @@ struct line_header
      pointers.  The memory is owned by debug_line_buffer.  */
   std::vector<const char *> m_include_dirs;
 
+  /* The include_directories table from .debug_line.dwo section.  */
+  std::vector<const char *> m_dwo_include_dirs;
+
   /* The file_names table. This is private because the meaning of indexes
      differs among DWARF versions (The first valid index is 1 in DWARF 4 and
      before, and is 0 in DWARF 5 and later).  So the client should use
      file_name_at method for access.  */
   std::vector<file_entry> m_file_names;
+
+  /* The file_names table from .debug_line.dwo section.  */
+  std::vector<file_entry> m_dwo_file_names;
 };
 
 typedef std::unique_ptr<line_header> line_header_up;
 
 inline const char *
-file_entry::include_dir (const line_header *lh) const
+file_entry::include_dir (const line_header *lh, bool is_dwo) const
 {
-  return lh->include_dir_at (d_index);
+  return lh->include_dir_at (d_index, is_dwo);
 }
 
 /* Read the statement program header starting at SECT_OFF in SECTION.
@@ -196,8 +242,9 @@ file_entry::include_dir (const line_header *lh) const
    the returned object point into the dwarf line section buffer,
    and must not be freed.  */
 
-extern line_header_up dwarf_decode_line_header
+extern void dwarf_decode_line_header
   (sect_offset sect_off, bool is_dwz, dwarf2_per_objfile *per_objfile,
-   struct dwarf2_section_info *section, const struct comp_unit_head *cu_header);
+   struct dwarf2_section_info *section, const struct comp_unit_head *cu_header,
+   line_header_up& lh, bool is_dwo);
 
 #endif /* DWARF2_LINE_HEADER_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4a963e4a236..6ee64615eab 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1560,7 +1560,7 @@ static const char *compute_include_file_name
      (const struct line_header *lh,
       const file_entry &fe,
       const file_and_directory &cu_info,
-      gdb::unique_xmalloc_ptr<char> *name_holder);
+      gdb::unique_xmalloc_ptr<char> *name_holder, bool is_dwo);
 
 static htab_up allocate_signatured_type_table ();
 
@@ -3043,7 +3043,19 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
 	{
 	  gdb::unique_xmalloc_ptr<char> name_holder;
 	  const char *include_name =
-	    compute_include_file_name (lh.get (), entry, fnd, &name_holder);
+	    compute_include_file_name (lh.get (), entry, fnd, &name_holder, false);
+	  if (include_name != nullptr)
+	    {
+	      include_name = per_objfile->objfile->intern (include_name);
+	      include_names.push_back (include_name);
+	    }
+	}
+
+      for (const auto &entry : lh->dwo_file_names ())
+	{
+	  gdb::unique_xmalloc_ptr<char> name_holder;
+	  const char *include_name =
+	    compute_include_file_name (lh.get (), entry, fnd, &name_holder, false);
 	  if (include_name != nullptr)
 	    {
 	      include_name = per_objfile->objfile->intern (include_name);
@@ -10774,7 +10786,7 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
 	{
 	  file_entry &fe = file_names[i];
 	  dwarf2_start_subfile (this, fe.name,
-				fe.include_dir (line_header));
+				fe.include_dir (line_header, false));
 	  buildsym_compunit *b = get_builder ();
 	  if (b->get_current_subfile ()->symtab == NULL)
 	    {
@@ -20704,7 +20716,7 @@ get_debug_line_section (struct dwarf2_cu *cu)
 }
 
 /* Read the statement program header starting at OFFSET in
-   .debug_line, or .debug_line.dwo.  Return a pointer
+   .debug_line and .debug_line.dwo.  Return a pointer
    to a struct line_header, allocated using xmalloc.
    Returns NULL if there is a problem reading the header, e.g., if it
    has a version we don't understand.
@@ -20717,21 +20729,42 @@ static line_header_up
 dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
 {
   struct dwarf2_section_info *section;
+  struct dwarf2_section_info *dwo_section = NULL;
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
   section = get_debug_line_section (cu);
   section->read (per_objfile->objfile);
+
   if (section->buffer == NULL)
+  {
+    if (cu->dwo_unit && cu->per_cu->is_debug_types)
+      complaint (_("missing .debug_line.dwo section"));
+    else
+      complaint (_("missing .debug_line section"));
+    return 0;
+  }
+
+  if (cu->dwo_unit && !cu->per_cu->is_debug_types)
     {
-      if (cu->dwo_unit && cu->per_cu->is_debug_types)
-	complaint (_("missing .debug_line.dwo section"));
-      else
-	complaint (_("missing .debug_line section"));
-      return 0;
+      dwo_section = &cu->dwo_unit->dwo_file->sections.line;
+      dwo_section->read (per_objfile->objfile);
+
+      if (dwo_section->buffer == NULL)
+	{
+	  complaint (_("missing .debug_line.dwo section"));
+	}
     }
 
-  return dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz,
-				   per_objfile, section, &cu->header);
+  line_header_up lh (new line_header ());
+
+  dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz,
+			    per_objfile, section,
+			    &cu->header, lh, false);
+  if (cu->dwo_unit)
+    dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz,
+			      per_objfile, dwo_section,
+			      &cu->header, lh, true);
+  return lh;
 }
 
 /* Subroutine of dwarf_decode_lines to simplify it.
@@ -20744,12 +20777,20 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
 static const char *
 compute_include_file_name (const struct line_header *lh, const file_entry &fe,
 			   const file_and_directory &cu_info,
-			   gdb::unique_xmalloc_ptr<char> *name_holder)
+			   gdb::unique_xmalloc_ptr<char> *name_holder, bool is_dwo)
 {
   const char *include_name = fe.name;
   const char *include_name_to_compare = include_name;
+  const char *dir_name;
 
-  const char *dir_name = fe.include_dir (lh);
+  if (is_dwo)
+    {
+      dir_name = fe.include_dir (lh, true);
+    }
+  else
+    {
+      dir_name = fe.include_dir (lh, false);
+    }
 
   gdb::unique_xmalloc_ptr<char> hold_compare;
   if (!IS_ABSOLUTE_PATH (include_name)
@@ -20819,7 +20860,7 @@ class lnp_state_machine
   {
     /* lh->file_names is 0-based, but the file name numbers in the
        statement program are 1-based.  */
-    return m_line_header->file_name_at (m_file);
+    return m_line_header->file_name_at (m_file, false);
   }
 
   /* Record the line in the state machine.  END_SEQUENCE is true if
@@ -20993,7 +21034,7 @@ lnp_state_machine::handle_set_file (file_name_index file)
     dwarf2_debug_line_missing_file_complaint ();
   else if (m_record_lines_p)
     {
-      const char *dir = fe->include_dir (m_line_header);
+      const char *dir = fe->include_dir (m_line_header, false);
 
       m_last_subfile = m_cu->get_builder ()->get_current_subfile ();
       m_line_has_non_zero_discriminator = m_discriminator != 0;
@@ -21285,7 +21326,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
 	  const file_entry *fe = state_machine.current_file ();
 
 	  if (fe != NULL)
-	    dwarf2_start_subfile (cu, fe->name, fe->include_dir (lh));
+	    dwarf2_start_subfile (cu, fe->name, fe->include_dir (lh, false));
 	}
 
       /* Decode the table.  */
@@ -21350,7 +21391,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
 		    length =
 		      read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
 		    line_ptr += bytes_read;
-		    lh->add_file_name (cur_file, dindex, mod_time, length);
+		    lh->add_file_name (cur_file, dindex, mod_time, length, false);
 		  }
 		  break;
 		case DW_LNE_set_discriminator:
@@ -21507,7 +21548,20 @@ dwarf_decode_lines (struct line_header *lh, const file_and_directory &fnd,
 	  {
 	    gdb::unique_xmalloc_ptr<char> name_holder;
 	    const char *include_name =
-	      compute_include_file_name (lh, file_entry, fnd, &name_holder);
+	      compute_include_file_name (lh, file_entry, fnd, &name_holder, false);
+	    if (include_name != NULL)
+	      dwarf2_create_include_psymtab
+		(cu->per_objfile->per_bfd, include_name, pst,
+		 cu->per_objfile->per_bfd->partial_symtabs.get (),
+		 objfile->per_bfd);
+	  }
+
+      for (auto &file_entry : lh->dwo_file_names ())
+	if (file_entry.included_p)
+	  {
+	    gdb::unique_xmalloc_ptr<char> name_holder;
+	    const char *include_name =
+	      compute_include_file_name (lh, file_entry, fnd, &name_holder, true);
 	    if (include_name != NULL)
 	      dwarf2_create_include_psymtab
 		(cu->per_objfile->per_bfd, include_name, pst,
@@ -21525,7 +21579,19 @@ dwarf_decode_lines (struct line_header *lh, const file_and_directory &fnd,
 
       for (auto &fe : lh->file_names ())
 	{
-	  dwarf2_start_subfile (cu, fe.name, fe.include_dir (lh));
+	  dwarf2_start_subfile (cu, fe.name, fe.include_dir (lh, false));
+	  if (builder->get_current_subfile ()->symtab == NULL)
+	    {
+	      builder->get_current_subfile ()->symtab
+		= allocate_symtab (cust,
+				   builder->get_current_subfile ()->name);
+	    }
+	  fe.symtab = builder->get_current_subfile ()->symtab;
+	}
+
+      for (auto &fe : lh->dwo_file_names ())
+	{
+	  dwarf2_start_subfile (cu, fe.name, fe.include_dir (lh, true));
 	  if (builder->get_current_subfile ()->symtab == NULL)
 	    {
 	      builder->get_current_subfile ()->symtab
@@ -21741,7 +21807,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 	  struct file_entry *fe;
 
 	  if (cu->line_header != NULL)
-	    fe = cu->line_header->file_name_at (file_index);
+	    fe = cu->line_header->file_name_at (file_index, (cu->dwo_unit != nullptr));
 	  else
 	    fe = NULL;
 
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index bf2d79d219f..0c2899d274f 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -238,7 +238,7 @@ compare_locations (struct macro_source_file *file1, int line1,
 
   /* If the two files are not the same, find their common ancestor in
      the #inclusion tree.  */
-  if (file1 != file2)
+  if (filename_cmp(file1->filename, file2->filename) != 0)
     {
       /* If one file is deeper than the other, walk up the #inclusion
 	 chain until the two files are at least at the same *depth*.
@@ -266,7 +266,7 @@ compare_locations (struct macro_source_file *file1, int line1,
 
       /* Now both file1 and file2 are at the same depth.  Walk toward
 	 the root of the tree until we find where the branches meet.  */
-      while (file1 != file2)
+      while (filename_cmp(file1->filename, file2->filename) != 0)
 	{
 	  line1 = file1->included_at_line;
 	  file1 = file1->included_by;
-- 
2.17.1


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

end of thread, other threads:[~2022-05-17  8:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-19  6:56 [PATCH] Fix for the gdb.base/macscp.exp testcase failure with split dwarf Achra, Nitika
2021-11-19 18:55 ` Keith Seitz
2022-03-14 14:32   ` Achra, Nitika
2022-03-18 20:15     ` Keith Seitz
2022-03-18 20:23       ` Keith Seitz
2022-05-17  5:40         ` Natarajan, Kavitha
2022-05-17  8:47           ` Natarajan, Kavitha

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