\f
+/* See c-lang.h. */
+
+gdb::unique_xmalloc_ptr<char>
+c_canonicalize_name (const char *name)
+{
+ if (strchr (name, ' ') != nullptr
+ || streq (name, "signed")
+ || streq (name, "unsigned"))
+ return cp_canonicalize_string (name);
+ return nullptr;
+}
+
+\f
+
void
c_language_arch_info (struct gdbarch *gdbarch,
struct language_arch_info *lai)
const struct block *expr_block,
CORE_ADDR expr_pc);
+/* Return the canonical form of the C symbol NAME. If NAME is already
+ canonical, return nullptr. */
+
+extern gdb::unique_xmalloc_ptr<char> c_canonicalize_name (const char *name);
+
#endif /* !defined (C_LANG_H) */
#include "complaints.h"
#include "cp-abi.h"
#include "cp-support.h"
+#include "c-lang.h"
#include "psympriv.h"
#include "block.h"
#include "aout/aout64.h"
new_name.get ());
}
}
+ else if (psymtab_language == language_c)
+ {
+ std::string name (namestring, p - namestring);
+ gdb::unique_xmalloc_ptr<char> new_name
+ = c_canonicalize_name (name.c_str ());
+ if (new_name != nullptr)
+ {
+ sym_len = strlen (new_name.get ());
+ sym_name = obstack_strdup (&objfile->objfile_obstack,
+ new_name.get ());
+ }
+ }
if (sym_len == 0)
{
#include "dwarf2/cooked-index.h"
#include "dwarf2/read.h"
#include "cp-support.h"
+#include "c-lang.h"
#include "ada-lang.h"
#include "split-name.h"
#include <algorithm>
m_names.push_back (std::move (canon_name));
}
}
- else if (entry->per_cu->lang () == language_cplus)
+ else if (entry->per_cu->lang () == language_cplus
+ || entry->per_cu->lang () == language_c)
{
void **slot = htab_find_slot (seen_names.get (), entry,
INSERT);
if (*slot == nullptr)
{
gdb::unique_xmalloc_ptr<char> canon_name
- = cp_canonicalize_string (entry->name);
+ = (entry->per_cu->lang () == language_cplus
+ ? cp_canonicalize_string (entry->name)
+ : c_canonicalize_name (entry->name));
if (canon_name == nullptr)
entry->canonical = entry->name;
else
dwarf2_canonicalize_name (const char *name, struct dwarf2_cu *cu,
struct objfile *objfile)
{
- if (name && cu->lang () == language_cplus)
+ if (name == nullptr)
+ return name;
+
+ if (cu->lang () == language_cplus)
{
gdb::unique_xmalloc_ptr<char> canon_name
= cp_canonicalize_string (name);
if (canon_name != nullptr)
name = objfile->intern (canon_name.get ());
}
+ else if (cu->lang () == language_c)
+ {
+ gdb::unique_xmalloc_ptr<char> canon_name
+ = c_canonicalize_name (name);
+
+ if (canon_name != nullptr)
+ name = objfile->intern (canon_name.get ());
+ }
return name;
}
switch (die->tag)
{
+ /* A member's name should not be canonicalized. This is a bit
+ of a hack, in that normally it should not be possible to run
+ into this situation; however, the dw2-unusual-field-names.exp
+ test creates custom DWARF that does. */
+ case DW_TAG_member:
case DW_TAG_compile_unit:
case DW_TAG_partial_unit:
/* Compilation units have a DW_AT_name that is a filename, not
struct type *
lookup_signed_typename (const struct language_defn *language, const char *name)
{
- struct type *t;
- char *uns = (char *) alloca (strlen (name) + 8);
-
- strcpy (uns, "signed ");
- strcpy (uns + 7, name);
- t = lookup_typename (language, uns, NULL, 1);
- /* If we don't find "signed FOO" just try again with plain "FOO". */
- if (t != NULL)
- return t;
+ /* In C and C++, "char" and "signed char" are distinct types. */
+ if (streq (name, "char"))
+ name = "signed char";
return lookup_typename (language, name, NULL, 0);
}
if (sym->language () == language_cplus)
{
- char *name = (char *) alloca (p - string + 1);
-
- memcpy (name, string, p - string);
- name[p - string] = '\0';
- new_name = cp_canonicalize_string (name);
+ std::string name (string, p - string);
+ new_name = cp_canonicalize_string (name.c_str ());
+ }
+ else if (sym->language () == language_c)
+ {
+ std::string name (string, p - string);
+ new_name = c_canonicalize_name (name.c_str ());
}
if (new_name != nullptr)
sym->compute_and_set_names (new_name.get (), true, objfile->per_bfd);
type_name = NULL;
if (get_current_subfile ()->language == language_cplus)
{
- char *name = (char *) alloca (p - *pp + 1);
-
- memcpy (name, *pp, p - *pp);
- name[p - *pp] = '\0';
-
- gdb::unique_xmalloc_ptr<char> new_name = cp_canonicalize_string (name);
+ std::string name (*pp, p - *pp);
+ gdb::unique_xmalloc_ptr<char> new_name
+ = cp_canonicalize_string (name.c_str ());
+ if (new_name != nullptr)
+ type_name = obstack_strdup (&objfile->objfile_obstack,
+ new_name.get ());
+ }
+ else if (get_current_subfile ()->language == language_c)
+ {
+ std::string name (*pp, p - *pp);
+ gdb::unique_xmalloc_ptr<char> new_name
+ = c_canonicalize_name (name.c_str ());
if (new_name != nullptr)
type_name = obstack_strdup (&objfile->objfile_obstack,
new_name.get ());
integer_label: DW_TAG_base_type {
{DW_AT_byte_size 4 DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_signed}
- {DW_AT_name integer}
+ {DW_AT_name int}
}
uinteger_label: DW_TAG_base_type {
{DW_AT_byte_size 4 DW_FORM_sdata}
{DW_AT_encoding @DW_ATE_unsigned}
- {DW_AT_name {unsigned integer}}
+ {DW_AT_name {unsigned int}}
}
DW_TAG_enumeration_type {
gdb_test "ptype enum EU" "type = enum EU {TWO = 2}" \
"ptype EU in enum C"
gdb_test_no_output "set lang c++"
-gdb_test "ptype enum EU" "type = enum EU : unsigned integer {TWO = 2}" \
+gdb_test "ptype enum EU" "type = enum EU : unsigned int {TWO = 2}" \
"ptype EU in C++"