From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15701 invoked by alias); 6 Dec 2010 21:35:18 -0000 Received: (qmail 15334 invoked by uid 22791); 6 Dec 2010 21:35:17 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL,BAYES_00,TW_RG X-Spam-Check-By: sourceware.org Received: from imr3.ericy.com (HELO imr3.ericy.com) (198.24.6.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Dec 2010 21:35:10 +0000 Received: from eusaamw0711.eamcs.ericsson.se ([147.117.20.178]) by imr3.ericy.com (8.13.8/8.13.8) with ESMTP id oB6LYX0x024621 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Mon, 6 Dec 2010 15:34:58 -0600 Received: from EUSAACMS0703.eamcs.ericsson.se ([169.254.1.63]) by eusaamw0711.eamcs.ericsson.se ([147.117.20.178]) with mapi; Mon, 6 Dec 2010 16:34:34 -0500 From: Marc Khouzam To: "'Tom Tromey'" CC: "'gdb-patches@sourceware.org'" Date: Mon, 06 Dec 2010 21:35:00 -0000 Subject: RE: [MI] Segfault using 'interpreter-exec mi' Message-ID: References: In-Reply-To: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes 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: 2010-12/txt/msg00060.txt.bz2 > -----Original Message----- > From: Tom Tromey [mailto:tromey@redhat.com]=20 > Sent: Thursday, December 02, 2010 11:35 AM > To: Marc Khouzam > Cc: 'gdb-patches@sourceware.org' > Subject: Re: [MI] Segfault using 'interpreter-exec mi' >=20 > >>>>> "Marc" =3D=3D Marc Khouzam writes: >=20 > Marc> I got a segfault when using 'interpreter-exec mi' and getting an > Marc> error result. I believe I tracked it down to mi_parse(). From > Marc> what I can see, we cannot call error() from mi_parse()=20 > because it > Marc> does not catch exceptions. >=20 > Marc> Note that the segfault does not happen in full MI mode,=20 > I think because > Marc> we are in the correct interpreter for output, however,=20 > the MI command > Marc> does not get the proper ^error and requires the user to=20 > enter a new line > Marc> to get the ^done. >=20 > Thanks for the patch. >=20 > Marc> The below patch removes the calls to error() and uses=20 > fprintf_unfiltered. > Marc> Because of the comment > Marc> /* FIXME: This should be a function call. */ > Marc> I took the opportunity to make a method mi_parse_error(). >=20 > I don't mind this approach, but I think it is probably better to just > change mi_parse to use exceptions like the rest of gdb. Then=20 > the caller > can handle them, just like it does for exceptions occurring in the > actual MI command. >=20 > The reason I think this is better is that a rule like "this=20 > code cannot > call error" is reasonably difficult to enforce in gdb. >=20 > What do you think of that? I agree with you and I started coding such a patch. Things got a bit more complex than I expected though. Mostly because the error output of mi_parse() has to use some of the data that=20 was actually parsed in mi_parse(), which lead me to have to=20 play around with return values while handling exceptions, or having to free some memory _after_ calling error(), which=20 I didn't know how to do. After a while, it started to feel a bit complicated of a fix for=20 something that I'm hoping to push to the 7_2 branch. Currently,=20 not getting the proper ^error message from MI could lead the=20 frontend into a pretty bad situation, which is why I think this should be fixed in 7_2. Could we have the brute force fix now, and leave the improvement for later? > A quick nit about the patch itself. >=20 > Marc> +void > Marc> +vmi_parse_error (struct mi_parse *parse, const char=20 > *format, va_list args) >=20 > The new functions need introductory comments. >=20 > I would have made them both static. Here is the same patch incorporating your two comments. Thanks Marc 2010-12-06 Marc Khouzam * mi/mi-parse.c (vmi_parse_error, mi_parse_error): Added. (mi_parse): Call mi_parse_error instead of error. ### Eclipse Workspace Patch 1.0 #P src Index: gdb/mi/mi-parse.c =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 RCS file: /cvs/src/src/gdb/mi/mi-parse.c,v retrieving revision 1.22 diff -u -r1.22 mi-parse.c --- gdb/mi/mi-parse.c 6 Dec 2010 14:16:43 -0000 1.22 +++ gdb/mi/mi-parse.c 6 Dec 2010 21:33:39 -0000 @@ -223,6 +223,26 @@ xfree (parse); } =20 +/* Output the error message from the mi_parse method using + a variable parameter list, and deallocate the struct parse */ +static void +vmi_parse_error (struct mi_parse *parse, const char *format, va_list args) +{ + vfprintf_unfiltered (raw_stdout, format, args); + mi_parse_free (parse); +} + +/* Output an error message for the mi_parse method, + and deallocate the struct parse */ +static void +mi_parse_error (struct mi_parse *parse, const char *format, ...)=20 +{ + va_list args; + + va_start (args, format); + vmi_parse_error (parse, format, args); + va_end (args); +} =20 struct mi_parse * mi_parse (char *cmd) @@ -272,12 +292,10 @@ parse->cmd =3D mi_lookup (parse->command); if (parse->cmd =3D=3D NULL) { - /* FIXME: This should be a function call. */ - fprintf_unfiltered - (raw_stdout, + mi_parse_error=20 + (parse, "%s^error,msg=3D\"Undefined MI command: %s\"\n", parse->token, parse->command); - mi_parse_free (parse); return NULL; } =20 @@ -312,24 +330,51 @@ if (strncmp (chp, "--thread-group ", tgs) =3D=3D 0) { if (parse->thread_group !=3D -1) - error (_("Duplicate '--thread-group' option")); + {=20=20=20 + mi_parse_error + (parse, + "%s^error,msg=3D\"Duplicate '--thread-group' option\"\n", + parse->token); + return NULL; + }=20=20=20 + chp +=3D tgs; if (*chp !=3D 'i') - error (_("Invalid thread group id")); + {=20=20=20 + mi_parse_error + (parse, + "%s^error,msg=3D\"Invalid thread group id\"\n", + parse->token); + return NULL; + } chp +=3D 1; parse->thread_group =3D strtol (chp, &chp, 10); } else if (strncmp (chp, "--thread ", ts) =3D=3D 0) { if (parse->thread !=3D -1) - error (_("Duplicate '--thread' option")); + {=20=20=20 + mi_parse_error + (parse, + "%s^error,msg=3D\"Duplicate '--thread' option\"\n", + parse->token); + return NULL; + }=20=20=20 + chp +=3D ts; parse->thread =3D strtol (chp, &chp, 10); } else if (strncmp (chp, "--frame ", fs) =3D=3D 0) { if (parse->frame !=3D -1) - error (_("Duplicate '--frame' option")); + {=20=20=20 + mi_parse_error + (parse, + "%s^error,msg=3D\"Duplicate '--frame' option\"\n", + parse->token); + return NULL; + } + chp +=3D fs; parse->frame =3D strtol (chp, &chp, 10); } @@ -337,8 +382,14 @@ break; =20 if (*chp !=3D '\0' && !isspace (*chp)) - error (_("Invalid value for the '%s' option"), - start[2] =3D=3D 't' ? "--thread" : "--frame"); + { + mi_parse_error + (parse, + "%s^error,msg=3D\"Invalid value for the '%s' option\"\n", + parse->token, start[2] =3D=3D 't' ? "--thread" : "--frame"); + return NULL; + } + while (isspace (*chp)) chp++; } @@ -350,12 +401,10 @@ mi_parse_argv (chp, parse); if (parse->argv =3D=3D NULL) { - /* FIXME: This should be a function call. */ - fprintf_unfiltered - (raw_stdout, + mi_parse_error + (parse, "%s^error,msg=3D\"Problem parsing arguments: %s %s\"\n", parse->token, parse->command, chp); - mi_parse_free (parse); return NULL; } }