summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python/py-format-string.exp
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite/gdb.python/py-format-string.exp')
-rw-r--r--gdb/testsuite/gdb.python/py-format-string.exp57
1 files changed, 54 insertions, 3 deletions
diff --git a/gdb/testsuite/gdb.python/py-format-string.exp b/gdb/testsuite/gdb.python/py-format-string.exp
index 4c78bed1203..63b87e73476 100644
--- a/gdb/testsuite/gdb.python/py-format-string.exp
+++ b/gdb/testsuite/gdb.python/py-format-string.exp
@@ -898,6 +898,43 @@ proc_with_prefix test_format {} {
}
}
+ # Binary.
+ set opts "format='t'"
+ with_test_prefix $opts {
+ set binary_pointer_regexp "\[0-1\]+"
+ gdb_test "python print (gdb.Value (42).format_string (${opts}))" \
+ "101010" \
+ "42 with option ${opts}"
+
+ check_format_string "a_point_t" $opts
+ check_format_string "a_point_t_pointer" $opts \
+ $binary_pointer_regexp
+ check_format_string "another_point" $opts
+ check_format_string "a_struct_with_union" $opts \
+ "\\{the_union = \\{an_int = 101010001010100010101000101010, a_char = 101010\\}\\}"
+ check_format_string "an_enum" $opts \
+ "1"
+ check_format_string "a_string" $opts \
+ $binary_pointer_regexp
+ check_format_string "a_binary_string" $opts \
+ $binary_pointer_regexp
+ check_format_string "a_binary_string_array" $opts \
+ "\\{1101000, 1100101, 1101100, 1101100, 1101111, 0, 1110111, 1101111, 1110010, 1101100, 1100100, 0\\}"
+ check_format_string "a_big_string" $opts \
+ "\\{1000001, 1000010, 1000011, 1000100, 1000101, \[, 0-1\]+\.\.\.\\}"
+ check_format_string "an_array" $opts \
+ "\\{10, 11, 101\\}"
+ check_format_string "an_array_with_repetition" $opts \
+ "\\{1, 11 <repeats 12 times>, 101, 101, 101\\}"
+ check_format_string "a_symbol_pointer" $opts \
+ $binary_pointer_regexp
+
+ if { $current_lang == "c++" } {
+ check_format_string "a_point_t_ref" $opts
+ check_format_string "a_base_ref" $opts
+ }
+ }
+
# Decimal.
set opts "format='d'"
with_test_prefix $opts {
@@ -991,6 +1028,13 @@ proc_with_prefix test_invalid_args {} {
"ValueError: a single character is required.*"
}
+# Check the styling argument to format_string. This function needs to
+# be called with TERM set such that styling can be applied.
+proc test_styling {} {
+ gdb_test "python print(gdb.parse_and_eval(\"a_point_t\").format_string(styling=True, raw=True))" \
+ "{[style x variable] = 42, [style y variable] = 12}"
+}
+
# Run all the tests in common for both C and C++.
proc_with_prefix test_all_common {} {
# No options.
@@ -1023,9 +1067,16 @@ with_test_prefix "format_string" {
# Perform C Tests.
if { [build_inferior "${binfile}" "c"] == 0 } {
with_test_prefix "lang_c" {
- set current_lang "c"
- prepare_gdb "${binfile}"
- test_all_common
+ save_vars { env(TERM) } {
+ # We run all of these tests in an environment where styling
+ # could work, but we only expect the final call to
+ # test_styling to actually produce any styled output.
+ setenv TERM ansi
+ set current_lang "c"
+ prepare_gdb "${binfile}"
+ test_all_common
+ test_styling
+ }
}
}