Re: `sentinel' gcc-3.x/OpenBSD compat. [Re: [patch 1/3] Make obconcat use stdarg]

Jan Kratochvil
2010-05-07T16:58:57Z

On Sat, 01 May 2010 10:53:32 +0200, Mark Kettenis wrote:
> > Date: Sat, 1 May 2010 00:18:39 +0200
> > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> > On Fri, 30 Apr 2010 21:08:48 +0200, Mark Kettenis wrote:
> > > > From: Jan Kratochvil <jan.kratochvil@redhat.com>
> > > > __attribute__ ((sentinel)) availability for gcc >= 4.0 I have copied from
> > > > <glib-2.0/glib/gmacros.h>. It roughly matches the GCC ChangeLog dates.
> > >
> > > The OpenBSD system compile, which is based on GCC 3.3.5, already has
> > > the sentinel attribute.
> >
> > FSF GCC 3.3.5 does not support this attribute:
[...]
> > Moreover I do not consider relevant to support this attribute on so obsolete
> > compiler. Not using the attribute has no effect on users building GDB.
> > This attribute is useful only for the GDB developers.
>
> Fair enough; this feature is nice to have but in no way essential.

Neither FSF GCC 3.4.6 which is the latest FSF GCC 3.x release. Therefore it
must be an OpenBSD specific patch which is irrelevant to the FSF GDB codebase.

Reposted - using now existing ansidecl.h ATTRIBUTE_SENTINEL instead.

Thanks,
Jan

gdb/
2010-05-07 Jan Kratochvil <jan.kratochvil@redhat.com>

* dwarf2read.c (typename_concat): Use (char *) NULL terminated stdarg
list for the obconcat call.
* mdebugread.c (parse_symbol): Likewise.
* stabsread.c (define_symbol, read_member_functions, read_cpp_abbrev):
Likewise.
* symfile.c (obconcat): Replace the s1, s2 and s3 parameters by `...'.
New variable ap. Remove variables len and val.
* symfile.h (obconcat): Likewise for the prototype.

--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -9200,7 +9200,7 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
else
{
/* We have an obstack. */
- return obconcat (obs, prefix, sep, suffix);
+ return obconcat (obs, prefix, sep, suffix, (char *) NULL);
}
}

--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -998,8 +998,8 @@ parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
TYPE_TAG_NAME (t) = NULL;
else
- TYPE_TAG_NAME (t) = obconcat (&current_objfile->objfile_obstack,
- "", "", name);
+ TYPE_TAG_NAME (t) = obconcat (&current_objfile->objfile_obstack, name,
+ (char *) NULL);

TYPE_CODE (t) = type_code;
TYPE_LENGTH (t) = sh->value;
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1279,9 +1279,9 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_VALUE (struct_sym) = valu;
SYMBOL_DOMAIN (struct_sym) = STRUCT_DOMAIN;
if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
- TYPE_NAME (SYMBOL_TYPE (sym))
- = obconcat (&objfile->objfile_obstack, "", "",
- SYMBOL_LINKAGE_NAME (sym));
+ TYPE_NAME (SYMBOL_TYPE (sym)) = obconcat (&objfile->objfile_obstack,
+ SYMBOL_LINKAGE_NAME (sym),
+ (char *) NULL);
add_symbol_to_list (struct_sym, &file_symbols);
}

@@ -1306,9 +1306,9 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_VALUE (sym) = valu;
SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
- TYPE_TAG_NAME (SYMBOL_TYPE (sym))
- = obconcat (&objfile->objfile_obstack, "", "",
- SYMBOL_LINKAGE_NAME (sym));
+ TYPE_TAG_NAME (SYMBOL_TYPE (sym)) = obconcat (&objfile->objfile_obstack,
+ SYMBOL_LINKAGE_NAME (sym),
+ (char *) NULL);
add_symbol_to_list (sym, &file_symbols);

