From: Tom de Vries Date: Sat, 15 Aug 2020 08:19:13 +0000 (+0200) Subject: [gdb/backtrace] Fix printing of fortran string args X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=547ce8f00b;p=binutils-gdb.git [gdb/backtrace] Fix printing of fortran string args When running test-case gdb.fortran/mixed-lang-stack.exp, it passes, but we find in gdb.log: ... (gdb) bt^M ... #7 0x000000000040113c in mixed_func_1b (a=1, b=2, c=3, d=(4,5), \ e=, g=..., _e=6) at mixed-lang-stack.f90:87^M ... while a bit later in gdb.log, we have instead for the same frame (after adding a gdb_test_no_output "set print frame-arguments all" to prevent getting "e=..."): ... (gdb) up^M #7 0x000000000040113c in mixed_func_1b (a=1, b=2, c=3, d=(4,5), \ e='abcdef', g=( a = 1.5, b = 2.5 ), _e=6) at mixed-lang-stack.f90:87^M ... The difference is that in the latter case, we print the frame while it's selected, while in the former, it's not. The problem is that while trying to resolve the dynamic type of e in resolve_dynamic_type, we call dwarf2_evaluate_property with a frame == NULL argument, and then use the selected frame as the context in which to evaluate the dwarf property, effectively evaluating a DW_OP_fbreg operation in the wrong frame context. Fix this by temporarily selecting the frame of which we're trying to print the arguments in print_frame_args, borrowing code from print_frame_local_vars that was added to fix a similar issue in commit 16c3b12f19 "error/internal-error printing local variable during "bt full". Build and tested on x86_64-linux. gdb/ChangeLog: 2020-08-15 Tom de Vries PR backtrace/26390 * stack.c (print_frame_args): Temporarily set the selected frame to FRAME while printing the frame's arguments. gdb/testsuite/ChangeLog: 2020-08-15 Tom de Vries PR backtrace/26390 * gdb.fortran/mixed-lang-stack.exp: Call bt with -frame-arguments all. Update expected pattern. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5106b28523b..9cc7e44cba7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-08-15 Tom de Vries + + PR backtrace/26390 + * stack.c (print_frame_args): Temporarily set the selected + frame to FRAME while printing the frame's arguments. + 2020-08-14 Pedro Franco de Carvalho PR breakpoints/26385 diff --git a/gdb/stack.c b/gdb/stack.c index 265e764dc24..616b629e208 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -744,6 +744,12 @@ print_frame_args (const frame_print_options &fp_opts, = (print_names && fp_opts.print_frame_arguments != print_frame_arguments_none); + /* Temporarily change the selected frame to the given FRAME. + This allows routines that rely on the selected frame instead + of being given a frame as parameter to use the correct frame. */ + scoped_restore_selected_frame restore_selected_frame; + select_frame (frame); + if (func) { const struct block *b = SYMBOL_BLOCK_VALUE (func); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f22401b305b..54a0ab568e2 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-08-15 Tom de Vries + + PR backtrace/26390 + * gdb.fortran/mixed-lang-stack.exp: Call bt with -frame-arguments all. + Update expected pattern. + 2020-08-13 Pedro Alves * gdb.fortran/complex.exp: Check skip_fortran_tests. diff --git a/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp b/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp index 793318626d6..edf2508537d 100644 --- a/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp +++ b/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp @@ -59,19 +59,23 @@ proc run_tests { lang } { } # Check the backtrace. - set bt_stack [multi_line \ - "#0\\s+breakpt \\(\\) at \[^\r\n\]+" \ - "#1\\s+$hex in mixed_func_1h \\(\\) at \[^\r\n\]+" \ - "#2\\s+$hex in mixed_func_1g \\(obj=\\.\\.\\.\\) at \[^\r\n\]+" \ - "#3\\s+$hex in mixed_func_1f \\(\\) at \[^\r\n\]+" \ - "#4\\s+$hex in mixed_func_1e \\(\\) at \[^\r\n\]+" \ - "#5\\s+$hex in mixed_func_1d \\(\[^\r\n\]+\\) at \[^\r\n\]+" \ - "#6\\s+$hex in mixed_func_1c \\(\[^\r\n\]+\\) at \[^\r\n\]+" \ - "#7\\s+$hex in mixed_func_1b \\(\[^\r\n\]+\\) at \[^\r\n\]+" \ - "#8\\s+$hex in mixed_func_1a \\(\\) at \[^\r\n\]+" \ - "#9\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" \ - "#10\\s+$hex in main \\(\[^\r\n\]+\\) at .*" ] - gdb_test "bt" $bt_stack + set e_arg "\['\"\]abcdef\['\"\]" + set 1b_args "\[^\r\n\]+$e_arg\[^\r\n\]+" + set 1g_args "obj=\[^\r\n\]+" + set bt_stack \ + [multi_line \ + "#0\\s+breakpt \\(\\) at \[^\r\n\]+" \ + "#1\\s+$hex in mixed_func_1h \\(\\) at \[^\r\n\]+" \ + "#2\\s+$hex in mixed_func_1g \\($1g_args\\) at \[^\r\n\]+" \ + "#3\\s+$hex in mixed_func_1f \\(\\) at \[^\r\n\]+" \ + "#4\\s+$hex in mixed_func_1e \\(\\) at \[^\r\n\]+" \ + "#5\\s+$hex in mixed_func_1d \\(\[^\r\n\]+\\) at \[^\r\n\]+" \ + "#6\\s+$hex in mixed_func_1c \\(\[^\r\n\]+\\) at \[^\r\n\]+" \ + "#7\\s+$hex in mixed_func_1b \\($1b_args\\) at \[^\r\n\]+" \ + "#8\\s+$hex in mixed_func_1a \\(\\) at \[^\r\n\]+" \ + "#9\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" \ + "#10\\s+$hex in main \\(\[^\r\n\]+\\) at .*" ] + gdb_test "bt -frame-arguments all" $bt_stack # Check the language for frame #0. gdb_test "info frame" "source language fortran\..*" \