| OLD | NEW |
| 1 /* Generate a core file for the inferior process. | 1 /* Generate a core file for the inferior process. |
| 2 | 2 |
| 3 Copyright (C) 2001-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2001-2012 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GDB. | 5 This file is part of GDB. |
| 6 | 6 |
| 7 This program is free software; you can redistribute it and/or modify | 7 This program is free software; you can redistribute it and/or modify |
| 8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
| 9 the Free Software Foundation; either version 3 of the License, or | 9 the Free Software Foundation; either version 3 of the License, or |
| 10 (at your option) any later version. | 10 (at your option) any later version. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 | 65 |
| 66 void | 66 void |
| 67 write_gcore_file (bfd *obfd) | 67 write_gcore_file (bfd *obfd) |
| 68 { | 68 { |
| 69 void *note_data = NULL; | 69 void *note_data = NULL; |
| 70 int note_size = 0; | 70 int note_size = 0; |
| 71 asection *note_sec = NULL; | 71 asection *note_sec = NULL; |
| 72 | 72 |
| 73 /* An external target method must build the notes section. */ | 73 /* An external target method must build the notes section. */ |
| 74 note_data = target_make_corefile_notes (obfd, ¬e_size); | 74 /* FIXME: uweigand/2011-10-06: All architectures that support core file |
| 75 generation should be converted to gdbarch_make_corefile_notes; at that |
| 76 point, the target vector method can be removed. */ |
| 77 if (!gdbarch_make_corefile_notes_p (target_gdbarch)) |
| 78 note_data = target_make_corefile_notes (obfd, ¬e_size); |
| 79 else |
| 80 note_data = gdbarch_make_corefile_notes (target_gdbarch, obfd, ¬e_size); |
| 81 |
| 82 if (note_data == NULL || note_size == 0) |
| 83 error (_("Target does not support core file generation.")); |
| 75 | 84 |
| 76 /* Create the note section. */ | 85 /* Create the note section. */ |
| 77 if (note_data != NULL && note_size != 0) | 86 note_sec = bfd_make_section_anyway_with_flags (obfd, "note0", |
| 78 { | 87 » » » » » » SEC_HAS_CONTENTS |
| 79 note_sec = bfd_make_section_anyway_with_flags (obfd, "note0", | 88 » » » » » » | SEC_READONLY |
| 80 » » » » » » SEC_HAS_CONTENTS | 89 » » » » » » | SEC_ALLOC); |
| 81 » » » » » » | SEC_READONLY | 90 if (note_sec == NULL) |
| 82 » » » » » » | SEC_ALLOC); | 91 error (_("Failed to create 'note' section for corefile: %s"), |
| 83 if (note_sec == NULL) | 92 » bfd_errmsg (bfd_get_error ())); |
| 84 » error (_("Failed to create 'note' section for corefile: %s"), | |
| 85 » bfd_errmsg (bfd_get_error ())); | |
| 86 | 93 |
| 87 bfd_set_section_vma (obfd, note_sec, 0); | 94 bfd_set_section_vma (obfd, note_sec, 0); |
| 88 bfd_set_section_alignment (obfd, note_sec, 0); | 95 bfd_set_section_alignment (obfd, note_sec, 0); |
| 89 bfd_set_section_size (obfd, note_sec, note_size); | 96 bfd_set_section_size (obfd, note_sec, note_size); |
| 90 } | |
| 91 | 97 |
| 92 /* Now create the memory/load sections. */ | 98 /* Now create the memory/load sections. */ |
| 93 if (gcore_memory_sections (obfd) == 0) | 99 if (gcore_memory_sections (obfd) == 0) |
| 94 error (_("gcore: failed to get corefile memory sections from target.")); | 100 error (_("gcore: failed to get corefile memory sections from target.")); |
| 95 | 101 |
| 96 /* Write out the contents of the note section. */ | 102 /* Write out the contents of the note section. */ |
| 97 if (note_data != NULL && note_size != 0) | 103 if (!bfd_set_section_contents (obfd, note_sec, note_data, 0, note_size)) |
| 98 { | 104 warning (_("writing note section (%s)"), bfd_errmsg (bfd_get_error ())); |
| 99 if (!bfd_set_section_contents (obfd, note_sec, note_data, 0, note_size)) | |
| 100 » warning (_("writing note section (%s)"), | |
| 101 » » bfd_errmsg (bfd_get_error ())); | |
| 102 } | |
| 103 } | 105 } |
| 104 | 106 |
| 105 static void | 107 static void |
| 106 do_bfd_delete_cleanup (void *arg) | 108 do_bfd_delete_cleanup (void *arg) |
| 107 { | 109 { |
| 108 bfd *obfd = arg; | 110 bfd *obfd = arg; |
| 109 const char *filename = obfd->filename; | 111 const char *filename = obfd->filename; |
| 110 | 112 |
| 111 bfd_close (arg); | 113 bfd_close (arg); |
| 112 unlink (filename); | 114 unlink (filename); |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 total_size -= size; | 554 total_size -= size; |
| 553 offset += size; | 555 offset += size; |
| 554 } | 556 } |
| 555 | 557 |
| 556 do_cleanups (old_chain); /* Frees MEMHUNK. */ | 558 do_cleanups (old_chain); /* Frees MEMHUNK. */ |
| 557 } | 559 } |
| 558 | 560 |
| 559 static int | 561 static int |
| 560 gcore_memory_sections (bfd *obfd) | 562 gcore_memory_sections (bfd *obfd) |
| 561 { | 563 { |
| 562 if (target_find_memory_regions (gcore_create_callback, obfd) != 0) | 564 /* Try gdbarch method first, then fall back to target method. */ |
| 563 return 0;» » » /* FIXME: error return/msg? */ | 565 if (!gdbarch_find_memory_regions_p (target_gdbarch) |
| 566 || gdbarch_find_memory_regions (target_gdbarch, |
| 567 » » » » gcore_create_callback, obfd) != 0) |
| 568 { |
| 569 if (target_find_memory_regions (gcore_create_callback, obfd) != 0) |
| 570 » return 0;» » » /* FIXME: error return/msg? */ |
| 571 } |
| 564 | 572 |
| 565 /* Record phdrs for section-to-segment mapping. */ | 573 /* Record phdrs for section-to-segment mapping. */ |
| 566 bfd_map_over_sections (obfd, make_output_phdrs, NULL); | 574 bfd_map_over_sections (obfd, make_output_phdrs, NULL); |
| 567 | 575 |
| 568 /* Copy memory region contents. */ | 576 /* Copy memory region contents. */ |
| 569 bfd_map_over_sections (obfd, gcore_copy_callback, NULL); | 577 bfd_map_over_sections (obfd, gcore_copy_callback, NULL); |
| 570 | 578 |
| 571 return 1; | 579 return 1; |
| 572 } | 580 } |
| 573 | 581 |
| 574 /* Provide a prototype to silence -Wmissing-prototypes. */ | 582 /* Provide a prototype to silence -Wmissing-prototypes. */ |
| 575 extern initialize_file_ftype _initialize_gcore; | 583 extern initialize_file_ftype _initialize_gcore; |
| 576 | 584 |
| 577 void | 585 void |
| 578 _initialize_gcore (void) | 586 _initialize_gcore (void) |
| 579 { | 587 { |
| 580 add_com ("generate-core-file", class_files, gcore_command, _("\ | 588 add_com ("generate-core-file", class_files, gcore_command, _("\ |
| 581 Save a core file with the current state of the debugged process.\n\ | 589 Save a core file with the current state of the debugged process.\n\ |
| 582 Argument is optional filename. Default filename is 'core.<process_id>'.")); | 590 Argument is optional filename. Default filename is 'core.<process_id>'.")); |
| 583 | 591 |
| 584 add_com_alias ("gcore", "generate-core-file", class_files, 1); | 592 add_com_alias ("gcore", "generate-core-file", class_files, 1); |
| 585 exec_set_find_memory_regions (objfile_find_memory_regions); | 593 exec_set_find_memory_regions (objfile_find_memory_regions); |
| 586 } | 594 } |
| OLD | NEW |