1 --- rpm-4.5/tools/debugedit.c 2008-04-06 23:32:15.000000000 +0300
2 +++ trunk/tools/debugedit.c 2010-01-27 18:57:49.758813670 +0200
4 -/* Copyright (C) 2001, 2002, 2003, 2005, 2007 Red Hat, Inc.
5 +/* Copyright (C) 2001, 2002, 2003, 2005, 2007, 2009 Red Hat, Inc.
6 Written by Alexander Larsson <alexl@redhat.com>, 2002
7 Based on code by Jakub Jelinek <jakub@redhat.com>, 2001.
10 int list_file_fd = -1;
13 -typedef unsigned int uint_32;
14 -typedef unsigned short uint_16;
15 +typedef unsigned char rpmuint8_t;
16 +typedef unsigned int rpmuint32_t;
17 +typedef unsigned short rpmuint16_t;
29 #define read_uleb128(ptr) ({ \
34 -static uint_16 (*do_read_16) (unsigned char *ptr);
35 -static uint_32 (*do_read_32) (unsigned char *ptr);
36 +static rpmuint16_t (*do_read_16) (unsigned char *ptr);
37 +static rpmuint32_t (*do_read_32) (unsigned char *ptr);
38 static void (*write_32) (unsigned char *ptr, GElf_Addr val);
41 +static int cu_version;
43 -static inline uint_16
44 +static inline rpmuint16_t
45 buf_read_ule16 (unsigned char *data)
47 return data[0] | (data[1] << 8);
50 -static inline uint_16
51 +static inline rpmuint16_t
52 buf_read_ube16 (unsigned char *data)
54 return data[1] | (data[0] << 8);
57 -static inline uint_32
58 +static inline rpmuint32_t
59 buf_read_ule32 (unsigned char *data)
61 return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
64 -static inline uint_32
65 +static inline rpmuint32_t
66 buf_read_ube32 (unsigned char *data)
68 return data[3] | (data[2] << 8) | (data[1] << 16) | (data[0] << 24);
72 && offset >= data->d_off
73 - && offset < data->d_off + data->d_size)
74 + && offset < data->d_off + (off_t)data->d_size)
75 return (const char *) data->d_buf + (offset - data->d_off);
79 #define read_1(ptr) *ptr++
81 #define read_16(ptr) ({ \
82 - uint_16 ret = do_read_16 (ptr); \
83 + rpmuint16_t ret = do_read_16 (ptr); \
88 #define read_32(ptr) ({ \
89 - uint_32 ret = do_read_32 (ptr); \
90 + rpmuint32_t ret = do_read_32 (ptr); \
97 #define do_read_32_relocated(ptr) ({ \
98 - uint_32 dret = do_read_32 (ptr); \
99 + rpmuint32_t dret = do_read_32 (ptr); \
102 while (relptr < relend && relptr->ptr < ptr) \
106 #define read_32_relocated(ptr) ({ \
107 - uint_32 ret = do_read_32_relocated (ptr); \
108 + rpmuint32_t ret = do_read_32_relocated (ptr); \
114 dwarf2_write_le32 (unsigned char *p, GElf_Addr val)
116 - uint_32 v = (uint_32) val;
117 + rpmuint32_t v = (rpmuint32_t) val;
123 dwarf2_write_be32 (unsigned char *p, GElf_Addr val)
125 - uint_32 v = (uint_32) val;
126 + rpmuint32_t v = (rpmuint32_t) val;
130 @@ -242,16 +240,18 @@
132 #define DEBUG_ARANGES 3
133 #define DEBUG_PUBNAMES 4
134 -#define DEBUG_MACINFO 5
137 -#define DEBUG_FRAME 8
138 -#define DEBUG_RANGES 9
139 +#define DEBUG_PUBTYPES 5
140 +#define DEBUG_MACINFO 6
143 +#define DEBUG_FRAME 9
144 +#define DEBUG_RANGES 10
145 { ".debug_info", NULL, NULL, 0, 0, 0 },
146 { ".debug_abbrev", NULL, NULL, 0, 0, 0 },
147 { ".debug_line", NULL, NULL, 0, 0, 0 },
148 { ".debug_aranges", NULL, NULL, 0, 0, 0 },
149 { ".debug_pubnames", NULL, NULL, 0, 0, 0 },
150 + { ".debug_pubtypes", NULL, NULL, 0, 0, 0 },
151 { ".debug_macinfo", NULL, NULL, 0, 0, 0 },
152 { ".debug_loc", NULL, NULL, 0, 0, 0 },
153 { ".debug_str", NULL, NULL, 0, 0, 0 },
158 - error (0, 0, "%s: Duplicate DWARF-2 abbreviation %d", dso->filename,
159 + error (0, 0, "%s: Duplicate DWARF abbreviation %d", dso->filename,
164 form = read_uleb128 (ptr);
165 if (form == 2 || form > DW_FORM_indirect)
167 - error (0, 0, "%s: Unknown DWARF-2 DW_FORM_%d", dso->filename, form);
168 + error (0, 0, "%s: Unknown DWARF DW_FORM_%d", dso->filename, form);
174 if (read_uleb128 (ptr) != 0)
176 - error (0, 0, "%s: DWARF-2 abbreviation does not end with 2 zeros",
177 + error (0, 0, "%s: DWARF abbreviation does not end with 2 zeros",
182 has_prefix (const char *str,
190 str_len = strlen (str);
191 prefix_len = strlen (prefix);
192 @@ -481,14 +481,14 @@
196 -edit_dwarf2_line (DSO *dso, uint_32 off, char *comp_dir, int phase)
197 +edit_dwarf2_line (DSO *dso, rpmuint32_t off, char *comp_dir, int phase)
199 unsigned char *ptr = debug_sections[DEBUG_LINE].data, *dir;
200 unsigned char **dirt;
201 unsigned char *endsec = ptr + debug_sections[DEBUG_LINE].size;
202 unsigned char *endcu, *endprol;
203 unsigned char opcode_base;
204 - uint_32 value, dirt_cnt;
205 + rpmuint32_t value, dirt_cnt;
206 size_t comp_dir_len = strlen (comp_dir);
207 size_t abs_file_cnt = 0, abs_dir_cnt = 0;
212 value = read_16 (ptr);
214 + if (value != 2 && value != 3)
216 error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
220 error (EXIT_FAILURE, 0,
221 "canonicalization unexpectedly shrank by one character");
222 - memset (ptr, 'X', shrank);
227 + memset (ptr, 'X', shrank);
233 if (abs_dir_cnt + abs_file_cnt != 0)
235 edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
239 + rpmuint32_t list_offs;
245 for (i = 0; i < t->nattr; ++i)
247 - uint_32 form = t->attr[i].form;
249 - int base_len, dest_len;
250 + rpmuint32_t form = t->attr[i].form;
252 + size_t base_len, dest_len;
260 - dir = (char *)debug_sections[DEBUG_STR].data
261 + dir = (char *) debug_sections[DEBUG_STR].data
262 + do_read_32_relocated (ptr);
269 - name = (char *)debug_sections[DEBUG_STR].data
270 + name = (char *) debug_sections[DEBUG_STR].data
271 + do_read_32_relocated (ptr);
272 if (*name == '/' && comp_dir == NULL)
278 - case DW_FORM_ref_addr: /* ptr_size in DWARF 2, offset in DWARF 3 */
279 + case DW_FORM_ref_addr:
280 + if (cu_version == 2)
289 assert (len < UINT_MAX);
292 - error (0, 0, "%s: Unknown DWARF-2 DW_FORM_%d", dso->filename,
293 + error (0, 0, "%s: Unknown DWARF DW_FORM_%d", dso->filename,
302 + /* Ensure the CU current directory will exist even if only empty. Source
303 + filenames possibly located in its parent directories refer relatively to
304 + it and the debugger (GDB) cannot safely optimize out the missing
305 + CU current dir subdirectories. */
306 + if (comp_dir && list_file_fd != -1)
311 + if (base_dir && has_prefix (comp_dir, base_dir))
312 + p = comp_dir + strlen (base_dir);
313 + else if (dest_dir && has_prefix (comp_dir, dest_dir))
314 + p = comp_dir + strlen (dest_dir);
318 + size = strlen (p) + 1;
321 + ssize_t ret = write (list_file_fd, p, size);
329 if (found_list_offs && comp_dir)
330 edit_dwarf2_line (dso, list_offs, comp_dir, phase);
332 @@ -1034,7 +1070,7 @@
333 if (debug_sections[DEBUG_INFO].data != NULL)
335 unsigned char *ptr, *endcu, *endsec;
339 struct abbrev_tag tag, *t;
341 @@ -1176,11 +1212,11 @@
345 - value = read_16 (ptr);
347 + cu_version = read_16 (ptr);
348 + if (cu_version != 2 && cu_version != 3)
350 error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
356 @@ -1190,7 +1226,7 @@
357 if (debug_sections[DEBUG_ABBREV].data == NULL)
358 error (0, 0, "%s: .debug_abbrev not present", dso->filename);
360 - error (0, 0, "%s: DWARF-2 CU abbrev offset too large",
361 + error (0, 0, "%s: DWARF CU abbrev offset too large",
365 @@ -1200,14 +1236,14 @@
366 ptr_size = read_1 (ptr);
367 if (ptr_size != 4 && ptr_size != 8)
369 - error (0, 0, "%s: Invalid DWARF-2 pointer size %d",
370 + error (0, 0, "%s: Invalid DWARF pointer size %d",
371 dso->filename, ptr_size);
375 else if (read_1 (ptr) != ptr_size)
377 - error (0, 0, "%s: DWARF-2 pointer size differs between CUs",
378 + error (0, 0, "%s: DWARF pointer size differs between CUs",
382 @@ -1225,7 +1261,7 @@
383 t = htab_find_with_hash (abbrev, &tag, tag.entry);
386 - error (0, 0, "%s: Could not find DWARF-2 abbreviation %d",
387 + error (0, 0, "%s: Could not find DWARF abbreviation %d",
388 dso->filename, tag.entry);
389 htab_delete (abbrev);
391 @@ -1374,12 +1410,12 @@
392 or Elf64 object, only that we are consistent in what bits feed the
393 hash so it comes out the same for the same file contents. */
395 - inline void process (const void *data, size_t size)
396 + auto inline void process (const void *data, size_t size);
397 + auto inline void process (const void *data, size_t size)
399 memchunk chunk = { .data = (void *) data, .size = size };
400 hashFunctionContextUpdateMC (&ctx, &chunk);
406 @@ -1439,11 +1475,11 @@
408 /* Now format the build ID bits in hex to print out. */
410 - const unsigned char * id = (unsigned char *) build_id->d_buf + build_id_offset;
411 + const rpmuint8_t * id = (rpmuint8_t *)build_id->d_buf + build_id_offset;
412 char hex[build_id_size * 2 + 1];
413 int n = snprintf (hex, 3, "%02" PRIx8, id[0]);
415 - for (i = 1; i < build_id_size; ++i)
416 + for (i = 1; i < (int)build_id_size; ++i)
418 n = snprintf (&hex[i * 2], 3, "%02" PRIx8, id[i]);
420 @@ -1466,8 +1502,7 @@
421 Elf_Data *build_id = NULL;
422 size_t build_id_offset = 0, build_id_size = 0;
424 - optCon = poptGetContext("debugedit", argc, (const char **)argv,
426 + optCon = poptGetContext("debugedit", argc, (const char **)argv, optionsTable, 0);
428 while ((nextopt = poptGetNextOpt (optCon)) > 0 || nextopt == POPT_ERROR_BADOPT)
430 @@ -1585,7 +1620,8 @@
432 src.d_buf = data->d_buf;
433 assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
434 - while ((char *) data->d_buf + data->d_size - (char *) src.d_buf > (int) sizeof nh
435 + while ((char *) data->d_buf + data->d_size -
436 + (char *) src.d_buf > (int) sizeof nh
437 && elf32_xlatetom (&dst, &src, dso->ehdr.e_ident[EI_DATA]))
439 Elf32_Word len = sizeof nh + nh.n_namesz;
440 @@ -1595,7 +1631,8 @@
441 && !memcmp ((char *) src.d_buf + sizeof nh, "GNU", sizeof "GNU"))
444 - build_id_offset = (char *) src.d_buf + len - (char *) data->d_buf;
445 + build_id_offset = (char *) src.d_buf + len -
446 + (char *) data->d_buf;
447 build_id_size = nh.n_descsz;