public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/3] gdb: handle default argument in make-target-delegates.py
Date: Tue, 14 Nov 2023 10:41:22 +0100	[thread overview]
Message-ID: <476f2068afadd0d56827493eb014a90b41eea887.1699953637.git.tankut.baris.aktemur@intel.com> (raw)
In-Reply-To: <b03f96baf03fd61dd4bda47fcd725a07938547a0.1699953637.git.tankut.baris.aktemur@intel.com>

The regular expression to dissect argument types in
make-target-delegates.py does not recognize default argument values.
For example, in target.h, we have

   virtual void rcmd (const char *command, struct ui_file *output)
     TARGET_DEFAULT_FUNC (default_rcmd);
   virtual const char *pid_to_exec_file (int pid)
     TARGET_DEFAULT_RETURN (NULL);

Suppose we change these to the following where we define default
values for the arguments.  The example for the default argument
of "pid" is deliberately chosen to contain a space character.

   virtual void rcmd (const char *command=0, struct ui_file *output = nullptr)
     TARGET_DEFAULT_FUNC (default_rcmd);
   virtual const char *pid_to_exec_file (int pid=sizeof n)
     TARGET_DEFAULT_RETURN (NULL);

After generating the target-delegates.c file via make-target-delegates.py
we obtain invalid code:

   void rcmd (const char *command=0 arg0, struct ui_file *output = nullptr arg1) override;
   const char *pid_to_exec_file (int pid=sizeof n arg0) override;
   ...
   void
   debug_target::rcmd (const char *command=0 arg0, struct ui_file *output = nullptr arg1)
   {
     ...
     target_debug_print_const_char_pcommand=0 (arg0);
     ...
     target_debug_print_struct_ui_file_poutput_=_nullptr (arg1);
   }
   ...
   const char *
   debug_target::pid_to_exec_file (int pid=sizeof n arg0)
   {
     ...
     target_debug_print_int_pid=sizeof_n (arg0);
     ...
   }

When the fix in this patch is applied, the default argument values
are correctly detected and we obtain the same generated result for
target-delegates.c, which is

   void rcmd (const char *arg0, struct ui_file *arg1) override;
   const char *pid_to_exec_file (int arg0) override;
   ...
   void
   debug_target::rcmd (const char *arg0, struct ui_file *arg1)
   {
     ...
     target_debug_print_const_char_p (arg0);
     ...
     target_debug_print_struct_ui_file_p (arg1);
   }
   ...
   const char *
   debug_target::pid_to_exec_file (int arg0)
   {
     ...
     target_debug_print_int (arg0);
     ...
   }

Currently, target.h does not contain any arguments with default
values.  The goal of this patch is to address potential future and
downstream cases; we (Intel) have cases with default argument values.
---
 gdb/make-target-delegates.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gdb/make-target-delegates.py b/gdb/make-target-delegates.py
index fd5f436a43d..2758f900c9b 100755
--- a/gdb/make-target-delegates.py
+++ b/gdb/make-target-delegates.py
@@ -76,6 +76,8 @@ METHOD = re.compile(
 # Space-separated symbols.
 CP_SYMBOLS = CP_SYMBOL + r"(\s+" + CP_SYMBOL + r")*"
 
+DEFAULT_ARG_VALUE = r"(\s*\=\s*[^\s].*)?"
+
 # Regular expression used to dissect argument types.
 ARGTYPES = re.compile(
     "^("
@@ -86,6 +88,7 @@ ARGTYPES = re.compile(
     + CP_SYMBOLS
     + r"(\s|\*|&)+)"
     + SYMBOL
+    + DEFAULT_ARG_VALUE
     + ")$"
 )
 
-- 
2.34.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


  parent reply	other threads:[~2023-11-14  9:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14  9:41 [PATCH 1/3] gdb: regenerate target-delegates.c Tankut Baris Aktemur
2023-11-14  9:41 ` [PATCH 2/3] gdb: refactor make-target-delegates.py's ARGTYPES Tankut Baris Aktemur
2023-11-14 13:47   ` Pedro Alves
2023-11-14  9:41 ` Tankut Baris Aktemur [this message]
2023-11-14 11:31   ` [PATCH 3/3] gdb: handle default argument in make-target-delegates.py Pedro Alves
2023-11-14 12:48     ` Aktemur, Tankut Baris
2023-11-14 13:36       ` Pedro Alves
2023-11-14 14:17     ` Tom Tromey
2023-11-16 18:11       ` Aktemur, Tankut Baris
2023-11-17 15:41         ` Tom Tromey
2023-11-14 11:14 ` [PATCH 1/3] gdb: regenerate target-delegates.c Pedro Alves
2023-11-14 14:18 ` Tom Tromey

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=476f2068afadd0d56827493eb014a90b41eea887.1699953637.git.tankut.baris.aktemur@intel.com \
    --to=tankut.baris.aktemur@intel.com \
    --cc=gdb-patches@sourceware.org \
    /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).