Index: lldb/trunk/test/tools/lldb-mi/TestMiGdbSetShow.py =================================================================== --- lldb/trunk/test/tools/lldb-mi/TestMiGdbSetShow.py +++ lldb/trunk/test/tools/lldb-mi/TestMiGdbSetShow.py @@ -117,5 +117,53 @@ self.runCmd("-gdb-show unknown") self.expect("\^error") + + @lldbmi_test + @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows") + @skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races + @skipIfLinux # llvm.org/pr22841: lldb-mi tests fail on all Linux buildbots + def test_lldbmi_gdb_set_ouptut_radix(self): + """Test that 'lldb-mi --interpreter' works for -gdb-set output-radix.""" + + self.spawnLldbMi(args = None) + + # Load executable + self.runCmd("-file-exec-and-symbols %s" % self.myexe) + self.expect("\^done") + + # Run to BP_printf + line = line_number('main.cpp', '// BP_printf') + self.runCmd("-break-insert main.cpp:%d" % line) + self.expect("\^done,bkpt={number=\"1\"") + self.runCmd("-exec-run") + self.expect("\^running"); + self.expect("\*stopped,reason=\"breakpoint-hit\"") + + # Setup variable + self.runCmd("-var-create var_a * a"); + self.expect("\^done,name=\"var_a\",numchild=\"0\",value=\"10\",type=\"int\",thread-id=\"1\",has_more=\"0\"") + + # Test default output + self.runCmd("-var-evaluate-expression var_a"); + self.expect("\^done,value=\"10\""); + + # Test hex output + self.runCmd("-gdb-set output-radix 16"); + self.expect("\^done"); + self.runCmd("-var-evaluate-expression var_a"); + self.expect("\^done,value=\"0xa\""); + + # Test octal output + self.runCmd("-gdb-set output-radix 8"); + self.expect("\^done"); + self.runCmd("-var-evaluate-expression var_a"); + self.expect("\^done,value=\"012\""); + + # Test decimal output + self.runCmd("-gdb-set output-radix 10"); + self.expect("\^done"); + self.runCmd("-var-evaluate-expression var_a"); + self.expect("\^done,value=\"10\""); + if __name__ == '__main__': unittest2.main() Index: lldb/trunk/test/tools/lldb-mi/main.cpp =================================================================== --- lldb/trunk/test/tools/lldb-mi/main.cpp +++ lldb/trunk/test/tools/lldb-mi/main.cpp @@ -12,6 +12,8 @@ int main(int argc, char const *argv[]) { - printf("argc=%d\n", argc); + int a = 10; + + printf("argc=%d\n", argc); // BP_printf return 0; } Index: lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h =================================================================== --- lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h +++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h @@ -71,6 +71,7 @@ bool GetOptionFn(const CMIUtilString &vrGdbOptionName, FnGdbOptionPtr &vrwpFn) const; bool OptionFnTargetAsync(const CMIUtilString::VecString_t &vrWords); bool OptionFnSolibSearchPath(const CMIUtilString::VecString_t &vrWords); + bool OptionFnOutputRadix(const CMIUtilString::VecString_t &vrWords); bool OptionFnFallback(const CMIUtilString::VecString_t &vrWords); // Attributes: Index: lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp =================================================================== --- lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp +++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp @@ -22,6 +22,7 @@ const CMICmdCmdGdbSet::MapGdbOptionNameToFnGdbOptionPtr_t CMICmdCmdGdbSet::ms_mapGdbOptionNameToFnGdbOptionPtr = { {"target-async", &CMICmdCmdGdbSet::OptionFnTargetAsync}, // { "auto-solib-add", &CMICmdCmdGdbSet::OptionFnAutoSolibAdd }, // Example code if need to implement GDB set other options + {"output-radix", &CMICmdCmdGdbSet::OptionFnOutputRadix}, {"solib-search-path", &CMICmdCmdGdbSet::OptionFnSolibSearchPath}, {"fallback", &CMICmdCmdGdbSet::OptionFnFallback}}; @@ -288,6 +289,58 @@ } //++ ------------------------------------------------------------------------------------ +// Details: Carry out work to complete the GDB set option 'output-radix' to prepare +// and send back information asked for. +// Type: Method. +// Args: vrWords - (R) List of additional parameters used by this option. +// Return: MIstatus::success - Functional succeeded. +// MIstatus::failure - Functional failed. +// Throws: None. +//-- +bool +CMICmdCmdGdbSet::OptionFnOutputRadix(const CMIUtilString::VecString_t &vrWords) +{ + // Check we have at least one argument + if (vrWords.size() < 1) + { + m_bGbbOptionFnHasError = true; + m_strGdbOptionFnError = MIRSRC(IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH); + return MIstatus::failure; + } + const CMIUtilString &rStrValOutputRadix(vrWords[0]); + + CMICmnLLDBDebugSessionInfoVarObj::varFormat_e format = CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Invalid; + MIint64 radix; + if (rStrValOutputRadix.ExtractNumber(radix)) + { + switch (radix) + { + case 8: + format = CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Octal; + break; + case 10: + format = CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Natural; + break; + case 16: + format = CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Hex; + break; + default: + format = CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Invalid; + break; + } + } + if (format == CMICmnLLDBDebugSessionInfoVarObj::eVarFormat_Invalid) + { + m_bGbbOptionFnHasError = false; + SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD), m_cmdData.strMiCmd.c_str(), "Output Radix")); + return MIstatus::failure; + } + CMICmnLLDBDebugSessionInfoVarObj::VarObjSetFormat(format); + + return MIstatus::success; +} + +//++ ------------------------------------------------------------------------------------ // Details: Carry out work to complete the GDB set option to prepare and send back the // requested information. // Type: Method. Index: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h =================================================================== --- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h +++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h @@ -67,6 +67,7 @@ static MIuint VarObjIdGet(void); static void VarObjIdResetToZero(void); static void VarObjClear(void); + static void VarObjSetFormat(varFormat_e eDefaultFormat); // Methods: public: @@ -117,6 +118,7 @@ static const MIchar *ms_aVarFormatChars[]; static MapKeyToVarObj_t ms_mapVarIdToVarObj; static MIuint ms_nVarUniqueId; + static varFormat_e ms_eDefaultFormat; // overrides "natural" format // // *** Upate the copy move constructors and assignment operator *** varFormat_e m_eVarFormat; Index: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.cpp =================================================================== --- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.cpp +++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.cpp @@ -23,6 +23,7 @@ "", "t", "o", "d", "x", "N"}; CMICmnLLDBDebugSessionInfoVarObj::MapKeyToVarObj_t CMICmnLLDBDebugSessionInfoVarObj::ms_mapVarIdToVarObj; MIuint CMICmnLLDBDebugSessionInfoVarObj::ms_nVarUniqueId = 0; // Index from 0 +CMICmnLLDBDebugSessionInfoVarObj::varFormat_e CMICmnLLDBDebugSessionInfoVarObj::ms_eDefaultFormat = eVarFormat_Natural; //++ ------------------------------------------------------------------------------------ // Details: CMICmnLLDBDebugSessionInfoVarObj constructor. @@ -302,8 +303,13 @@ const CMICmnLLDBDebugSessionInfoVarObj::varFormat_e veVarFormat) { CMIUtilString strFormattedValue; + CMICmnLLDBDebugSessionInfoVarObj::varFormat_e veFormat = veVarFormat; + if (ms_eDefaultFormat != eVarFormat_Invalid && veVarFormat == eVarFormat_Natural) + { + veFormat = ms_eDefaultFormat; + } - switch (veVarFormat) + switch (veFormat) { case eVarFormat_Binary: strFormattedValue = CMIUtilString::FormatBinary(vnValue); @@ -422,6 +428,20 @@ } //++ ------------------------------------------------------------------------------------ +// Details: Default format is globally used as the data format when "natural" is in effect, that is, this overrides the default +// Type: Static method. +// Args: None. +// Returns: None. +// Throws: None. +//-- +void +CMICmnLLDBDebugSessionInfoVarObj::VarObjSetFormat(varFormat_e eDefaultFormat) +{ + ms_eDefaultFormat = eDefaultFormat; +} + + +//++ ------------------------------------------------------------------------------------ // Details: A count is kept of the number of var value objects created. This is count is // used to ID the var value object. Increment the count by 1. // Type: Static method.