Changeset View
Changeset View
Standalone View
Standalone View
devel/gdb/files/kgdb/fbsd-kvm.c
Show All 16 Lines | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||
* | |||||
*/ | */ | ||||
#include "defs.h" | #include "defs.h" | ||||
#include "command.h" | #include "command.h" | ||||
#include "elf-bfd.h" | #include "elf-bfd.h" | ||||
#include "filenames.h" | #include "filenames.h" | ||||
#include "gdbcore.h" | #include "gdbcore.h" | ||||
#include "gdbthread.h" | #include "gdbthread.h" | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | fbsd_kernel_osabi_sniffer(bfd *abfd) | ||||
/* First, determine if this is a FreeBSD/ELF binary. */ | /* First, determine if this is a FreeBSD/ELF binary. */ | ||||
switch (elf_elfheader(abfd)->e_ident[EI_OSABI]) { | switch (elf_elfheader(abfd)->e_ident[EI_OSABI]) { | ||||
case ELFOSABI_FREEBSD: | case ELFOSABI_FREEBSD: | ||||
break; | break; | ||||
case ELFOSABI_NONE: { | case ELFOSABI_NONE: { | ||||
enum gdb_osabi osabi = GDB_OSABI_UNKNOWN; | enum gdb_osabi osabi = GDB_OSABI_UNKNOWN; | ||||
bfd_map_over_sections (abfd, | for (asection *sect : gdb_bfd_sections (abfd)) | ||||
generic_elf_osabi_sniff_abi_tag_sections, | generic_elf_osabi_sniff_abi_tag_sections (abfd, sect, &osabi); | ||||
&osabi); | |||||
/* | /* | ||||
* aarch64 and RISC-V kernels don't have the right | * aarch64 and RISC-V kernels don't have the right | ||||
* note tag for kernels so just look for /red/herring | * note tag for kernels so just look for /red/herring | ||||
* anyway. | * anyway. | ||||
*/ | */ | ||||
if (osabi == GDB_OSABI_UNKNOWN && | if (osabi == GDB_OSABI_UNKNOWN && | ||||
((elf_elfheader(abfd)->e_machine == EM_AARCH64) || | ((elf_elfheader(abfd)->e_machine == EM_AARCH64) || | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | nkvm = kvm_openfiles(kernel, filename, NULL, | ||||
writeable ? O_RDWR : O_RDONLY, kvm_err); | writeable ? O_RDWR : O_RDONLY, kvm_err); | ||||
#endif | #endif | ||||
if (nkvm == NULL) { | if (nkvm == NULL) { | ||||
xfree (filename); | xfree (filename); | ||||
error ("Failed to open vmcore: %s", kvm_err); | error ("Failed to open vmcore: %s", kvm_err); | ||||
} | } | ||||
/* Don't free the filename now and close any previous vmcore. */ | /* Don't free the filename now and close any previous vmcore. */ | ||||
unpush_target(&fbsd_kvm_ops); | current_inferior ()->unpush_target (&fbsd_kvm_ops); | ||||
#ifdef HAVE_KVM_DISP | #ifdef HAVE_KVM_DISP | ||||
/* Relocate kernel objfile if needed. */ | /* Relocate kernel objfile if needed. */ | ||||
if (symfile_objfile && | struct objfile *symfile_objfile = | ||||
current_program_space->symfile_object_file; | |||||
if (symfile_objfile != nullptr && | |||||
(bfd_get_file_flags(symfile_objfile->obfd) & | (bfd_get_file_flags(symfile_objfile->obfd) & | ||||
(EXEC_P | DYNAMIC)) != 0) { | (EXEC_P | DYNAMIC)) != 0) { | ||||
CORE_ADDR displacement = kvm_kerndisp(nkvm); | CORE_ADDR displacement = kvm_kerndisp(nkvm); | ||||
if (displacement != 0) { | if (displacement != 0) { | ||||
section_offsets new_offsets (symfile_objfile->section_offsets.size (), | section_offsets new_offsets (symfile_objfile->section_offsets.size (), | ||||
displacement); | displacement); | ||||
objfile_relocate(symfile_objfile, new_offsets); | objfile_relocate(symfile_objfile, new_offsets); | ||||
} | } | ||||
Show All 36 Lines | |||||
#else | #else | ||||
pcb_size = sizeof(struct pcb); | pcb_size = sizeof(struct pcb); | ||||
#endif | #endif | ||||
} | } | ||||
} | } | ||||
kvm = nkvm; | kvm = nkvm; | ||||
vmcore = filename; | vmcore = filename; | ||||
push_target (&fbsd_kvm_ops); | current_inferior()->push_target (&fbsd_kvm_ops); | ||||
kgdb_dmesg(); | kgdb_dmesg(); | ||||
inf = current_inferior(); | inf = current_inferior(); | ||||
if (inf->pid == 0) { | if (inf->pid == 0) { | ||||
inferior_appeared(inf, 1); | inferior_appeared(inf, 1); | ||||
inf->fake_pid_p = 1; | inf->fake_pid_p = 1; | ||||
} | } | ||||
Show All 15 Lines | #endif | ||||
print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC, 1); | print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC, 1); | ||||
} | } | ||||
void | void | ||||
fbsd_kvm_target::close() | fbsd_kvm_target::close() | ||||
{ | { | ||||
if (kvm != NULL) { | if (kvm != NULL) { | ||||
switch_to_no_thread (); | |||||
exit_inferior_silent (current_inferior ()); | |||||
clear_solib(); | clear_solib(); | ||||
if (kvm_close(kvm) != 0) | if (kvm_close(kvm) != 0) | ||||
warning("cannot close \"%s\": %s", vmcore, | warning("cannot close \"%s\": %s", vmcore, | ||||
kvm_geterr(kvm)); | kvm_geterr(kvm)); | ||||
kvm = NULL; | kvm = NULL; | ||||
xfree(vmcore); | xfree(vmcore); | ||||
vmcore = NULL; | vmcore = NULL; | ||||
} | } | ||||
switch_to_no_thread (); | |||||
exit_inferior_silent (current_inferior ()); | |||||
} | } | ||||
#if 0 | #if 0 | ||||
static void | static void | ||||
kgdb_trgt_detach(struct target_ops *ops, const char *args, int from_tty) | kgdb_trgt_detach(struct target_ops *ops, const char *args, int from_tty) | ||||
{ | { | ||||
if (args) | if (args) | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | if (kvm != NULL && addr >= kernstart) { | ||||
thr = kgdb_thr_lookup_taddr(addr); | thr = kgdb_thr_lookup_taddr(addr); | ||||
if (thr == NULL) | if (thr == NULL) | ||||
error("invalid thread address"); | error("invalid thread address"); | ||||
addr = thr->tid; | addr = thr->tid; | ||||
} | } | ||||
kgdb_switch_to_thread(arg, addr); | kgdb_switch_to_thread(arg, addr); | ||||
} | } | ||||
void _initialize_kgdb_target(void); | void _initialize_kgdb_target (); | ||||
void | void | ||||
_initialize_kgdb_target(void) | _initialize_kgdb_target () | ||||
{ | { | ||||
add_target(fbsd_kvm_target_info, fbsd_kvm_target_open, | add_target(fbsd_kvm_target_info, fbsd_kvm_target_open, | ||||
filename_completer); | filename_completer); | ||||
fbsd_vmcore_data = gdbarch_data_register_pre_init(fbsd_vmcore_init); | fbsd_vmcore_data = gdbarch_data_register_pre_init(fbsd_vmcore_init); | ||||
add_com ("proc", class_obscure, kgdb_set_proc_cmd, | add_com ("proc", class_obscure, kgdb_set_proc_cmd, | ||||
Show All 14 Lines |