This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[MI] Segfault using 'interpreter-exec mi'
- From: Marc Khouzam <marc dot khouzam at ericsson dot com>
- To: "'gdb-patches at sourceware dot org'" <gdb-patches at sourceware dot org>
- Date: Thu, 25 Nov 2010 15:53:55 -0500
- Subject: [MI] Segfault using 'interpreter-exec mi'
Hi,
I got a segfault when using 'interpreter-exec mi' and getting an error result.
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
#0 0x080a002a in ui_file_put (file=0xa9, write=0x8113503 <do_write>, dest=0x85547e8) at ../../src/gdb/ui-file.c:195
#1 0x08113555 in mi_out_put (uiout=0x8555560, stream=0x85547e8) 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=0x8555560, data=0x85573a0) at ../../src/gdb/mi/mi-main.c:1850
#3 0x081ae4ae in catch_exception (uiout=0x8555560, func=0x811b054 <captured_mi_execute_command>, func_args=0x85573a0, mask=6)
at ../../src/gdb/exceptions.c:468
#4 0x0811b390 in mi_execute_command (cmd=0x8554bf0 "", from_tty=1) at ../../src/gdb/mi/mi-main.c:1895
#5 0x081171c3 in mi_execute_command_wrapper (cmd=0x8554bf0 "") at ../../src/gdb/mi/mi-interp.c:262
#6 0x081b5c24 in gdb_readline2 (client_data=0x0) at ../../src/gdb/event-top.c:783
#7 0x081b5463 in stdin_event_handler (error=0, client_data=0x0) at ../../src/gdb/event-top.c:433
#8 0x081b414e in handle_file_event (data=...) at ../../src/gdb/event-loop.c:817
#9 0x081b375c in process_event () at ../../src/gdb/event-loop.c:399
#10 0x081b3820 in gdb_do_one_event (data=0x0) at ../../src/gdb/event-loop.c:464
#11 0x081ae66c in catch_errors (func=0x81b376a <gdb_do_one_event>, func_args=0x0, errstring=0x8386077 "", mask=6) at ../../src/gdb/exceptions.c:518
#12 0x0811f319 in tui_command_loop (data=0x0) at ../../src/gdb/tui/tui-interp.c:171
#13 0x081aed60 in current_interp_command_loop () at ../../src/gdb/interps.c:291
#14 0x0809042e in captured_command_loop (data=0x0) at ../../src/gdb/main.c:228
#15 0x081ae66c in catch_errors (func=0x8090423 <captured_command_loop>, func_args=0x0, errstring=0x8366fbf "", mask=6) at ../../src/gdb/exceptions.c:518
#16 0x0809130d in captured_main (data=0xbffff750) at ../../src/gdb/main.c:912
#17 0x081ae66c in catch_errors (func=0x8090464 <captured_main>, func_args=0xbffff750, errstring=0x8366fbf "", mask=6) at ../../src/gdb/exceptions.c:518
#18 0x08091343 in gdb_main (args=0xbffff750) at ../../src/gdb/main.c:921
#19 0x080901b3 in main (argc=1, argv=0xbffff814) 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 <marc.khouzam@ericsson.com>
* 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
===================================================================
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);
}
+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, ...)
+{
+ va_list args;
+
+ va_start (args, format);
+ vmi_parse_error (parse, format, args);
+ va_end (args);
+}
struct mi_parse *
mi_parse (char *cmd)
@@ -272,12 +288,10 @@
parse->cmd = mi_lookup (parse->command);
if (parse->cmd == NULL)
{
- /* FIXME: This should be a function call. */
- fprintf_unfiltered
- (raw_stdout,
+ mi_parse_error
+ (parse,
"%s^error,msg=\"Undefined MI command: %s\"\n",
parse->token, parse->command);
- mi_parse_free (parse);
return NULL;
}
@@ -312,24 +326,48 @@
if (strncmp (chp, "--thread-group ", tgs) == 0)
{
if (parse->thread_group != -1)
- error (_("Duplicate '--thread-group' option"));
+ {
+ mi_parse_error
+ (parse,
+ "%s^error,msg=\"Duplicate '--thread-group' option\"\n",
+ parse->token);
+ return NULL;
+ }
chp += tgs;
if (*chp != 'i')
- error (_("Invalid thread group id"));
+ {
+ mi_parse_error
+ (parse,
+ "%s^error,msg=\"Invalid thread group id\"\n",
+ parse->token);
+ return NULL;
+ }
chp += 1;
parse->thread_group = strtol (chp, &chp, 10);
}
if (strncmp (chp, "--thread ", ts) == 0)
{
if (parse->thread != -1)
- error (_("Duplicate '--thread' option"));
+ {
+ mi_parse_error
+ (parse,
+ "%s^error,msg=\"Duplicate '--thread' option\"\n",
+ parse->token);
+ return NULL;
+ }
chp += ts;
parse->thread = strtol (chp, &chp, 10);
}
else if (strncmp (chp, "--frame ", fs) == 0)
{
if (parse->frame != -1)
- error (_("Duplicate '--frame' option"));
+ {
+ mi_parse_error
+ (parse,
+ "%s^error,msg=\"Duplicate '--frame' option\"\n",
+ parse->token);
+ return NULL;
+ }
chp += fs;
parse->frame = strtol (chp, &chp, 10);
}
@@ -337,8 +375,13 @@
break;
if (*chp != '\0' && !isspace (*chp))
- error (_("Invalid value for the '%s' option"),
- start[2] == 't' ? "--thread" : "--frame");
+ {
+ mi_parse_error
+ (parse,
+ "%s^error,msg=\"Invalid value for the '%s' option\"\n",
+ parse->token, start[2] == 't' ? "--thread" : "--frame");
+ return NULL;
+ }
while (isspace (*chp))
chp++;
}
@@ -350,12 +393,10 @@
mi_parse_argv (chp, parse);
if (parse->argv == NULL)
{
- /* FIXME: This should be a function call. */
- fprintf_unfiltered
- (raw_stdout,
+ mi_parse_error
+ (parse,
"%s^error,msg=\"Problem parsing arguments: %s %s\"\n",
parse->token, parse->command, chp);
- mi_parse_free (parse);
return NULL;
}
}