[PATCH v2] Fix raw-frame-arguments in combination with frame-filters
Hannes Domani
ssbssa@yahoo.de
Sun Jan 31 13:46:11 GMT 2021
Currently, if frame-filters are active, raw-values is used instead of
raw-frame-arguments to decide if a pretty-printer should be invoked for
frame arguments in a backtrace.
In this example, "super struct" is the output of the pretty-printer:
(gdb) disable frame-filter global BasicFrameFilter
(gdb) bt
#0 foo (x=42, ss=super struct = {...}) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
If no frame-filter is active, then the raw-values print option does not
affect the backtrace output:
(gdb) set print raw-values on
(gdb) bt
#0 foo (x=42, ss=super struct = {...}) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
(gdb) set print raw-values off
Instead, the raw-frame-arguments option disables the pretty-printer in the
backtrace:
(gdb) bt -raw-frame-arguments on
#0 foo (x=42, ss=...) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
But if a frame-filter is active, the same rules don't apply.
The option raw-frame-arguments is ignored, but raw-values decides if the
pretty-printer is used:
(gdb) enable frame-filter global BasicFrameFilter
(gdb) bt
#0 foo (x=42, ss=super struct = {...}) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
(gdb) set print raw-values on
(gdb) bt
#0 foo (x=42, ss=...) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
(gdb) set print raw-values off
(gdb) bt -raw-frame-arguments on
#0 foo (x=42, ss=super struct = {...}) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
So this adds the PRINT_RAW_FRAME_ARGUMENTS flag to frame_filter_flag, which
is then used in the frame-filter to override the raw flag in enumerate_args.
Then the output is the same if a frame-filter is active, the pretty-printer
for backtraces is only disabled with the raw-frame-arguments option:
(gdb) enable frame-filter global BasicFrameFilter
(gdb) bt
#0 foo (x=42, ss=super struct = {...}) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
(gdb) set print raw-values on
(gdb) bt
#0 foo (x=42, ss=super struct = {...}) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
(gdb) set print raw-values off
(gdb) bt -raw-frame-arguments on
#0 foo (x=42, ss=...) at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:47
#1 0x004016aa in main () at C:/src/repos/gdb-testsuite/gdb/testsuite/gdb.python/py-frame-args.c:57
gdb/ChangeLog:
2021-01-31 Hannes Domani <ssbssa@yahoo.de>
* extension.h (enum frame_filter_flag): Add
PRINT_RAW_FRAME_ARGUMENTS.
* python/py-framefilter.c (enumerate_args): Override raw flag.
raw_frame_args argument.
(py_mi_print_variables): Forward raw flag.
(py_print_args): Forward raw_frame_args flag.
(py_print_frame): Handle PRINT_RAW_FRAME_ARGUMENTS.
* stack.c (backtrace_command_1): Set PRINT_RAW_FRAME_ARGUMENTS.
gdb/testsuite/ChangeLog:
2021-01-31 Hannes Domani <ssbssa@yahoo.de>
* gdb.python/py-frame-args.exp: Add bt raw-frame-arguments tests.
* gdb.python/py-frame-args.py: Add basic frame-filter.
---
v2:
- More detailed commit message describing the problem.
---
gdb/extension.h | 4 ++++
gdb/python/py-framefilter.c | 14 ++++++++++----
gdb/stack.c | 2 ++
gdb/testsuite/gdb.python/py-frame-args.exp | 20 ++++++++++++++++++++
gdb/testsuite/gdb.python/py-frame-args.py | 13 +++++++++++++
5 files changed, 49 insertions(+), 4 deletions(-)
diff --git a/gdb/extension.h b/gdb/extension.h
index a505c68d25e..7067e232cd3 100644
--- a/gdb/extension.h
+++ b/gdb/extension.h
@@ -103,6 +103,10 @@ enum frame_filter_flag
/* Set this flag if elided frames should not be printed. */
PRINT_HIDE = 1 << 5,
+
+ /* Set this flag if pretty printers for frame arguments should not
+ be invoked. */
+ PRINT_RAW_FRAME_ARGUMENTS = 1 << 6,
};
DEF_ENUM_FLAGS_TYPE (enum frame_filter_flag, frame_filter_flags);
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 6dd741ab704..e53e3409235 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -422,12 +422,14 @@ static enum ext_lang_bt_status
enumerate_args (PyObject *iter,
struct ui_out *out,
enum ext_lang_frame_args args_type,
+ bool raw_frame_args,
int print_args_field,
struct frame_info *frame)
{
struct value_print_options opts;
get_user_print_options (&opts);
+ opts.raw = raw_frame_args;
if (args_type == CLI_SCALAR_VALUES)
{
@@ -655,8 +657,8 @@ py_mi_print_variables (PyObject *filter, struct ui_out *out,
ui_out_emit_list list_emitter (out, "variables");
if (args_iter != Py_None
- && (enumerate_args (args_iter.get (), out, args_type, 1, frame)
- == EXT_LANG_BT_ERROR))
+ && (enumerate_args (args_iter.get (), out, args_type, opts->raw, 1,
+ frame) == EXT_LANG_BT_ERROR))
return EXT_LANG_BT_ERROR;
if (locals_iter != Py_None
@@ -701,6 +703,7 @@ static enum ext_lang_bt_status
py_print_args (PyObject *filter,
struct ui_out *out,
enum ext_lang_frame_args args_type,
+ bool raw_frame_args,
struct frame_info *frame)
{
gdbpy_ref<> args_iter (get_py_iter_from_func (filter, "frame_args"));
@@ -726,7 +729,8 @@ py_print_args (PyObject *filter,
}
}
else if (args_iter != Py_None
- && (enumerate_args (args_iter.get (), out, args_type, 0, frame)
+ && (enumerate_args (args_iter.get (), out, args_type,
+ raw_frame_args, 0, frame)
== EXT_LANG_BT_ERROR))
return EXT_LANG_BT_ERROR;
@@ -957,7 +961,9 @@ py_print_frame (PyObject *filter, frame_filter_flags flags,
wrong. */
if (print_args && (location_print || out->is_mi_like_p ()))
{
- if (py_print_args (filter, out, args_type, frame) == EXT_LANG_BT_ERROR)
+ bool raw_frame_args = (flags & PRINT_RAW_FRAME_ARGUMENTS) != 0;
+ if (py_print_args (filter, out, args_type, raw_frame_args, frame)
+ == EXT_LANG_BT_ERROR)
return EXT_LANG_BT_ERROR;
}
diff --git a/gdb/stack.c b/gdb/stack.c
index bce6a2f42f8..dbca5ade1c2 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2028,6 +2028,8 @@ backtrace_command_1 (const frame_print_options &fp_opts,
flags |= PRINT_LOCALS;
if (bt_opts.hide)
flags |= PRINT_HIDE;
+ if (fp_opts.print_raw_frame_arguments)
+ flags |= PRINT_RAW_FRAME_ARGUMENTS;
if (!bt_opts.no_filters)
{
diff --git a/gdb/testsuite/gdb.python/py-frame-args.exp b/gdb/testsuite/gdb.python/py-frame-args.exp
index 5d35323c0e6..dae0c0ac29e 100644
--- a/gdb/testsuite/gdb.python/py-frame-args.exp
+++ b/gdb/testsuite/gdb.python/py-frame-args.exp
@@ -34,6 +34,26 @@ gdb_test_no_output "source ${remote_python_file}" "load python file"
gdb_breakpoint [gdb_get_line_number "break-here"]
gdb_continue_to_breakpoint "break-here" ".* break-here .*"
+# Test raw-frame-arguments on backtrace with and without frame-filter
+foreach_with_prefix filtered {enable disable} {
+ gdb_test_no_output "$filtered frame-filter global BasicFrameFilter"
+
+ gdb_test "bt 1" \
+ ".*foo \\(x=42, ss=super struct = {\[.\]{3}}\\).*" \
+ "bt pretty"
+
+ gdb_test "bt -raw-frame-arguments on 1" \
+ ".*foo \\(x=42, ss=\[.\]{3}\\).*" \
+ "bt raw"
+
+ # "set print raw-values" should not affect frame arguments
+ gdb_test_no_output "set print raw-values on"
+ gdb_test "bt 1" \
+ ".*foo \\(x=42, ss=super struct = {\[.\]{3}}\\).*" \
+ "bt pretty,raw-values"
+ gdb_test_no_output "set print raw-values off"
+}
+
# Test all combinations with raw off.
gdb_test_no_output "set print raw-frame-arguments off"
diff --git a/gdb/testsuite/gdb.python/py-frame-args.py b/gdb/testsuite/gdb.python/py-frame-args.py
index d80d761b995..3b65eed0dad 100644
--- a/gdb/testsuite/gdb.python/py-frame-args.py
+++ b/gdb/testsuite/gdb.python/py-frame-args.py
@@ -73,3 +73,16 @@ pretty_printers_dict = {}
register_pretty_printers ()
gdb.pretty_printers.append (lookup_function)
+
+
+class BasicFrameFilter (object):
+ def __init__ (self):
+ self.name = "BasicFrameFilter"
+ self.priority = 100
+ self.enabled = True
+ gdb.frame_filters[self.name] = self
+
+ def filter (self, frame_iter):
+ return frame_iter
+
+BasicFrameFilter ()
--
2.30.0
More information about the Gdb-patches
mailing list