/* BSD Kernel Data Access Library (libkvm) interface.
- Copyright (C) 2004-2021 Free Software Foundation, Inc.
+ Copyright (C) 2004-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "defs.h"
#include "cli/cli-cmds.h"
#include "command.h"
+#include "filenames.h"
#include "frame.h"
#include "regcache.h"
#include "target.h"
#include "inferior.h" /* for get_exec_file */
#include "gdbthread.h"
#include "gdbsupport/pathstuff.h"
+#include "gdbsupport/gdb_tilde_expand.h"
#include <fcntl.h>
#include <kvm.h>
#include "bsd-kvm.h"
/* Kernel memory device file. */
-static const char *bsd_kvm_corefile;
+static std::string bsd_kvm_corefile;
/* Kernel memory interface descriptor. */
static kvm_t *core_kd;
char errbuf[_POSIX2_LINE_MAX];
const char *execfile = NULL;
kvm_t *temp_kd;
- char *filename = NULL;
+ std::string filename;
target_preopen (from_tty);
if (arg)
{
- filename = tilde_expand (arg);
- if (filename[0] != '/')
- {
- gdb::unique_xmalloc_ptr<char> temp (gdb_abspath (filename));
-
- xfree (filename);
- filename = temp.release ();
- }
+ filename = gdb_tilde_expand (arg);
+ if (!IS_ABSOLUTE_PATH (filename))
+ filename = gdb_abspath (filename.c_str ());
}
execfile = get_exec_file (0);
- temp_kd = kvm_openfiles (execfile, filename, NULL,
+ temp_kd = kvm_openfiles (execfile, filename.c_str (), NULL,
write_files ? O_RDWR : O_RDONLY, errbuf);
if (temp_kd == NULL)
error (("%s"), errbuf);
core_kd = NULL;
}
+ bsd_kvm_corefile.clear ();
switch_to_no_thread ();
exit_inferior_silent (current_inferior ());
}
void
bsd_kvm_target::files_info ()
{
- if (bsd_kvm_corefile && strcmp (bsd_kvm_corefile, _PATH_MEM) != 0)
- printf_filtered (_("\tUsing the kernel crash dump %s.\n"),
- bsd_kvm_corefile);
+ if (bsd_kvm_corefile != _PATH_MEM)
+ gdb_printf (_("\tUsing the kernel crash dump %s.\n"),
+ bsd_kvm_corefile.c_str ());
else
- printf_filtered (_("\tUsing the currently running kernel.\n"));
+ gdb_printf (_("\tUsing the currently running kernel.\n"));
}
/* Fetch process control block at address PADDR. */
/* On dumping core, BSD kernels store the faulting context (PCB)
in the variable "dumppcb". */
memset (nl, 0, sizeof nl);
- nl[0].n_name = "_dumppcb";
+ nl[0].n_name = (char *) "_dumppcb";
if (kvm_nlist (core_kd, nl) == -1)
error (("%s"), kvm_geterr (core_kd));
"proc0paddr". */
memset (nl, 0, sizeof nl);
- nl[0].n_name = "_proc0paddr";
+ nl[0].n_name = (char *) "_proc0paddr";
if (kvm_nlist (core_kd, nl) == -1)
error (("%s"), kvm_geterr (core_kd));
variable "thread0". */
memset (nl, 0, sizeof nl);
- nl[0].n_name = "_thread0";
+ nl[0].n_name = (char *) "_thread0";
if (kvm_nlist (core_kd, nl) == -1)
error (("%s"), kvm_geterr (core_kd));
add_prefix_cmd ("kvm", class_obscure, bsd_kvm_cmd, _("\
Generic command for manipulating the kernel memory interface."),
- &bsd_kvm_cmdlist, "kvm ", 0, &cmdlist);
+ &bsd_kvm_cmdlist, 0, &cmdlist);
#ifndef HAVE_STRUCT_THREAD_TD_PCB
add_cmd ("proc", class_obscure, bsd_kvm_proc_cmd,