Skip to content

Commit

Permalink
Rename GdbCommand to DebuggerExtensionCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
rocallahan committed Jun 4, 2024
1 parent a757a9e commit 29e28f9
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ set(RR_SOURCES
src/FileNameCommand.cc
src/Flags.cc
src/ftrace.cc
src/GdbCommand.cc
src/DebuggerExtensionCommand.cc
src/DebuggerExtensionCommandHandler.cc
src/GdbServerConnection.cc
src/GdbServerExpression.cc
Expand Down
8 changes: 4 additions & 4 deletions scripts/rr-gdb-script-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def strip_prefix(s: str, needle: str) -> Optional[str]:

GdbNewObjfileEventCallback = Callable[[object], None]

class GdbCommand:
class DebuggerExtensionCommand:
def __init__(self, *args, **kwargs):
logging.debug("GdbCommand(%s, %s)" % (args, kwargs))
logging.debug("DebuggerExtensionCommand(%s, %s)" % (args, kwargs))

class GdbScriptHost:
""" The filename of the main symbol file """
Expand Down Expand Up @@ -166,8 +166,8 @@ def COMMAND_USER(self) -> int:
return 13

@property
def Command(self) -> GdbCommand:
return GdbCommand
def Command(self) -> DebuggerExtensionCommand:
return DebuggerExtensionCommand

if __name__ == '__main__':
with open(sys.argv[1], 'r') as user_script_file:
Expand Down
24 changes: 12 additions & 12 deletions src/GdbCommand.cc → src/DebuggerExtensionCommand.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- Mode: C++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#include "GdbCommand.h"
#include "DebuggerExtensionCommand.h"

#include "ReplayTask.h"
#include "log.h"
Expand All @@ -9,7 +9,7 @@ using namespace std;

namespace rr {

static SimpleGdbCommand elapsed_time(
static SimpleDebuggerExtensionCommand elapsed_time(
"elapsed-time",
"Print elapsed time (in seconds) since the start of the trace, in the"
" 'record' timeline.",
Expand All @@ -25,7 +25,7 @@ static SimpleGdbCommand elapsed_time(
return string("Elapsed Time (s): ") + to_string(elapsed_time);
});

static SimpleGdbCommand when(
static SimpleDebuggerExtensionCommand when(
"when", "Print the number of the last completely replayed rr event.",
[](GdbServer&, Task* t, const vector<string>&) {
if (!t->session().is_replaying()) {
Expand All @@ -38,7 +38,7 @@ static SimpleGdbCommand when(
static_cast<ReplayTask*>(t)->current_trace_frame().time() - 1);
});

static SimpleGdbCommand when_ticks(
static SimpleDebuggerExtensionCommand when_ticks(
"when-ticks", "Print the current rr tick count for the current thread.",
[](GdbServer&, Task* t, const vector<string>&) {
if (!t->session().is_replaying()) {
Expand All @@ -47,7 +47,7 @@ static SimpleGdbCommand when_ticks(
return string("Current tick: ") + to_string(t->tick_count());
});

static SimpleGdbCommand when_tid(
static SimpleDebuggerExtensionCommand when_tid(
"when-tid", "Print the real tid for the current thread.",
[](GdbServer&, Task* t, const vector<string>&) {
if (!t->session().is_replaying()) {
Expand All @@ -59,7 +59,7 @@ static SimpleGdbCommand when_tid(
static std::vector<ReplayTimeline::Mark> back_stack;
static ReplayTimeline::Mark current_history_cp;
static std::vector<ReplayTimeline::Mark> forward_stack;
static SimpleGdbCommand rr_history_push(
static SimpleDebuggerExtensionCommand rr_history_push(
"rr-history-push", "Push an entry into the rr history.",
[](GdbServer& gdb_server, Task* t, const vector<string>&) {
if (!gdb_server.timeline()) {
Expand All @@ -76,7 +76,7 @@ static SimpleGdbCommand rr_history_push(
forward_stack.clear();
return string();
});
static SimpleGdbCommand back(
static SimpleDebuggerExtensionCommand back(
"back", "Go back one entry in the rr history.",
[](GdbServer& gdb_server, Task* t, const vector<string>&) {
if (!gdb_server.timeline()) {
Expand All @@ -94,7 +94,7 @@ static SimpleGdbCommand back(
gdb_server.timeline()->seek_to_mark(current_history_cp);
return string();
});
static SimpleGdbCommand forward(
static SimpleDebuggerExtensionCommand forward(
"forward", "Go forward one entry in the rr history.",
[](GdbServer& gdb_server, Task* t, const vector<string>&) {
if (!gdb_server.timeline()) {
Expand Down Expand Up @@ -135,7 +135,7 @@ string invoke_checkpoint(GdbServer& gdb_server, Task*,
*gdb_server.timeline(), gdb_server.last_continue_task, e, where);
return string("Checkpoint ") + to_string(checkpoint_id) + " at " + where;
}
static SimpleGdbCommand checkpoint(
static SimpleDebuggerExtensionCommand checkpoint(
"checkpoint",
"create a checkpoint representing a point in the execution\n"
"use the 'restart' command to return to the checkpoint",
Expand All @@ -161,7 +161,7 @@ string invoke_delete_checkpoint(GdbServer& gdb_server, Task*,
return string("No checkpoint number ") + to_string(id) + ".";
}
}
static SimpleGdbCommand delete_checkpoint(
static SimpleDebuggerExtensionCommand delete_checkpoint(
"delete checkpoint",
"remove a checkpoint created with the 'checkpoint' command",
invoke_delete_checkpoint);
Expand All @@ -178,12 +178,12 @@ string invoke_info_checkpoints(GdbServer& gdb_server, Task*,
}
return out;
}
static SimpleGdbCommand info_checkpoints(
static SimpleDebuggerExtensionCommand info_checkpoints(
"info checkpoints",
"list all checkpoints created with the 'checkpoint' command",
invoke_info_checkpoints);

/*static*/ void GdbCommand::init_auto_args() {
/*static*/ void DebuggerExtensionCommand::init_auto_args() {
checkpoint.add_auto_arg("rr-where");
}

Expand Down
18 changes: 9 additions & 9 deletions src/GdbCommand.h → src/DebuggerExtensionCommand.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- Mode: C++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#ifndef RR_GDB_COMMAND_H_
#define RR_GDB_COMMAND_H_
#ifndef RR_DEBUGGER_EXTENSION_COMMAND_H_
#define RR_DEBUGGER_EXTENSION_COMMAND_H_

#include "DebuggerExtensionCommandHandler.h"
#include "GdbServer.h"
Expand All @@ -12,15 +12,15 @@

namespace rr {

class GdbCommand {
class DebuggerExtensionCommand {
protected:
GdbCommand(const std::string& cmd_name, const std::string& documentation)
DebuggerExtensionCommand(const std::string& cmd_name, const std::string& documentation)
: cmd_name(cmd_name), documentation(documentation) {
DebuggerExtensionCommandHandler::register_command(*this);
}

public:
virtual ~GdbCommand() {}
virtual ~DebuggerExtensionCommand() {}

const std::string& name() const { return cmd_name; }
const std::string& docs() const { return documentation; }
Expand Down Expand Up @@ -56,13 +56,13 @@ class GdbCommand {
std::vector<std::string> cmd_auto_args;
};

class SimpleGdbCommand : public GdbCommand {
class SimpleDebuggerExtensionCommand : public DebuggerExtensionCommand {
public:
SimpleGdbCommand(
SimpleDebuggerExtensionCommand(
const std::string& cmd_name, const std::string& documentation,
const std::function<std::string(
GdbServer&, Task* t, const std::vector<std::string>&)>& invoker)
: GdbCommand(cmd_name, documentation), invoker(invoker) {}
: DebuggerExtensionCommand(cmd_name, documentation), invoker(invoker) {}

virtual std::string invoke(GdbServer& gdb_server, Task* t,
const std::vector<std::string>& args) override {
Expand All @@ -76,4 +76,4 @@ class SimpleGdbCommand : public GdbCommand {

} // namespace rr

#endif
#endif /* RR_DEBUGGER_EXTENSION_COMMAND_H_ */
16 changes: 8 additions & 8 deletions src/DebuggerExtensionCommandHandler.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- Mode: C++; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#include "DebuggerExtensionCommandHandler.h"
#include "GdbCommand.h"
#include "DebuggerExtensionCommand.h"
#include "log.h"

#include <sstream>
Expand All @@ -13,9 +13,9 @@ namespace rr {

// HashMap would be better here but the unordered_map API is annoying
// and linear search is fine.
static vector<GdbCommand*>* gdb_command_list;
static vector<DebuggerExtensionCommand*>* gdb_command_list;

static string gdb_macro_binding(const GdbCommand& cmd) {
static string gdb_macro_binding(const DebuggerExtensionCommand& cmd) {
string auto_args_str = "[";
for (size_t i = 0; i < cmd.auto_args().size(); i++) {
if (i > 0) {
Expand All @@ -32,7 +32,7 @@ static string gdb_macro_binding(const GdbCommand& cmd) {
}

/* static */ string DebuggerExtensionCommandHandler::gdb_macros() {
GdbCommand::init_auto_args();
DebuggerExtensionCommand::init_auto_args();
stringstream ss;
ss << string(R"Delimiter(
Expand Down Expand Up @@ -186,7 +186,7 @@ end
return ss.str();
}

/*static*/ GdbCommand* DebuggerExtensionCommandHandler::command_for_name(const string& name) {
/*static*/ DebuggerExtensionCommand* DebuggerExtensionCommandHandler::command_for_name(const string& name) {
if (!gdb_command_list) {
return nullptr;
}
Expand All @@ -198,10 +198,10 @@ end
return nullptr;
}

void DebuggerExtensionCommandHandler::register_command(GdbCommand& cmd) {
void DebuggerExtensionCommandHandler::register_command(DebuggerExtensionCommand& cmd) {
LOG(debug) << "registering command: " << cmd.name();
if (!gdb_command_list) {
gdb_command_list = new vector<GdbCommand*>();
gdb_command_list = new vector<DebuggerExtensionCommand*>();
}
gdb_command_list->push_back(&cmd);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ static string gdb_unescape(const string& str) {
args.push_back(gdb_unescape(arg));
}

GdbCommand* cmd = command_for_name(rr_cmd.name);
DebuggerExtensionCommand* cmd = command_for_name(rr_cmd.name);
if (!cmd) {
return gdb_escape(string() + "Command '" + rr_cmd.name + "' not found.\n");
}
Expand Down
6 changes: 3 additions & 3 deletions src/DebuggerExtensionCommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace rr {

class GdbCommand;
class DebuggerExtensionCommand;
class GdbServer;
class Task;

Expand All @@ -23,7 +23,7 @@ class DebuggerExtensionCommandHandler {
// wrapper code.
static std::string gdb_macros();

static void register_command(GdbCommand& cmd);
static void register_command(DebuggerExtensionCommand& cmd);

/**
* Process an incoming GDB payload of the following form:
Expand All @@ -35,7 +35,7 @@ class DebuggerExtensionCommandHandler {
static std::string process_command(GdbServer& gdb_server, Task* t,
const GdbRequest::RRCmd& rr_cmd);

static GdbCommand* command_for_name(const std::string& name);
static DebuggerExtensionCommand* command_for_name(const std::string& name);

/**
* Special return value for commands that immediately end a diversion session
Expand Down
2 changes: 1 addition & 1 deletion src/GdbServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace rr {

class GdbServer {
// Not ideal but we can't inherit friend from GdbCommand
// Not ideal but we can't inherit friend from DebuggerExtensionCommand
friend std::string invoke_checkpoint(GdbServer&, Task*,
const std::vector<std::string>&);
friend std::string invoke_delete_checkpoint(GdbServer&, Task*,
Expand Down

0 comments on commit 29e28f9

Please sign in to comment.