Remove tracer (debugger "heaptrace" command)
[hiphop-php.git] / hphp / runtime / debugger / cmd / cmd_macro.cpp
blob5dae65a95e2ae1992ea5252b33257ccbe5226ff5
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/debugger/cmd/cmd_macro.h"
19 namespace HPHP { namespace Eval {
20 ///////////////////////////////////////////////////////////////////////////////
22 TRACE_SET_MOD(debugger);
24 void CmdMacro::list(DebuggerClient &client) {
25 if (client.argCount() == 0) {
26 static const char *keywords[] =
27 { "start", "end", "replay", "list", "clear", nullptr};
28 client.addCompletion(keywords);
32 void CmdMacro::help(DebuggerClient &client) {
33 client.helpTitle("Macro Command");
34 client.helpCmds(
35 "& [s]tart", "starts recording of default macro",
36 "& [s]tart {name}", "starts recording of a named macro",
37 "& [e]nd", "stops and saves recorded macro",
38 "& [r]eplay", "replays default macro",
39 "& [r]eplay {name}", "replays a named macro",
40 "& [l]ist", "lists all macros",
41 "& [c]lear {index}", "deletes a macro",
42 nullptr
44 client.helpBody(
45 "Macro command allows you to record a series of debugger command, so "
46 "you can replay later by its name. When name is not specified, it will "
47 "use \"default\" as the name.\n"
48 "\n"
49 "There is also a special macro \"startup\" that will be replayed "
50 "every time when debugger is just started. Use startup macro to load "
51 "certain PHP files or perform certain debugging environment setup.\n"
52 "\n"
53 "The space between & and command is not needed. '&s' works as well."
57 void CmdMacro::processList(DebuggerClient &client) {
58 const auto& macros = client.getMacros();
59 for (unsigned int i = 0; i < macros.size(); i++) {
60 auto macro = macros[i];
61 client.output("%4d %s", i + 1, macro->m_name.c_str());
62 client.print("%s", macro->desc(" > ").c_str());
66 void CmdMacro::onClient(DebuggerClient &client) {
67 if (DebuggerCommand::displayedHelp(client)) return;
68 if (client.argCount() == 0) {
69 help(client);
70 return;
73 if (client.arg(1, "start")) {
74 client.startMacro(client.argValue(2));
75 } else if (client.arg(1, "end")) {
76 client.endMacro();
77 } else if (client.arg(1, "replay")) {
78 if (!client.playMacro(client.argValue(2))) {
79 client.error("Unable to find specified macro.");
80 processList(client);
82 } else if (client.arg(1, "list")) {
83 processList(client);
84 } else if (client.arg(1, "clear")) {
85 std::string snum = client.argValue(2);
86 if (!DebuggerClient::IsValidNumber(snum)) {
87 client.error("'& [c]lear' needs an {index} argument.");
88 client.tutorial(
89 "You will have to run '& [l]ist' first to see a list of valid "
90 "numbers or indices to specify."
92 return;
95 int num = atoi(snum.c_str());
96 if (!client.deleteMacro(num)) {
97 client.error("\"%s\" is not a valid macro index. Choose one from "
98 "this list:", snum.c_str());
99 processList(client);
100 return;
105 ///////////////////////////////////////////////////////////////////////////////