void CmdVariable::PrintVariable(DebuggerClient &client, const String& varName) { CmdVariable cmd(client.isStackTraceAsync() ? KindOfVariableAsync : KindOfVariable); auto charCount = client.getDebuggerClientShortPrintCharCount(); cmd.m_frame = client.getFrame(); auto rcmd = client.xend<CmdVariable>(&cmd); always_assert(rcmd->m_version == 2); // Using the new protocol. rcmd contains a list of variables only. Fetch // value of varName only, so that we can recover nicely when its value is too // large to serialize. cmd.m_varName = varName; cmd.m_variables.reset(); cmd.m_formatMaxLen = charCount; cmd.m_version = 2; rcmd = client.xend<CmdVariable>(&cmd); if (rcmd->m_variables.empty()) { // Perhaps the value is too large? See recvImpl. Retry the command with // version 1, in which case values are omitted. cmd.m_version = 1; rcmd = client.xend<CmdVariable>(&cmd); if (!rcmd->m_variables.empty()) { // It's there without values, and gone with values, so it is too large. client.output(s_omitted); } return; } auto const get_var = [varName] (const CmdVariable& cmd) { assert(cmd.m_variables.size() == 1); assert(cmd.m_variables.exists(varName, true /* isKey */)); assert(cmd.m_variables[varName].isString()); return cmd.m_variables[varName].toString(); }; auto const value = get_var(*rcmd); if (charCount <= 0 || value.size() <= charCount) { client.output(value); return; } // Don't show the "omitted" suffix. client.output(StringSlice(value.data(), charCount)); if (client.ask("There are more characters. Continue? [y/N]") == 'y') { // Now we get the full value, and show the rest. cmd.m_variables.reset(); cmd.m_formatMaxLen = -1; rcmd = client.xend<CmdVariable>(&cmd); auto value = get_var(*rcmd); auto rest = StringSlice(value.data() + charCount, value.size() - charCount); client.output(rest); client.tutorial("You can use 'set cc n' to increase the character" " limit. 'set cc -1' will remove the limit."); } }
void CmdConfig::listVars(DebuggerClient &client) { std::string LogFile = client.getLogFile(); client.print("LogFile(lf) %s", LogFile == "" ? "off" : LogFile.c_str()); client.print("BypassAccessCheck(bac) %s", client.getDebuggerClientBypassCheck() ? "on" : "off"); client.print("PrintLevel(pl) %d", client.getDebuggerClientPrintLevel()); client.print("ShortPrintCharCount(cc) %d", client.getDebuggerClientShortPrintCharCount()); client.print("SmallStep(ss) %s", client.getDebuggerClientSmallStep() ? "on" : "off"); client.print("StackArgs(sa) %s", client.getDebuggerClientStackArgs() ? "on" : "off"); client.print("MaxCodeLines(mcl) %d", client.getDebuggerClientMaxCodeLines()); }
void CmdVariable::PrintVariable(DebuggerClient &client, const String& varName) { CmdVariable cmd(client.isStackTraceAsync() ? KindOfVariableAsync : KindOfVariable); auto charCount = client.getDebuggerClientShortPrintCharCount(); cmd.m_frame = client.getFrame(); auto rcmd = client.xend<CmdVariable>(&cmd); if (rcmd->m_version == 2) { // Using the new protocol. rcmd contains a list of variables only. // Fetch value of varName only, so that we can recover nicely when its // value is too large to serialize. cmd.m_varName = varName; cmd.m_variables.reset(); cmd.m_version = 2; rcmd = client.xend<CmdVariable>(&cmd); if (rcmd->m_variables.empty()) { // Perhaps the value is too large? See recvImpl. // Retry the command with version 1, in which case values are omitted. cmd.m_version = 1; rcmd = client.xend<CmdVariable>(&cmd); if (!rcmd->m_variables.empty()) { // It's there without values, and gone with values, so it is too large. client.output("...(omitted)"); return; } } } if (!rcmd->m_variables.empty()) { for (ArrayIter iter(rcmd->m_variables); iter; ++iter) { String name = iter.first().toString(); if (!name.equal(varName)) continue; String value = DebuggerClient::FormatVariable(iter.second(), -1); auto excess = value.length() - charCount; if (charCount <= 0 || excess <= 0) { client.output("%s", value.data()); } else { client.output("%s", value.substr(0, charCount).data()); if (client.ask("There are %d more characters. Continue? [y/N]", excess) == 'y') { client.output("%s", value.substr(charCount).data()); client.tutorial("You can use 'set cc n' to increase the character" " limit. 'set cc -1' will remove the limit."); } } } } }