Changeset 58898d1d in mainline for uspace/app/taskdump/elf_core.c
- Timestamp:
- 2017-03-24T20:31:54Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- File:
-
- 1 edited
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 */
Note:
See TracChangeset
for help on using the changeset viewer.