comparison src/unexhp9k3.c @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 850242ba4a81
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
39 #include <sys/stat.h> 39 #include <sys/stat.h>
40 #include <sys/types.h> 40 #include <sys/types.h>
41 #include <string.h> 41 #include <string.h>
42 #include <stdio.h> 42 #include <stdio.h>
43 #include <signal.h> 43 #include <signal.h>
44 #ifdef __hp9000s300
45 # include </usr/include/debug.h>
46 #endif
44 #include <a.out.h> 47 #include <a.out.h>
45 #include <unistd.h> 48 #include <unistd.h>
46 #include <ctype.h> 49 #include <ctype.h>
47 #include <sys/dir.h> 50 #include <sys/dir.h>
48 51
380 printf ( "text pad size is %#x\n", old_dataddr - old_hdr.a_text); 383 printf ( "text pad size is %#x\n", old_dataddr - old_hdr.a_text);
381 #endif 384 #endif
382 unexec_pad (new_fd, old_dataddr - old_hdr.a_text); 385 unexec_pad (new_fd, old_dataddr - old_hdr.a_text);
383 386
384 /* 387 /*
388 * Update debug header spoo
389 */
390 if (new_hdr.a_extension > 0)
391 {
392 new_hdr.a_extension += LESYM_OFFSET(new_hdr) - LESYM_OFFSET(old_hdr);
393 }
394
395 /*
385 * go back and write the new header. 396 * go back and write the new header.
386 */ 397 */
387 unexec_write (new_fd, 0, (char *) &new_hdr, sizeof (new_hdr)); 398 unexec_write (new_fd, 0, (char *) &new_hdr, sizeof (new_hdr));
388 399
389 400
446 printf ("Copying %#lx bytes of junk from %#lx (old) to %#lx (new)\n", 457 printf ("Copying %#lx bytes of junk from %#lx (old) to %#lx (new)\n",
447 old_buf.st_size - old_mcaloff, old_mcaloff, new_mcaloff); 458 old_buf.st_size - old_mcaloff, old_mcaloff, new_mcaloff);
448 #endif 459 #endif
449 unexec_copy (new_fd, old_fd, old_mcaloff, new_mcaloff, 460 unexec_copy (new_fd, old_fd, old_mcaloff, new_mcaloff,
450 old_buf.st_size - old_mcaloff); 461 old_buf.st_size - old_mcaloff);
462
463 {
464 long curpos, offset;
465 struct _debug_header dhdr;
466 int new_header_delta;
467
468 new_header_delta = LESYM_OFFSET(new_hdr) - LESYM_OFFSET(old_hdr);
469 if ((new_header_delta > 0) &&
470 ((offset = EXT_OFFSET(old_hdr)) > 0))
471 {
472 curpos = lseek(new_fd, 0, SEEK_CUR);
473 lseek(old_fd, offset, 0);
474 if (read(old_fd, &dhdr, sizeof(dhdr)) == sizeof(dhdr))
475 {
476 dhdr.header_offset += new_header_delta;
477 dhdr.gntt_offset += new_header_delta;
478 dhdr.lntt_offset += new_header_delta;
479 dhdr.slt_offset += new_header_delta;
480 dhdr.vt_offset += new_header_delta;
481 dhdr.xt_offset += new_header_delta;
482 lseek(new_fd, EXT_OFFSET(new_hdr), SEEK_SET);
483 if (write(new_fd, &dhdr, sizeof(dhdr)) != sizeof(dhdr))
484 {
485 unexec_error("Unable to write debug information to \"%s\"\n",
486 1, new_name);
487 }
488 lseek(new_fd, curpos, SEEK_SET);
489 }
490 else
491 {
492 unexec_error("Unable to read debug information from \"%s\"\n",
493 1, old_name);
494 }
495 }
496 }
451 } 497 }
452 498
453 499
454 /* make the output file executable -- then quit */ 500 /* make the output file executable -- then quit */
455 unexec_fchmod (new_fd, 0755); 501 unexec_fchmod (new_fd, 0755);
456 close (old_fd); 502 close (old_fd);
457 close (new_fd); 503 close (new_fd);