1 --- trunk/tools/debugedit.c 2010-01-27 18:57:49.758813670 +0200
2 +++ rpm-4.5/tools/debugedit.c 2008-04-06 23:32:15.000000000 +0300
4 -/* Copyright (C) 2001, 2002, 2003, 2005, 2007, 2009 Red Hat, Inc.
5 +/* Copyright (C) 2001, 2002, 2003, 2005, 2007 Red Hat, Inc.
6 Written by Alexander Larsson <alexl@redhat.com>, 2002
7 Based on code by Jakub Jelinek <jakub@redhat.com>, 2001.
10 #define DW_FORM_indirect 0x16
12 #include <beecrypt/beecrypt.h>
17 #define DW_TAG_partial_unit 0x3c
20 int list_file_fd = -1;
23 +typedef unsigned int uint_32;
24 +typedef unsigned short uint_16;
37 #define read_uleb128(ptr) ({ \
42 -static rpmuint16_t (*do_read_16) (unsigned char *ptr);
43 -static rpmuint32_t (*do_read_32) (unsigned char *ptr);
44 +static uint_16 (*do_read_16) (unsigned char *ptr);
45 +static uint_32 (*do_read_32) (unsigned char *ptr);
46 static void (*write_32) (unsigned char *ptr, GElf_Addr val);
49 -static int cu_version;
51 -static inline rpmuint16_t
52 +static inline uint_16
53 buf_read_ule16 (unsigned char *data)
55 return data[0] | (data[1] << 8);
58 -static inline rpmuint16_t
59 +static inline uint_16
60 buf_read_ube16 (unsigned char *data)
62 return data[1] | (data[0] << 8);
65 -static inline rpmuint32_t
66 +static inline uint_32
67 buf_read_ule32 (unsigned char *data)
69 return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
72 -static inline rpmuint32_t
73 +static inline uint_32
74 buf_read_ube32 (unsigned char *data)
76 return data[3] | (data[2] << 8) | (data[1] << 16) | (data[0] << 24);
80 && offset >= data->d_off
81 - && offset < data->d_off + (off_t)data->d_size)
82 + && offset < data->d_off + data->d_size)
83 return (const char *) data->d_buf + (offset - data->d_off);
87 #define read_1(ptr) *ptr++
89 #define read_16(ptr) ({ \
90 - rpmuint16_t ret = do_read_16 (ptr); \
91 + uint_16 ret = do_read_16 (ptr); \
96 #define read_32(ptr) ({ \
97 - rpmuint32_t ret = do_read_32 (ptr); \
98 + uint_32 ret = do_read_32 (ptr); \
105 #define do_read_32_relocated(ptr) ({ \
106 - rpmuint32_t dret = do_read_32 (ptr); \
107 + uint_32 dret = do_read_32 (ptr); \
110 while (relptr < relend && relptr->ptr < ptr) \
114 #define read_32_relocated(ptr) ({ \
115 - rpmuint32_t ret = do_read_32_relocated (ptr); \
116 + uint_32 ret = do_read_32_relocated (ptr); \
122 dwarf2_write_le32 (unsigned char *p, GElf_Addr val)
124 - rpmuint32_t v = (rpmuint32_t) val;
125 + uint_32 v = (uint_32) val;
131 dwarf2_write_be32 (unsigned char *p, GElf_Addr val)
133 - rpmuint32_t v = (rpmuint32_t) val;
134 + uint_32 v = (uint_32) val;
138 @@ -240,18 +242,16 @@
140 #define DEBUG_ARANGES 3
141 #define DEBUG_PUBNAMES 4
142 -#define DEBUG_PUBTYPES 5
143 -#define DEBUG_MACINFO 6
146 -#define DEBUG_FRAME 9
147 -#define DEBUG_RANGES 10
148 +#define DEBUG_MACINFO 5
151 +#define DEBUG_FRAME 8
152 +#define DEBUG_RANGES 9
153 { ".debug_info", NULL, NULL, 0, 0, 0 },
154 { ".debug_abbrev", NULL, NULL, 0, 0, 0 },
155 { ".debug_line", NULL, NULL, 0, 0, 0 },
156 { ".debug_aranges", NULL, NULL, 0, 0, 0 },
157 { ".debug_pubnames", NULL, NULL, 0, 0, 0 },
158 - { ".debug_pubtypes", NULL, NULL, 0, 0, 0 },
159 { ".debug_macinfo", NULL, NULL, 0, 0, 0 },
160 { ".debug_loc", NULL, NULL, 0, 0, 0 },
161 { ".debug_str", NULL, NULL, 0, 0, 0 },
166 - error (0, 0, "%s: Duplicate DWARF abbreviation %d", dso->filename,
167 + error (0, 0, "%s: Duplicate DWARF-2 abbreviation %d", dso->filename,
172 form = read_uleb128 (ptr);
173 if (form == 2 || form > DW_FORM_indirect)
175 - error (0, 0, "%s: Unknown DWARF DW_FORM_%d", dso->filename, form);
176 + error (0, 0, "%s: Unknown DWARF-2 DW_FORM_%d", dso->filename, form);
182 if (read_uleb128 (ptr) != 0)
184 - error (0, 0, "%s: DWARF abbreviation does not end with 2 zeros",
185 + error (0, 0, "%s: DWARF-2 abbreviation does not end with 2 zeros",
190 has_prefix (const char *str,
198 str_len = strlen (str);
199 prefix_len = strlen (prefix);
200 @@ -481,14 +481,14 @@
204 -edit_dwarf2_line (DSO *dso, rpmuint32_t off, char *comp_dir, int phase)
205 +edit_dwarf2_line (DSO *dso, uint_32 off, char *comp_dir, int phase)
207 unsigned char *ptr = debug_sections[DEBUG_LINE].data, *dir;
208 unsigned char **dirt;
209 unsigned char *endsec = ptr + debug_sections[DEBUG_LINE].size;
210 unsigned char *endcu, *endprol;
211 unsigned char opcode_base;
212 - rpmuint32_t value, dirt_cnt;
213 + uint_32 value, dirt_cnt;
214 size_t comp_dir_len = strlen (comp_dir);
215 size_t abs_file_cnt = 0, abs_dir_cnt = 0;
220 value = read_16 (ptr);
221 - if (value != 2 && value != 3)
224 error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
228 error (EXIT_FAILURE, 0,
229 "canonicalization unexpectedly shrank by one character");
232 - memset (ptr, 'X', shrank);
236 + memset (ptr, 'X', shrank);
241 if (abs_dir_cnt + abs_file_cnt != 0)
243 edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
246 - rpmuint32_t list_offs;
253 for (i = 0; i < t->nattr; ++i)
255 - rpmuint32_t form = t->attr[i].form;
257 - size_t base_len, dest_len;
258 + uint_32 form = t->attr[i].form;
260 + int base_len, dest_len;
268 - dir = (char *) debug_sections[DEBUG_STR].data
269 + dir = (char *)debug_sections[DEBUG_STR].data
270 + do_read_32_relocated (ptr);
277 - name = (char *) debug_sections[DEBUG_STR].data
278 + name = (char *)debug_sections[DEBUG_STR].data
279 + do_read_32_relocated (ptr);
280 if (*name == '/' && comp_dir == NULL)
286 - case DW_FORM_ref_addr:
287 - if (cu_version == 2)
292 + case DW_FORM_ref_addr: /* ptr_size in DWARF 2, offset in DWARF 3 */
297 assert (len < UINT_MAX);
300 - error (0, 0, "%s: Unknown DWARF DW_FORM_%d", dso->filename,
301 + error (0, 0, "%s: Unknown DWARF-2 DW_FORM_%d", dso->filename,
310 - /* Ensure the CU current directory will exist even if only empty. Source
311 - filenames possibly located in its parent directories refer relatively to
312 - it and the debugger (GDB) cannot safely optimize out the missing
313 - CU current dir subdirectories. */
314 - if (comp_dir && list_file_fd != -1)
319 - if (base_dir && has_prefix (comp_dir, base_dir))
320 - p = comp_dir + strlen (base_dir);
321 - else if (dest_dir && has_prefix (comp_dir, dest_dir))
322 - p = comp_dir + strlen (dest_dir);
326 - size = strlen (p) + 1;
329 - ssize_t ret = write (list_file_fd, p, size);
337 if (found_list_offs && comp_dir)
338 edit_dwarf2_line (dso, list_offs, comp_dir, phase);
340 @@ -1070,7 +1034,7 @@
341 if (debug_sections[DEBUG_INFO].data != NULL)
343 unsigned char *ptr, *endcu, *endsec;
347 struct abbrev_tag tag, *t;
349 @@ -1212,11 +1176,11 @@
353 - cu_version = read_16 (ptr);
354 - if (cu_version != 2 && cu_version != 3)
355 + value = read_16 (ptr);
358 error (0, 0, "%s: DWARF version %d unhandled", dso->filename,
364 @@ -1226,7 +1190,7 @@
365 if (debug_sections[DEBUG_ABBREV].data == NULL)
366 error (0, 0, "%s: .debug_abbrev not present", dso->filename);
368 - error (0, 0, "%s: DWARF CU abbrev offset too large",
369 + error (0, 0, "%s: DWARF-2 CU abbrev offset too large",
373 @@ -1236,14 +1200,14 @@
374 ptr_size = read_1 (ptr);
375 if (ptr_size != 4 && ptr_size != 8)
377 - error (0, 0, "%s: Invalid DWARF pointer size %d",
378 + error (0, 0, "%s: Invalid DWARF-2 pointer size %d",
379 dso->filename, ptr_size);
383 else if (read_1 (ptr) != ptr_size)
385 - error (0, 0, "%s: DWARF pointer size differs between CUs",
386 + error (0, 0, "%s: DWARF-2 pointer size differs between CUs",
390 @@ -1261,7 +1225,7 @@
391 t = htab_find_with_hash (abbrev, &tag, tag.entry);
394 - error (0, 0, "%s: Could not find DWARF abbreviation %d",
395 + error (0, 0, "%s: Could not find DWARF-2 abbreviation %d",
396 dso->filename, tag.entry);
397 htab_delete (abbrev);
399 @@ -1410,12 +1374,12 @@
400 or Elf64 object, only that we are consistent in what bits feed the
401 hash so it comes out the same for the same file contents. */
403 - auto inline void process (const void *data, size_t size);
404 - auto inline void process (const void *data, size_t size)
405 + inline void process (const void *data, size_t size)
407 memchunk chunk = { .data = (void *) data, .size = size };
408 hashFunctionContextUpdateMC (&ctx, &chunk);
414 @@ -1475,11 +1439,11 @@
416 /* Now format the build ID bits in hex to print out. */
418 - const rpmuint8_t * id = (rpmuint8_t *)build_id->d_buf + build_id_offset;
419 + const unsigned char * id = (unsigned char *) build_id->d_buf + build_id_offset;
420 char hex[build_id_size * 2 + 1];
421 int n = snprintf (hex, 3, "%02" PRIx8, id[0]);
423 - for (i = 1; i < (int)build_id_size; ++i)
424 + for (i = 1; i < build_id_size; ++i)
426 n = snprintf (&hex[i * 2], 3, "%02" PRIx8, id[i]);
428 @@ -1502,7 +1466,8 @@
429 Elf_Data *build_id = NULL;
430 size_t build_id_offset = 0, build_id_size = 0;
432 - optCon = poptGetContext("debugedit", argc, (const char **)argv, optionsTable, 0);
433 + optCon = poptGetContext("debugedit", argc, (const char **)argv,
436 while ((nextopt = poptGetNextOpt (optCon)) > 0 || nextopt == POPT_ERROR_BADOPT)
438 @@ -1620,8 +1585,7 @@
440 src.d_buf = data->d_buf;
441 assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
442 - while ((char *) data->d_buf + data->d_size -
443 - (char *) src.d_buf > (int) sizeof nh
444 + while ((char *) data->d_buf + data->d_size - (char *) src.d_buf > (int) sizeof nh
445 && elf32_xlatetom (&dst, &src, dso->ehdr.e_ident[EI_DATA]))
447 Elf32_Word len = sizeof nh + nh.n_namesz;
448 @@ -1631,8 +1595,7 @@
449 && !memcmp ((char *) src.d_buf + sizeof nh, "GNU", sizeof "GNU"))
452 - build_id_offset = (char *) src.d_buf + len -
453 - (char *) data->d_buf;
454 + build_id_offset = (char *) src.d_buf + len - (char *) data->d_buf;
455 build_id_size = nh.n_descsz;