[Lldb-commits] [lldb] r235804 - Add -gdb-set/-gdb-show print char-array-as-string option (MI)
Ilia K
ki.stfu at gmail.com
Sat Apr 25 12:44:57 PDT 2015
Author: ki.stfu
Date: Sat Apr 25 14:44:56 2015
New Revision: 235804
URL: http://llvm.org/viewvc/llvm-project?rev=235804&view=rev
Log:
Add -gdb-set/-gdb-show print char-array-as-string option (MI)
Added:
lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
Modified:
lldb/trunk/test/tools/lldb-mi/variable/main.cpp
lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp
lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h
lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp
lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.h
lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
lldb/trunk/tools/lldb-mi/MICmnResources.cpp
lldb/trunk/tools/lldb-mi/MICmnResources.h
Added: lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py?rev=235804&view=auto
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py (added)
+++ lldb/trunk/test/tools/lldb-mi/variable/TestMiGdbSetShowPrint.py Sat Apr 25 14:44:56 2015
@@ -0,0 +1,69 @@
+"""
+Test lldb-mi -gdb-set and -gdb-show commands for 'print option-name'.
+"""
+
+import lldbmi_testcase
+from lldbtest import *
+import unittest2
+
+class MiGdbSetShowTestCase(lldbmi_testcase.MiTestCaseBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @lldbmi_test
+ @expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
+ def test_lldbmi_gdb_set_show_print_char_array_as_string(self):
+ """Test that 'lldb-mi --interpreter' can print array of chars as string."""
+
+ self.spawnLldbMi(args = None)
+
+ # Load executable
+ self.runCmd("-file-exec-and-symbols %s" % self.myexe)
+ self.expect("\^done")
+
+ # Run to BP_gdb_set_show_print_char_array_as_string_test
+ line = line_number('main.cpp', '// BP_gdb_set_show_print_char_array_as_string_test')
+ 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\"")
+
+ # Test that default print char-array-as-string value is "off"
+ self.runCmd("-gdb-show print char-array-as-string")
+ self.expect("\^done,value=\"off\"")
+
+ # Test that an char* is expanded to string when print char-array-as-string is "off"
+ self.runCmd("-var-create var1 * string_ptr")
+ self.expect("\^done,name=\"var1\",numchild=\"1\",value=\"0x[0-9a-f]+ \\\\\\\"string - const char \*\\\\\\\"\",type=\"const char \*\",thread-id=\"1\",has_more=\"0\"")
+
+ # Test that an char[] isn't expanded to string when print char-array-as-string is "off"
+ self.runCmd("-var-create var2 * string_arr")
+ self.expect("\^done,name=\"var2\",numchild=\"17\",value=\"\[17\]\",type=\"const char \[17\]\",thread-id=\"1\",has_more=\"0\"")
+
+ # Test that -gdb-set can set print char-array-as-string flag
+ self.runCmd("-gdb-set print char-array-as-string on")
+ self.expect("\^done")
+ self.runCmd("-gdb-set print char-array-as-string 1")
+ self.expect("\^done")
+ self.runCmd("-gdb-show print char-array-as-string")
+ self.expect("\^done,value=\"on\"")
+
+ # Test that an char* is expanded to string when print char-array-as-string is "on"
+ self.runCmd("-var-create var1 * string_ptr")
+ self.expect("\^done,name=\"var1\",numchild=\"1\",value=\"0x[0-9a-f]+ \\\\\\\"string - const char \*\\\\\\\"\",type=\"const char \*\",thread-id=\"1\",has_more=\"0\"")
+
+ # Test that an char[] isn't expanded to string when print char-array-as-string is "on"
+ self.runCmd("-var-create var2 * string_arr")
+ self.expect("\^done,name=\"var2\",numchild=\"17\",value=\"\\\\\\\"string - char \[\]\\\\\\\"\",type=\"const char \[17\]\",thread-id=\"1\",has_more=\"0\"")
+
+ # Test that -gdb-set print char-array-as-string fails if "on"/"off" isn't specified
+ self.runCmd("-gdb-set print char-array-as-string")
+ self.expect("\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
+
+ # Test that -gdb-set print char-array-as-string fails when option is unknown
+ self.runCmd("-gdb-set print char-array-as-string unknown")
+ self.expect("\^error,msg=\"The request ''print' expects option-name and \"on\" or \"off\"' failed.\"")
+
+if __name__ == '__main__':
+ unittest2.main()
Modified: lldb/trunk/test/tools/lldb-mi/variable/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-mi/variable/main.cpp?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-mi/variable/main.cpp (original)
+++ lldb/trunk/test/tools/lldb-mi/variable/main.cpp Sat Apr 25 14:44:56 2015
@@ -34,6 +34,15 @@ var_update_test(void)
// BP_var_update_test_complx_array
}
+void
+gdb_set_show_print_char_array_as_string_test(void)
+{
+ const char *string_ptr = "string - const char *";
+ const char string_arr[] = "string - char []";
+
+ // BP_gdb_set_show_print_char_array_as_string_test
+}
+
int g_MyVar = 3;
static int s_MyVar = 4;
@@ -43,5 +52,6 @@ main(int argc, char const *argv[])
int a = 10, b = 20;
s_MyVar = a + b;
var_update_test();
+ gdb_set_show_print_char_array_as_string_test();
return 0; // BP_return
}
Modified: lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.cpp Sat Apr 25 14:44:56 2015
@@ -21,6 +21,7 @@
// Instantiations:
const CMICmdCmdGdbSet::MapGdbOptionNameToFnGdbOptionPtr_t CMICmdCmdGdbSet::ms_mapGdbOptionNameToFnGdbOptionPtr = {
{"target-async", &CMICmdCmdGdbSet::OptionFnTargetAsync},
+ {"print", &CMICmdCmdGdbSet::OptionFnPrint},
// { "auto-solib-add", &CMICmdCmdGdbSet::OptionFnAutoSolibAdd }, // Example code if need to implement GDB set other options
{"output-radix", &CMICmdCmdGdbSet::OptionFnOutputRadix},
{"solib-search-path", &CMICmdCmdGdbSet::OptionFnSolibSearchPath},
@@ -254,6 +255,50 @@ CMICmdCmdGdbSet::OptionFnTargetAsync(con
return MIstatus::success;
}
+
+//++ ------------------------------------------------------------------------------------
+// Details: Carry out work to complete the GDB set option 'print-char-array-as-string' to
+// prepare and send back information asked for.
+// Type: Method.
+// Args: vrWords - (R) List of additional parameters used by this option.
+// Return: MIstatus::success - Function succeeded.
+// MIstatus::failure - Function failed.
+// Throws: None.
+//--
+bool
+CMICmdCmdGdbSet::OptionFnPrint(const CMIUtilString::VecString_t &vrWords)
+{
+ const bool bAllArgs(vrWords.size() == 2);
+ const bool bArgOn(bAllArgs && (CMIUtilString::Compare(vrWords[1], "on") || CMIUtilString::Compare(vrWords[1], "1")));
+ const bool bArgOff(bAllArgs && (CMIUtilString::Compare(vrWords[1], "off") || CMIUtilString::Compare(vrWords[1], "0")));
+ if (!bAllArgs || (!bArgOn && !bArgOff))
+ {
+ m_bGbbOptionFnHasError = true;
+ m_strGdbOptionFnError = MIRSRC(IDS_CMD_ERR_GDBSET_OPT_PRINT_BAD_ARGS);
+ return MIstatus::failure;
+ }
+
+ const CMIUtilString strOption(vrWords[0]);
+ CMIUtilString strOptionKey;
+ if (CMIUtilString::Compare(strOption, "char-array-as-string"))
+ strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintCharArrayAsString;
+ else
+ {
+ m_bGbbOptionFnHasError = true;
+ m_strGdbOptionFnError = CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_GDBSET_OPT_PRINT_UNKNOWN_OPTION), strOption.c_str());
+ return MIstatus::failure;
+ }
+
+ const bool bOptionValue(bArgOn);
+ if (!m_rLLDBDebugSessionInfo.SharedDataAdd<bool>(strOptionKey, bOptionValue))
+ {
+ m_bGbbOptionFnHasError = false;
+ SetError(CMIUtilString::Format(MIRSRC(IDS_DBGSESSION_ERR_SHARED_DATA_ADD), m_cmdData.strMiCmd.c_str(), strOptionKey.c_str()));
+ return MIstatus::failure;
+ }
+
+ return MIstatus::success;
+}
//++ ------------------------------------------------------------------------------------
// Details: Carry out work to complete the GDB set option 'solib-search-path' to prepare
Modified: lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbSet.h Sat Apr 25 14:44:56 2015
@@ -70,6 +70,7 @@ class CMICmdCmdGdbSet : public CMICmdBas
private:
bool GetOptionFn(const CMIUtilString &vrGdbOptionName, FnGdbOptionPtr &vrwpFn) const;
bool OptionFnTargetAsync(const CMIUtilString::VecString_t &vrWords);
+ bool OptionFnPrint(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);
Modified: lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.cpp Sat Apr 25 14:44:56 2015
@@ -21,6 +21,7 @@
// Instantiations:
const CMICmdCmdGdbShow::MapGdbOptionNameToFnGdbOptionPtr_t CMICmdCmdGdbShow::ms_mapGdbOptionNameToFnGdbOptionPtr = {
{"target-async", &CMICmdCmdGdbShow::OptionFnTargetAsync},
+ {"print", &CMICmdCmdGdbShow::OptionFnPrint},
{"fallback", &CMICmdCmdGdbShow::OptionFnFallback}};
//++ ------------------------------------------------------------------------------------
@@ -238,6 +239,46 @@ CMICmdCmdGdbShow::OptionFnTargetAsync(co
return MIstatus::success;
}
+//++ ------------------------------------------------------------------------------------
+// Details: Carry out work to complete the GDB show option 'print' to prepare and send
+// back the requested information.
+// Type: Method.
+// Args: vrWords - (R) List of additional parameters used by this option.
+// Return: MIstatus::success - Function succeeded.
+// MIstatus::failure - Function failed.
+// Throws: None.
+//--
+bool
+CMICmdCmdGdbShow::OptionFnPrint(const CMIUtilString::VecString_t &vrWords)
+{
+ const bool bAllArgs(vrWords.size() == 1);
+ if (!bAllArgs)
+ {
+ m_bGbbOptionFnHasError = true;
+ m_strGdbOptionFnError = MIRSRC(IDS_CMD_ERR_GDBSHOW_OPT_PRINT_BAD_ARGS);
+ return MIstatus::failure;
+ }
+
+ const CMIUtilString strOption(vrWords[0]);
+ CMIUtilString strOptionKey;
+ bool bOptionValueDefault = false;
+ if (CMIUtilString::Compare(strOption, "char-array-as-string"))
+ strOptionKey = m_rLLDBDebugSessionInfo.m_constStrPrintCharArrayAsString;
+ else
+ {
+ m_bGbbOptionFnHasError = true;
+ m_strGdbOptionFnError = CMIUtilString::Format(MIRSRC(IDS_CMD_ERR_GDBSHOW_OPT_PRINT_UNKNOWN_OPTION), strOption.c_str());
+ return MIstatus::failure;
+ }
+
+ bool bOptionValue = false;
+ bOptionValue = bOptionValueDefault ? !m_rLLDBDebugSessionInfo.SharedDataRetrieve<bool>(strOptionKey, bOptionValue) || bOptionValue
+ : m_rLLDBDebugSessionInfo.SharedDataRetrieve<bool>(strOptionKey, bOptionValue) && bOptionValue;
+
+ m_strValue = bOptionValue ? "on" : "off";
+ return MIstatus::success;
+}
+
//++ ------------------------------------------------------------------------------------
// Details: Carry out work to complete the GDB show option to prepare and send back the
// requested information.
Modified: lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.h?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmdCmdGdbShow.h Sat Apr 25 14:44:56 2015
@@ -67,6 +67,7 @@ class CMICmdCmdGdbShow : public CMICmdBa
private:
bool GetOptionFn(const CMIUtilString &vrGdbOptionName, FnGdbOptionPtr &vrwpFn) const;
bool OptionFnTargetAsync(const CMIUtilString::VecString_t &vrWords);
+ bool OptionFnPrint(const CMIUtilString::VecString_t &vrWords);
bool OptionFnFallback(const CMIUtilString::VecString_t &vrWords);
// Attributes:
Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.cpp Sat Apr 25 14:44:56 2015
@@ -40,6 +40,7 @@ CMICmnLLDBDebugSessionInfo::CMICmnLLDBDe
, m_currentSelectedThread(LLDB_INVALID_THREAD_ID)
, m_constStrSharedDataKeyWkDir("Working Directory")
, m_constStrSharedDataSolibPath("Solib Path")
+ , m_constStrPrintCharArrayAsString("Print CharArrayAsString")
{
}
Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBDebugSessionInfo.h Sat Apr 25 14:44:56 2015
@@ -183,6 +183,7 @@ class CMICmnLLDBDebugSessionInfo : publi
// Note: This list is expected to grow and will be moved and abstracted in the future.
const CMIUtilString m_constStrSharedDataKeyWkDir;
const CMIUtilString m_constStrSharedDataSolibPath;
+ const CMIUtilString m_constStrPrintCharArrayAsString;
// Typedefs:
private:
Modified: lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnLLDBUtilSBValue.cpp Sat Apr 25 14:44:56 2015
@@ -144,10 +144,25 @@ CMICmnLLDBUtilSBValue::GetSimpleValue(co
return MIstatus::success;
}
}
- else if (IsArrayType() && vbHandleArrayType)
+ else if (IsArrayType())
{
- vwrValue = CMIUtilString::Format("[%u]", nChildren);
- return MIstatus::success;
+ CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
+ bool bPrintCharArrayAsString = false;
+ bPrintCharArrayAsString = rSessionInfo.SharedDataRetrieve<bool>(rSessionInfo.m_constStrPrintCharArrayAsString,
+ bPrintCharArrayAsString) && bPrintCharArrayAsString;
+ if (bPrintCharArrayAsString && m_bHandleCharType && IsFirstChildCharType())
+ {
+ // TODO: to match char* it should be the following
+ // vwrValue = CMIUtilString::Format("[%u] \"%s\"", nChildren, prefix.c_str());
+ const CMIUtilString prefix(GetValueCString().Escape().AddSlashes());
+ vwrValue = CMIUtilString::Format("\"%s\"", prefix.c_str());
+ return MIstatus::success;
+ }
+ else if (vbHandleArrayType)
+ {
+ vwrValue = CMIUtilString::Format("[%u]", nChildren);
+ return MIstatus::success;
+ }
}
// Composite variable type i.e. struct
Modified: lldb/trunk/tools/lldb-mi/MICmnResources.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnResources.cpp?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnResources.cpp (original)
+++ lldb/trunk/tools/lldb-mi/MICmnResources.cpp Sat Apr 25 14:44:56 2015
@@ -244,7 +244,11 @@ const CMICmnResources::SRsrcTextData CMI
{IDS_CMD_ERR_INFO_PRINTFN_NOT_FOUND, "The request '%s' was not recogised, not implemented"},
{IDS_CMD_ERR_INFO_PRINTFN_FAILED, "The request '%s' failed."},
{IDS_CMD_ERR_GDBSET_OPT_TARGETASYNC, "'target-async' expects \"on\" or \"off\""},
- {IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH, "'solib-search-path' requires at least one argument"}};
+ {IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH, "'solib-search-path' requires at least one argument"},
+ {IDS_CMD_ERR_GDBSET_OPT_PRINT_BAD_ARGS, "'print' expects option-name and \"on\" or \"off\""},
+ {IDS_CMD_ERR_GDBSET_OPT_PRINT_UNKNOWN_OPTION, "'print' error. The option '%s' not found"},
+ {IDS_CMD_ERR_GDBSHOW_OPT_PRINT_BAD_ARGS, "'print' expects option-name and \"on\" or \"off\""},
+ {IDS_CMD_ERR_GDBSHOW_OPT_PRINT_UNKNOWN_OPTION, "'print' error. The option '%s' not found"}};
//++ ------------------------------------------------------------------------------------
// Details: CMICmnResources constructor.
Modified: lldb/trunk/tools/lldb-mi/MICmnResources.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-mi/MICmnResources.h?rev=235804&r1=235803&r2=235804&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-mi/MICmnResources.h (original)
+++ lldb/trunk/tools/lldb-mi/MICmnResources.h Sat Apr 25 14:44:56 2015
@@ -262,7 +262,11 @@ enum
IDS_CMD_ERR_INFO_PRINTFN_NOT_FOUND,
IDS_CMD_ERR_INFO_PRINTFN_FAILED,
IDS_CMD_ERR_GDBSET_OPT_TARGETASYNC,
- IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH
+ IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH,
+ IDS_CMD_ERR_GDBSET_OPT_PRINT_BAD_ARGS,
+ IDS_CMD_ERR_GDBSET_OPT_PRINT_UNKNOWN_OPTION,
+ IDS_CMD_ERR_GDBSHOW_OPT_PRINT_BAD_ARGS,
+ IDS_CMD_ERR_GDBSHOW_OPT_PRINT_UNKNOWN_OPTION
};
//++ ============================================================================
More information about the lldb-commits
mailing list