1
0
Fork 0
mirror of https://github.com/tobast/libunwind-eh_elf.git synced 2024-11-28 18:07:37 +01:00

Whitespace cleanup

This commit is contained in:
Arun Sharma 2012-03-23 22:18:37 -07:00
parent 0c0ea23cf2
commit 0628a9872c

View file

@ -122,15 +122,15 @@ _UCD_create(const char *filename)
if (_64bits && sizeof(elf_header64.e_entry) > sizeof(off_t)) if (_64bits && sizeof(elf_header64.e_entry) > sizeof(off_t))
{ {
Debug(0, "Can't process '%s': 64-bit file " Debug(0, "Can't process '%s': 64-bit file "
"while only %ld bits are supported", "while only %ld bits are supported",
filename, 8L * sizeof(off_t)); filename, 8L * sizeof(off_t));
goto err; goto err;
} }
/* paranoia check */ /* paranoia check */
if (_64bits if (_64bits
? 0 /* todo: (elf_header64.e_ehsize != NN || elf_header64.e_phentsize != NN) */ ? 0 /* todo: (elf_header64.e_ehsize != NN || elf_header64.e_phentsize != NN) */
: (elf_header32.e_ehsize != 52 || elf_header32.e_phentsize != 32) : (elf_header32.e_ehsize != 52 || elf_header32.e_phentsize != 32)
) )
{ {
Debug(0, "'%s' has wrong e_ehsize or e_phentsize\n", filename); Debug(0, "'%s' has wrong e_ehsize or e_phentsize\n", filename);
@ -150,139 +150,143 @@ _UCD_create(const char *filename)
coredump_phdr_t *cur = phdrs; coredump_phdr_t *cur = phdrs;
unsigned i = 0; unsigned i = 0;
while (i < size) while (i < size)
{ {
Elf64_Phdr hdr64; Elf64_Phdr hdr64;
if (read(fd, &hdr64, sizeof(hdr64)) != sizeof(hdr64)) if (read(fd, &hdr64, sizeof(hdr64)) != sizeof(hdr64))
{ {
Debug(0, "Can't read phdrs from '%s'\n", filename); Debug(0, "Can't read phdrs from '%s'\n", filename);
goto err; goto err;
} }
cur->p_type = hdr64.p_type ; cur->p_type = hdr64.p_type ;
cur->p_flags = hdr64.p_flags ; cur->p_flags = hdr64.p_flags ;
cur->p_offset = hdr64.p_offset; cur->p_offset = hdr64.p_offset;
cur->p_vaddr = hdr64.p_vaddr ; cur->p_vaddr = hdr64.p_vaddr ;
/*cur->p_paddr = hdr32.p_paddr ; always 0 */ /*cur->p_paddr = hdr32.p_paddr ; always 0 */
//TODO: check that and abort if it isn't? //TODO: check that and abort if it isn't?
cur->p_filesz = hdr64.p_filesz; cur->p_filesz = hdr64.p_filesz;
cur->p_memsz = hdr64.p_memsz ; cur->p_memsz = hdr64.p_memsz ;
cur->p_align = hdr64.p_align ; cur->p_align = hdr64.p_align ;
/* cur->backing_filename = NULL; - done by memset */ /* cur->backing_filename = NULL; - done by memset */
cur->backing_fd = -1; cur->backing_fd = -1;
cur->backing_filesize = hdr64.p_filesz; cur->backing_filesize = hdr64.p_filesz;
i++; i++;
cur++; cur++;
} }
} else { } else {
coredump_phdr_t *cur = phdrs; coredump_phdr_t *cur = phdrs;
unsigned i = 0; unsigned i = 0;
while (i < size) while (i < size)
{ {
Elf32_Phdr hdr32; Elf32_Phdr hdr32;
if (read(fd, &hdr32, sizeof(hdr32)) != sizeof(hdr32)) if (read(fd, &hdr32, sizeof(hdr32)) != sizeof(hdr32))
{ {
Debug(0, "Can't read phdrs from '%s'\n", filename); Debug(0, "Can't read phdrs from '%s'\n", filename);
goto err; goto err;
} }
cur->p_type = hdr32.p_type ; cur->p_type = hdr32.p_type ;
cur->p_flags = hdr32.p_flags ; cur->p_flags = hdr32.p_flags ;
cur->p_offset = hdr32.p_offset; cur->p_offset = hdr32.p_offset;
cur->p_vaddr = hdr32.p_vaddr ; cur->p_vaddr = hdr32.p_vaddr ;
/*cur->p_paddr = hdr32.p_paddr ; always 0 */ /*cur->p_paddr = hdr32.p_paddr ; always 0 */
cur->p_filesz = hdr32.p_filesz; cur->p_filesz = hdr32.p_filesz;
cur->p_memsz = hdr32.p_memsz ; cur->p_memsz = hdr32.p_memsz ;
cur->p_align = hdr32.p_align ; cur->p_align = hdr32.p_align ;
/* cur->backing_filename = NULL; - done by memset */ /* cur->backing_filename = NULL; - done by memset */
cur->backing_fd = -1; cur->backing_fd = -1;
cur->backing_filesize = hdr32.p_memsz; cur->backing_filesize = hdr32.p_memsz;
i++; i++;
cur++; cur++;
} }
} }
unsigned i = 0; unsigned i = 0;
coredump_phdr_t *cur = phdrs; coredump_phdr_t *cur = phdrs;
while (i < size) while (i < size)
{ {
Debug(2, "phdr[%03d]: type:%d", i, cur->p_type); Debug(2, "phdr[%03d]: type:%d", i, cur->p_type);
if (cur->p_type == PT_NOTE) if (cur->p_type == PT_NOTE)
{ {
unsigned char *p, *note_end; unsigned char *p, *note_end;
unsigned n_threads; unsigned n_threads;
ui->note_phdr = malloc(cur->p_filesz); ui->note_phdr = malloc(cur->p_filesz);
if (lseek(fd, cur->p_offset, SEEK_SET) != (off_t)cur->p_offset if (lseek(fd, cur->p_offset, SEEK_SET) != (off_t)cur->p_offset
|| (uoff_t)read(fd, ui->note_phdr, cur->p_filesz) != cur->p_filesz || (uoff_t)read(fd, ui->note_phdr, cur->p_filesz) != cur->p_filesz)
) {
{ Debug(0, "Can't read PT_NOTE from '%s'\n", filename);
Debug(0, "Can't read PT_NOTE from '%s'\n", filename); goto err;
goto err; }
}
note_end = (unsigned char *)ui->note_phdr + cur->p_filesz; note_end = (unsigned char *)ui->note_phdr + cur->p_filesz;
/* Count number of threads */ /* Count number of threads */
n_threads = 0; n_threads = 0;
p = ui->note_phdr; p = ui->note_phdr;
while (p + sizeof (Elf32_Nhdr) <= note_end) while (p + sizeof (Elf32_Nhdr) <= note_end)
{ {
Elf32_Nhdr *note_hdr = (Elf32_Nhdr *)p; Elf32_Nhdr *note_hdr = (Elf32_Nhdr *)p;
unsigned char *p_next; unsigned char *p_next;
p_next = p + sizeof (Elf32_Nhdr) + ((note_hdr->n_namesz + 3) & ~3L) + note_hdr->n_descsz; p_next = p + sizeof (Elf32_Nhdr)
+ ((note_hdr->n_namesz + 3) & ~3L)
+ note_hdr->n_descsz;
if (p_next >= note_end) if (p_next >= note_end)
break; break;
if (note_hdr->n_type == NT_PRSTATUS) if (note_hdr->n_type == NT_PRSTATUS)
n_threads++; n_threads++;
p = p_next; p = p_next;
} }
ui->n_threads = n_threads; ui->n_threads = n_threads;
ui->threads = malloc(sizeof (void *) * n_threads); ui->threads = malloc(sizeof (void *) * n_threads);
n_threads = 0; n_threads = 0;
p = ui->note_phdr; p = ui->note_phdr;
while (p + sizeof (Elf32_Nhdr) <= note_end) while (p + sizeof (Elf32_Nhdr) <= note_end)
{ {
Elf32_Nhdr *note_hdr = (Elf32_Nhdr *)p; Elf32_Nhdr *note_hdr = (Elf32_Nhdr *)p;
unsigned char *p_next; unsigned char *p_next;
p_next = p + sizeof (Elf32_Nhdr) + ((note_hdr->n_namesz + 3) & ~3L) + note_hdr->n_descsz; p_next = p + sizeof (Elf32_Nhdr)
+ ((note_hdr->n_namesz + 3) & ~3L)
+ note_hdr->n_descsz;
if (p_next >= note_end) if (p_next >= note_end)
break; break;
if (note_hdr->n_type == NT_PRSTATUS) if (note_hdr->n_type == NT_PRSTATUS)
ui->threads[n_threads++] = (void*) ((((long)note_hdr + sizeof(*note_hdr) + note_hdr->n_namesz) + 3) & ~3L); ui->threads[n_threads++] = (void*) ((((long)note_hdr
+ sizeof(*note_hdr) + note_hdr->n_namesz) + 3) & ~3L);
p = p_next; p = p_next;
} }
} }
if (cur->p_type == PT_LOAD) if (cur->p_type == PT_LOAD)
{ {
Debug(2, " ofs:%08llx va:%08llx filesize:%08llx memsize:%08llx flg:%x", Debug(2, " ofs:%08llx va:%08llx filesize:%08llx memsize:%08llx flg:%x",
(unsigned long long) cur->p_offset, (unsigned long long) cur->p_offset,
(unsigned long long) cur->p_vaddr, (unsigned long long) cur->p_vaddr,
(unsigned long long) cur->p_filesz, (unsigned long long) cur->p_filesz,
(unsigned long long) cur->p_memsz, (unsigned long long) cur->p_memsz,
cur->p_flags cur->p_flags
); );
if (cur->p_filesz < cur->p_memsz) if (cur->p_filesz < cur->p_memsz)
Debug(2, " partial"); Debug(2, " partial");
if (cur->p_flags & PF_X) if (cur->p_flags & PF_X)
Debug(2, " executable"); Debug(2, " executable");
} }
Debug(2, "\n"); Debug(2, "\n");
i++; i++;
cur++; cur++;
} }
if (ui->n_threads == 0) if (ui->n_threads == 0)
{ {
Debug(0, "No NT_PRSTATUS note found in '%s'\n", filename); Debug(0, "No NT_PRSTATUS note found in '%s'\n", filename);
goto err; goto err;
} }
ui->prstatus = ui->threads[0]; ui->prstatus = ui->threads[0];
@ -355,9 +359,9 @@ int _UCD_add_backing_file_at_segment(struct UCD_info *ui, int phdr_no, const cha
{ {
/* This is expected */ /* This is expected */
Debug(2, "Note: phdr[%u] is %lld bytes, file is larger: %lld bytes\n", Debug(2, "Note: phdr[%u] is %lld bytes, file is larger: %lld bytes\n",
phdr_no, phdr_no,
(unsigned long long)phdr->p_memsz, (unsigned long long)phdr->p_memsz,
(unsigned long long)phdr->backing_filesize (unsigned long long)phdr->backing_filesize
); );
} }
//TODO: else loudly complain? Maybe even fail? //TODO: else loudly complain? Maybe even fail?
@ -370,31 +374,31 @@ int _UCD_add_backing_file_at_segment(struct UCD_info *ui, int phdr_no, const cha
if (lseek(ui->coredump_fd, phdr->p_offset, SEEK_SET) != (off_t)phdr->p_offset if (lseek(ui->coredump_fd, phdr->p_offset, SEEK_SET) != (off_t)phdr->p_offset
|| (uoff_t)read(ui->coredump_fd, core_buf, phdr->p_filesz) != phdr->p_filesz || (uoff_t)read(ui->coredump_fd, core_buf, phdr->p_filesz) != phdr->p_filesz
) )
{ {
Debug(0, "Error reading from coredump file\n"); Debug(0, "Error reading from coredump file\n");
err_read: err_read:
free(core_buf); free(core_buf);
free(file_buf); free(file_buf);
goto err; goto err;
} }
if ((uoff_t)read(fd, file_buf, phdr->p_filesz) != phdr->p_filesz) if ((uoff_t)read(fd, file_buf, phdr->p_filesz) != phdr->p_filesz)
{ {
Debug(0, "Error reading from '%s'\n", filename); Debug(0, "Error reading from '%s'\n", filename);
goto err_read; goto err_read;
} }
int r = memcmp(core_buf, file_buf, phdr->p_filesz); int r = memcmp(core_buf, file_buf, phdr->p_filesz);
free(core_buf); free(core_buf);
free(file_buf); free(file_buf);
if (r != 0) if (r != 0)
{ {
Debug(1, "Note: phdr[%u] first %lld bytes in core dump and in file do not match\n", Debug(1, "Note: phdr[%u] first %lld bytes in core dump and in file do not match\n",
phdr_no, (unsigned long long)phdr->p_filesz phdr_no, (unsigned long long)phdr->p_filesz
); );
} else { } else {
Debug(1, "Note: phdr[%u] first %lld bytes in core dump and in file match\n", Debug(1, "Note: phdr[%u] first %lld bytes in core dump and in file match\n",
phdr_no, (unsigned long long)phdr->p_filesz phdr_no, (unsigned long long)phdr->p_filesz
); );
} }
} }
/* Success */ /* Success */
@ -412,8 +416,8 @@ int _UCD_add_backing_file_at_segment(struct UCD_info *ui, int phdr_no, const cha
} }
int _UCD_add_backing_file_at_vaddr(struct UCD_info *ui, int _UCD_add_backing_file_at_vaddr(struct UCD_info *ui,
unsigned long vaddr, unsigned long vaddr,
const char *filename) const char *filename)
{ {
unsigned i; unsigned i;
for (i = 0; i < ui->phdrs_count; i++) for (i = 0; i < ui->phdrs_count; i++)