* [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg
@ 2026-08-20 18:02 Simon Marchi
2026-08-20 18:02 ` [PATCH 2/2] gdb: introduce demangle_parse_info_up Simon Marchi
2026-08-21 15:05 ` [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Tom Tromey
0 siblings, 2 replies; 5+ messages in thread
From: Simon Marchi @ 2026-08-20 18:02 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Most call sites pass NULL as cp_demangled_name_to_comp's errmsg
parameter (they are not interested in the error message). Make errmsg
have a nullptr default value and simplify those call sites.
I am generally not a big fan of default values, especially when the
parameter changes how the function behaves. But in this case it does
really change the behavior of the function, so I think it's fine.
There is one spot (should_parse) that passed a non-NULL value but then
did not use it, remove that.
Change-Id: I9d30229047d9892cc44953914e6416a607949152
---
gdb/cp-name-parser.y | 3 +--
gdb/cp-support.c | 12 ++++++------
gdb/cp-support.h | 2 +-
3 files changed, 8 insertions(+), 9 deletions(-)
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 4be50599762e..aee5d8341519 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -2098,8 +2098,7 @@ should_be_the_same (const char *one, const char *two)
static void
should_parse (const char *name)
{
- std::string err;
- auto parsed = cp_demangled_name_to_comp (name, &err);
+ auto parsed = cp_demangled_name_to_comp (name);
SELF_CHECK (parsed != nullptr);
}
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 335e06a039f2..36d7c8dd113e 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -253,7 +253,7 @@ inspect_type (struct demangle_parse_info *info,
tree will contain pointers into NAME, so NAME cannot
be free'd until all typedef conversion is done and
the final result is converted into a string. */
- i = cp_demangled_name_to_comp (name, NULL);
+ i = cp_demangled_name_to_comp (name);
if (i != NULL)
{
/* Merge the two trees. */
@@ -600,7 +600,7 @@ cp_canonicalize_string_full (const char *string,
std::unique_ptr<demangle_parse_info> info;
estimated_len = strlen (string) * 2;
- info = cp_demangled_name_to_comp (string, NULL);
+ info = cp_demangled_name_to_comp (string);
if (info != NULL)
{
/* Replace all the typedefs in the tree. */
@@ -647,7 +647,7 @@ cp_canonicalize_string (const char *string)
if (cp_already_canonical (string))
return nullptr;
- info = cp_demangled_name_to_comp (string, NULL);
+ info = cp_demangled_name_to_comp (string);
if (info == NULL)
return nullptr;
@@ -709,7 +709,7 @@ mangled_name_to_comp (const char *mangled_name, int options,
/* If we could demangle the name, parse it to build the component
tree. */
std::unique_ptr<demangle_parse_info> info
- = cp_demangled_name_to_comp (demangled_name.get (), NULL);
+ = cp_demangled_name_to_comp (demangled_name.get ());
if (info == NULL)
return NULL;
@@ -904,7 +904,7 @@ cp_func_name (const char *full_name)
struct demangle_component *ret_comp;
std::unique_ptr<demangle_parse_info> info;
- info = cp_demangled_name_to_comp (full_name, NULL);
+ info = cp_demangled_name_to_comp (full_name);
if (!info)
return nullptr;
@@ -933,7 +933,7 @@ cp_remove_params_1 (const char *demangled_name, bool require_params)
if (demangled_name == NULL)
return NULL;
- info = cp_demangled_name_to_comp (demangled_name, NULL);
+ info = cp_demangled_name_to_comp (demangled_name);
if (info == NULL)
return NULL;
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 2bd3430a7a81..e495895afdbc 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -169,7 +169,7 @@ struct type *cp_find_type_baseclass_by_name (struct type *parent_type,
/* Functions from cp-name-parser.y. */
extern std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp
- (const char *demangled_name, std::string *errmsg);
+ (const char *demangled_name, std::string *errmsg = nullptr);
/* Convert RESULT to a string. ESTIMATED_LEN is used only as a guide
to the length of the result. */
base-commit: d2102b0d6a95ba3b37204976fb3f6ebd935822fb
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] gdb: introduce demangle_parse_info_up
2026-08-20 18:02 [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Simon Marchi
@ 2026-08-20 18:02 ` Simon Marchi
2026-08-21 15:06 ` Tom Tromey
2026-08-21 15:05 ` [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Tom Tromey
1 sibling, 1 reply; 5+ messages in thread
From: Simon Marchi @ 2026-08-20 18:02 UTC (permalink / raw)
To: gdb-patches; +Cc: Simon Marchi
Introduce the demangle_parse_info_up type alias, as per our convention.
I find that more legible.
Change-Id: I31944c7d81c8fd7d16df4aac5691fad38ef40ac2
---
gdb/cp-name-parser.y | 4 +--
gdb/cp-support.c | 59 +++++++++++++++++++-------------------------
gdb/cp-support.h | 10 +++++---
gdb/python/py-type.c | 2 +-
4 files changed, 36 insertions(+), 39 deletions(-)
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index aee5d8341519..1fd4a17db06a 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -2040,7 +2040,7 @@ cp_comp_to_string (struct demangle_component *result, int estimated_len)
void
cp_merge_demangle_parse_infos (struct demangle_parse_info *dest,
struct demangle_component *target,
- std::unique_ptr<demangle_parse_info> src)
+ demangle_parse_info_up src)
{
/* Copy the SRC's parse data into DEST. */
@@ -2055,7 +2055,7 @@ cp_merge_demangle_parse_infos (struct demangle_parse_info *dest,
error, NULL is returned, and an error message will be set in
*ERRMSG. */
-struct std::unique_ptr<demangle_parse_info>
+demangle_parse_info_up
cp_demangled_name_to_comp (const char *demangled_name,
std::string *errmsg)
{
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 36d7c8dd113e..b17f1e77d683 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -182,7 +182,6 @@ inspect_type (struct demangle_parse_info *info,
long len;
int is_anon;
struct type *type;
- std::unique_ptr<demangle_parse_info> i;
/* Get the real type of the typedef. */
type = check_typedef (otype);
@@ -253,8 +252,9 @@ inspect_type (struct demangle_parse_info *info,
tree will contain pointers into NAME, so NAME cannot
be free'd until all typedef conversion is done and
the final result is converted into a string. */
- i = cp_demangled_name_to_comp (name);
- if (i != NULL)
+ if (demangle_parse_info_up i
+ = cp_demangled_name_to_comp (name);
+ i != nullptr)
{
/* Merge the two trees. */
cp_merge_demangle_parse_infos (info, ret_comp, std::move (i));
@@ -596,12 +596,10 @@ cp_canonicalize_string_full (const char *string,
canonicalization_ftype *finder,
void *data)
{
- unsigned int estimated_len;
- std::unique_ptr<demangle_parse_info> info;
+ unsigned int estimated_len = strlen (string) * 2;
+ demangle_parse_info_up info = cp_demangled_name_to_comp (string);
- estimated_len = strlen (string) * 2;
- info = cp_demangled_name_to_comp (string);
- if (info != NULL)
+ if (info != nullptr)
{
/* Replace all the typedefs in the tree. */
replace_typedefs (info.get (), info->tree, finder, data);
@@ -641,17 +639,15 @@ cp_canonicalize_string_no_typedefs (const char *string)
gdb::unique_xmalloc_ptr<char>
cp_canonicalize_string (const char *string)
{
- std::unique_ptr<demangle_parse_info> info;
- unsigned int estimated_len;
-
if (cp_already_canonical (string))
return nullptr;
- info = cp_demangled_name_to_comp (string);
- if (info == NULL)
+ demangle_parse_info_up info = cp_demangled_name_to_comp (string);
+
+ if (info == nullptr)
return nullptr;
- estimated_len = strlen (string) * 2;
+ unsigned int estimated_len = strlen (string) * 2;
gdb::unique_xmalloc_ptr<char> us (cp_comp_to_string (info->tree,
estimated_len));
@@ -677,7 +673,7 @@ cp_canonicalize_string (const char *string)
freed when finished with the tree, or NULL if none was needed.
OPTIONS will be passed to the demangler. */
-static std::unique_ptr<demangle_parse_info>
+static demangle_parse_info_up
mangled_name_to_comp (const char *mangled_name, int options,
void **memory,
gdb::unique_xmalloc_ptr<char> *demangled_p)
@@ -708,7 +704,7 @@ mangled_name_to_comp (const char *mangled_name, int options,
/* If we could demangle the name, parse it to build the component
tree. */
- std::unique_ptr<demangle_parse_info> info
+ demangle_parse_info_up info
= cp_demangled_name_to_comp (demangled_name.get ());
if (info == NULL)
@@ -727,13 +723,12 @@ cp_class_name_from_physname (const char *physname)
gdb::unique_xmalloc_ptr<char> demangled_name;
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp, *prev_comp, *cur_comp;
- std::unique_ptr<demangle_parse_info> info;
+ demangle_parse_info_up info
+ = mangled_name_to_comp (physname, DMGL_ANSI, &storage, &demangled_name);
int done;
- info = mangled_name_to_comp (physname, DMGL_ANSI,
- &storage, &demangled_name);
- if (info == NULL)
- return NULL;
+ if (info == nullptr)
+ return nullptr;
done = 0;
ret_comp = info->tree;
@@ -874,12 +869,11 @@ method_name_from_physname (const char *physname)
gdb::unique_xmalloc_ptr<char> demangled_name;
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp;
- std::unique_ptr<demangle_parse_info> info;
+ demangle_parse_info_up info
+ = mangled_name_to_comp (physname, DMGL_ANSI, &storage, &demangled_name);
- info = mangled_name_to_comp (physname, DMGL_ANSI,
- &storage, &demangled_name);
- if (info == NULL)
- return NULL;
+ if (info == nullptr)
+ return nullptr;
ret_comp = unqualified_name_from_comp (info->tree);
@@ -902,10 +896,9 @@ cp_func_name (const char *full_name)
{
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp;
- std::unique_ptr<demangle_parse_info> info;
+ demangle_parse_info_up info = cp_demangled_name_to_comp (full_name);
- info = cp_demangled_name_to_comp (full_name);
- if (!info)
+ if (info == nullptr)
return nullptr;
ret_comp = unqualified_name_from_comp (info->tree);
@@ -927,15 +920,15 @@ cp_remove_params_1 (const char *demangled_name, bool require_params)
{
bool done = false;
struct demangle_component *ret_comp;
- std::unique_ptr<demangle_parse_info> info;
gdb::unique_xmalloc_ptr<char> ret;
if (demangled_name == NULL)
return NULL;
- info = cp_demangled_name_to_comp (demangled_name);
- if (info == NULL)
- return NULL;
+ demangle_parse_info_up info = cp_demangled_name_to_comp (demangled_name);
+
+ if (info == nullptr)
+ return nullptr;
/* First strip off any qualifiers, if we have a function or method. */
ret_comp = info->tree;
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index e495895afdbc..da8e777f516b 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -53,6 +53,10 @@ struct using_direct;
#define CP_OPERATOR_LEN 8
+struct demangle_parse_info;
+
+using demangle_parse_info_up = std::unique_ptr<demangle_parse_info>;
+
/* The result of parsing a name. */
struct demangle_parse_info
@@ -69,7 +73,7 @@ struct demangle_parse_info
/* Any other objects referred to by this object, and whose storage
lifetime must be linked. */
- std::vector<std::unique_ptr<demangle_parse_info>> infos;
+ std::vector<demangle_parse_info_up> infos;
};
@@ -168,7 +172,7 @@ struct type *cp_find_type_baseclass_by_name (struct type *parent_type,
/* Functions from cp-name-parser.y. */
-extern std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp
+extern demangle_parse_info_up cp_demangled_name_to_comp
(const char *demangled_name, std::string *errmsg = nullptr);
/* Convert RESULT to a string. ESTIMATED_LEN is used only as a guide
@@ -179,7 +183,7 @@ extern gdb::unique_xmalloc_ptr<char> cp_comp_to_string
extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *,
struct demangle_component *,
- std::unique_ptr<demangle_parse_info>);
+ demangle_parse_info_up);
/* The list of "maint cplus" commands. */
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 9dd0fe2ab37f..f374af23d2a2 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -925,7 +925,7 @@ typy_legacy_template_argument (struct type *type, const struct block *block,
{
int i;
struct demangle_component *demangled;
- std::unique_ptr<demangle_parse_info> info;
+ demangle_parse_info_up info;
std::string err;
struct type *argtype;
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg
2026-08-20 18:02 [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Simon Marchi
2026-08-20 18:02 ` [PATCH 2/2] gdb: introduce demangle_parse_info_up Simon Marchi
@ 2026-08-21 15:05 ` Tom Tromey
2026-08-22 5:22 ` Simon Marchi
1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2026-08-21 15:05 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
Simon> I am generally not a big fan of default values, especially when the
Simon> parameter changes how the function behaves. But in this case it does
Simon> really change the behavior of the function, so I think it's fine.
I think maybe you left out a "not" from the second sentence here.
Anyway this looks good to me.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] gdb: introduce demangle_parse_info_up
2026-08-20 18:02 ` [PATCH 2/2] gdb: introduce demangle_parse_info_up Simon Marchi
@ 2026-08-21 15:06 ` Tom Tromey
0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2026-08-21 15:06 UTC (permalink / raw)
To: Simon Marchi; +Cc: gdb-patches
>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
Simon> Introduce the demangle_parse_info_up type alias, as per our convention.
Simon> I find that more legible.
Ok.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg
2026-08-21 15:05 ` [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Tom Tromey
@ 2026-08-22 5:22 ` Simon Marchi
0 siblings, 0 replies; 5+ messages in thread
From: Simon Marchi @ 2026-08-22 5:22 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 8/21/26 11:05 AM, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
>
> Simon> I am generally not a big fan of default values, especially when the
> Simon> parameter changes how the function behaves. But in this case it does
> Simon> really change the behavior of the function, so I think it's fine.
>
> I think maybe you left out a "not" from the second sentence here.
>
> Anyway this looks good to me.
> Approved-By: Tom Tromey <tom@tromey.com>
>
> Tom
I pushed both patches, but I forgot to address you comment about the
commit message, sorry.
Simon
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-08-22 5:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-20 18:02 [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Simon Marchi
2026-08-20 18:02 ` [PATCH 2/2] gdb: introduce demangle_parse_info_up Simon Marchi
2026-08-21 15:06 ` Tom Tromey
2026-08-21 15:05 ` [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Tom Tromey
2026-08-22 5:22 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox