/* BSD Kernel Data Access Library (libkvm) interface.
- Copyright (C) 2004-2018 Free Software Foundation, Inc.
+ Copyright (C) 2004-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "frame.h"
#include "regcache.h"
#include "target.h"
+#include "process-stratum-target.h"
#include "value.h"
-#include "gdbcore.h" /* for get_exec_file */
+#include "gdbcore.h"
+#include "inferior.h" /* for get_exec_file */
#include "gdbthread.h"
+#include "gdbsupport/pathstuff.h"
#include <fcntl.h>
#include <kvm.h>
/* The libkvm target. */
-class bsd_kvm_target final : public target_ops
+static const target_info bsd_kvm_target_info = {
+ "kvm",
+ N_("Kernel memory interface"),
+ N_("Use a kernel virtual memory image as a target.\n\
+Optionally specify the filename of a core dump.")
+};
+
+class bsd_kvm_target final : public process_stratum_target
{
public:
- bsd_kvm_target ()
- { this->to_stratum = process_stratum; }
-
- const char *shortname () override
- { return "kvm"; }
+ bsd_kvm_target () = default;
- const char *longname () override
- { return _("Kernel memory interface"); }
+ const target_info &info () const override
+ { return bsd_kvm_target_info; }
- const char *doc () override
- {
- return _("Use a kernel virtual memory image as a target.\n\
-Optionally specify the filename of a core dump.");
- }
-
- void open (const char *, int) override;
void close () override;
void fetch_registers (struct regcache *, int) override;
ULONGEST *xfered_len) override;
void files_info () override;
- int thread_alive (ptid_t ptid) override;
- const char *pid_to_str (ptid_t) override;
+ bool thread_alive (ptid_t ptid) override;
+ std::string pid_to_str (ptid_t) override;
- int has_memory () override { return 1; }
- int has_stack () override { return 1; }
- int has_registers () override { return 1; }
+ bool has_memory () override { return true; }
+ bool has_stack () override { return true; }
+ bool has_registers () override { return true; }
};
/* Target ops for libkvm interface. */
static bsd_kvm_target bsd_kvm_ops;
static void
-bsd_kvm_target::open (const char *arg, int from_tty)
+bsd_kvm_target_open (const char *arg, int from_tty)
{
char errbuf[_POSIX2_LINE_MAX];
- char *execfile = NULL;
+ const char *execfile = NULL;
kvm_t *temp_kd;
char *filename = NULL;
if (arg)
{
- char *temp;
-
filename = tilde_expand (arg);
if (filename[0] != '/')
{
- temp = concat (current_directory, "/", filename, (char *)NULL);
+ gdb::unique_xmalloc_ptr<char> temp (gdb_abspath (filename));
+
xfree (filename);
- filename = temp;
+ filename = temp.release ();
}
}
}
inferior_ptid = null_ptid;
- delete_thread_silent (bsd_kvm_ptid);
+ discard_all_inferiors ();
}
static LONGEST
print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC, 1);
}
-int
+bool
bsd_kvm_target::thread_alive (ptid_t ptid)
{
- return 1;
+ return true;
}
-const char *
+std::string
bsd_kvm_target::pid_to_str (ptid_t ptid)
{
- static char buf[64];
- xsnprintf (buf, sizeof buf, "<kvm>");
- return buf;
+ return "<kvm>";
}
/* Add the libkvm interface to the list of all possible targets and
gdb_assert (bsd_kvm_supply_pcb == NULL);
bsd_kvm_supply_pcb = supply_pcb;
- add_target (&bsd_kvm_ops);
+ add_target (bsd_kvm_target_info, bsd_kvm_target_open);
add_prefix_cmd ("kvm", class_obscure, bsd_kvm_cmd, _("\
Generic command for manipulating the kernel memory interface."),
ptid (1, 1, 2) -> kvm inferior 1, process 2
ptid (1, 1, n) -> kvm inferior 1, process n */
- bsd_kvm_ptid = ptid_build (1, 1, 0);
+ bsd_kvm_ptid = ptid_t (1, 1, 0);
}