From: Ilia K Date: Tue, 7 Apr 2015 09:47:23 +0000 (+0000) Subject: implement gdb-set output-radix X-Git-Tag: llvmorg-3.7.0-rc1~7391 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68757ed2e96f67faacea1fbd7728dbe0f8a4aee5;p=platform%2Fupstream%2Fllvm.git implement gdb-set output-radix Summary: Patch from chuckr@microsoft.com Reviewers: abidh, ChuckR Reviewed By: abidh Subscribers: paulmaybee, ki.stfu, greggm, scarroll, lldb-commits Differential Revision: http://reviews.llvm.org/D8430 llvm-svn: 234305 --- diff --git a/lldb/test/tools/lldb-mi/TestMiGdbSetShow.py b/lldb/test/tools/lldb-mi/TestMiGdbSetShow.py index df6d34d..8c62854 100644 --- a/lldb/test/tools/lldb-mi/TestMiGdbSetShow.py +++ b/lldb/test/tools/lldb-mi/TestMiGdbSetShow.py @@ -117,5 +117,53 @@ class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase): 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() diff --git a/lldb/test/tools/lldb-mi/main.cpp b/lldb/test/tools/lldb-mi/main.cpp index d4c353f..6a2079f 100644 --- a/lldb/test/tools/lldb-mi/main.cpp +++ b/lldb/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; } diff --git a/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp b/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp index 82ced28..ace1475 100644 --- a/lldb/tools/lldb-mi/MICmdCmdGdbSet.cpp +++ b/lldb/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 @@ CMICmdCmdGdbSet::OptionFnSolibSearchPath(const CMIUtilString::VecString_t &vrWor } //++ ------------------------------------------------------------------------------------ +// 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. diff --git a/lldb/tools/lldb-mi/MICmdCmdGdbSet.h b/lldb/tools/lldb-mi/MICmdCmdGdbSet.h index d9684bd..3aa3e39 100644 --- a/lldb/tools/lldb-mi/MICmdCmdGdbSet.h +++ b/lldb/tools/lldb-mi/MICmdCmdGdbSet.h @@ -71,6 +71,7 @@ class CMICmdCmdGdbSet : public CMICmdBase 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: diff --git a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.cpp b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.cpp index f58a68c..1e1c79f 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.cpp +++ b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.cpp @@ -23,6 +23,7 @@ const MIchar *CMICmnLLDBDebugSessionInfoVarObj::ms_aVarFormatChars[] = { "", "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 @@ CMICmnLLDBDebugSessionInfoVarObj::GetStringFormatted(const MIuint64 vnValue, con 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 @@ CMICmnLLDBDebugSessionInfoVarObj::VarObjIdResetToZero(void) } //++ ------------------------------------------------------------------------------------ +// 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. diff --git a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h index 890fb33..3fc18fe 100644 --- a/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h +++ b/lldb/tools/lldb-mi/MICmnLLDBDebugSessionInfoVarObj.h @@ -67,6 +67,7 @@ class CMICmnLLDBDebugSessionInfoVarObj static MIuint VarObjIdGet(void); static void VarObjIdResetToZero(void); static void VarObjClear(void); + static void VarObjSetFormat(varFormat_e eDefaultFormat); // Methods: public: @@ -117,6 +118,7 @@ class CMICmnLLDBDebugSessionInfoVarObj 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;