1 http://sourceware.org/ml/gdb-patches/2011-09/msg00450.html
2 Subject: [patch 1/2] Code cleanup: Unify dwarf2_per_cu_addr_size, dwarf2_per_cu_offset_size
6 this is more rather for patch 2/2, it has positive LoC change but still
7 I would find it applicable even on its own.
9 No functionality change intended.
17 2011-09-26 Jan Kratochvil <jan.kratochvil@redhat.com>
20 * dwarf2read.c (per_cu_header_read_in): New function.
21 (dwarf2_per_cu_addr_size, dwarf2_per_cu_offset_size): Use it, with new
22 variables cu_header_local and cu_headerp.
24 --- a/gdb/dwarf2read.c
25 +++ b/gdb/dwarf2read.c
26 @@ -15187,26 +15187,42 @@ dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
30 +/* Return comp_unit_head for PER_CU, either already available in PER_CU->CU
31 + (CU_HEADERP is unused in such case) or prepare a temporary copy at
32 + CU_HEADERP first. */
34 +static const struct comp_unit_head *
35 +per_cu_header_read_in (struct comp_unit_head *cu_headerp,
36 + struct dwarf2_per_cu_data *per_cu)
38 + struct objfile *objfile;
39 + struct dwarf2_per_objfile *per_objfile;
43 + return &per_cu->cu->header;
45 + objfile = per_cu->objfile;
46 + per_objfile = objfile_data (objfile, dwarf2_objfile_data_key);
47 + info_ptr = per_objfile->info.buffer + per_cu->offset;
49 + memset (cu_headerp, 0, sizeof (*cu_headerp));
50 + read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd);
55 /* Return the address size given in the compilation unit header for CU. */
58 dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
61 - return per_cu->cu->header.addr_size;
64 - /* If the CU is not currently read in, we re-read its header. */
65 - struct objfile *objfile = per_cu->objfile;
66 - struct dwarf2_per_objfile *per_objfile
67 - = objfile_data (objfile, dwarf2_objfile_data_key);
68 - gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
69 - struct comp_unit_head cu_header;
70 + struct comp_unit_head cu_header_local;
71 + const struct comp_unit_head *cu_headerp;
73 - memset (&cu_header, 0, sizeof cu_header);
74 - read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
75 - return cu_header.addr_size;
77 + cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
79 + return cu_headerp->addr_size;
82 /* Return the offset size given in the compilation unit header for CU. */
83 @@ -15214,21 +15230,12 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
85 dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
88 - return per_cu->cu->header.offset_size;
91 - /* If the CU is not currently read in, we re-read its header. */
92 - struct objfile *objfile = per_cu->objfile;
93 - struct dwarf2_per_objfile *per_objfile
94 - = objfile_data (objfile, dwarf2_objfile_data_key);
95 - gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset;
96 - struct comp_unit_head cu_header;
97 + struct comp_unit_head cu_header_local;
98 + const struct comp_unit_head *cu_headerp;
100 - memset (&cu_header, 0, sizeof cu_header);
101 - read_comp_unit_head (&cu_header, info_ptr, objfile->obfd);
102 - return cu_header.offset_size;
104 + cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
106 + return cu_headerp->offset_size;
109 /* Return the text offset of the CU. The returned offset comes from