This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v3] gdbinit.in: allow to pass function argument explicitly


Generally, people expect functions to accept arguments directly. But
ones defined in gdbinit did not use the argument, which may be confusing
for newcomers. But we can't change behavior to use the argument without
breaking existing users of the gdbinit. Let's fix this by adding a check
for whether a user passed an argument, and either use it or go with
older behavior.

2019-11-14  Konstantin Kharlamov  <Hi-Angel@yandex.ru>

        * gdbinit.in (pp, pr, prl, pt, pct, pgg, pgq, pgs, pge, pmz, ptc, pdn,
        ptn, pdd, prc, pi, pbm, pel, trt): Make use of $arg0 if a user passed it
---

v3: use the way to detect arg0 suggested by Alexander on mailing list

 gcc/gdbinit.in | 57 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 38 insertions(+), 19 deletions(-)

diff --git a/gcc/gdbinit.in b/gcc/gdbinit.in
index a933ddc6141..ae177fd40d5 100644
--- a/gcc/gdbinit.in
+++ b/gcc/gdbinit.in
@@ -17,7 +17,8 @@
 # <http://www.gnu.org/licenses/>.
 
 define pp
-call debug ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug ($debug_arg)
 end
 
 document pp
@@ -26,7 +27,8 @@ Works only when an inferior is executing.
 end
 
 define pr
-call debug_rtx ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_rtx ($debug_arg)
 end
 
 document pr
@@ -35,7 +37,8 @@ Works only when an inferior is executing.
 end
 
 define prl
-call debug_rtx_list ($, debug_rtx_count)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_rtx_list ($debug_arg, debug_rtx_count)
 end
 
 document prl
@@ -50,7 +53,8 @@ it using debug_rtx_list. Usage example: set $foo=debug_rtx_find(first, 42)
 end
 
 define pt
-call debug_tree ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_tree ($debug_arg)
 end
 
 document pt
@@ -59,7 +63,8 @@ Works only when an inferior is executing.
 end
 
 define pct
-call debug_c_tree ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_c_tree ($debug_arg)
 end
 
 document pct
@@ -68,7 +73,8 @@ Works only when an inferior is executing.
 end
 
 define pgg
-call debug_gimple_stmt ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_gimple_stmt ($debug_arg)
 end
 
 document pgg
@@ -77,7 +83,8 @@ Works only when an inferior is executing.
 end
 
 define pgq
-call debug_gimple_seq ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_gimple_seq ($debug_arg)
 end
 
 document pgq
@@ -86,7 +93,8 @@ Works only when an inferior is executing.
 end
 
 define pgs
-call debug_generic_stmt ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_generic_stmt ($debug_arg)
 end
 
 document pgs
@@ -95,7 +103,8 @@ Works only when an inferior is executing.
 end
 
 define pge
-call debug_generic_expr ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_generic_expr ($debug_arg)
 end
 
 document pge
@@ -104,7 +113,8 @@ Works only when an inferior is executing.
 end
 
 define pmz
-call mpz_out_str(stderr, 10, $)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call mpz_out_str(stderr, 10, $debug_arg)
 end
 
 document pmz
@@ -113,7 +123,8 @@ Works only when an inferior is executing.
 end
 
 define ptc
-output (enum tree_code) $.base.code
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+output (enum tree_code) $debug_arg.base.code
 echo \n
 end
 
@@ -122,7 +133,8 @@ Print the tree-code of the tree node that is $.
 end
 
 define pdn
-output $.decl_minimal.name->identifier.id.str
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+output $debug_arg.decl_minimal.name->identifier.id.str
 echo \n
 end
 
@@ -131,7 +143,8 @@ Print the name of the decl-node that is $.
 end
 
 define ptn
-output $.type.name->decl_minimal.name->identifier.id.str
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+output $debug_arg.type.name->decl_minimal.name->identifier.id.str
 echo \n
 end
 
@@ -140,7 +153,8 @@ Print the name of the type-node that is $.
 end
 
 define pdd
-call debug_dwarf_die ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call debug_dwarf_die ($debug_arg)
 end
 
 document pdd
@@ -148,7 +162,8 @@ Print the dw_die_ref that is in $.
 end
 
 define prc
-output (enum rtx_code) $.code
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+output (enum rtx_code) $debug_arg.code
 echo \ (
 output $.mode
 echo )\n
@@ -159,7 +174,8 @@ Print the rtx-code and machine mode of the rtx that is $.
 end
 
 define pi
-print $.u.fld[0].rt_rtx@7
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+print $debug_arg.u.fld[0].rt_rtx@7
 end
 
 document pi
@@ -176,7 +192,8 @@ including the global binding level.
 end
 
 define pbm
-call bitmap_print (stderr, $, "", "\n")
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+call bitmap_print (stderr, $debug_arg, "", "\n")
 end
 
 document pbm
@@ -184,7 +201,8 @@ Dump the bitmap that is in $ as a comma-separated list of numbers.
 end
 
 define pel
-output expand_location ($)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+output expand_location ($debug_arg)
 echo \n
 end
 
@@ -202,7 +220,8 @@ Print current function.
 end
 
 define trt
-print ($.typed.type)
+eval "set $debug_arg = $%s", $argc ? "arg0" : ""
+print ($debug_arg.typed.type)
 end
 
 document trt
-- 
2.24.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]