Changeset 58898d1d in mainline for uspace/app/taskdump
- Timestamp:
- 2017-03-24T20:31:54Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- Location:
- uspace/app/taskdump
- Files:
-
- 2 edited
-
elf_core.c (modified) (13 diffs)
-
symtab.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskdump/elf_core.c
rc9e3692 r58898d1d 67 67 68 68 static off64_t align_foff_up(off64_t, uintptr_t, size_t); 69 static int align_pos(int, size_t); 70 static int write_mem_area(int, as_area_info_t *, async_sess_t *); 69 static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *); 71 70 72 71 #define BUFFER_SIZE 0x1000 … … 97 96 elf_note_t note; 98 97 size_t word_size; 98 aoff64_t pos = 0; 99 99 100 100 int fd; … … 207 207 } 208 208 209 rc = write(fd, & elf_hdr, sizeof(elf_hdr));209 rc = write(fd, &pos, &elf_hdr, sizeof(elf_hdr)); 210 210 if (rc != sizeof(elf_hdr)) { 211 211 printf("Failed writing ELF header.\n"); … … 215 215 216 216 for (i = 0; i < n_ph; ++i) { 217 rc = write(fd, &p _hdr[i], sizeof(p_hdr[i]));217 rc = write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i])); 218 218 if (rc != sizeof(p_hdr[i])) { 219 219 printf("Failed writing program header.\n"); … … 223 223 } 224 224 225 if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) { 226 printf("Failed writing memory data.\n"); 227 free(p_hdr); 228 return EIO; 229 } 225 pos = p_hdr[0].p_offset; 230 226 231 227 /* … … 236 232 note.type = NT_PRSTATUS; 237 233 238 rc = write(fd, & note, sizeof(elf_note_t));234 rc = write(fd, &pos, ¬e, sizeof(elf_note_t)); 239 235 if (rc != sizeof(elf_note_t)) { 240 236 printf("Failed writing note header.\n"); … … 243 239 } 244 240 245 rc = write(fd, "CORE", note.namesz);241 rc = write(fd, &pos, "CORE", note.namesz); 246 242 if (rc != (ssize_t) note.namesz) { 247 243 printf("Failed writing note header.\n"); … … 250 246 } 251 247 252 rc = align_pos(fd, word_size); 253 if (rc != EOK) { 254 printf("Failed writing note header.\n"); 255 free(p_hdr); 256 return EIO; 257 } 258 259 rc = write(fd, &pr_status, sizeof(elf_prstatus_t)); 248 pos = ALIGN_UP(pos, word_size); 249 250 rc = write(fd, &pos, &pr_status, sizeof(elf_prstatus_t)); 260 251 if (rc != sizeof(elf_prstatus_t)) { 261 252 printf("Failed writing register data.\n"); … … 265 256 266 257 for (i = 1; i < n_ph; ++i) { 267 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) { 268 printf("Failed writing memory data.\n"); 269 free(p_hdr); 270 return EIO; 271 } 272 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) { 258 pos = p_hdr[i].p_offset; 259 if (write_mem_area(fd, &pos, &ainfo[i - 1], sess) != EOK) { 273 260 printf("Failed writing memory data.\n"); 274 261 free(p_hdr); … … 297 284 * 298 285 * @param fd File to write to. 286 * @param pos Pointer to the position to write to. 299 287 * @param area Memory area info structure. 300 288 * @param sess Debugging session. … … 303 291 * 304 292 */ 305 static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess) 293 static int write_mem_area(int fd, aoff64_t *pos, as_area_info_t *area, 294 async_sess_t *sess) 306 295 { 307 296 size_t to_copy; … … 321 310 } 322 311 323 rc = write(fd, buffer, to_copy);312 rc = write(fd, pos, buffer, to_copy); 324 313 if (rc != (ssize_t) to_copy) { 325 314 printf("Failed writing memory contents.\n"); … … 334 323 } 335 324 336 static int align_pos(int fd, size_t align)337 {338 off64_t cur_pos;339 size_t rem, adv;340 341 cur_pos = lseek(fd, 0, SEEK_CUR);342 if (cur_pos < 0)343 return -1;344 345 rem = cur_pos % align;346 adv = align - rem;347 348 cur_pos = lseek(fd, adv, SEEK_CUR);349 if (cur_pos < 0)350 return -1;351 352 return EOK;353 }354 355 325 /** @} 356 326 */ -
uspace/app/taskdump/symtab.c
rc9e3692 r58898d1d 68 68 char *shstrt, *sec_name; 69 69 void *data; 70 aoff64_t pos = 0; 70 71 71 72 int fd; … … 88 89 } 89 90 90 rc = read(fd, & elf_hdr, sizeof(elf_header_t));91 rc = read(fd, &pos, &elf_hdr, sizeof(elf_header_t)); 91 92 if (rc != sizeof(elf_header_t)) { 92 93 printf("failed reading elf header\n"); … … 304 305 { 305 306 int rc; 306 307 rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t), 308 SEEK_SET); 309 if (rc == (off64_t) -1) 310 return EIO; 311 312 rc = read(fd, sec_hdr, sizeof(elf_section_header_t)); 307 aoff64_t pos = elf_hdr->e_shoff + idx * sizeof(elf_section_header_t); 308 309 rc = read(fd, &pos, sec_hdr, sizeof(elf_section_header_t)); 313 310 if (rc != sizeof(elf_section_header_t)) 314 311 return EIO; … … 331 328 { 332 329 ssize_t rc; 333 off64_t offs; 334 335 offs = lseek(fd, start, SEEK_SET); 336 if (offs == (off64_t) -1) { 337 printf("failed seeking chunk\n"); 338 *ptr = NULL; 339 return EIO; 340 } 330 aoff64_t pos = start; 341 331 342 332 *ptr = malloc(size); … … 346 336 } 347 337 348 rc = read(fd, *ptr, size);338 rc = read(fd, &pos, *ptr, size); 349 339 if (rc != (ssize_t) size) { 350 340 printf("failed reading chunk\n");
Note:
See TracChangeset
for help on using the changeset viewer.
