From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7745 invoked by alias); 10 Aug 2007 10:03:20 -0000 Received: (qmail 7613 invoked by uid 22791); 10 Aug 2007 10:03:19 -0000 X-Spam-Check-By: sourceware.org Received: from province.act-europe.fr (HELO province.act-europe.fr) (212.157.227.214) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 10 Aug 2007 10:03:16 +0000 Received: by province.act-europe.fr (Postfix, from userid 560) id AF696165B0E; Fri, 10 Aug 2007 12:03:13 +0200 (CEST) Date: Fri, 10 Aug 2007 10:03:00 -0000 From: Jerome Guitton To: gdb-patches@sources.redhat.com Subject: [RFA] backtrace in mixed language applications Message-ID: <20070810100313.GA29799@adacore.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZPt4rx8FFjLCG7dd" Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-08/txt/msg00201.txt.bz2 --ZPt4rx8FFjLCG7dd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1228 Hello, when doing a backtrace in a mixed-language application, GDB should use the appriorate language for printing the frames (in particular for printing arguments). Not the case for now, it prints every frame with the language of the first one. This is quite visible in a mixed C/Ada application; for example, in Ada, pointer to unconstrained strings can be represented with "fat pointers", which are records containing a pointer to the bound information (P_BOUNDS) and a pointer to the array of characters (P_ARRAY). Imagine that you have an ada procedure lang_switch.ada_procedure, which takes an Ada string in parameter, calling some C code. If you get a backtrace from the C code, you'll get: [...] #0 c_procedure (msg=0xbfffc170 "msg") at foo.c:4 #1 0x08049b91 in lang_switch.ada_procedure (msg={P_ARRAY = 0x805524c, P_BOUNDS = 0x8055250}) at lang_switch.adb:14 [...] the msg is bogus in frame #1 is bogus. you should have got: [...] #0 c_procedure (msg=0xbfffaa00 "msg") at foo.c:4 #1 0x08049b91 in lang_switch.ada_procedure (msg=0x805524c) at lang_switch.adb:14 [...] The patch in attachment should fix that. Tested on x86-linux. The Ada/C testcase will follow. OK to apply? Thanks in advance, Jerome --ZPt4rx8FFjLCG7dd Content-Type: video/dv Content-Disposition: attachment; filename="stack.c.dif" Content-Transfer-Encoding: quoted-printable Content-length: 1988 2007-08-10 Jerome Guitton =0A= =0A= * stack.c (backtrace_command_1): select the frame that we are=0A= about to print.=0A= =0A= Index: stack.c=0A= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A= RCS file: /cvs/src/src/gdb/stack.c,v=0A= retrieving revision 1.150=0A= diff -u -p -r1.150 stack.c=0A= --- stack.c 25 Jul 2007 00:28:25 -0000 1.150=0A= +++ stack.c 10 Aug 2007 09:41:20 -0000=0A= @@ -1104,12 +1104,14 @@ backtrace_command_1 (char *count_exp, in=0A= struct frame_info *fi;=0A= int count;=0A= int i;=0A= - struct frame_info *trailing;=0A= + struct frame_info *trailing, *selected_frame;=0A= int trailing_level;=0A= =20=0A= if (!target_has_stack)=0A= error (_("No stack."));=0A= =20=0A= + selected_frame =3D get_selected_frame (NULL);=0A= +=0A= /* The following code must do two things. First, it must set the=0A= variable TRAILING to the frame from which we should start=0A= printing. Second, it must set the variable count to the number=0A= @@ -1177,6 +1179,10 @@ backtrace_command_1 (char *count_exp, in=0A= {=0A= QUIT;=0A= =20=0A= + /* Select the frame that we are printing, so that the parameters=0A= + are displayed using the appropriate language. */=0A= + select_frame (fi);=0A= +=0A= /* Don't use print_stack_frame; if an error() occurs it probably=0A= means further attempts to backtrace would fail (on the other=0A= hand, perhaps the code does or could be fixed to make sure=0A= @@ -1188,6 +1194,7 @@ backtrace_command_1 (char *count_exp, in=0A= /* Save the last frame to check for error conditions. */=0A= trailing =3D fi;=0A= }=0A= + select_frame (selected_frame);=0A= =20=0A= /* If we've stopped before the end, mention that. */=0A= if (fi && from_tty)=0A= --ZPt4rx8FFjLCG7dd--