if (synonym)
@@ -1321,9 +1321,9 @@ define_symbol (CORE_ADDR valu, char *string, int desc, int type,
SYMBOL_VALUE (typedef_sym) = valu;
SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
- TYPE_NAME (SYMBOL_TYPE (sym))
- = obconcat (&objfile->objfile_obstack, "", "",
- SYMBOL_LINKAGE_NAME (sym));
+ TYPE_NAME (SYMBOL_TYPE (sym)) = obconcat (&objfile->objfile_obstack,
+ SYMBOL_LINKAGE_NAME (sym),
+ (char *) NULL);
add_symbol_to_list (typedef_sym, &file_symbols);
}
break;
@@ -2609,8 +2609,8 @@ read_member_functions (struct field_info *fip, char **pp, struct type *type,
make_cleanup (xfree, destr_fnlist);
memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
destr_fnlist->fn_fieldlist.name
- = obconcat (&objfile->objfile_obstack, "", "~",
- new_fnlist->fn_fieldlist.name);
+ = obconcat (&objfile->objfile_obstack, "~",
+ new_fnlist->fn_fieldlist.name, (char *) NULL);

destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
obstack_alloc (&objfile->objfile_obstack,
@@ -2747,8 +2747,8 @@ read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
{
name = "";
}
- fip->list->field.name =
- obconcat (&objfile->objfile_obstack, vptr_name, name, "");
+ fip->list->field.name = obconcat (&objfile->objfile_obstack,
+ vptr_name, name, (char *) NULL);
break;

case 'b': /* $vb -- a virtual bsomethingorother */
@@ -2760,15 +2760,15 @@ read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
symnum);
name = "FOO";
}
- fip->list->field.name =
- obconcat (&objfile->objfile_obstack, vb_name, name, "");
+ fip->list->field.name = obconcat (&objfile->objfile_obstack, vb_name,
+ name, (char *) NULL);
break;

default:
invalid_cpp_abbrev_complaint (*pp);
- fip->list->field.name =
- obconcat (&objfile->objfile_obstack,
- "INVALID_CPLUSPLUS_ABBREV", "", "");
+ fip->list->field.name = obconcat (&objfile->objfile_obstack,
+ "INVALID_CPLUSPLUS_ABBREV",
+ (char *) NULL);
break;
}

--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -212,19 +212,29 @@ obsavestring (const char *ptr, int size, struct obstack *obstackp)
return p;
}

-/* Concatenate strings S1, S2 and S3; return the new string. Space is found
- in the obstack pointed to by OBSTACKP. */
+/* Concatenate NULL terminated variable argument list of `const char *' strings;
+ return the new string. Space is found in the OBSTACKP. Argument list must
+ be terminated by a sentinel expression `(char *) NULL'. */

char *
-obconcat (struct obstack *obstackp, const char *s1, const char *s2,
- const char *s3)
-{
- int len = strlen (s1) + strlen (s2) + strlen (s3) + 1;
- char *val = (char *) obstack_alloc (obstackp, len);
- strcpy (val, s1);
- strcat (val, s2);
- strcat (val, s3);
- return val;
+obconcat (struct obstack *obstackp, ...)
+{
+ va_list ap;
+
+ va_start (ap, obstackp);
+ for (;;)
+ {
+ const char *s = va_arg (ap, const char *);
+
+ if (s == NULL)
+ break;
+
+ obstack_grow_str (obstackp, s);
+ }
+ va_end (ap);
+ obstack_1grow (obstackp, 0);
+
+ return obstack_finish (obstackp);
}

/* True if we are reading a symbol table. */
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -458,11 +458,11 @@ extern struct partial_symtab *start_psymtab_common (struct objfile *,

extern char *obsavestring (const char *, int, struct obstack *);

-/* Concatenate strings S1, S2 and S3; return the new string. Space is
- found in the OBSTACKP */
+/* Concatenate NULL terminated variable argument list of `const char *' strings;
+ return the new string. Space is found in the OBSTACKP. Argument list must
+ be terminated by a sentinel expression `(char *) NULL'. */

-extern char *obconcat (struct obstack *obstackp, const char *, const char *,
- const char *);
+extern char *obconcat (struct obstack *obstackp, ...) ATTRIBUTE_SENTINEL;

/* Variables */