Ejemplo n.º 1
0
void CmdFlowControl::onClient(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;

  client.setFrame(0);

  if (client.argCount() > 1) {
    help(client);
    return;
  }

  if (client.argCount() == 1) {
    std::string snum = client.argValue(1);
    if (!DebuggerClient::IsValidNumber(snum)) {
      client.error("Count needs to be a number.");
      return;
    }

    m_count = atoi(snum.c_str());
    if (m_count < 1) {
      client.error("Count needs to be a positive number.");
      return;
    }
  }
  m_smallStep = client.getDebuggerClientSmallStep();
  client.sendToServer(this);
  throw DebuggerConsoleExitException();
}
Ejemplo n.º 2
0
bool CmdMachine::AttachSandbox(DebuggerClient &client,
                               DSandboxInfoPtr sandbox,
                               bool force /* = false */) {
  if (client.isLocal()) {
    client.error("Local script doesn't have sandbox to attach to.");
    return false;
  }

  CmdMachine cmd;
  cmd.m_body = "attach";
  cmd.m_sandboxes.push_back(sandbox);
  cmd.m_force = force;

  client.info("Attaching to %s and pre-loading, please wait...",
               sandbox->desc().c_str());
  CmdMachinePtr cmdMachine = client.xend<CmdMachine>(&cmd);
  if (cmdMachine->m_succeed) {
    client.playMacro("startup");
  } else {
    // Note: it would be nice to give them more info about the process we think
    // is debugging this sandbox: what machine it's on, what it's pid is, etc.
    // Unfortunately, we don't have any of that data. We'd need a protocol
    // change to have the client give us more info when it attaches.
    client.error(
      "Failed to attach to the sandbox. Maybe another client is debugging, \n"
      "or a client failed to detach cleanly.\n"
      "You can attach to another sandbox, or exit the other attached client, \n"
      "or force this client to take over the sandbox with: \n"
      "\n"
      "\t[m]achine [a]ttach [f]orce %s %s"
      "\n",
      sandbox->m_user.c_str(), sandbox->m_name.c_str());
  }
  return cmdMachine->m_succeed;
}
Ejemplo n.º 3
0
bool CmdMachine::AttachSandbox(DebuggerClient &client,
                               DSandboxInfoPtr sandbox,
                               bool force /* = false */) {
  if (client.isLocal()) {
    client.error("Local script doesn't have sandbox to attach to.");
    return false;
  }

  CmdMachine cmd;
  cmd.m_body = "attach";
  cmd.m_sandboxes.push_back(sandbox);
  cmd.m_force = force;

  client.info("Attaching to %s and pre-loading, please wait...",
               sandbox->desc().c_str());
  CmdMachinePtr cmdMachine = client.xend<CmdMachine>(&cmd);
  if (cmdMachine->m_succeed) {
    client.playMacro("startup");
  } else {
    client.error("failed to attach to sandbox, maybe another client is "
                  "debugging, \nattach to another sandbox, exit the "
                  "attached hphpd client, or try \n"
                  "[m]achine [a]ttach [f]orce [%s] [%s]",
                  sandbox->m_user.c_str(), sandbox->m_name.c_str());
  }
  return cmdMachine->m_succeed;
}
Ejemplo n.º 4
0
void CmdWhere::onClientImpl(DebuggerClient &client) {
    if (DebuggerCommand::displayedHelp(client)) return;
    if (client.argCount() > 1) {
        help(client);
        return;
    }

    Array st = fetchStackTrace(client);
    if (st.empty()) {
        client.info("(no stacktrace to display or in global scope)");
        client.info("if you hit serialization limit, consider do "
                    "\"set sa off\" and then get the stack without args");
        return;
    }

    // so list command can default to current frame
    client.moveToFrame(client.getFrame(), false);

    if (client.argCount() == 0) {
        int i = 0;
        for (ArrayIter iter(st); iter; ++iter) {
            client.printFrame(i, iter.second().toArray());
            ++i;
            if (!client.isApiMode() &&
                    i % DebuggerClient::ScrollBlockSize == 0 &&
                    client.ask("There are %zd more frames. Continue? [Y/n]",
                               st.size() - i) == 'n') {
                break;
            }
        }
    } else {
        string snum = client.argValue(1);
        int num = atoi(snum.c_str());
        if (snum[0] == '-') {
            snum = snum.substr(1);
        }
        if (!DebuggerClient::IsValidNumber(snum)) {
            client.error("The argument, if specified, has to be numeric.");
            return;
        }
        if (num > 0) {
            for (int i = 0; i < num && i < st.size(); i++) {
                client.printFrame(i, st[i].toArray());
            }
        } else if (num < 0) {
            for (int i = st.size() + num; i < st.size(); i++) {
                client.printFrame(i, st[i].toArray());
            }
        } else {
            client.error("0 was specified for the number of frames");
            client.tutorial(
                "The optional argument is the number of frames to print out. "
                "Use a positive number to print out innermost frames. Use a negative "
                "number to print out outermost frames."
            );
        }
    }
}
Ejemplo n.º 5
0
void CmdInstrument::onClientImpl(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() == 1) {
    if (client.argValue(1) == "list" || client.argValue(1) == "l") {
      listInst(client);
      return;
    }
    if (client.argValue(1) == "clear" || client.argValue(1) == "c") {
      clearInst(client);
      return;
    }
  }
  if (client.argCount() < 2 || client.argValue(1) == "help") {
    help(client);
    return;
  }

  std::string loc = client.argValue(1);
  std::string file = client.argValue(2);
  std::string desc;
  if (client.argCount() >= 3) {
    desc = client.argValue(3);
  }
  Variant code = f_file_get_contents(file.c_str());
  if (code.isNull()) {
    client.error("Unable to read from file %s", file.c_str());
    return;
  }
  m_instPoints = client.getInstPoints();
  if (loc == "here") {
    InstPointInfoPtr ipi(new InstPointInfo());
    ipi->setLocHere();
    ipi->m_code = (std::string) code.toString();
    ipi->m_desc = desc;
    m_instPoints->push_back(ipi);
  } else if (loc.rfind("()") == loc.size() - 2){
    InstPointInfoPtr ipi(new InstPointInfo());
    ipi->setLocFuncEntry(loc.substr(0, loc.size() - 2));
    ipi->m_code = (std::string) code.toString();
    ipi->m_desc = desc;
    m_instPoints->push_back(ipi);
  } else {
    client.error("Not implemented\n");
    return;
  }
  m_type = ActionWrite;
  CmdInstrumentPtr instCmdPtr = client.xend<CmdInstrument>(this);
  if (!instCmdPtr->m_enabled) {
    client.error("Instrumentation is not enabled on the server");
  }
  client.setInstPoints(instCmdPtr->m_ips);
  CmdInstrument::PrintInstPoints(client);
}
Ejemplo n.º 6
0
void CmdPrint::onClientImpl(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() == 0) {
    help(client);
    return;
  }

  int index = 1;
  if (client.arg(1, "always")) {
    m_isForWatch = true;
    if (client.argCount() == 1) {
      client.error("'[p]rint [a]lways' needs an expression to watch.");
      return;
    }
    index++;
  } else if (client.arg(1, "list")) {
    m_isForWatch = true;
    processList(client);
    return;
  } else if (client.arg(1, "clear")) {
    m_isForWatch = true;
    processClear(client);
    return;
  }

  const char *format = nullptr;
  for (const char **fmt = Formats; *fmt; fmt++) {
    if (client.arg(index, *fmt)) {
      format = *fmt;
      index++;
      break;
    }
  }
  m_body = client.lineRest(index);
  if (m_isForWatch) {
    client.addWatch(format, m_body);
    return;
  }
  m_bypassAccessCheck = client.getDebuggerBypassCheck();
  m_printLevel = client.getDebuggerPrintLevel();
  assert(m_printLevel <= 0 || m_printLevel >= DebuggerClient::MinPrintLevel);
  m_frame = client.getFrame();
  CmdPrintPtr res = client.xend<CmdPrint>(this);
  if (!res->is(m_type)) {
    assert(client.isApiMode());
    m_incomplete = true;
    res->setClientOutput(client);
  } else {
    m_output = res->m_output;
    m_ret = res->m_ret;
    if (!m_output.empty()) {
      client.output(m_output);
    }
    client.output(FormatResult(format, m_ret));
  }
}
Ejemplo n.º 7
0
void CmdExtension::onClient(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  m_args = *client.args();
  auto cmd = client.xend<CmdExtension>(this);
  if (cmd->m_out.empty()) {
    client.error(cmd->m_err);
  } else {
    client.print(cmd->m_out);
  }
}
Ejemplo n.º 8
0
// If there is no current file, print the desired range of eval code
// or give an error message if the debugger is not currently performing
// an eval command.
void CmdList::listEvalCode(DebuggerClient &client) {
  assert(m_file.empty());

  std::string evalCode = client.getCode();
  if (evalCode.empty()) {
    client.error("There is no current source file.");
  } else {
    client.print(highlight_php(evalCode));
  }
}
Ejemplo n.º 9
0
static String format_string(DebuggerClient &client,
                            int _argc, CStrRef format, CArrRef _argv) {
  TRACE(5, "c_DebuggerClientCmdUser::format_string\n");
  Variant ret = f_sprintf(_argc, format, _argv);
  if (ret.isString()) {
    return ret.toString();
  }
  client.error("Debugger extension failed to format string: %s",
                 format.data());
  return "";
}
Ejemplo n.º 10
0
void CmdMacro::onClientImpl(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() == 0) {
    help(client);
    return;
  }

  if (client.arg(1, "start")) {
    client.startMacro(client.argValue(2));
  } else if (client.arg(1, "end")) {
    client.endMacro();
  } else if (client.arg(1, "replay")) {
    if (!client.playMacro(client.argValue(2))) {
      client.error("Unable to find specified macro.");
      processList(client);
    }
  } else if (client.arg(1, "list")) {
    processList(client);
  } else if (client.arg(1, "clear")) {
    string snum = client.argValue(2);
    if (!DebuggerClient::IsValidNumber(snum)) {
      client.error("'& [c]lear' needs an {index} argument.");
      client.tutorial(
        "You will have to run '& [l]ist' first to see a list of valid "
        "numbers or indices to specify."
      );
      return;
    }

    int num = atoi(snum.c_str());
    if (!client.deleteMacro(num)) {
      client.error("\"%s\" is not a valid macro index. Choose one from "
                    "this list:", snum.c_str());
      processList(client);
      return;
    }
  }
}
Ejemplo n.º 11
0
void CmdPrint::processClear(DebuggerClient &client) {
  DebuggerClient::WatchPtrVec &watches = client.getWatches();
  if (watches.empty()) {
    client.error("There is no watch expression to clear.");
    client.tutorial(
      "Use '[p]rint [a]lways ...' to set new watch expressions. "
      "Use '[p]rint ?|[h]elp' to read how to set them. "
    );
    return;
  }

  if (client.arg(2, "all")) {
    watches.clear();
    client.info("All watch expressions are cleared.");
    return;
  }

  string snum = client.argValue(2);
  if (!DebuggerClient::IsValidNumber(snum)) {
    client.error("'[p]rint [c]lear' needs an {index} argument.");
    client.tutorial(
      "You will have to run '[p]rint [l]ist' first to see a list of valid "
      "numbers or indices to specify."
    );
    return;
  }

  int num = atoi(snum.c_str()) - 1;
  if (num < 0 || num >= (int)watches.size()) {
    client.error("\"%s\" is not a valid index. Choose one from this list:",
                  snum.c_str());
    processList(client);
    return;
  }

  watches.erase(watches.begin() + num);
}
Ejemplo n.º 12
0
void CmdThread::onClient(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() > 1) {
    help(client);
    return;
  }

  if (client.argCount() == 0) {
    m_body = "info";
    auto res = client.xend<CmdThread>(this);
    client.print(res->m_out);
  } else if (client.arg(1, "list")) {
    processList(client);
  } else if (client.arg(1, "normal")) {
    m_body = "normal";
    client.sendToServer(this);
    client.info("Thread is running in normal mode now. Other threads will "
                 "interleave when they hit breakpoints as well.");
  } else if (client.arg(1, "sticky")) {
    m_body = "sticky";
    client.sendToServer(this);
    client.info("Thread is running in sticky mode now. All other threads "
                 "will wait until this thread finishes, when they hit "
                 "breakpoints.");
  } else if (client.arg(1, "exclusive")) {
    m_body = "exclusive";
    client.sendToServer(this);
    client.info("Thread is running in exclusive mode now. All other threads "
                 "will not break, even when they hit breakpoints.");
  } else {
    std::string snum = client.argValue(1);
    if (!DebuggerClient::IsValidNumber(snum)) {
      client.error("'[t]hread {index}' needs a numeric argument.");
      client.tutorial(
        "You will have to run '[t]hread [l]ist' first to see a list of valid "
        "numbers or indices to specify. Thread 1 is always your current "
        "thread. If that's the only thread on the list, you do not have "
        "another thread at break to switch to."
      );
      return;
    }

    int num = atoi(snum.c_str());
    DThreadInfoPtr thread = client.getThread(num);
    if (!thread) {
      processList(client, false);
      thread = client.getThread(num);
      if (!thread) {
        client.error("\"%s\" is not a valid thread index. Choose one from "
                      "this list:", snum.c_str());
        processList(client);
        return;
      }
    }

    if (thread->m_id == client.getCurrentThreadId()) {
      client.info("This is your current thread already.");
      return;
    }

    m_body = "switch";
    m_threads.push_back(thread);
    client.sendToServer(this);
    throw DebuggerConsoleExitException();
  }
}
Ejemplo n.º 13
0
void CmdConfig::onClient(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() == 0) {
    listVars(client);
    return;
  }
  std::string var = client.argValue(1);
  if (var == "help" || client.argCount() < 2) {
    help(client);
    return;
  }

  std::string value = client.argValue(2);
  if (var == "BypassAccessCheck" || var == "bac") {
    if (value == "on") {
      client.print("BypassAccessCheck(bac) set to on.\n"
                    "All code executed from debugger is bypassing "
                    "access check!");
      client.setDebuggerClientBypassCheck(true);
    } else if (value == "off") {
      client.print("BypassAccessCheck(bac) set to off");
      client.setDebuggerClientBypassCheck(false);
    } else {
      help(client);
    }
    return;
  }
  if (var == "LogFile" || var == "lf") {
    // Close the current log file handler
    FILE *f = client.getLogFileHandler();
    if (f != nullptr) {
      fclose(f);
      client.setLogFileHandler(nullptr);
    }

    if (value == "off") {
      value = "";
    } else {
      // Try open the log file and error if it's not working
      f = fopen(value.c_str(), "a");
      if (f == nullptr) {
        client.error("Cannot open log file '%s'",
          value.c_str());
        value = "";
        client.setLogFileHandler(nullptr);
      } else {
        client.setLogFileHandler(f);
      }
    }
    client.print("LogFile(lf) is set to %s", value == "" ? "off"
                                                          : value.c_str());
    client.setLogFile(value);
    return;
  }
  if (var == "PrintLevel" || var == "pl") {
    int pl = strtol(value.c_str(), nullptr, 10);
    if (pl > 0 && pl < DebuggerClient::MinPrintLevel) {
      client.error("%d is invalid for PrintLevel(pl)", pl);
      return;
    }
    client.setDebuggerClientPrintLevel(pl);
    client.print("PrintLevel(pl) is set to %d", pl);
    return;
  }
  if (var == "ShortPrintCharCount" || var == "cc") {
    int cc = strtol(value.c_str(), nullptr, 10);
    if (cc < -1) {
      client.error("%d is invalid for ShortPrintCharCount(cc)", cc);
    } else {
      client.setDebuggerClientShortPrintCharCount(cc);
      client.print("ShortPrintCharCount(cc) is set to %d", cc);
    }
    return;
  }
  if (var == "SmallStep" || var == "ss") {
    if (value == "on") {
      client.print("SmallStep(ss) set to on.\n");
      client.setDebuggerClientSmallStep(true);
    } else if (value == "off") {
      client.print("SmallStep(ss) set to off");
      client.setDebuggerClientSmallStep(false);
    } else {
      help(client);
    }
    return;
  }
  if (var == "StackArgs" || var == "sa") {
    if (value == "on") {
      client.print("StackArgs(sa) set to on.\n");
      client.setDebuggerClientStackArgs(true);
    } else if (value == "off") {
      client.print("StackArgs(sa) set to off");
      client.setDebuggerClientStackArgs(false);
    } else {
      help(client);
    }
    return;
  }
  if (var == "MaxCodeLines" || var == "mcl") {
    // MaxCodeLines: a useful configuration variable for emacs/hphpd-integration
    // to prevent or limit code spew after each breakpoint is hit (since emacs
    // hphpd-mode already loads the source file into a buffer and displays a
    // pointer to the current line).
    int mcl = strtol(value.c_str(), nullptr, 10);
    if (mcl < -1) {
      client.error("%d is invalid for MaxCodeLines(mcl)", mcl);
    } else {
      client.setDebuggerClientMaxCodeLines(mcl);
      client.print("MaxCodeLines(mcl) is set to %d", mcl);
    }
    return;
  }

  listVars(client);
}
Ejemplo n.º 14
0
void CmdMachine::onClientImpl(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() == 0) {
    help(client);
    return;
  }

  bool rpc = client.arg(1, "rpc");
  if (rpc || client.arg(1, "connect")) {
    if (client.argCount() != 2) {
      help(client);
      return;
    }
    string host = client.argValue(2);
    int port = 0;
    size_t pos = host.find(":");
    if (pos != string::npos) {
      if (!DebuggerClient::IsValidNumber(host.substr(pos + 1))) {
        client.error("Port needs to be a number");
        help(client);
        return;
      }
      port = atoi(host.substr(pos + 1).c_str());
      host = host.substr(0, pos);
    }

    if (rpc) {
      if (client.connectRPC(host, port)) {
        throw DebuggerConsoleExitException();
      }
    } else {
      if (client.connect(host, port)) {
        throw DebuggerConsoleExitException();
      }
    }
    if (!client.initializeMachine()) {
      throw DebuggerConsoleExitException();
    }
    return;
  }

  if (client.arg(1, "disconnect")) {
    if (client.disconnect()) {
      throw DebuggerConsoleExitException();
    }
    if (!client.initializeMachine()) {
      throw DebuggerConsoleExitException();
    }
    return;
  }

  if (client.arg(1, "list")) {
    processList(client);
    return;
  }

  if (client.arg(1, "attach")) {
    DSandboxInfoPtr sandbox;

    string snum = client.argValue(2);
    if (DebuggerClient::IsValidNumber(snum)) {
      int num = atoi(snum.c_str());
      sandbox = client.getSandbox(num);
      if (!sandbox) {
        processList(client, false);
        sandbox = client.getSandbox(num);
        if (!sandbox) {
          client.error("\"%s\" is not a valid sandbox index. Choose one from "
                        "this list:", snum.c_str());
          processList(client);
          return;
        }
      }
    } else {
      int argBase = 2;
      if (client.argCount() >= 2 && client.arg(2, "force")) {
        m_force = true;
        argBase++;
      }
      sandbox = DSandboxInfoPtr(new DSandboxInfo());
      if (client.argCount() < argBase) {
        sandbox->m_user = client.getCurrentUser();
        sandbox->m_name = "default";
      } else if (client.argCount() == argBase) {
        sandbox->m_user = client.getCurrentUser();
        sandbox->m_name = client.argValue(argBase);
      } else if (client.argCount() == argBase + 1) {
        sandbox->m_user = client.argValue(argBase);
        sandbox->m_name = client.argValue(argBase + 1);
      } else {
        help(client);
        return;
      }
    }
    if (AttachSandbox(client, sandbox, m_force)) {
      // Attach succeed, wait for next interrupt
      throw DebuggerConsoleExitException();
    }
    return;
  }

  help(client);
}
Ejemplo n.º 15
0
// Checks the command arguments, report errors and returning as appropriate.
// Then communicates with the server to retrieve source information. Also
// retrieves and updates location information stored in the client.
void CmdList::onClient(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() > 1) {
    help(client);
    return;
  }

  int line = 0;
  m_line1 = m_line2 = 0;
  if (client.argCount() == 1) {
    std::string arg = client.argValue(1);
    if (DebuggerClient::IsValidNumber(arg)) {
      line = atoi(arg.c_str());
      if (line <= 0) {
        client.error("A line number has to be a positive integer.");
        help(client);
        return;
      }
      m_line1 = line - DebuggerClient::CodeBlockSize/2;
      m_line2 = m_line1 + DebuggerClient::CodeBlockSize;
    } else if (arg.find("::") != std::string::npos) {
      if (!listFunctionOrClass(client)) {
        client.error("Unable to read specified method.");
      }
      return;
    } else {
      size_t pos = arg.find(':');
      if (pos != std::string::npos) {
        m_file = arg.substr(0, pos);
        if (m_file.empty()) {
          client.error("File name cannot be empty.");
          help(client);
          return;
        }
        arg = arg.substr(pos + 1);
      }
      pos = arg.find('-');
      if (pos != std::string::npos) {
        std::string line1 = arg.substr(0, pos);
        std::string line2 = arg.substr(pos + 1);
        if (!DebuggerClient::IsValidNumber(line1) ||
            !DebuggerClient::IsValidNumber(line2)) {
          if (m_file.empty()) {
            m_file = arg;
            m_line1 = 1;
            m_line2 = DebuggerClient::CodeBlockSize;
          } else {
            client.error("Line numbers have to be integers.");
            help(client);
            return;
          }
        } else {
          m_line1 = atoi(line1.c_str());
          m_line2 = atoi(line2.c_str());
          if (line1.empty()) {
            m_line1 = m_line2 - DebuggerClient::CodeBlockSize;
          }
          if (line2.empty()) {
            m_line2 = m_line1 + DebuggerClient::CodeBlockSize;
          }
          if (m_line1 <= 0 || m_line2 <= 0) {
            client.error("Line numbers have to be positive integers.");
            help(client);
            return;
          }
        }
      } else {
        if (!DebuggerClient::IsValidNumber(arg)) {
          if (m_file.empty()) {
            if (client.argCount() == 1 && listFunctionOrClass(client)) {
              return;
            }
            m_file = arg;
            m_line1 = 1;
            m_line2 = DebuggerClient::CodeBlockSize;
          } else {
            client.error("A line number has to be an integer.");
            help(client);
            return;
          }
        } else {
          int line = atoi(arg.c_str());
          if (line <= 0) {
            client.error("A line number has to be a positive integer.");
            help(client);
            return;
          }
          m_line1 = line - DebuggerClient::CodeBlockSize/2;
          m_line2 = m_line1 + DebuggerClient::CodeBlockSize;
        }
      }
    }
  }

  int charFocus0 = 0;
  int lineFocus1 = 0;
  int charFocus1 = 0;

  if (m_file.empty()) {
    getListLocation(client, line, charFocus0, lineFocus1, charFocus1);
    if (m_file.empty()) {
      listEvalCode(client);
      return;
    }
  } else if (m_file[0] == '/') {
    struct stat sb;
    stat(m_file.c_str(), &sb);
    if ((sb.st_mode & S_IFMT) == S_IFDIR) {
      client.setSourceRoot(m_file);
      client.info("PHP source root directory is set to %s", m_file.c_str());
      return;
    }
  }

   if (!listFileRange(client, line, charFocus0, lineFocus1, charFocus1)) {
     client.error(
       "Unable to read specified function, class or source file location.");
  }
}
Ejemplo n.º 16
0
void CmdWhere::onClient(DebuggerClient &client) {
  if (DebuggerCommand::displayedHelp(client)) return;
  if (client.argCount() > 2) {
    help(client);
    return;
  }
  int argBase = 1;
  if ((client.argCount() > 0) && client.arg(argBase, "async")) {
    // We use a different command type for an async stack trace, so we
    // can both send and receive different data and still keep the
    // existing Where command unchanged. This ensures that old clients
    // can still get a stack trace from a newer server, and vice
    // versa.
    m_type = KindOfWhereAsync;
    argBase++;
    client.info("Fetching async stacktrace...");
  }

  Array st = fetchStackTrace(client);
  if (st.empty()) {
    if (m_type != KindOfWhereAsync) {
      client.info("(no stacktrace to display or in global scope)");
      client.info("If you hit the serialization limit, try "
                  "\"set sa off\" to get the stack without args");
    } else {
      client.info("(no async stacktrace to display)");
    }
    return;
  }

  // so list command can default to current frame
  client.moveToFrame(client.getFrame(), false);

  if (client.argCount() < argBase) {
    int i = 0;
    for (ArrayIter iter(st); iter; ++iter) {
      client.printFrame(i, iter.second().toArray());
      ++i;
      if (i % DebuggerClient::ScrollBlockSize == 0 &&
          client.ask("There are %zd more frames. Continue? [Y/n]",
                      st.size() - i) == 'n') {
        break;
      }
    }
  } else {
    std::string snum = client.argValue(argBase);
    int num = atoi(snum.c_str());
    if (snum[0] == '-') {
      snum = snum.substr(1);
    }
    if (!DebuggerClient::IsValidNumber(snum)) {
      client.error("The argument, if specified, has to be numeric.");
      return;
    }
    if (num > 0) {
      for (int i = 0; i < num && i < st.size(); i++) {
        client.printFrame(i, st[i].toArray());
      }
    } else if (num < 0) {
      for (int i = st.size() + num; i < st.size(); i++) {
        client.printFrame(i, st[i].toArray());
      }
    } else {
      client.error("0 was specified for the number of frames");
      client.tutorial(
        "The optional argument is the number of frames to print out. "
        "Use a positive number to print out innermost frames. Use a negative "
        "number to print out outermost frames."
      );
    }
  }
}
Ejemplo n.º 17
0
void CmdInterrupt::onClient(DebuggerClient &client) {
  client.setCurrentLocation(m_threadId, m_bpi);
  if (!client.getDebuggerClientSmallStep()) {
    // Adjust line and char if it's not small stepping
    if (m_bpi->m_line1 == m_bpi->m_line2) {
      m_bpi->m_char1 = 1;
      m_bpi->m_char2 = 100;
    }
  }
  client.setMatchedBreakPoints(m_matched);

  switch (m_interrupt) {
    case SessionStarted:
      if (!m_program.empty()) {
        client.info("Program %s loaded. Type '[r]un' or '[c]ontinue' to go.",
                     m_program.c_str());
        m_bpi->m_file = m_program;
      }
      break;
    case SessionEnded:
      if (!m_program.empty()) {
        client.info("Program %s exited normally.", m_program.c_str());
      }
      break;
    case RequestStarted:
      if (!m_program.empty()) {
        client.info("Web request %s started.", m_program.c_str());
      }
      break;
    case RequestEnded:
      if (!m_program.empty()) {
        client.info("Web request %s ended.", m_program.c_str());
      }
      break;
    case PSPEnded:
      if (!m_program.empty()) {
        client.info("Post-Send Processing for %s was ended.",
                     m_program.c_str());
      }
      break;
    case HardBreakPoint:
    case BreakPointReached:
    case ExceptionThrown: {
      bool found = false;
      bool toggled = false;
      auto *bps = client.getBreakPoints();
      for (unsigned int i = 0; i < m_matched.size(); i++) {
        BreakPointInfoPtr bpm = m_matched[i];
        BreakPointInfoPtr bp;
        int index = 0;
        for (; index < (int)bps->size(); index++) {
          if (bpm->same((*bps)[index])) {
            bp = (*bps)[index];
            break;
          }
        }
        if (bp) {
          found = true;
          if (bp->m_state == BreakPointInfo::Once) {
            bp->m_state = BreakPointInfo::Disabled;
            toggled = true;
          }
          if (m_interrupt == BreakPointReached ||
              m_interrupt == HardBreakPoint) {
            client.info("Breakpoint %d reached %s", bp->index(),
                         m_bpi->site().c_str());
            client.shortCode(m_bpi);
          } else {
            if (m_bpi->m_exceptionClass == BreakPointInfo::ErrorClassName) {
              client.info("Breakpoint %d reached: An error occurred %s",
                           bp->index(), m_bpi->site().c_str());
              client.shortCode(m_bpi);
              client.error("Error Message: %s",
                            m_bpi->m_exceptionObject.c_str());
            } else {
              client.info("Breakpoint %d reached: Throwing %s %s",
                           bp->index(),
                           m_bpi->m_exceptionClass.c_str(),
                           m_bpi->site().c_str());
              client.shortCode(m_bpi);
              if (client.getLogFileHandler()) {
                client.output(m_bpi->m_exceptionObject);
              }
            }
          }
          if (!bpm->m_output.empty()) {
            client.print(bpm->m_output);
          }
        }
      }
      if (toggled) {
        CmdBreak::SendClientBreakpointListToServer(client);
      }
      if (!found) {
        if (m_interrupt == HardBreakPoint) {
          // for HardBreakPoint, default the frame to the caller
          client.setFrame(1);
        }
        client.info("Break %s", m_bpi->site().c_str());
        client.shortCode(m_bpi);
      }
      break;
    }
  }

  if (!m_errorMsg.empty()) {
    client.error(m_errorMsg);
  }

  // watches
  switch (m_interrupt) {
    case SessionStarted:
    case RequestStarted:
      break;
    default: {
      DebuggerClient::WatchPtrVec &watches = client.getWatches();
      for (int i = 0; i < (int)watches.size(); i++) {
        if (i > 0) client.output("%s", "");
        client.info("Watch %d: %s =", i + 1, watches[i]->second.c_str());
        Variant v = CmdPrint().processWatch(client, watches[i]->first,
                                            watches[i]->second);
        client.output(CmdPrint::FormatResult(watches[i]->first, v));
      }
    }
  }
}