From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2889 invoked by alias); 25 Nov 2010 20:54:14 -0000 Received: (qmail 2872 invoked by uid 22791); 25 Nov 2010 20:54:11 -0000 X-SWARE-Spam-Status: No, hits=-0.1 required=5.0 tests=AWL,BAYES_50,TW_RG X-Spam-Check-By: sourceware.org Received: from imr4.ericy.com (HELO imr4.ericy.com) (198.24.6.8) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 25 Nov 2010 20:54:05 +0000 Received: from eusaamw0712.eamcs.ericsson.se ([147.117.20.181]) by imr4.ericy.com (8.14.3/8.14.3/Debian-9.1ubuntu1) with ESMTP id oAPLKpZ4030533 for ; Thu, 25 Nov 2010 15:20:52 -0600 Received: from EUSAACMS0703.eamcs.ericsson.se ([169.254.1.63]) by eusaamw0712.eamcs.ericsson.se ([147.117.20.181]) with mapi; Thu, 25 Nov 2010 15:53:57 -0500 From: Marc Khouzam To: "'gdb-patches@sourceware.org'" Date: Thu, 25 Nov 2010 20:54:00 -0000 Subject: [MI] Segfault using 'interpreter-exec mi' Message-ID: 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-11/txt/msg00436.txt.bz2 Hi, I got a segfault when using 'interpreter-exec mi' and getting an error resu= lt. I believe I tracked it down to mi_parse(). From what I can see, we cannot call error() from mi_parse() because it does not catch exceptions. Note that the segfault does not happen in full MI mode, I think because we are in the correct interpreter for output, however, the MI command does not get the proper ^error and requires the user to enter a new line to get the ^done. Session, backtrace, and patch below. > ./gdb GNU gdb (GDB) 7.2.50.20101125-cvs (gdb) interpreter-exec mi "-break-insert --thread a" &"Invalid value for the '--thread' option\n" &"\n" Segmentation fault (top-gdb) backtrace=20 #0 0x080a002a in ui_file_put (file=3D0xa9, write=3D0x8113503 , d= est=3D0x85547e8) at ../../src/gdb/ui-file.c:195 #1 0x08113555 in mi_out_put (uiout=3D0x8555560, stream=3D0x85547e8) at ../= ../src/gdb/mi/mi-out.c:390 During symbol reading, unsupported tag: 'DW_TAG_const_type'. #2 0x0811b290 in captured_mi_execute_command (uiout=3D0x8555560, data=3D0x= 85573a0) at ../../src/gdb/mi/mi-main.c:1850 #3 0x081ae4ae in catch_exception (uiout=3D0x8555560, func=3D0x811b054 , func_args=3D0x85573a0, mask=3D6) at ../../src/gdb/exceptions.c:468 #4 0x0811b390 in mi_execute_command (cmd=3D0x8554bf0 "", from_tty=3D1) at = ../../src/gdb/mi/mi-main.c:1895 #5 0x081171c3 in mi_execute_command_wrapper (cmd=3D0x8554bf0 "") at ../../= src/gdb/mi/mi-interp.c:262 #6 0x081b5c24 in gdb_readline2 (client_data=3D0x0) at ../../src/gdb/event-= top.c:783 #7 0x081b5463 in stdin_event_handler (error=3D0, client_data=3D0x0) at ../= ../src/gdb/event-top.c:433 #8 0x081b414e in handle_file_event (data=3D...) at ../../src/gdb/event-loo= p.c:817 #9 0x081b375c in process_event () at ../../src/gdb/event-loop.c:399 #10 0x081b3820 in gdb_do_one_event (data=3D0x0) at ../../src/gdb/event-loop= .c:464 #11 0x081ae66c in catch_errors (func=3D0x81b376a , func_a= rgs=3D0x0, errstring=3D0x8386077 "", mask=3D6) at ../../src/gdb/exceptions.= c:518 #12 0x0811f319 in tui_command_loop (data=3D0x0) at ../../src/gdb/tui/tui-in= terp.c:171 #13 0x081aed60 in current_interp_command_loop () at ../../src/gdb/interps.c= :291 #14 0x0809042e in captured_command_loop (data=3D0x0) at ../../src/gdb/main.= c:228 #15 0x081ae66c in catch_errors (func=3D0x8090423 , f= unc_args=3D0x0, errstring=3D0x8366fbf "", mask=3D6) at ../../src/gdb/except= ions.c:518 #16 0x0809130d in captured_main (data=3D0xbffff750) at ../../src/gdb/main.c= :912 #17 0x081ae66c in catch_errors (func=3D0x8090464 , func_args= =3D0xbffff750, errstring=3D0x8366fbf "", mask=3D6) at ../../src/gdb/excepti= ons.c:518 #18 0x08091343 in gdb_main (args=3D0xbffff750) at ../../src/gdb/main.c:921 #19 0x080901b3 in main (argc=3D1, argv=3D0xbffff814) at ../../src/gdb/gdb.c= :34 The below patch removes the calls to error() and uses fprintf_unfiltered. Because of the comment /* FIXME: This should be a function call. */ I took the opportunity to make a method mi_parse_error(). No regressions. Comments? Thanks Marc 2010-11-25 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.21 diff -u -r1.21 mi-parse.c --- gdb/mi/mi-parse.c 17 May 2010 20:49:39 -0000 1.21 +++ gdb/mi/mi-parse.c 25 Nov 2010 20:14:40 -0000 @@ -223,6 +223,22 @@ xfree (parse); } =20 +void +vmi_parse_error (struct mi_parse *parse, const char *format, va_list args) +{ + vfprintf_unfiltered (raw_stdout, format, args); + mi_parse_free (parse); +} + +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 +288,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 +326,48 @@ if (strncmp (chp, "--thread-group ", tgs) =3D=3D 0) { if (parse->thread_group !=3D -1) - error (_("Duplicate '--thread-group' option")); + { + mi_parse_error + (parse, + "%s^error,msg=3D\"Duplicate '--thread-group' option\"\n", + parse->token); + return NULL; + } chp +=3D tgs; if (*chp !=3D 'i') - error (_("Invalid thread group id")); + { + 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); } if (strncmp (chp, "--thread ", ts) =3D=3D 0) { if (parse->thread !=3D -1) - error (_("Duplicate '--thread' option")); + { + mi_parse_error + (parse, + "%s^error,msg=3D\"Duplicate '--thread' option\"\n", + parse->token); + return NULL; + } 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")); + { + 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 +375,13 @@ 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 +393,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; } }