From: Don Breazeal <donb@codesourcery.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH] Fix -var-update for registers in frames 1 and up
Date: Tue, 07 Jun 2016 21:37:00 -0000 [thread overview]
Message-ID: <1465335417-36881-1-git-send-email-donb@codesourcery.com> (raw)
This patch fixes a problem with using the MI -var-update command
to access the values of registers in frames other than the current
frame. The patch includes a test that demonstrates the problem:
* run so there are several frames on the stack
* create a varobj for $pc in each frame, #'s 1 and above
* step one instruction, to modify the value of $pc
* call -var-update for each of the previously created varobjs
to verify that they are not reported as having changed.
Without the patch, the -var-update command reported that $pc for all
frames 1 and above had changed to the value of $pc in frame 0.
The -var-create command takes a '--frame' argument and uses that
to select the frame for retrieving the register value. But -var-update
has no such argument, and previously didn't do anything to select the
frame, so for frames other than frame 0 it returned the value of the
register for frame 0, instead of reporting the value as unchanged.
The solution implemented here is for varobj.c:varobj_update to
handle register varobjs by calling select_frame using the frame
associated with the varobj's value. If the frame isn't found
varobj_update throws an error.
Thanks
--Don
gdb/testsuite/ChangeLog:
2016-06-07 Don Breazeal <donb@codesourcery.com>
* gdb.mi/mi-frame-regs.exp: New test.
gdb/ChangeLog:
2016-06-07 Don Breazeal <donb@codesourcery.com>
* varobj.c (varobj_update): If the varobj represents a register,
select the frame associated with the varobj's value.
---
gdb/testsuite/gdb.mi/mi-frame-regs.exp | 92 ++++++++++++++++++++++++++++++++++
gdb/varobj.c | 13 +++++
2 files changed, 105 insertions(+)
diff --git a/gdb/testsuite/gdb.mi/mi-frame-regs.exp b/gdb/testsuite/gdb.mi/mi-frame-regs.exp
new file mode 100644
index 0000000..9ae0fb0
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-frame-regs.exp
@@ -0,0 +1,92 @@
+# Copyright 1999-2016 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test essential Machine interface (MI) operations
+#
+# Verify that the pc register values for stack frames 1 and above are
+# not reported as changed by -var-update after the current pc changes.
+#
+
+global gdb_prompt
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+gdb_exit
+if {[mi_gdb_start]} then {
+ continue
+}
+
+standard_testfile basics.c
+
+if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
+ executable {debug}] != "" } then {
+ untested mi-frame-regs.exp
+ return -1
+}
+
+# Create a varobj for the pc register in each of the frames other
+# than frame 0.
+
+proc var_create_regs {nframes} {
+ global hex
+
+ for {set i 1} {$i < $nframes} {incr i} {
+ mi_gdb_test "-var-create --thread 1 --frame $i - \* \$pc" \
+ "\\^done,.*value=\"$hex.*" \
+ "create varobj for pc in frame $i"
+ }
+}
+
+# Check that the value of the pc register for each of the
+# frames 1 and above is not reported to have changed.
+
+proc var_update_regs {nframes} {
+
+ for {set i 1} {$i < $nframes} {incr i} {
+ mi_gdb_test "-var-update 1 var$i" \
+ "\\^done,(changelist=\\\[\\\])" \
+ "pc unchanged in -var-update for frame $i"
+ }
+}
+
+mi_run_to_main
+
+# Run to the function 'callee3'.
+set line_callee3_head [gdb_get_line_number "callee3 ("]
+set line_callee3_body [expr $line_callee3_head + 2]
+mi_create_breakpoint "basics.c:callee3" \
+ "insert breakpoint at basics.c:callee3" \
+ -number 2 -func callee3 -file ".*basics.c" \
+ -line $line_callee3_body
+
+mi_execute_to "exec-continue" "breakpoint-hit" "callee3" ".*" ".*${srcfile}" "$line_callee3_body" \
+ { "" "disp=\"keep\"" } "breakpoint hit"
+
+# At the breakpoint in callee3 there are 4 frames. Create a varobj
+# for the pc in each of frames 1 and above.
+set nframes 4
+var_create_regs $nframes
+
+# Step one instruction to change the program counter.
+mi_execute_to "exec-next-instruction" "end-stepping-range" \
+ "callee3" ".*" ".*${srcfile}" ".*" "" \
+ "next instruction in callee3"
+
+# Make sure all is well with -var-update.
+var_update_regs $nframes
+
+mi_gdb_exit
+return 0
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 6f56cba..e8f2e04 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -1610,6 +1610,19 @@ varobj_update (struct varobj **varp, int is_explicit)
r.varobj = *varp;
r.status = VAROBJ_IN_SCOPE;
+ /* If updating a register varobj, select the correct frame. */
+ if ((*varp)->root->exp != NULL
+ && (*varp)->root->exp->elts[0].opcode == OP_REGISTER)
+ {
+ struct frame_info *fi;
+
+ fi = frame_find_by_id (VALUE_FRAME_ID ((*varp)->value));
+ if (fi != NULL)
+ select_frame (fi);
+ else
+ error (_("Failed to find the frame for the specified register"));
+ }
+
/* Update the root variable. value_of_root can return NULL
if the variable is no longer around, i.e. we stepped out of
the frame in which a local existed. We are letting the
--
2.8.1
next reply other threads:[~2016-06-07 21:37 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 21:37 Don Breazeal [this message]
2016-06-08 13:01 ` Andrew Burgess
2016-06-08 13:09 ` Andrew Burgess
2016-06-09 0:48 ` Don Breazeal
2016-06-09 18:23 ` Don Breazeal
[not found] ` <20160610103220.GJ26734@embecosm.com>
2016-06-10 21:25 ` Don Breazeal
2016-06-13 9:05 ` Andrew Burgess
2016-06-13 21:54 ` [PATCH v2] " Don Breazeal
2016-06-20 15:32 ` [PING] " Don Breazeal
2016-07-11 14:48 ` Don Breazeal
2016-07-20 21:07 ` Don Breazeal
2016-07-21 16:59 ` Don Breazeal
2016-07-29 16:13 ` [PING^4] " Don Breazeal
2016-08-05 18:22 ` [PING] " Don Breazeal
2016-08-10 15:49 ` Pedro Alves
2016-10-04 20:56 ` [PATCH v3] PR mi/20395 - " Don Breazeal
2016-10-05 14:18 ` Pedro Alves
2016-10-07 0:05 ` Andrew Burgess
2016-10-14 16:59 ` Don Breazeal
2016-10-26 18:04 ` [PING] " Don Breazeal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465335417-36881-1-git-send-email-donb@codesourcery.com \
--to=donb@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox