This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hello, This is a problem impacting multi-language applications that Jerome reported a while ago: On Fri, Aug 10, 2007 at 12:03:13PM +0200, Jerome Guitton wrote: > 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 > [...] Jerome posted a patch which I reviewed, and we decided that the patch needed to be reworked. Since then, Jerome has been quite busy and asked me to do it for him. I looked into the problem some more, and found that we could quite easily avoid switching a global variable, and instead find the appropriate language and explicitly pass that language to the val_print routine. This implies the addition of the language to a couple of routines (common_val_print and val_print), and a lot of mechanical edits all over, but it's a good step in the right direction anyway. As a side note, I am still thinking about updating the *parsing* routines to take a new struct parse_context parameter. In this structure, we will have the input_radix in addition to the language. I considered using that same structure for the *printing* but as a matter for fact, only the language is relevant in the printing case. So I only added the language. The meat of the change is in valprint.c (update of the val_print and common_val_print function profiles, as well as removing the use of the current_language), in stack.c (where we get the language from the symbol to be printed - we could get it from the frame but I think it's the same), and mi-stack.c. The rest are mechanical edits where I added the current_language. I didn't want to look at each of the call sites individually and try to guess whether we can pass something better. I'd much rather leave that for later, as a series of separate patches. 2008-01-09 Joel Brobecker <brobecker@adacore.com> * valprint.c (val_print): Add new language parameter and use it instead of using the current_language. Update calls to val_print throughout. (common_val_print): Add new langauge parameter and pass it to val_print. * value.h (struct language_defn): Add opaque declaration. (val_print, common_val_print): Update declarations. * stack.c (print_frame_args): Update call to common_val_print using the appropriate language. * mi/mi-cmd-stack.c (list_args_or_locals): Likewise. * c-valprint, f-valprint.c, m2-valprint.c, mt-tdep.c, infcmd.c, mi/mi-main.c, jv-valprint.c, ada-valprint.c, varobj.c, p-valprint.c, scm-valprint.c, cp-valprint.c, sh64-tdep.c, printcmd.c: #include "language.h" if necessary. Update calls to val_print and common_val_print. * Makefile.in (mt-tdep.o, sh64-tdep.o, mi-cmds.o, mi-main.o): Update dependencies. The testcase is still pretty much the same. I just fixed a couple of errors that show up when testing out of tree. 2008-01-09 Jerome Guitton <guitton@adacore.com> * gdb.ada/lang_switch: New test program. * gdb.ada/lang_switch.exp: New testcase. Tested on x86-linux. OK to apply? Thanks, -- Joel
Attachment:
lang_switch.diff
Description: Text document
Attachment:
lang_switch-tc.diff
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |