This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] MI: Error out on -var-create invalid FRAME-ADDR
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: Dodji Seketeli <dseketel at redhat dot com>
- Date: Mon, 10 Aug 2009 18:29:49 +0200
- Subject: [patch] MI: Error out on -var-create invalid FRAME-ADDR
Hi,
-var-create could create VAROBJ with uninitialized thread_id leading to
unexpected processing.
The frame parameter of -var-create is FRAME-ADDR, one could expect it is
FRAME-ID. It is even commented in the source:
/* FIXME: cagney/2002-11-23: This code should be doing a
lookup using the frame ID and not just the frame's
``address''. This, of course, means an interface
change. However, with out that interface change ISAs,
such as the ia64 with its two stacks, won't work.
Similar goes for the case where there is a frameless
function. */
fi = find_frame_addr_in_frame_chain (frame);
At least error out when the frame is not found AND it harms.
Therefore the original command Dodji bugreporting it:
-var-create var2 0 variable
should have been instead:
-var-create --thread 1 --frame 0 var2 * variable
Regression tested on {x86_64,i686}-fedora11-linux-gnu.
find_frame_addr_in_frame_chain already has an explicit check for 0 so 0
currently can never be a valid frame address on any arch:
if (frame_addr == (CORE_ADDR) 0)
return NULL;
Thanks,
Jan
gdb/
2009-08-10 Jan Kratochvil <jan.kratochvil@redhat.com>
* varobj.c (varobj_create): Error if the specified frame was not found
and it is needed.
gdb/testsuite/
2009-08-10 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.mi/mi2-var-cmd.exp (create variable with invalid FRAME-ADDR): New.
--- a/gdb/testsuite/gdb.mi/mi2-var-cmd.exp
+++ b/gdb/testsuite/gdb.mi/mi2-var-cmd.exp
@@ -126,6 +126,11 @@ mi_gdb_test "-var-create int * int" \
"&\"Attempt to use a type name as an expression.\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
"create int"
+# The number 0 must be an invalid frame address and linteger a local variable.
+mi_gdb_test "-var-create invalidframe 0 linteger" \
+ "&\"Failed to find the specified frame.\\\\n\".*\\^error,msg=\"mi_cmd_var_create: unable to create variable object\"" \
+ "create variable with invalid FRAME-ADDR"
+
##### #####
# #
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -565,8 +567,19 @@ varobj_create (char *objname,
we must select the appropriate frame before parsing
the expression, otherwise the value will not be current.
Since select_frame is so benign, just call it for all cases. */
- if (innermost_block && fi != NULL)
+ if (innermost_block)
{
+ /* User could specify explicit FRAME-ADDR which was not found but
+ EXPRESSION is frame specific and we would not be able to evaluate
+ it correctly next time. With VALID_BLOCK set we must also set
+ FRAME and THREAD_ID. */
+ if (fi == NULL)
+ {
+ fprintf_unfiltered (gdb_stderr, "Failed to find the specified"
+ " frame.\n");
+ return NULL;
+ }
+
var->root->frame = get_frame_id (fi);
var->root->thread_id = pid_to_thread_id (inferior_ptid);
old_fi = get_selected_frame (NULL);