mkolar / rpms / gdb

Forked from rpms/gdb 3 years ago
Clone
Jan Kratochvil b37d386
http://sourceware.org/ml/gdb-patches/2011-09/msg00450.html
Jan Kratochvil b37d386
Subject: [patch 1/2] Code cleanup: Unify dwarf2_per_cu_addr_size, dwarf2_per_cu_offset_size
Jan Kratochvil b37d386
Jan Kratochvil b37d386
Hi,
Jan Kratochvil b37d386
Jan Kratochvil b37d386
this is more rather for patch 2/2, it has positive LoC change but still
Jan Kratochvil b37d386
I would find it applicable even on its own.
Jan Kratochvil b37d386
Jan Kratochvil b37d386
No functionality change intended.
Jan Kratochvil b37d386
Jan Kratochvil b37d386
Jan Kratochvil b37d386
Thanks,
Jan Kratochvil b37d386
Jan
Jan Kratochvil b37d386
Jan Kratochvil b37d386
Jan Kratochvil b37d386
gdb/
Jan Kratochvil b37d386
2011-09-26  Jan Kratochvil  <jan.kratochvil@redhat.com>
Jan Kratochvil b37d386
Jan Kratochvil b37d386
	Code cleanup.
Jan Kratochvil b37d386
	* dwarf2read.c (per_cu_header_read_in): New function.
Jan Kratochvil b37d386
	(dwarf2_per_cu_addr_size, dwarf2_per_cu_offset_size): Use it, with new
Jan Kratochvil b37d386
	variables cu_header_local and cu_headerp.
Jan Kratochvil b37d386
Jan Kratochvil b37d386
--- a/gdb/dwarf2read.c
Jan Kratochvil b37d386
+++ b/gdb/dwarf2read.c
Jan Kratochvil b37d386
@@ -15187,26 +15187,42 @@ dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
Jan Kratochvil b37d386
   return objfile;
Jan Kratochvil b37d386
 }
Jan Kratochvil b37d386
 
Jan Kratochvil b37d386
+/* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
Jan Kratochvil b37d386
+   (CU_HEADERP is unused in such case) or prepare a temporary copy at
Jan Kratochvil b37d386
+   CU_HEADERP first.  */
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
+static const struct comp_unit_head *
Jan Kratochvil b37d386
+per_cu_header_read_in (struct comp_unit_head *cu_headerp,
Jan Kratochvil b37d386
+		       struct dwarf2_per_cu_data *per_cu)
Jan Kratochvil b37d386
+{
Jan Kratochvil b37d386
+  struct objfile *objfile;
Jan Kratochvil b37d386
+  struct dwarf2_per_objfile *per_objfile;
Jan Kratochvil b37d386
+  gdb_byte *info_ptr;
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
+  if (per_cu->cu)
Jan Kratochvil b37d386
+    return &per_cu->cu->header;
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
+  objfile = per_cu->objfile;
Jan Kratochvil b37d386
+  per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
Jan Kratochvil b37d386
+  info_ptr = per_objfile->info.buffer + per_cu->offset;
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
+  memset (cu_headerp, 0, sizeof (*cu_headerp));
Jan Kratochvil b37d386
+  read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
+  return cu_headerp;
Jan Kratochvil b37d386
+}
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
 /* Return the address size given in the compilation unit header for CU.  */
Jan Kratochvil b37d386
 
Jan Kratochvil b37d386
 CORE_ADDR
Jan Kratochvil b37d386
 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
Jan Kratochvil b37d386
 {
Jan Kratochvil b37d386
-  if (per_cu->cu)
Jan Kratochvil b37d386
-    return per_cu->cu->header.addr_size;
Jan Kratochvil b37d386
-  else
Jan Kratochvil b37d386
-    {
Jan Kratochvil b37d386
-      /* If the CU is not currently read in, we re-read its header.  */
Jan Kratochvil b37d386
-      struct objfile *objfile = per_cu->objfile;
Jan Kratochvil b37d386
-      struct dwarf2_per_objfile *per_objfile
Jan Kratochvil b37d386
-	= objfile_data (objfile, dwarf2_objfile_data_key);
Jan Kratochvil b37d386
-      gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
Jan Kratochvil b37d386
-      struct comp_unit_head cu_header;
Jan Kratochvil b37d386
+  struct comp_unit_head cu_header_local;
Jan Kratochvil b37d386
+  const struct comp_unit_head *cu_headerp;
Jan Kratochvil b37d386
 
Jan Kratochvil b37d386
-      memset (&cu_header, 0, sizeof cu_header);
Jan Kratochvil b37d386
-      read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
Jan Kratochvil b37d386
-      return cu_header.addr_size;
Jan Kratochvil b37d386
-    }
Jan Kratochvil b37d386
+  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
+  return cu_headerp->addr_size;
Jan Kratochvil b37d386
 }
Jan Kratochvil b37d386
 
Jan Kratochvil b37d386
 /* Return the offset size given in the compilation unit header for CU.  */
Jan Kratochvil b37d386
@@ -15214,21 +15230,12 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
Jan Kratochvil b37d386
 int
Jan Kratochvil b37d386
 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
Jan Kratochvil b37d386
 {
Jan Kratochvil b37d386
-  if (per_cu->cu)
Jan Kratochvil b37d386
-    return per_cu->cu->header.offset_size;
Jan Kratochvil b37d386
-  else
Jan Kratochvil b37d386
-    {
Jan Kratochvil b37d386
-      /* If the CU is not currently read in, we re-read its header.  */
Jan Kratochvil b37d386
-      struct objfile *objfile = per_cu->objfile;
Jan Kratochvil b37d386
-      struct dwarf2_per_objfile *per_objfile
Jan Kratochvil b37d386
-	= objfile_data (objfile, dwarf2_objfile_data_key);
Jan Kratochvil b37d386
-      gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
Jan Kratochvil b37d386
-      struct comp_unit_head cu_header;
Jan Kratochvil b37d386
+  struct comp_unit_head cu_header_local;
Jan Kratochvil b37d386
+  const struct comp_unit_head *cu_headerp;
Jan Kratochvil b37d386
 
Jan Kratochvil b37d386
-      memset (&cu_header, 0, sizeof cu_header);
Jan Kratochvil b37d386
-      read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
Jan Kratochvil b37d386
-      return cu_header.offset_size;
Jan Kratochvil b37d386
-    }
Jan Kratochvil b37d386
+  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
Jan Kratochvil b37d386
+
Jan Kratochvil b37d386
+  return cu_headerp->offset_size;
Jan Kratochvil b37d386
 }
Jan Kratochvil b37d386
 
Jan Kratochvil b37d386
 /* Return the text offset of the CU.  The returned offset comes from
Jan Kratochvil b37d386