]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add address keyword to Value.format_string
authorHannes Domani <ssbssa@yahoo.de>
Fri, 18 Dec 2020 16:23:06 +0000 (17:23 +0100)
committerHannes Domani <ssbssa@yahoo.de>
Fri, 18 Dec 2020 21:04:16 +0000 (22:04 +0100)
This makes it possible to disable the address in the result string:

const char *str = "alpha";

(gdb) py print(gdb.parse_and_eval("str").format_string())
0x404000 "alpha"
(gdb) py print(gdb.parse_and_eval("str").format_string(address=False))
"alpha"

gdb/ChangeLog:

2020-12-18  Hannes Domani  <ssbssa@yahoo.de>

* python/py-value.c (valpy_format_string): Implement address keyword.

gdb/doc/ChangeLog:

2020-12-18  Hannes Domani  <ssbssa@yahoo.de>

* python.texi (Values From Inferior): Document the address keyword.

gdb/testsuite/ChangeLog:

2020-12-18  Hannes Domani  <ssbssa@yahoo.de>

* gdb.python/py-format-string.exp: Add tests for address keyword.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/python.texi
gdb/python/py-value.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-format-string.exp

index 1a104b1f339dd15c62a58360b199e6f4a8bc5ffa..7891f491906209cea39f258829a443fc450bebb3 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-18  Hannes Domani  <ssbssa@yahoo.de>
+
+       * python/py-value.c (valpy_format_string): Implement address keyword.
+
 2020-12-18  Hannes Domani  <ssbssa@yahoo.de>
 
        * python/py-type.c (typy_get_composite): Add TYPE_CODE_METHOD.
index 223c8fcfe40218038f5675d56b8c730855a51043..f5ab5432b98bb13542d41eb02242482dac161a3a 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-18  Hannes Domani  <ssbssa@yahoo.de>
+
+       * python.texi (Values From Inferior): Document the address keyword.
+
 2020-12-17  Simon Marchi  <simon.marchi@polymtl.ca>
 
        PR gdb/27088
index c107d4506d67066bc84569a3f05ce43e2d61cf6a..ad7df2cdd325f303e56d3ef43bb52e58d133a460 100644 (file)
@@ -906,6 +906,11 @@ corresponding symbol name (if one exists), @code{False} if it shouldn't
 should be expanded, @code{False} if they shouldn't (see @code{set print
 union} in @ref{Print Settings}).
 
+@item address
+@code{True} if the string representation of a pointer should include the
+address, @code{False} if it shouldn't (see @code{set print address} in
+@ref{Print Settings}).
+
 @item deref_refs
 @code{True} if C@t{++} references should be resolved to the value they
 refer to, @code{False} (the default) if they shouldn't.  Note that, unlike
index c1ff8e8eca94b97d4eda4976021edc6dc64071cd..a6afcad4f2b81e08d3026749e3628c0ee06bb6b6 100644 (file)
@@ -617,6 +617,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
       "array_indexes",         /* See set print array-indexes on|off.  */
       "symbols",               /* See set print symbol on|off.  */
       "unions",                        /* See set print union on|off.  */
+      "address",               /* See set print address on|off.  */
       /* C++ options.  */
       "deref_refs",            /* No corresponding setting.  */
       "actual_objects",                /* See set print object on|off.  */
@@ -660,13 +661,14 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
   PyObject *array_indexes_obj = NULL;
   PyObject *symbols_obj = NULL;
   PyObject *unions_obj = NULL;
+  PyObject *address_obj = NULL;
   PyObject *deref_refs_obj = NULL;
   PyObject *actual_objects_obj = NULL;
   PyObject *static_members_obj = NULL;
   char *format = NULL;
   if (!gdb_PyArg_ParseTupleAndKeywords (args,
                                        kw,
-                                       "|O!O!O!O!O!O!O!O!O!IIIs",
+                                       "|O!O!O!O!O!O!O!O!O!O!IIIs",
                                        keywords,
                                        &PyBool_Type, &raw_obj,
                                        &PyBool_Type, &pretty_arrays_obj,
@@ -674,6 +676,7 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
                                        &PyBool_Type, &array_indexes_obj,
                                        &PyBool_Type, &symbols_obj,
                                        &PyBool_Type, &unions_obj,
+                                       &PyBool_Type, &address_obj,
                                        &PyBool_Type, &deref_refs_obj,
                                        &PyBool_Type, &actual_objects_obj,
                                        &PyBool_Type, &static_members_obj,
@@ -696,6 +699,8 @@ valpy_format_string (PyObject *self, PyObject *args, PyObject *kw)
     return NULL;
   if (!copy_py_bool_obj (&opts.unionprint, unions_obj))
     return NULL;
+  if (!copy_py_bool_obj (&opts.addressprint, address_obj))
+    return NULL;
   if (!copy_py_bool_obj (&opts.deref_ref, deref_refs_obj))
     return NULL;
   if (!copy_py_bool_obj (&opts.objectprint, actual_objects_obj))
index 73425638a23b12b272b3c4c339511fc9edb34d0a..551dd7192daa6e77b5a5f036a6ba96abdc835bf7 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-18  Hannes Domani  <ssbssa@yahoo.de>
+
+       * gdb.python/py-format-string.exp: Add tests for address keyword.
+
 2020-12-18  Hannes Domani  <ssbssa@yahoo.de>
 
        * gdb.python/py-type.exp: Add tests for TYPE_CODE_METHOD.
index b7acc242ed320cb1ce2ad53930b5962f0bc4bf44..f4eaad0450468270c6662ee9d6309f98f53a81f3 100644 (file)
@@ -487,6 +487,48 @@ proc test_unions {} {
   }
 }
 
+# Test the address option for gdb.Value.format_string.
+proc test_address {} {
+  global undefined
+  global current_lang
+
+  check_var_with_bool_opt "address" "a_point_t"
+  check_var_with_bool_opt "address" "a_point_t_pointer" \
+    $undefined \
+    ""
+  check_var_with_bool_opt "address" "another_point"
+  check_var_with_bool_opt "symbols" "a_struct_with_union"
+  check_var_with_bool_opt "address" "an_enum"
+  check_var_with_bool_opt "address" "a_string" \
+    $undefined \
+    "\"hello world\""
+  check_var_with_bool_opt "address" "a_binary_string" \
+    $undefined \
+    "\"hello\""
+  check_var_with_bool_opt "address" "a_binary_string_array"
+  check_var_with_bool_opt "address" "a_big_string"
+  check_var_with_bool_opt "address" "an_array"
+  check_var_with_bool_opt "address" "an_array_with_repetition"
+  check_var_with_bool_opt "address" "a_symbol_pointer" \
+    $undefined \
+    "<global_symbol>"
+
+  if { $current_lang == "c++" } {
+    check_var_with_bool_opt "address" "a_point_t_ref"
+    check_var_with_bool_opt "address" "a_base_ref" \
+      $undefined \
+      ""
+  }
+
+  with_temp_option "set print address off" "set print address on" {
+    check_var_with_no_opts "a_string" \
+      "\"hello world\""
+    check_var_with_bool_opt "address" "a_string" \
+      $undefined \
+      "\"hello world\""
+  }
+}
+
 # Test the deref_refs option for gdb.Value.format_string.
 proc test_deref_refs {} {
   global current_lang
@@ -943,6 +985,7 @@ proc test_all_common {} {
   test_array_indexes
   test_symbols
   test_unions
+  test_address
   test_deref_refs
   test_actual_objects
   test_static_members