<div dir="ltr"><div>This patch introduces option that when given to cplus_demangle, drops template from a symbol during demangling (in printing stage)<br></div><div dir="ltr"><br>diff --git a/include/demangle.h b/include/demangle.h<br>index 49b84d4de88..89a3b64e436 100644<br>--- a/include/demangle.h<br>+++ b/include/demangle.h<br>@@ -51,6 +51,8 @@ extern "C" {<br>                                            types, even if present.  It applies<br>                                        only to the toplevel function type.<br>                                         */<br>+#define DMGL_TMPL_DROP   (1 << 7)       /* Supress printing of templates, even<br>+                                       if present. */<br> <br> #define DMGL_AUTO      (1 << 8)<br> #define DMGL_GNU_V3   (1 << 14)<br>diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c<br>index fc2cf64e6e0..ad873ed6177 100644<br>--- a/libiberty/cp-demangle.c<br>+++ b/libiberty/cp-demangle.c<br>@@ -5315,6 +5315,9 @@ d_print_comp_inner (struct d_print_info *dpi, int options,<br>         else<br>           {<br>          d_print_comp (dpi, options, dcl);<br>+          if ((options & DMGL_TMPL_DROP) != 0)<br>+             return;<br>+<br>      if (d_last_char (dpi) == '<')<br>             d_append_char (dpi, ' ');<br>       d_append_char (dpi, '<');<br>@@ -5333,6 +5336,9 @@ d_print_comp_inner (struct d_print_info *dpi, int options,<br>       }<br> <br>     case DEMANGLE_COMPONENT_TEMPLATE_PARAM:<br>+      if ((options & DMGL_TMPL_DROP) != 0)<br>+  break;<br>+<br>       if (dpi->lambda_tpl_parms > dc->u.s_number.number + 1)<br>        {<br>      const struct demangle_component *a<br>@@ -5492,6 +5498,23 @@ d_print_comp_inner (struct d_print_info *dpi, int options,<br>       return;<br> <br>     case DEMANGLE_COMPONENT_SUB_STD:<br>+      /* Special-case substitions are stored wholly as a string. They need<br>+    to be stripped of templates manually */<br>+      if ((options & DMGL_TMPL_DROP) != 0)<br>+      {<br>+    char *template_begin = strchr(dc->u.s_string.string, '<');<br>+     if (template_begin != NULL)<br>+  {<br>+      d_append_buffer(dpi, dc->u.s_string.string, (template_begin - dc->u.s_string.string));<br>+<br>+     char *template_end= strrchr(dc->u.s_string.string, '>');<br>+      if (template_end == NULL)<br>+     return;<br>+<br>+       d_append_buffer(dpi, template_end, dc->u.s_string.len - (template_end - dc->u.s_string.string) - 1);<br>+          return;<br>+   }<br>+      }<br>       d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len);<br>       return;<br><br><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">pt., 8 mar 2024 o 19:04 Mikołaj Piróg <<a href="mailto:mikolajpirog@gmail.com">mikolajpirog@gmail.com</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>This patch refines my previous attempt of implementing short name search (<a href="https://sourceware.org/pipermail/binutils/2024-February/132713.html" target="_blank">https://sourceware.org/pipermail/binutils/2024-February/132713.html</a>). The idea is to enable such usage:<br><br>objdump --disassemble=ns::foo -C file<br><br></div><div>The objdump will then output all symbols matching the name "ns::foo". I introduced new demangling option to remove template qualification, so for example, "--dissassemble=std::vector::push_back" will match all instances of push_back in the file.<br><br></div><div>The motivation behind this usage is to ease a process of a quick disassembly of a binary in search for a particular function. Providing a function signature isn't comfortable.<br></div><div><br><br></div><div><div><br><br><br><br></div></div></div>
</blockquote></div></div>