This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Make interrupting tab-completion safe.
- From: Sterling Augustine <saugustine at google dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 10 Jun 2011 17:19:05 -0700
- Subject: [PATCH] Make interrupting tab-completion safe.
As discussed on IRC, gdb can crash on the following sequence:
gdb <really big program>
b <tab><tab>
[ctrl-c before tab-completion is done]
b <tab>
(segmentation fault)
The problem comes because the dwarf2read.c tries to discover the full
linkage name of symbols, and assumes that it won't be interrupted.
But the *_type_print* and *_print_type* functions do contain calls to
QUIT.
I'm sure it also occurs at times other than tab-completion--any time a
psymtab being converted to a symtab is interrupted.
This patch adjusts the functions in question to conditionally call
quit based on the variable show, which is -1 when they are called to
discover the full linkage name--among other times.
Sterling
2011-06-10 Sterling Augustine <saugustine@google.com>
* typeprint.h (TYPE_PRINT_QUIT): New macro.
* psymtab.c (map_symbol_filenames_psymtab): Call QUIT.
* p-typeprint.c (pascal_type_print_varspec_prefix): Call
TYPE_PRINT_QUIT instead of QUIT.
(pascal_type_print_varspec_suffix): Likewise.
(pascal_type_print_base): Likewise.
* m2-typeprint.c (m2_print_type): Likewise.
* jv-typeprint.c (java_type_print_base): Likewise.
* f-typeprint.c: Include typeprint.h.
(f_type_print_varspec_prefix): Call
TYPE_PRINT_QUIT instead of QUIT.
(f_type_print_varspec_suffix): Likewise.
(f_type_print_base): Likewise.
* c-typeprint.c (c_type_print_varspec_prefix): Likewise.
(c_type_print_varspec_suffix): Likewise.
(c_type_print_base): Likewise. Remove extraneous calls to QUIT.
* ada-typeprint.c (print_enum_type): Add show parameter. Call
TYPE_PRINT_QUIT.
(ada_print_type): Likewise.
Index: ada-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-typeprint.c,v
retrieving revision 1.40
diff -u -r1.40 ada-typeprint.c
--- ada-typeprint.c 1 Jan 2011 15:32:56 -0000 1.40
+++ ada-typeprint.c 11 Jun 2011 00:07:16 -0000
@@ -271,7 +271,7 @@
/* Print enumerated type TYPE on STREAM. */
static void
-print_enum_type (struct type *type, struct ui_file *stream)
+print_enum_type (struct type *type, struct ui_file *stream, int show)
{
int len = TYPE_NFIELDS (type);
int i, lastval;
@@ -282,7 +282,7 @@
lastval = 0;
for (i = 0; i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
if (i)
fprintf_filtered (stream, ", ");
wrap_here (" ");
@@ -570,7 +570,7 @@
for (i = fld0; i <= fld1; i += 1)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
if (ada_is_parent_field (type, i) || ada_is_ignored_field (type, i))
;
@@ -846,7 +846,7 @@
if (show < 0)
fprintf_filtered (stream, "(...)");
else
- print_enum_type (type, stream);
+ print_enum_type (type, stream, show);
break;
case TYPE_CODE_STRUCT:
if (ada_is_array_descriptor_type (type))
Index: c-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/c-typeprint.c,v
retrieving revision 1.70
diff -u -r1.70 c-typeprint.c
--- c-typeprint.c 22 Mar 2011 17:35:22 -0000 1.70
+++ c-typeprint.c 11 Jun 2011 00:07:16 -0000
@@ -247,7 +247,7 @@
if (TYPE_NAME (type) && show <= 0)
return;
- QUIT;
+ TYPE_PRINT_QUIT (show);
switch (TYPE_CODE (type))
{
@@ -613,7 +613,7 @@
if (TYPE_NAME (type) && show <= 0)
return;
- QUIT;
+ TYPE_PRINT_QUIT (show);
switch (TYPE_CODE (type))
{
@@ -730,7 +730,7 @@
int need_access_label = 0;
int j, len2;
- QUIT;
+ TYPE_PRINT_QUIT (show);
wrap_here (" ");
if (type == NULL)
@@ -842,7 +842,6 @@
if (TYPE_DECLARED_CLASS (type))
{
- QUIT;
len = TYPE_NFIELDS (type);
for (i = TYPE_N_BASECLASSES (type); i < len; i++)
if (!TYPE_FIELD_PRIVATE (type, i))
@@ -850,7 +849,6 @@
need_access_label = 1;
break;
}
- QUIT;
if (!need_access_label)
{
len2 = TYPE_NFN_FIELDS (type);
@@ -871,7 +869,6 @@
}
else
{
- QUIT;
len = TYPE_NFIELDS (type);
for (i = TYPE_N_BASECLASSES (type); i < len; i++)
if (TYPE_FIELD_PRIVATE (type, i)
@@ -880,13 +877,12 @@
need_access_label = 1;
break;
}
- QUIT;
if (!need_access_label)
{
len2 = TYPE_NFN_FIELDS (type);
for (j = 0; j < len2; j++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
len = TYPE_FN_FIELDLIST_LENGTH (type, j);
for (i = 0; i < len; i++)
if (TYPE_FN_FIELD_PROTECTED (TYPE_FN_FIELDLIST1 (type,
@@ -911,7 +907,7 @@
vptr_fieldno = get_vptr_fieldno (type, &basetype);
for (i = TYPE_N_BASECLASSES (type); i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
/* If we have a virtual table pointer, omit it. Even if
virtual table pointers are not specifically marked in
@@ -1011,7 +1007,7 @@
if (TYPE_FN_FIELD_ARTIFICIAL (f, j))
continue;
- QUIT;
+ TYPE_PRINT_QUIT (show);
if (TYPE_FN_FIELD_PROTECTED (f, j))
{
if (section_type != s_protected)
@@ -1192,7 +1188,7 @@
lastval = 0;
for (i = 0; i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
if (i)
fprintf_filtered (stream, ", ");
wrap_here (" ");
Index: f-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/f-typeprint.c,v
retrieving revision 1.35
diff -u -r1.35 f-typeprint.c
--- f-typeprint.c 7 Jan 2011 19:36:16 -0000 1.35
+++ f-typeprint.c 11 Jun 2011 00:07:16 -0000
@@ -32,6 +32,7 @@
#include "gdbcore.h"
#include "target.h"
#include "f-lang.h"
+#include "typeprint.h"
#include "gdb_string.h"
#include <errno.h>
@@ -101,7 +102,7 @@
if (TYPE_NAME (type) && show <= 0)
return;
- QUIT;
+ TYPE_PRINT_QUIT (show);
switch (TYPE_CODE (type))
{
@@ -163,7 +164,7 @@
if (TYPE_NAME (type) && show <= 0)
return;
- QUIT;
+ TYPE_PRINT_QUIT (show);
switch (TYPE_CODE (type))
{
@@ -261,7 +262,7 @@
int upper_bound;
int index;
- QUIT;
+ TYPE_PRINT_QUIT (show);
wrap_here (" ");
if (type == NULL)
Index: jv-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-typeprint.c,v
retrieving revision 1.22
diff -u -r1.22 jv-typeprint.c
--- jv-typeprint.c 9 Jan 2011 03:08:57 -0000 1.22
+++ jv-typeprint.c 11 Jun 2011 00:07:16 -0000
@@ -91,7 +91,7 @@
char *mangled_name;
char *demangled_name;
- QUIT;
+ TYPE_PRINT_QUIT (show);
wrap_here (" ");
if (type == NULL)
@@ -165,7 +165,7 @@
len = TYPE_NFIELDS (type);
for (i = TYPE_N_BASECLASSES (type); i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
/* Don't print out virtual function table. */
if (strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0
&& is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
@@ -239,7 +239,7 @@
= (is_constructor_name (physname)
|| is_destructor_name (physname));
- QUIT;
+ TYPE_PRINT_QUIT (show);
print_spaces_filtered (level + 4, stream);
Index: m2-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/m2-typeprint.c,v
retrieving revision 1.28
diff -u -r1.28 m2-typeprint.c
--- m2-typeprint.c 9 Jan 2011 03:20:33 -0000 1.28
+++ m2-typeprint.c 11 Jun 2011 00:07:16 -0000
@@ -75,7 +75,7 @@
CHECK_TYPEDEF (type);
- QUIT;
+ TYPE_PRINT_QUIT (show);
wrap_here (" ");
if (type == NULL)
@@ -560,7 +560,7 @@
for (i = TYPE_N_BASECLASSES (type); i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
print_spaces_filtered (level + 4, stream);
fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
@@ -603,7 +603,7 @@
lastval = 0;
for (i = 0; i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
if (i > 0)
fprintf_filtered (stream, ", ");
wrap_here (" ");
Index: p-typeprint.c
===================================================================
RCS file: /cvs/src/src/gdb/p-typeprint.c,v
retrieving revision 1.40
diff -u -r1.40 p-typeprint.c
--- p-typeprint.c 10 Mar 2011 20:25:44 -0000 1.40
+++ p-typeprint.c 11 Jun 2011 00:07:17 -0000
@@ -215,7 +215,7 @@
if (TYPE_NAME (type) && show <= 0)
return;
- QUIT;
+ TYPE_PRINT_QUIT (show);
switch (TYPE_CODE (type))
{
@@ -349,7 +349,7 @@
if (TYPE_NAME (type) && show <= 0)
return;
- QUIT;
+ TYPE_PRINT_QUIT (show);
switch (TYPE_CODE (type))
{
@@ -451,7 +451,7 @@
}
section_type;
- QUIT;
+ TYPE_PRINT_QUIT (show);
wrap_here (" ");
if (type == NULL)
{
@@ -562,7 +562,8 @@
len = TYPE_NFIELDS (type);
for (i = TYPE_N_BASECLASSES (type); i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
+
/* Don't print out virtual function table. */
if ((strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5) == 0)
&& is_cplus_marker ((TYPE_FIELD_NAME (type, i))[5]))
@@ -643,7 +644,8 @@
int is_constructor = (strncmp (physname, "__ct__", 6) == 0);
int is_destructor = (strncmp (physname, "__dt__", 6) == 0);
- QUIT;
+ TYPE_PRINT_QUIT (show);
+
if (TYPE_FN_FIELD_PROTECTED (f, j))
{
if (section_type != s_protected)
@@ -747,7 +749,7 @@
lastval = 0;
for (i = 0; i < len; i++)
{
- QUIT;
+ TYPE_PRINT_QUIT (show);
if (i)
fprintf_filtered (stream, ", ");
wrap_here (" ");
Index: psymtab.c
===================================================================
RCS file: /cvs/src/src/gdb/psymtab.c,v
retrieving revision 1.26.2.1
diff -u -r1.26.2.1 psymtab.c
--- psymtab.c 20 Apr 2011 20:10:29 -0000 1.26.2.1
+++ psymtab.c 11 Jun 2011 00:07:17 -0000
@@ -1086,7 +1086,7 @@
if (ps->readin)
continue;
-
+ QUIT;
fullname = psymtab_to_fullname (ps);
(*fun) (ps->filename, fullname, data);
}
Index: typeprint.h
===================================================================
RCS file: /cvs/src/src/gdb/typeprint.h,v
retrieving revision 1.11
diff -u -r1.11 typeprint.h
--- typeprint.h 1 Jan 2011 15:33:18 -0000 1.11
+++ typeprint.h 11 Jun 2011 00:07:17 -0000
@@ -29,4 +29,16 @@
int, int);
void c_type_print_args (struct type *, struct ui_file *, int, enum language);
+
+/* The variable show will be negative when being used to print the
+ full linkage name of a variable (among other times). Code that
+ calls *_type_print* and *_print_type* to discover a full linkage
+ name assumes that the process will not be interrupted--especially
+ from inside dwarf2read.c. Using this macro to control calls to
+ QUIT allows, for example, a ptype command to be interrupted safely,
+ but not other operations that cannot be interrupted safely. */
+
+#define TYPE_PRINT_QUIT(show) \
+ do { if (show >= 0) QUIT; } while (0)
+
#endif