This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC] references and -stack-list-variables --simple-values
On Friday 26 March 2010 18:05:29 Daniel Jacobowitz wrote:
> On Fri, Mar 26, 2010 at 12:50:48PM +0300, Vladimir Prus wrote:
> >
> > I've noticed that -stack-list-variables, with the --simple-values option,
> > will still print value that have 'reference to complex thing' type, such
> > as references to structures. This does not seem right, so the attached
> > patch fixes it.
>
> No patch attached.
Sorry, here it is.
> > The only concern I have is that somehow, adding a local
> > reference variable makes the order of variables in GDB output change in
> > a random way. That is, given:
> >
> > int A=1;
> > int B=2;
> > int C;
> > int D[3] = {0, 1, 2};
> > int (&E)[3] = D;
> >
> > GDB outputs A, C, E, B, D in that order. Is that expected and test adjustment
> > is right, or I need something else?
>
> GDB goes to some trouble (ordered dictionaries) to preserve the order
> in the debug info. Could you check the dwarf with readelf -wi before
> and after the change? If this is compiler dependent, we might need a
> more flexible test.
It seems that dwarf lists variables in the natural order, so GDB reorders
them somehow :-( I'll look into this some more.
Thanks,
--
Vladimir Prus
CodeSourcery
vladimir@codesourcery.com
(650) 331-3385 x722
? .kdev4
Index: gdb/mi/mi-cmd-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-stack.c,v
retrieving revision 1.49
diff -u -p -r1.49 mi-cmd-stack.c
--- gdb/mi/mi-cmd-stack.c 10 Feb 2010 22:22:02 -0000 1.49
+++ gdb/mi/mi-cmd-stack.c 26 Mar 2010 16:48:59 -0000
@@ -328,9 +328,13 @@ list_args_or_locals (enum what_to_list w
switch (values)
{
case PRINT_SIMPLE_VALUES:
- type = check_typedef (sym2->type);
+ type = check_typedef (sym2->type);
type_print (sym2->type, "", stb->stream, -1);
ui_out_field_stream (uiout, "type", stb);
+ if (TYPE_CODE (type) == TYPE_CODE_REF) {
+ type = TYPE_TARGET_TYPE (type);
+ type = check_typedef (type);
+ }
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
&& TYPE_CODE (type) != TYPE_CODE_STRUCT
&& TYPE_CODE (type) != TYPE_CODE_UNION)
Index: gdb/testsuite/gdb.mi/mi-stack.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-stack.c,v
retrieving revision 1.6
diff -u -p -r1.6 mi-stack.c
--- gdb/testsuite/gdb.mi/mi-stack.c 1 Jan 2010 07:32:03 -0000 1.6
+++ gdb/testsuite/gdb.mi/mi-stack.c 26 Mar 2010 16:49:01 -0000
@@ -29,26 +29,28 @@ int callee4 (void)
int B=2;
int C;
int D[3] = {0, 1, 2};
+ int (&E)[3] = D;
C = A + B;
return 0;
}
-callee3 (char *strarg)
+
+void callee3 (const char *strarg)
{
callee4 ();
}
-callee2 (int intarg, char *strarg)
+void callee2 (int intarg, const char *strarg)
{
callee3 (strarg);
}
-callee1 (int intarg, char *strarg, double fltarg)
+void callee1 (int intarg, const char *strarg, double fltarg)
{
callee2 (intarg, strarg);
}
-main ()
+int main ()
{
callee1 (2, "A string argument.", 3.5);
callee1 (2, "A string argument.", 3.5);
Index: gdb/testsuite/gdb.mi/mi-stack.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.mi/mi-stack.exp,v
retrieving revision 1.30
diff -u -p -r1.30 mi-stack.exp
--- gdb/testsuite/gdb.mi/mi-stack.exp 1 Jan 2010 07:32:03 -0000 1.30
+++ gdb/testsuite/gdb.mi/mi-stack.exp 26 Mar 2010 16:49:01 -0000
@@ -34,7 +34,7 @@ if [mi_gdb_start] {
set testfile "mi-stack"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++ additional_flags=-DFAKEARGV}] != "" } {
untested mi-stack.exp
return -1
}
@@ -167,22 +167,22 @@ proc test_stack_locals_listing {} {
# -stack-list-arguments
mi_gdb_test "232-stack-list-locals 0" \
- "232\\^done,locals=\\\[name=\"A\",name=\"B\",name=\"C\",name=\"D\"\\\]" \
+ "232\\^done,locals=\\\[name=\"A\",name=\"C\",name=\"E\",name=\"B\",name=\"D\"\\\]" \
"stack locals listing of names"
set line_callee4_return_0 [gdb_get_line_number "return 0;"]
# step until A, B, C, D have some reasonable values.
-mi_execute_to "exec-next 4" "end-stepping-range" "callee4" "" ".*${srcfile}" $line_callee4_return_0 ""\
+mi_execute_to "exec-next 5" "end-stepping-range" "callee4" "" ".*${srcfile}" $line_callee4_return_0 ""\
"next's in callee4"
mi_gdb_test "232-stack-list-locals 1" \
- "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"B\",value=\"2\"\},\{name=\"C\",value=\"3\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
- "stack locals listing of names and values"
+ "232\\^done,locals=\\\[\{name=\"A\",value=\"1\"\},\{name=\"C\",value=\"3\"\},\{name=\"E\",value=\".*\"\},\{name=\"B\",value=\"2\"\},\{name=\"D\",value=\"\\{0, 1, 2\\}\"\}\\\]" \
+ "stack locals listing of names and values"
mi_gdb_test "232-stack-list-locals --simple-values" \
- "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
- "stack locals listing, simple types: names and values, complex type: names and types"
+ "232\\^done,locals=\\\[\{name=\"A\",type=\"int\",value=\"1\"\},\{name=\"C\",type=\"int\",value=\"3\"\},\{name=\"E\",type=\"int \\\(&\\\)\\\[3\\\]\"\},\{name=\"B\",type=\"int\",value=\"2\"\},\{name=\"D\",type=\"int \\\[3\\\]\"\}\\\]" \
+ "stack locals listing, simple types: names and values, complex type: names and types"
mi_gdb_test "234-stack-list-locals" \
"234\\^error,msg=\"mi_cmd_stack_list_locals: Usage.*PRINT_VALUES.*\"" \