public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: Pedro Alves <pedro@palves.net>,
	Simon Marchi <simon.marchi@polymtl.ca>,
	 Simon Marchi <simon.marchi@efficios.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb: consider null terminator for length arguments of value_cstring calls
Date: Wed, 21 Jul 2021 17:21:04 +0200	[thread overview]
Message-ID: <cbac83d6e394d89b64801f71614fd22303f37743.camel@skynet.be> (raw)
In-Reply-To: <f52b2301-f86c-188a-3ff3-4903522b2d3d@palves.net>

On Wed, 2021-07-14 at 11:25 +0100, Pedro Alves wrote:
> Such an inferior call in Ada (and other non-terminated string languages) will now
> be passing an unexpected \0 to the called function, of course.  I wonder
> whether that's why Philippe didn't add the \0 in the first place, given his
> Ada bias?  :-)

The idea for $_gdb_setting was to allow a user defined command to access
the gdb settings and provide a behaviour depending on these settings.

I did not envisage the use case of providing the values created by $_gdb_setting
to the inferior.

For the "user defined command" use case, typically, $_streq will be used to 
implement the behaviour depending on the string setting values.

It looks like $_streq works without a null terminator:

(gdb) set var $ccc = "foo"
(gdb) set lang ada
(gdb) set var $aaa := "foo"
(gdb) p $_streq($ccc, $aaa)
$1 = true
(gdb) ptype $ccc
type = array (0 .. 3) of char
(gdb) ptype $aaa
type = array (1 .. 3) of character
(gdb) set lang c
(gdb) p $_streq($ccc, $aaa)
$2 = 1
(gdb) ptype $ccc
type = char [4]
(gdb) ptype $aaa
type = character [3]
(gdb) 

(gdb) set args foo
(gdb) p $_streq($_gdb_setting("args"), "foo")
$1 = 1
(gdb) set lang ada
(gdb) p $_streq($_gdb_setting("args"), "foo")
$2 = true
(gdb) 


So, at least for the initially envisaged use case, I do not see a problem
with the absence (or presence) of a trailing null terminator.

Philippe



      parent reply	other threads:[~2021-07-21 15:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 15:31 Simon Marchi
2021-07-13 17:07 ` Pedro Alves
2021-07-13 18:44   ` Simon Marchi
2021-07-14 10:25     ` Pedro Alves
2021-07-14 13:50       ` Simon Marchi
2021-07-15 14:29         ` Pedro Alves
2021-07-23 19:37           ` Simon Marchi
2021-07-21 15:21       ` Philippe Waroquiers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cbac83d6e394d89b64801f71614fd22303f37743.camel@skynet.be \
    --to=philippe.waroquiers@skynet.be \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).