This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Typedef'd method parameters [3/4]


On 04/27/2011 11:55 AM, Jan Kratochvil wrote:
On Thu, 21 Apr 2011 23:15:37 +0200, Keith Seitz wrote:
[...]
--- cp-support.c	26 Feb 2011 02:07:07 -0000	1.49
+++ cp-support.c	21 Apr 2011 17:03:35 -0000
@@ -117,6 +117,115 @@ cp_already_canonical (const char *string
      return 0;
  }

+/* Insepct the given RET_COMP for its type.  If it is a typedef,
+   replace the name stored in the tree with the typedef's fully resolved
+   type.  If no changes have been made to the tree, set CHANGED to 0;
+   otherwise set it to 1.  FREE_LIST contains any temprorary storage

temporary

Eew. Lots of typos. I've updated the comments and fixed the typos.



+ that was used to revise the tree. It should be freed by the caller. */

CHANGED/FREE_LIST I do not understand what they refer to at all.

That was cruft from a previous version of the patch. Unfortunately, I've had to reintroduce the free_list idea because more testing exposed other problems.


+static void
+inspect_type (struct demangle_component *ret_comp)
+{
+  char *name;
+  struct symbol *sym;
+
+  name = (char *) alloca (ret_comp->u.s_name.len + 1);
+  strncpy (name, ret_comp->u.s_name.s, ret_comp->u.s_name.len);
+  name[ret_comp->u.s_name.len] = '\0';
+  sym = lookup_symbol (name, 0, VAR_DOMAIN, 0);
+  if (sym != NULL)
+    {
+      struct type *type = SYMBOL_TYPE (sym);
+
+      if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+	{
+	  char *canon;
+	  struct ui_file *buf = mem_fileopen ();
+
+	  CHECK_TYPEDEF (type);

BUF should be make_cleanup protected against exceptions.

Done.


This table is incomplete, for example DEMANGLE_COMPONENT_ARRAY_TYPE is
missing.
	C++ source / GDB input:
	f(CORE_ADDR (*)[10])
	GDB output:
	f(CORE_ADDR (*) [10])
	GCC output:
	f(unsigned long (*) [10])
	_Z1fPA10_m

I've updated the table further and added a few more tests to test this.



Also there should be an equivalent of the CLOSED-FIXED PR: Bug 12328 - Can't set breakpoint on method taking const, non-reference/pointer scalar parameter

I have also added something to deal with this case.


+
+/* Parse STRING and convert it to canonical form, resolving any typedefs.
+   If parsing fails, or if STRING is already canonical, return NULL.
+   Otherwise return the canonical form.  The return value is allocated via
+   xmalloc.  */
+
+char *
+cp_canonicalize_string_no_typedefs (const char *string)
+{
+  char *ret;
+  unsigned int estimated_len;
+  struct demangle_parse_info *info;
+
+  ret = NULL;
+  estimated_len = strlen (string) * 2;
+  info = cp_demangled_name_to_comp (string, NULL);
+  if (info != NULL)
+    {
+      replace_typedefs (info->tree);
+      ret = cp_comp_to_string (info->tree, estimated_len);
+      cp_demangled_name_parse_free (info);
+      if (strcmp (string, ret) == 0)

cp_comp_to_string can return NULL, OK, it may not obviously happen but still some gdb_assert / internal_error would be appropriate IMO.

I've added an assert.



BTW already present in [patch 1/4].



An accident: I was splitting this patch by hand every time. I've got everything split up onto separate git branches now, so hopefully this won't happen again. [And hopefully it will be easier to keep track of these different patches!]


I've attached the updated patch.

Keith

Attachment: cp_canonicalize_no_typedefs-2.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]