This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v2 31/31] Support an "unlimited" number of user-defined arguments
Hi
On Wed, 19 Oct 2016 02:12:19 +0100
Pedro Alves <palves@redhat.com> wrote:
> I recently wrote a user-defined command that could benefit from
> supporting an unlimited number of arguments:
>
> http://palves.net/list-active-signal-handlers-with-gdb/
>
> E.g., 'info signal-dispositions 1 2 3 4 5 6 7 8 9 10 11'
>
> However, we currently only support up to 10 arguments passed to
> user-defined commands ($arg0..$arg9).
>
> I can't find a good reason for that, other than "old code with hard
> coded limits". This patch removes that limit and modernizes the code
> along the way:
>
> - Makes the user_args struct a real C++ class that uses std::vector
> for storage.
>
> - Removes the "next" pointer from within user_args and uses a
> std::vector to maintain a stack instead.
>
> - Adds a new RAII-based scoped_user_args_level class to help
> push/pop user args in the stack instead of using a cleanup.
>
> I also needed a way to convert a number to a std::string, so I added a
> new utility for that, gdb::to_string. Yet another thing that can go
> away with C++11.
[... snip ...]
> +/* Returns a string representation of VAL. Replacement for
> + std::to_string, which is only available in C++11 or later. */
> +
> +namespace gdb {
> +
> +template <class T>
> +inline std::string
> +to_string (const T &val)
> +{
> + std::stringstream ss;
> +
> + ss << val;
> + return ss.str ();
> +}
> +
> +}
> +
> /* Make a copy of the string at PTR with LEN characters
> (and add a null character at the end in the copy).
> Uses malloc to get the space. Returns the address of the copy. */
Is this really necessary?
As far as I understood the discussion, we jump directly to C++11. Thus there is no need for an homemade to_string.
Philipp