]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implement front end GDB commands for Valgrind gdbserver monitor commands.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Tue, 27 Dec 2022 20:51:30 +0000 (21:51 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sun, 8 Jan 2023 15:00:57 +0000 (16:00 +0100)
This commit implements in python a set of GDB commands corresponding to the
Valgrind gdbserver monitor commands.

Basically, the idea is that one GDB command is defined for each valgrind
gdbserver subcommand and will generate and send a monitor command to valgrind.

The python code is auto-loaded by GDB as soon as GDB observes that the valgrind
preload core shared lib is loaded (e.g. vgpreload_core-amd64-linux.so).
This automatic loading is done thanks to the .debug_gdb_scripts section
added in vg_preloaded.c file.

Sadly, the auto-load only happens once valgrind has started to execute the code
of ld that loads this vg_preload file.

I have tried 2 approaches to have the python code auto-loaded when attaching at
startup to valgrind:
  * have valgrind gdbserver reporting first to GDB that the executable file is
    the tool executable (with a .debug_gdb_scripts section) and then reporting
    the real (guest) executable file.
    The drawback of this approach is that it triggers a warning/question in GDB
    according to the GDB setting 'set exec-file-mismatch'.
  * have valgrind gdbserver pretending to be multiprocess enabled, and report
    a fake process using the tool executable with a .debug_gdb_scripts section.
    The drawback of this is that this always creates a second inferior in GDB,
    which will be confusing.

Possibly, we might complete the below message :
  ==2984378== (action at startup) vgdb me ...
  ==2984378==
  ==2984378== TO DEBUG THIS PROCESS USING GDB: start GDB like this
  ==2984378==   /path/to/gdb /home/philippe/valgrind/littleprogs/some_mem
  ==2984378== and then give GDB the following command
  ==2984378==   target remote | /home/philippe/valgrind/git/improve/Inst/libexec/valgrind/../../bin/vgdb --pid=2984378
  ==2984378== --pid is optional if only one valgrind process is running

with:
  ==2984378== GDB valgrind python specific commands will be auto-loaded when execution begins.
  ==2984378== Alternatively, you might load it before with the GDB command:
  ==2984378==   source /abs/path/to/valgrind/install/libexec/valgrind/valgrind-monitor.py

The following GDB setting traces the monitor commands sent by a GDB valgrind
command to the valgrind gdbserver:
  set debug valgrind-execute-monitor on

How to use the new GDB valgrind commands?
-----------------------------------------

The usage of the GDB front end commands is compatible with the
monitor command as accepted today by Valgrind.

For example, the memcheck monitor command "xb' has the following usage:
 xb <addr> [<len>]

With some piece of code:
   'char some_mem [5];'
xb can be used the following way:
  (gdb) print &some_mem
  (gdb) $2 = (char (*)[5]) 0x1ffefffe8b
  (gdb) monitor xb 0x1ffefffe8b 5
       ff   ff   ff   ff   ff
  0x4A43040:   0x00 0x00 0x00 0x00 0x00
  (gdb)

The same action can be done with the new GDB 'memcheck xb' command:
  (gdb) memcheck xb 0x1ffefffe8b 5
       ff   ff   ff   ff   ff
  0x1FFEFFFE8B:   0x00 0x00 0x00 0x00 0x00
  (gdb)

At this point, you might ask yourself: "what is the interest ?".

Using GDB valgrind commands provides several advantages compared to
the valgrind gdbserver monitor commands.

Evaluation of arguments by GDB:
-------------------------------
For relevant arguments, the GDB command will evaluate its arguments using
the usual GDB evaluation logic, for example, instead of printing/copying
the address and size of 'some_mem', the following will work:
  (gdb) memcheck xb &some_mem sizeof(some_mem)
       ff   ff   ff   ff   ff
  0x1FFEFFFE8B:   0x00 0x00 0x00 0x00 0x00
  (gdb)

or:
  (gdb) p some_mem
  $4 = "\000\000\000\000"
  (gdb) memcheck xb &$4
       ff   ff   ff   ff   ff
  0x1FFEFFFE8B:   0x00 0x00 0x00 0x00 0x00
  (gdb)

This is both easier to use interactively and easier to use in GDB scripts,
as you can directly use variable names in the GDB valgrind commands.

Command completion by GDB:
--------------------------
The usual command completion in GDB will work for the GDB valgrind commands.
For example, typing TAB after the letter 'l' in:
  (gdb) valgrind v.info l
will show the 2 "valgrind v.info" subcommands:
  last_error  location
  (gdb) valgrind v.info l

Note that as usual, GDB will recognise a command as soon as it is unambiguous.

Usual help and apropos support by GDB:
--------------------------------------
The Valgrind gdbserver provides an online help using:
  (gdb) monitor help
However, this gives the help for all monitor commands, and is not searchable.
GDB provides a better help and documentation search.
For example, the following commands can be used to get various help
or search the GDB Valgrind command online documentation:
   help valgrind
   help memcheck
   help helgrind
   help callgrind
   help massif
to get help about the general valgrind commands or the tool specific commands.

Examples of searching the online documentation:
  apropos valgrind.*location
  apropos -v validity
  apropos -v leak

User can define aliases for the valgrind commands:
--------------------------------------------------
The following aliases are predefined:
  v and vg for valgrind
  mc for memcheck
  hg for helgrind
  cg for callgrind
  ms for massif

So, the following will be equivalent:
   (gdb) valgrind v.info location &some_mem
   (gdb) v v.i lo &some_mem
   (gdb) alias Vl = valgrind v.info location
   (gdb) Vl &some_mem

Thanks to Hassan El Karouni for the help in factorising the python
code common to all valgrind python commands using a decorator.

12 files changed:
NEWS
callgrind/docs/cl-manual.xml
coregrind/Makefile.am
coregrind/m_gdbserver/valgrind-monitor-def.py [new file with mode: 0644]
coregrind/m_gdbserver/valgrind-monitor.py [new file with mode: 0644]
coregrind/vg_preloaded.c
coregrind/vgdb.c
docs/xml/manual-core-adv.xml
gdbserver_tests/filter_gdb.in
helgrind/docs/hg-manual.xml
massif/docs/ms-manual.xml
memcheck/docs/mc-manual.xml

diff --git a/NEWS b/NEWS
index 3f9e2987de5ded32bd3a445bd98f6703470f222f..fb3b05fa9de3a767ea7153c0873d0dc50114cc36 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,30 @@ AMD64/macOS 10.13 and nanoMIPS/Linux.
 * Make the address space limit on FreeBSD amd64 128Gbytes
   (the same as Linux and Solaris, it was 32Gbytes)
 
+* When GDB is used to debug a program running under valgrind using
+  the valgrind gdbserver, GDB will automatically load some
+  python code provided in valgrind defining GDB front end commands
+  corresponding to the valgrind monitor commands.
+  These GDB front end commands accept the same format as
+  the monitor commands directly sent to the Valgrind gdbserver.
+  These GDB front end commands provide a better integration
+  in the GDB command line interface, so as to use for example
+  GDB auto-completion, command specific help, searching for
+  a command or command help matching a regexp, ...
+  For relevant monitor commands, GDB will evaluate arguments
+  to make the use of monitor commands easier.
+  For example, instead of having to print the address of a variable
+  to pass it to a subsequent monitor command, the GDB front end
+  command will evaluate the address argument. It is for example
+  possible to do:
+    (gdb) memcheck who_point_at &some_struct sizeof(some_struct)
+  instead of:
+    (gdb) p &some_struct
+    $2 = (some_struct_type *) 0x1130a0 <some_struct>
+    (gdb) p sizeof(some_struct)
+    $3 = 40
+    (gdb) monitor who_point_at 0x1130a0 40
+
 * ==================== TOOL CHANGES ===================
 
 * Memcheck:
@@ -24,11 +48,23 @@ AMD64/macOS 10.13 and nanoMIPS/Linux.
     Whenever a "delta" leak search is done (i.e. when specifying
     "new" or "increased" or "changed" in the monitor command),
     the new loss records have a "new" marker.
+  - Valgrind now contains python code that defines GDB memcheck
+    front end monitor commands. See CORE CHANGES.
 
 * Helgrind:
   - The option ---history-backtrace-size=<number> allows to configure
     the number of entries to record in the stack traces of "old"
     accesses. Previously, this number was hardcoded to 8.
+  - Valgrind now contains python code that defines GDB helgrind
+    front end monitor commands. See CORE CHANGES.
+
+* Callgrind:
+  - Valgrind now contains python code that defines GDB callgrind
+    front end monitor commands. See CORE CHANGES.
+
+* Massif:
+  - Valgrind now contains python code that defines GDB massif
+    front end monitor commands. See CORE CHANGES.
 
 * ==================== FIXED BUGS ====================
 
index 7b7172ed4b6a01fc520366267f375943156fa962..8b4e50d853ab6ff41ec313b037316a9060b498c7 100644 (file)
@@ -1133,6 +1133,17 @@ Also see <xref linkend="cl-manual.cycles"/>.</para>
 <title>Callgrind Monitor Commands</title>
 <para>The Callgrind tool provides monitor commands handled by the Valgrind
 gdbserver (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>).
+Valgrind python code provides GDB front end commands giving an easier usage of
+the callgrind monitor commands (see
+<xref linkend="manual-core-adv.gdbserver-gdbmonitorfrontend"/>).  To launch a
+callgrind monitor command via its GDB front end command, instead of prefixing
+the command with "monitor", you must use the GDB <varname>callgrind</varname>
+command (or the shorter aliases <varname>cg</varname>).  Using the callgrind GDB
+front end command provide a more flexible usage, such as auto-completion of the
+command by GDB. In GDB, you can use <varname>help callgrind</varname> to get
+help about the callgrind front end monitor commands and you can
+use <varname>apropos callgrind</varname> to get all the commands mentionning the
+word "callgrind" in their name or on-line help.
 </para>
 
 <itemizedlist>
index 151f5c2f007b8397960e0cabbeb34fc6a0cae77b..dda0689ddfb7d5cbf2e6b6d0072c4829c347fe6b 100644 (file)
@@ -766,6 +766,8 @@ GDBSERVER_XML_FILES = \
 # so as to make sure these get copied into the install tree
 vglibdir = $(pkglibexecdir)
 vglib_DATA  = $(GDBSERVER_XML_FILES)
+vglib_DATA  += m_gdbserver/valgrind-monitor.py
+vglib_DATA  += m_gdbserver/valgrind-monitor-def.py
 
 # so as to make sure these get copied into the tarball
 EXTRA_DIST  += $(GDBSERVER_XML_FILES)
diff --git a/coregrind/m_gdbserver/valgrind-monitor-def.py b/coregrind/m_gdbserver/valgrind-monitor-def.py
new file mode 100644 (file)
index 0000000..da617cb
--- /dev/null
@@ -0,0 +1,854 @@
+# This file is part of Valgrind, a dynamic binary instrumentation
+# framework.
+
+# Copyright (C) 2022-2022 Philippe Waroquiers
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+# The GNU General Public License is contained in the file COPYING.
+   
+"""
+This file defines a series of gdb commands and subcommands to help interfacing
+gdb with the Valgrind gdbserver.
+
+!!! This only works with GDB version >= 9.1, as some command names contains
+a dot character only allowed from this version onwards.
+
+Type "help valgrind" to get help about the top of the command hierarchy.
+"""
+
+from typing import Callable
+from enum import Enum
+import re
+
+class _Debug_Valgrind_Execute_Monitor(gdb.Parameter):
+    """Set valgrind monitor command execution debugging.
+Usage: set debug valgrind-execute-monitor [on|off]"""
+    def __init__(self):
+        super().__init__("debug valgrind-execute-monitor",
+                         gdb.COMMAND_MAINTENANCE,
+                         gdb.PARAM_BOOLEAN)
+
+Debug_Valgrind_Execute_Monitor = _Debug_Valgrind_Execute_Monitor()
+
+def gdb_execute_monitor(monitor_command : str, from_tty : bool) -> None:
+    """Execute the given monitor command."""
+    cmd = "monitor " + monitor_command
+    if Debug_Valgrind_Execute_Monitor.value:
+        print('[valgrind-execute-monitor] sending "' + cmd + '" to valgrind')
+    try:
+        gdb.execute (cmd, from_tty)
+    except Exception as inst:
+        if monitor_command == "v.kill" and str(inst).find('Remote connection closed') >= 0:
+            print('Remote connection closed')
+        else:
+            print('Error sending "' + monitor_command + '" to valgrind: '+ str(inst))
+
+class Valgrind_Command(gdb.Command):
+    """Parent class for all Valgrind commands."""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        """Generic Valgrind Command invoke method to override if needed."""
+        # print("generic invoke", self.mname)
+        if arg_str:
+            gdb_execute_monitor (self.mname + " " + arg_str, from_tty)
+        else:
+            gdb_execute_monitor (self.mname, from_tty)
+
+def Vinit(toolname : str,
+          mname : str,
+          command_class : Enum,
+          completer_class : Enum,
+          prefix : bool) -> Callable[[Valgrind_Command],
+                                                Valgrind_Command]:
+    """Class decorator to initialise and register a Valgrind_Command class.
+MNAME is the Valgrind monitor name string for this command.
+The gdb command is the concatenation of TOOLNAME and MNAME.
+TOOLNAME is valgrind for the general valgrind commands."""
+    def instantiate(GDB_Command : Valgrind_Command) -> Valgrind_Command:
+        def adhoc_init (self):
+            # print("initializing", GDB_Command)
+            if completer_class:
+                super(GDB_Command, self).__init__(name = toolname + " " + mname,
+                                                  command_class = command_class,
+                                                  completer_class = completer_class,
+                                                  prefix = prefix)
+            else:
+                super(GDB_Command, self).__init__(name = toolname + " " + mname,
+                                                  command_class = command_class,
+                                                  prefix = prefix)
+            self.toolname=toolname
+            self.mname=mname
+        GDB_Command.__init__ = adhoc_init
+        GDB_Command() # register the command
+        return GDB_Command
+    return instantiate
+
+def build_name(command : Valgrind_Command) -> str:
+    """Returns the GDB full name for the given COMMAND."""
+    if command.mname:
+        return command.toolname + ' ' + command.mname
+    else:
+        return command.toolname
+
+def build_help(command : Valgrind_Command) -> str:
+    """Returns a string to ask help for the given COMMAND."""
+    return "help " + build_name(command)
+
+def build_type_help(command : Valgrind_Command) -> str:
+    """Returns a string giving what to type to get helps about the given command"""
+    return 'Type "' + build_help(command) + '"'
+
+class Valgrind_Prefix_Command(Valgrind_Command):
+    """Parent class for all Valgrind prefix commands."""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        """Generic Valgrind prefix Command invoke method to override if needed."""
+        # print("generic prefix invoke", self.mname)
+        if arg_str:
+            # If it is not a recognised sub-command, raise an error.
+            raise gdb.GdbError(('Undefined ' + build_name (self)
+                                + ' command: "' + arg_str + '".\n'
+                                + build_type_help(self)))
+        else:
+            gdb.execute (build_help(self), from_tty)
+
+class Valgrind_Prefix_Exec_Command(Valgrind_Prefix_Command):
+    """Parent class for all Valgrind prefix commands that can be executed without subcommands."""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        """Invoke for a prefix command that can be executed."""
+        if arg_str:
+            super().invoke(arg_str, from_tty)
+        else:
+            gdb_execute_monitor (self.mname, from_tty)
+
+def eval_execute(command : Valgrind_Command,
+                 arg_str : str,
+                 arg_opt : bool, arg_descr : str, format_fn,
+                 from_tty : bool) -> None:
+    """Evaluates ARG_STR, format the result with FORMAT_FN and
+executes the monitor command COMMAND.mname + FORMAT_FN(evaluated ARG_STR).
+ARG_OPT True indicates the argument is optional.
+ARG_DESCR is used in error messages."""
+    if arg_str:
+        eval_arg_str = gdb.parse_and_eval (arg_str)
+        gdb_execute_monitor (command.mname + " " + format_fn(eval_arg_str), from_tty)
+    elif arg_opt:
+        gdb_execute_monitor (command.mname, from_tty)
+    else:
+        raise gdb.GdbError(('Argument "' + arg_descr + '" required.\n'
+                            + build_type_help(command)))
+
+def eval_execute_2(command : Valgrind_Command,
+                   arg_str : str,
+                   arg1_opt : bool, arg1_descr : str, format_fn1,
+                   arg2_opt : bool, arg2_descr : str, format_fn2,
+                   from_tty : bool) -> None:
+    """Like eval_execute but allowing 2 arguments to be extracted from ARG_STR).
+The second argument starts after the first space in ARG_STR."""
+    if arg1_opt and not arg2_opt:
+        raise gdb.GdbError(('Cannot have arg1_opt True and arg2_opt False'
+                            + ' in definition of '
+                            + build_name(command)))
+    if arg_str:
+        arg_str_v = arg_str.split(' ', 1);
+        eval_arg1_str = gdb.parse_and_eval (arg_str_v[0])
+        if len(arg_str_v) <= 1:
+            if arg2_opt:
+                gdb_execute_monitor (command.mname + " " + format_fn1(eval_arg1_str), from_tty)
+            else:
+                raise gdb.GdbError(('Argument 2 "' + arg2_descr + '" required.\n'
+                                    + build_type_help(command)))
+        else:
+            eval_arg2_str = gdb.parse_and_eval (arg_str_v[1])
+            gdb_execute_monitor (command.mname
+                                 + " " + format_fn1(eval_arg1_str)
+                                 + " " + format_fn1(eval_arg2_str),
+                                 from_tty)
+    elif arg1_opt and arg2_opt:
+        gdb_execute_monitor (command.mname, from_tty)
+    else:
+        raise gdb.GdbError(('Argument 1 "' + arg1_descr + '" required.\n'
+                            + ('' if arg2_opt
+                               else 'Argument 2 "' + arg2_descr + '" required.\n')
+                            + build_type_help(command)))
+
+def def_alias(alias : str, command_name : str) -> None:
+    """Defines an alias ALIAS = COMMAND_NAME.
+Traps the error if ALIAS is already defined (so as to be able to source
+this file again)."""
+    d = "alias " + alias + ' = ' + command_name
+    try:
+        gdb.execute (d)
+    except Exception as inst:
+        print('"' + d + '" : '+ str(inst))
+
+class Valgrind_ADDR(Valgrind_Command):
+    """Common class for Valgrind commands taking ADDR arg."""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        eval_execute(self, arg_str,
+                     False, "ADDR (address expression)", hex,
+                     from_tty)
+    
+class Valgrind_ADDR_opt(Valgrind_Command):
+    """Common class for Valgrind commands taking [ADDR] arg."""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        eval_execute(self, arg_str,
+                     True, "ADDR (address expression)", hex,
+                     from_tty)
+    
+class Valgrind_ADDR_LEN_opt(Valgrind_Command):
+    """Common class for Valgrind commands taking ADDR and [LEN] args.
+For compatibility reason with the Valgrind gdbserver monitor command,
+we detect and accept usages such as 0x1234ABCD[10]."""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        if re.fullmatch("^0x[0123456789ABCDEFabcdef]+\[[^\[\]]+\]$", arg_str):
+            arg_str = arg_str.replace("[", " ")
+            arg_str = arg_str.replace("]", " ")
+        eval_execute_2(self, arg_str,
+                       False, "ADDR (address expression)", hex,
+                       True, "LEN (integer length expression)", str,
+                       from_tty)
+    
+############# The rest of this file defines first the valgrind general commands
+# then the tool specific commands.
+# The commands are defined in the same order as produced by
+#   (gdb) monitor help debug
+
+############# valgrind general commands.
+
+###### Top of the hierarchy of the valgrind general commands.
+@Vinit("valgrind", "", gdb.COMMAND_SUPPORT, gdb.COMPLETE_COMMAND, True)
+class Valgrind_Monitor_Command(Valgrind_Prefix_Command):
+    """Front end GDB command for Valgrind gdbserver monitor commands.
+Usage: valgrind VALGRIND_MONITOR_COMMAND [ARG...]
+VALGRIND_MONITOR_COMMAND is a valgrind subcommand, matching a
+gdbserver Valgrind monitor command.
+ARG... are optional arguments.  They depend on the VALGRIND_MONITOR_COMMAND.)
+
+Type "help memcheck" or "help mc" for memcheck specific commands.
+Type "help helgrind" or "help hg" for helgrind specific commands.
+Type "help callgrind" or "help cg" for callgrind specific commands.
+Type "help massif" or "help ms" for massif specific commands.
+"""
+
+def_alias("vg", "valgrind")
+def_alias("v", "valgrind") # To avoid 'v' reported as ambiguous for 'vg' and 'valgrind' !
+
+@Vinit("valgrind", "help", gdb.COMMAND_SUPPORT, gdb.COMPLETE_COMMAND, True)
+class Valgrind_Help_Command(Valgrind_Prefix_Exec_Command):
+    """Ask Valgrind gdbserver to output the help for its monitor commands.
+Usage: valgrind help
+This shows the help string reported by the Valgrind gdbserver.
+Type "help valgrind" to get help about the GDB front end commands interfacing
+to the Valgrind gdbserver monitor commands.
+"""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        """Invoke for a prefix command that can be executed."""
+        if arg_str:
+            super().invoke(arg_str, from_tty)
+        else:
+            gdb_execute_monitor (self.mname, from_tty)
+
+@Vinit("valgrind", "help debug", gdb.COMMAND_SUPPORT, gdb.COMPLETE_NONE, False)
+class Valgrind_Help_Debug_Command(Valgrind_Command):
+    """Ask Valgrind gdbserver to output the help for its monitor commands (including debugging commands).
+Usage: valgrind help debug
+This shows the help string reported by the Valgrind gdbserver.
+Type "help valgrind" to get help about the GDB front end commands interfacing
+to the Valgrind gdbserver monitor commands.
+"""
+
+@Vinit("valgrind", "v.wait", gdb.COMMAND_OBSCURE, gdb.COMPLETE_EXPRESSION, False)
+class Valgrind_Wait_Command(Valgrind_Command):
+    """Have Valgrind gdbserver sleeping for MS (default 0) milliseconds.
+Usage: valgrind v.wait [MS]
+MS is an integer expression evaluated by GDB.
+"""
+    def invoke(self, arg_str : str, from_tty: bool) -> None:
+        eval_execute(self, arg_str,
+                     True, "MS (integer expression in milliseconds)", str,
+                     from_tty)
+
+@Vinit("valgrind", "v.info", gdb.COMMAND_STATUS, gdb.COMPLETE_COMMAND, True)
+class Valgrind_Info_Command(Valgrind_Prefix_Command):
+    """Get various information about Valgrind gdbserver.
+Usage: valgrind v.info WHAT [ARG...]
+WHAT is the v.info subcommand, specifying the type of information requested.
+ARG are optional arguments, depending on the WHAT subcommand.
+"""
+
+@Vinit("valgrind", "v.info all_errors", gdb.COMMAND_STATUS, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_All_Errors_Command(Valgrind_Command):
+    """Show all errors found so far by Valgrind.
+Usage: valgrind v.info all_errors
+"""
+
+@Vinit("valgrind", "v.info last_error", gdb.COMMAND_STATUS, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_Last_Error_Command(Valgrind_Command):
+    """Show last error found by Valgrind.
+Usage: valgrind v.info last_error
+"""
+
+@Vinit("valgrind", "v.info location", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Valgrind_Info_Location_Command(Valgrind_ADDR):
+    """Show information known by Valgrind about location ADDR.
+Usage: valgrind v.info location ADDR
+ADDR is an address expression evaluated by GDB.
+"""
+
+@Vinit("valgrind", "v.info n_errs_found", gdb.COMMAND_STATUS, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_N_Errs_Found_Command(Valgrind_Command):
+    """Show the nr of errors found so far by Valgrind and the given MSG.
+Usage: valgrind v.info n_errs_found [MSG]
+The optional MSG is made of all what follows n_errs_found and is not evaluated.
+"""
+
+@Vinit("valgrind", "v.info open_fds", gdb.COMMAND_DATA, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_Open_Fds_Command(Valgrind_Command):
+    """Show open file descriptors tracked by Valgrind (only if --track-fds=yes).
+Usage: valgrind v.info open_fds
+"""
+
+@Vinit("valgrind", "v.kill", gdb.COMMAND_RUNNING, gdb.COMPLETE_NONE, False)
+class Valgrind_Kill_Command(Valgrind_Command):
+    """Instruct valgrind gdbserver to kill the valgrind process.
+Usage: valgrind v.kill
+"""
+
+@Vinit("valgrind", "v.clo", gdb.COMMAND_RUNNING, gdb.COMPLETE_NONE, False)
+class Valgrind_Clo_Command(Valgrind_Command):
+    """Change one or more Valgrind dynamic command line options.
+Usage: valgrind v.clo [VALGRIND_OPTION]...
+VALGRIND_OPTION is the command line option to change.
+Example:   (gdb) valgrind v.clo --stats=yes --show-below-main=yes
+
+Without VALGRIND_OPTION, shows the dynamically changeable options.
+"""
+
+@Vinit("valgrind", "v.set", gdb.COMMAND_STATUS, gdb.COMPLETE_COMMAND, True)
+class Valgrind_Set_Command(Valgrind_Prefix_Command):
+    """Modify various setting of Valgrind gdbserver.
+Usage: valgrind v.set WHAT [ARG]...
+WHAT is the v.set subcommand, specifying the setting to change.
+ARG are optional arguments, depending on the WHAT subcommand.
+"""
+
+@Vinit("valgrind", "v.set gdb_output", gdb.COMMAND_STATUS, gdb.COMPLETE_NONE, False)
+class Valgrind_Set_Gdb_Output_Command(Valgrind_Command):
+    """Set Valgrind output to gdb.
+Usage: valgrind v.set gdb_output
+"""
+
+@Vinit("valgrind", "v.set log_output", gdb.COMMAND_STATUS, gdb.COMPLETE_NONE, False)
+class Valgrind_Set_Log_Output_Command(Valgrind_Command):
+    """Set Valgrind output to Valgrind log.
+Usage: valgrind v.set log_output
+"""
+
+@Vinit("valgrind", "v.set mixed_output", gdb.COMMAND_STATUS, gdb.COMPLETE_NONE, False)
+class Valgrind_Set_Mixed_Output_Command(Valgrind_Command):
+    """Set Valgrind output to Valgrind log, interactive output to gdb.
+Usage: valgrind v.set mixed_output
+"""
+
+@Vinit("valgrind", "v.set merge-recursive-frames", gdb.COMMAND_STATUS, gdb.COMPLETE_EXPRESSION, False)
+class Valgrind_Set_Merge_Recursive_Frames_Command(Valgrind_Command):
+    """Set the number of frames for recursive calls merging in Valgrind stacktraces.
+Usage: valgrind v.set merge-recursive-frames NUM
+NUM is an integer expression evaluated by GDB.
+"""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        eval_execute(self, arg_str, 
+                     False, "NUM (number of frames for recursive calls merging)",
+                     str,
+                     from_tty)
+
+@Vinit("valgrind", "v.set vgdb-error", gdb.COMMAND_RUNNING, gdb.COMPLETE_EXPRESSION, False)
+class Valgrind_Set_Vgdb_Error_Command(Valgrind_Command):
+    """Set the number of errors at which Valgrind gdbserver gives control to gdb.
+Usage: valgrind v.set vgdb-error NUM
+NUM is an integer expression evaluated by GDB.
+"""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        eval_execute(self, arg_str,
+                     False, "NUM (number of errors)",
+                     str,
+                     from_tty)
+
+@Vinit("valgrind", "v.do", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_COMMAND, True)
+class Valgrind_Do_Command(Valgrind_Prefix_Command):
+    """Ask Valgrind gdbserver to do an internal/maintenance action.
+Usage: valgrind v.do WHAT
+WHAT is the valgrind v.do subcommand, specifying the type of action requested.
+"""
+
+@Vinit("valgrind", "v.do expensive_sanity_check_general", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Do_Expensive_Sanity_Check_General_Command(Valgrind_Command):
+    """Do an expensive Valgrind sanity check now.
+Usage: valgrind v.do expensive_sanity_check_general
+"""
+
+@Vinit("valgrind", "v.info gdbserver_status", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_Gdbserver_Status_Command(Valgrind_Command):
+    """Show gdbserver status.
+Usage: valgrind v.info gdbserver_status
+"""
+
+@Vinit("valgrind", "v.info memory", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_COMMAND, True)
+class Valgrind_Info_Memory_Status_Command(Valgrind_Prefix_Exec_Command):
+    """Show valgrind heap memory stats.
+Usage: valgrind v.info memory
+"""
+
+@Vinit("valgrind", "v.info memory aspacemgr", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_Memory_Aspacemgr_Command(Valgrind_Command):
+    """Show Valgrind heap memory stats and show Valgrind segments on log output.
+Usage: valgrind v.info memory aspacemgr
+"""
+
+@Vinit("valgrind", "v.info exectxt", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_Exectxt_Command(Valgrind_Command):
+    """Show stacktraces and stats of all execontexts record by Valgrind.
+Usage: valgrind v.info exectxt
+"""
+
+@Vinit("valgrind", "v.info scheduler", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_Scheduler_Command(Valgrind_Command):
+    """Show Valgrind thread state and stacktrace.
+Usage: valgrind v.info scheduler
+"""
+
+@Vinit("valgrind", "v.info stats", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Info_Stats_Command(Valgrind_Command):
+    """Show various Valgrind and tool stats.
+Usage: valgrind v.info stats
+"""
+
+@Vinit("valgrind", "v.info unwind", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_EXPRESSION, False)
+class Valgrind_Info_Unwind_Command(Valgrind_ADDR_LEN_opt):
+    """Show unwind debug info for ADDR .. ADDR+LEN.
+Usage: valgrind v.info unwind ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+"""
+
+@Vinit("valgrind", "v.set debuglog", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_EXPRESSION, False)
+class Valgrind_Set_Debuglog_Command(Valgrind_Command):
+    """Set Valgrind debug log level to LEVEL.
+Usage: valgrind v.set LEVEL
+LEVEL is an integer expression evaluated by GDB.
+"""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        eval_execute(self, arg_str, 
+                     False, "LEVEL (valgrind debug log level)",
+                     str,
+                     from_tty)
+@Vinit("valgrind", "v.set hostvisibility", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_COMMAND, True)
+class Valgrind_Set_Hostvisibility_Command(Valgrind_Prefix_Exec_Command):
+    """Set visibility of the internal Valgrind 'host' state.
+Without arguments, enables the host visibility.
+Host visibility allows to examine with GDB the internal status and memory
+of Valgrind.
+Usage: valgrind v.set hostvisibility
+"""
+
+@Vinit("valgrind", "v.set hostvisibility yes", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Set_Hostvisibility_Yes_Command(Valgrind_Command):
+    """Enable visibility of the internal Valgrind 'host' state.
+Usage: valgrind v.set hostvisibility yes
+See "help v.set hostvisibility".
+"""
+
+@Vinit("valgrind", "v.set hostvisibility no", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_NONE, False)
+class Valgrind_Set_Hostvisibility_No_Command(Valgrind_Command):
+    """Disable visibility of the internal Valgrind 'host' state.
+Usage: valgrind v.set hostvisibility no
+See "help v.set hostvisibility".
+"""
+
+def base2(value : int) -> str:
+    """Image of value in base 2 prefixed with 0b."""
+    "0b" + "{0:b}".format(value)
+
+@Vinit("valgrind", "v.translate", gdb.COMMAND_MAINTENANCE, gdb.COMPLETE_EXPRESSION, False)
+class Valgrind_Translate_Command(Valgrind_Command):
+    """Show the translation of instructions at ADDR with TRACEFLAGS.
+Usage: valgrind v.translate ADDR [TRACEFLAG]
+For TRACEFLAG values, type in shell "valgrind --help-debug".
+An additional flag  0b100000000 allows one to show gdbserver instrumentation.
+ADDR is an address expression evaluated by GDB.
+TRACEFLAG is an integer expression (used as a bitmask) evaluated by GDB.
+"""
+    def invoke(self, arg_str : str, from_tty : bool) -> None:
+        eval_execute_2(self, arg_str,
+                       False, "ADDR (address expression)", hex,
+                       True, "TRACEFLAGS (bit mask expression)", base2,
+                       from_tty)
+
+############# memcheck commands.
+
+######  Top of the hierarchy of the memcheck commands.
+@Vinit("memcheck", "", gdb.COMMAND_SUPPORT, gdb.COMPLETE_COMMAND, True)
+class Memcheck_Command(Valgrind_Prefix_Command):
+    """Front end GDB command for Valgrind memcheck gdbserver monitor commands.
+Usage: memcheck MEMCHECK_MONITOR_COMMAND [ARG...]
+MEMCHECK_MONITOR_COMMAND is a memcheck subcommand, matching 
+a gdbserver Valgrind memcheck monitor command.
+ARG... are optional arguments.  They depend on the MEMCHECK_MONITOR_COMMAND.
+"""
+    
+def_alias("mc", "memcheck")
+
+@Vinit("memcheck", "xtmemory", gdb.COMMAND_DATA, gdb.COMPLETE_FILENAME, False)
+class Memcheck_Xtmemory_Command(Valgrind_Command):
+    """Dump xtree memory profile in FILENAME (default xtmemory.kcg.%p.%n).
+Usage: memcheck xtmemory [FILENAME]
+
+Example:   (gdb) memcheck xtmemory my_program_xtree.kcg
+"""
+
+@Vinit("memcheck", "xb", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Xb_Command(Valgrind_ADDR_LEN_opt):
+    """Print validity bits for LEN (default 1) bytes at ADDR.
+            bit values 0 = valid, 1 = invalid, __ = unaddressable byte
+Prints the bytes values below the corresponding validity bits
+in a layout similar to the gdb command 'x /LENxb ADDR
+Usage: memcheck xb ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck xb &p sizeof(p)
+"""
+
+@Vinit("memcheck", "get_vbits", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Get_Vbits_Command(Valgrind_ADDR_LEN_opt):
+    """Print validity bits for LEN (default 1) bytes at ADDR.
+            bit values 0 = valid, 1 = invalid, __ = unaddressable byte
+Usage: memcheck get_vbits ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck get_vbits &p sizeof(p)
+
+Note: the command 'memcheck xb ADDR [LEN]' prints the value 
+and validity bits of ADDR [LEN] bytes in an easier to read format.
+"""
+
+@Vinit("memcheck", "make_memory", gdb.COMMAND_DATA, gdb.COMPLETE_COMMAND, True)
+class Memcheck_Make_Memory_Command(Valgrind_Prefix_Command):
+    """Prefix command to change memory accessibility."""
+
+@Vinit("memcheck", "make_memory noaccess", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Make_Memory_Noaccess_Command(Valgrind_ADDR_LEN_opt):
+    """Mark LEN (default 1) bytes at ADDR as noaccess.
+Usage: memcheck make_memory noaccess ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck make_memory noaccess &p sizeof(p)
+"""
+
+@Vinit("memcheck", "make_memory undefined", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Make_Memory_Undefined_Command(Valgrind_ADDR_LEN_opt):
+    """Mark LEN (default 1) bytes at ADDR as undefined.
+Usage: memcheck make_memory undefined ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck make_memory undefined &p sizeof(p)
+"""
+
+@Vinit("memcheck", "make_memory defined", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Make_Memory_Defined_Command(Valgrind_ADDR_LEN_opt):
+    """Mark LEN (default 1) bytes at ADDR as defined.
+Usage: memcheck make_memory defined ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck make_memory defined &p sizeof(p)
+"""
+
+@Vinit("memcheck", "make_memory Definedifaddressable", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Make_Memory_Definedifaddressable_Command(Valgrind_ADDR_LEN_opt):
+    """Mark LEN (default 1) bytes at ADDR as Definedifaddressable.
+Usage: memcheck make_memory Definedifaddressable ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck make_memory Definedifaddressable &p sizeof(p)
+"""
+
+@Vinit("memcheck", "check_memory", gdb.COMMAND_DATA, gdb.COMPLETE_COMMAND, True)
+class Memcheck_Check_Memory_Command(Valgrind_Prefix_Command):
+    """Command to check memory accessibility."""
+
+@Vinit("memcheck", "check_memory addressable", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Check_Memory_Addressable_Command(Valgrind_ADDR_LEN_opt):
+    """Check that LEN (default 1) bytes at ADDR are addressable.
+Usage: memcheck check_memory addressable ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck check_memory addressable &p sizeof(p)
+"""
+
+@Vinit("memcheck", "check_memory defined", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Check_Memory_Defined_Command(Valgrind_ADDR_LEN_opt):
+    """Check that LEN (default 1) bytes at ADDR are defined.
+Usage: memcheck check_memory defined ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) memcheck check_memory defined &p sizeof(p)
+"""
+
+@Vinit("memcheck", "leak_check", gdb.COMMAND_DATA, gdb.COMPLETE_NONE, False)
+class Memcheck_Leak_Check_Command(Valgrind_Command):
+    """Execute a memcheck leak search.
+Usage: leak_check [full*|summary|xtleak]
+                [kinds KIND1,KIND2,...|reachable|possibleleak*|definiteleak]
+                [heuristics HEUR1,HEUR2,...]
+                [new|increased*|changed|any]
+                [unlimited*|limited MAX_LOSS_RECORDS_OUTPUT]
+            * = defaults
+
+full:    outputs stacktraces of all leaks followed by a summary.
+summary: outputs only the leak summary.
+xtleak:  produce an xtree full leak result in xtleak.kcg.%p.%n
+
+KIND indicates which kind of leaks to report, and is one of:
+    definite indirect possible reachable all none
+
+HEUR indicates an heuristic to activate when doing leak search and is one of:
+    stdstring length64 newarray multipleinheritance all none*
+
+new:       only outputs the new leak loss records since last leak search.
+increased: only outputs the leak loss records with an increase since 
+              last leak search.
+changed:   also outputs the leak loss records with a decrease.
+any:       also outputs the leak loss records that did not change.
+
+unlimited: outputs all matching loss records.
+limited:   outputs only the first matching MAX_LOSS_RECORDS_OUTPUT.
+
+This command auto-completes the user input by providing the full list of
+keywords still relevant according to what is already typed. For example, if the
+"summary" keyword has been provided, the following TABs to auto-complete other
+items will not propose anymore "full" and "xtleak".  Note that KIND and HEUR
+values are not part of auto-completed elements.
+
+Examples:   (gdb) memcheck leak_check
+            (gdb) memcheck leak_check summary any
+            (gdb) memcheck leak_check full kinds indirect,possible
+            (gdb) memcheck leak_check full reachable any limited 100
+
+    """
+
+    def complete(self, text, word):
+        # print('/' + text + ' ' + word + '/\n')
+        leak_check_mode = ["full", "summary", "xtleak"]
+        leak_kind = ["kinds", "reachable", "possibleleak", "definiteleak"]
+        leak_heuristic = ["heuristics"]
+        leak_check_delta_mode = ["new", "increased", "changed", "any"]
+        leak_check_loss_record_limit = ["unlimited", "limited"]
+        kwd_lists = [leak_check_mode, leak_kind, leak_heuristic,
+                     leak_check_delta_mode, leak_check_loss_record_limit]
+        # Build the list of still allowed keywords.
+        # We append all the keywords of a list unless we find already one
+        # existing word in text that starts with the first letter of a keyword
+        # of the list. Checking the first letter is ok (currently!)
+        # as all keywords of leak_check monitor command starts with a different
+        # letter.
+        keywords = []
+        command_words = text.split()
+        for kwd_list in kwd_lists:
+            list_ok = True
+            # print('list:/' + str(kwd_list) + '/')
+            for kwd in kwd_list:
+                for command_word in command_words:
+                    # print('word:/' + command_word + '/' + kwd)
+                    if kwd[0] == command_word[0]:
+                        # print("setting to false")
+                        list_ok = False
+                        if (kwd.startswith(word) and
+                            word != kwd
+                            and kwd not in command_words
+                            ):
+                            # print('/' + word + '/' + kwd + '/')
+                            keywords.append(kwd)
+            if list_ok:
+                for kwd in kwd_list:
+                    keywords.append(kwd)
+        result = []
+        for keyword in keywords:
+            if keyword.startswith(word):
+                result.append(keyword)
+        return result
+
+@Vinit("memcheck", "block_list", gdb.COMMAND_DATA, gdb.COMPLETE_NONE, False)
+class Memcheck_Block_List_Command(Valgrind_Command):
+    """Show the list of blocks for a leak search loss record.
+Usage: memcheck block_list LOSS_RECORD_NR|LOSS_RECORD_NR_FROM..LOSS_RECORD_NR_TO
+                unlimited*|limited MAX_BLOCKS
+                [heuristics HEUR1,HEUR2,...]
+            * = defaults
+
+After a leak search, use block_list to show the list of blocks matching a loss
+record or matching a range of loss records.
+
+unlimited: outputs all blocks matching the selected loss records.
+limited:   outputs only the first matching MAX_BLOCKS.
+
+Use heuristics to only output the blocks found via one of the given heuristics,
+where HEUR is one of:
+    stdstring length64 newarray multipleinheritance all none*
+    """
+
+@Vinit("memcheck", "who_points_at", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Memcheck_Who_Points_At_Command(Valgrind_ADDR_LEN_opt):
+    """Show places pointing inside LEN (default 1) bytes at ADDR.
+Usage: memcheck who_points_at ADDR [MEN]
+With LEN 1, only shows "start pointers" pointing exactly to ADDR.
+With LEN > 1, will also show "interior pointers"
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+"""
+
+############# helgrind commands.
+
+######  Top of the hierarchy of the helgrind commands.
+@Vinit("helgrind", "", gdb.COMMAND_SUPPORT, gdb.COMPLETE_COMMAND, True)
+class Helgrind_Command(Valgrind_Prefix_Command):
+    """Front end GDB command for Valgrind helgrind gdbserver monitor commands.
+Usage: helgrind HELGRIND_MONITOR_COMMAND [ARG...]
+HELGRIND_MONITOR_COMMAND is a helgrind subcommand, matching 
+a gdbserver Valgrind helgrind monitor command.
+ARG... are optional arguments.  They depend on the HELGRIND_MONITOR_COMMAND.
+"""
+    
+def_alias("hg", "helgrind")
+
+@Vinit("helgrind", "info", gdb.COMMAND_STATUS, gdb.COMPLETE_COMMAND, True)
+class Helgrind_Info_Command(Valgrind_Prefix_Command):
+    """Get various information about helgrind tool status.
+Usage: helgrind info WHAT
+WHAT is the helgrind info subcommand, specifying the type of information requested.
+"""
+
+@Vinit("helgrind", "info locks", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Helgrind_Info_Locks_Command(Valgrind_ADDR_opt):
+    """Show the status of one or all locks recorded by helgrind.
+Usage: helgrind info locks [ADDR]
+ADDR is an address expression evaluated by GDB.
+When ADDR is provided, shows the status of the lock located at ADDR,
+otherwise shows the status of all locks.
+"""
+
+@Vinit("helgrind", "accesshistory", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION, False)
+class Helgrind_Accesshistory_Command(Valgrind_ADDR_LEN_opt):
+    """Show access history recorded for LEN (default 1) bytes at ADDR.
+Usage: helgrind accesshistory ADDR [LEN]
+ADDR is an address expression evaluated by GDB.
+LEN is an integer expression evaluated by GDB.
+
+Example:   (gdb) helgrind accesshistory &p sizeof(p)
+"""
+
+@Vinit("helgrind", "xtmemory", gdb.COMMAND_DATA, gdb.COMPLETE_FILENAME, False)
+class Helgrind_Xtmemory_Command(Valgrind_Command):
+    """Dump xtree memory profile in FILENAME (default xtmemory.kcg.%p.%n).
+Usage: helgrind xtmemory [FILENAME]
+
+Example:   (gdb) helgrind xtmemory my_program_xtree.kcg
+"""
+
+############# callgrind commands.
+
+######  Top of the hierarchy of the callgrind commands.
+@Vinit("callgrind", "", gdb.COMMAND_SUPPORT, gdb.COMPLETE_COMMAND, True)
+class Callgrind_Command(Valgrind_Prefix_Command):
+    """Front end GDB command for Valgrind callgrind gdbserver monitor commands.
+Usage: callgrind CALLGRIND_MONITOR_COMMAND [ARG...]
+CALLGRIND_MONITOR_COMMAND is a callgrind subcommand, matching 
+a gdbserver Valgrind callgrind monitor command.
+ARG... are optional arguments.  They depend on the CALLGRIND_MONITOR_COMMAND.
+"""
+    
+def_alias("cg", "callgrind")
+
+@Vinit("callgrind", "dump", gdb.COMMAND_DATA, gdb.COMPLETE_COMMAND, False)
+class Callgrind_Dump_Command(Valgrind_Command):
+    """Dump the callgrind counters.
+Usage: callgrind dump [DUMP_HINT]
+DUMP_HINT is a message stored in the resulting callgrind dump file.
+"""
+
+@Vinit("callgrind", "zero", gdb.COMMAND_DATA, gdb.COMPLETE_COMMAND, False)
+class Callgrind_Zero_Command(Valgrind_Command):
+    """Set the callgrind counters to zero.
+Usage: callgrind zero
+"""
+
+@Vinit("callgrind", "status", gdb.COMMAND_STATUS, gdb.COMPLETE_NONE, False)
+class Callgrind_Status_Command(Valgrind_Command):
+    """Show the status of callgrind.
+Usage: callgrind status
+"""
+    
+@Vinit("callgrind", "instrumentation", gdb.COMMAND_STATUS, gdb.COMPLETE_COMMAND, False)
+class Callgrind_Instrumentation_Command(Valgrind_Command):
+    """Get or set the callgrind instrumentation state.
+Usage: callgrind instrumentation [on|off]
+Without argument, shows the current state of instrumentation,
+otherwise changes the instrumentation state to the given argument.
+"""
+
+############# massif commands.
+
+######  Top of the hierarchy of the massif commands.
+@Vinit("massif", "", gdb.COMMAND_SUPPORT, gdb.COMPLETE_COMMAND, True)
+class Massif_Command(Valgrind_Prefix_Command):
+    """Front end GDB command for Valgrind massif gdbserver monitor commands.
+Usage: massif MASSIF_MONITOR_COMMAND [ARG...]
+MASSIF_MONITOR_COMMAND is a massif subcommand, matching 
+a gdbserver Valgrind massif monitor command.
+ARG... are optional arguments.  They depend on the MASSIF_MONITOR_COMMAND.
+"""
+
+def_alias("ms", "massif")
+
+@Vinit("massif", "snapshot", gdb.COMMAND_DATA, gdb.COMPLETE_FILENAME, False)
+class Massif_Dump_Command(Valgrind_Command):
+    """Take a massif snapshot in FILENAME (default massif.vgdb.out).
+Usage: massif snapshot [FILENAME]
+"""
+
+@Vinit("massif", "detailed_snapshot", gdb.COMMAND_DATA, gdb.COMPLETE_FILENAME, False)
+class Massif_Dump_Command(Valgrind_Command):
+    """Take a massif detailed snapshot in FILENAME (default massif.vgdb.out).
+Usage: massif detailed_snapshot [FILENAME]
+"""
+
+@Vinit("massif", "all_snapshots", gdb.COMMAND_DATA, gdb.COMPLETE_FILENAME, False)
+class Massif_Dump_Command(Valgrind_Command):
+    """Save all snapshot(s) taken so far in FILENAME (default massif.vgdb.out).
+Usage: massif all_snapshots [FILENAME]
+"""
+
+@Vinit("massif", "xtmemory", gdb.COMMAND_DATA, gdb.COMPLETE_FILENAME, False)
+class Massic_Xtmemory_Command(Valgrind_Command):
+    """Dump xtree memory profile in FILENAME (default xtmemory.kcg.%p.%n).
+Usage: massif xtmemory [FILENAME]
+
+Example:   (gdb) massif xtmemory my_program_xtree.kcg
+"""
diff --git a/coregrind/m_gdbserver/valgrind-monitor.py b/coregrind/m_gdbserver/valgrind-monitor.py
new file mode 100644 (file)
index 0000000..713319d
--- /dev/null
@@ -0,0 +1,34 @@
+# This file is part of Valgrind, a dynamic binary instrumentation
+# framework.
+
+# Copyright (C) 2022-2022 Philippe Waroquiers
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+# The GNU General Public License is contained in the file COPYING.
+   
+"""
+Loads valgrind-monitor-def.py if not yet loaded.
+The purpose of this file is to avoid re-defining the python commands
+by reloading valgrind-monitor-def.py, as such redefinition causes a
+segmentation violation in GDB <= 13.
+"""
+
+import os
+
+if gdb.convenience_variable("valgrind_monitor_loaded") == None:
+    gdb.execute("source " + os.path.dirname(__file__) + "/valgrind-monitor-def.py")
+    gdb.set_convenience_variable ("valgrind_monitor_loaded", 1)
+    print("Loaded "+  __file__)
+    print("""Type "help valgrind" for more info.""")
index 3809811aede7b0a0e9455caf5c5614b6086a6400..75a3b7ed0c4cbdf681d80a40ff11b610060c4b41 100644 (file)
 #include <features.h>
 #endif
 
+/* Instruct GDB via a .debug_gdb_scripts section to load the valgrind and tool
+   front-end commands.  */
+/* Note: The "MS" section flags are to remove duplicates.  */
+#define DEFINE_GDB_PY_SCRIPT(script_name) \
+  asm("\
+.pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n\
+.byte 1 /* Python */\n\
+.asciz \"" script_name "\"\n\
+.popsection \n\
+");
+
+DEFINE_GDB_PY_SCRIPT(VG_LIBDIR "/valgrind-monitor.py")
+
 #if defined(VGO_linux) || defined(VGO_solaris) || defined(VGO_freebsd)
 
 /* ---------------------------------------------------------------------
index 83f49c840dae0e5411bae658366a94901226139f..9a9b90e5859dfdcaf8420aecb66c2c98a032d247 100644 (file)
@@ -1167,8 +1167,9 @@ void usage(void)
 "  -d  arg tells to show debug info. Multiple -d args for more debug info\n"
 "\n"
 "  -h --help shows this message\n"
+"  The GDB python code defining GDB front end valgrind commands is:\n       %s\n"
 "  To get help from the Valgrind gdbserver, use vgdb help\n"
-"\n", vgdb_prefix_default()
+"\n", vgdb_prefix_default(), VG_LIBDIR "/valgrind-monitor.py"
            );
    invoker_restrictions_msg();
 }
index 6991a95e0695315224e10b016746d9368d71bb3a..1609ee2a95fc3dd7eeff3fa2494b496b195a8880 100644 (file)
@@ -591,7 +591,7 @@ works across all devices and scenarios.
        xreflabel="Monitor command handling by the Valgrind gdbserver">
 <title>Monitor command handling by the Valgrind gdbserver</title>
 
-<para> The Valgrind gdbserver provides additional Valgrind-specific
+<para>The Valgrind gdbserver provides additional Valgrind-specific
 functionality via "monitor commands".  Such monitor commands can be
 sent from the GDB command line or from the shell command line or
 requested by the client program using the VALGRIND_MONITOR_COMMAND
@@ -628,11 +628,11 @@ command:
 ]]></screen>
 </para>
 
-<para>GDB will send the <computeroutput>leak_check</computeroutput>
-command to the Valgrind gdbserver.  The Valgrind gdbserver will
-execute the monitor command itself, if it recognises it to be a Valgrind core
-monitor command.  If it is not recognised as such, it is assumed to
-be tool-specific and is handed to the tool for execution.  For example:
+<para>GDB sends as a single string all what follows 'monitor' to the Valgrind
+gdbserver.  The Valgrind gdbserver parses the string and will execute the
+monitor command itself, if it recognises it to be a Valgrind core monitor
+command.  If it is not recognised as such, it is assumed to be tool-specific and
+is handed to the tool for execution.  For example:  
 </para>
 <programlisting><![CDATA[
 (gdb) monitor leak_check full reachable any
@@ -650,9 +650,9 @@ be tool-specific and is handed to the tool for execution.  For example:
 (gdb) 
 ]]></programlisting>
 
-<para>As with other GDB commands, the Valgrind gdbserver will accept
-abbreviated monitor command names and arguments, as long as the given
-abbreviation is unambiguous.  For example, the above
+<para>Similarly to GDB, the Valgrind gdbserver will accept abbreviated monitor
+command names and arguments, as long as the given abbreviation is unambiguous.
+For example, the above
 <computeroutput>leak_check</computeroutput>
 command can also be typed as:
 <screen><![CDATA[
@@ -705,6 +705,130 @@ continue: the program execution is controlled explicitly using GDB
 
 </sect2>
 
+<sect2 id="manual-core-adv.gdbserver-gdbmonitorfrontend"
+       xreflabel="GDB front end commands for Valgrind gdbserver monitor commands">
+<title>GDB front end commands for Valgrind gdbserver monitor commands</title>
+
+<para>As explained in
+  <xref linkend="manual-core-adv.gdbserver-commandhandling"/>, valgrind monitor
+  commands consist in strings that are not interpreted by GDB.  GDB has no
+  knowledge of these valgrind monitor commands.  The GDB 'command line
+  interface' infrastructure however provides interesting functionalities to help
+  typing commands such as auto-completion, command specific help, searching for
+  a command or command help matching a regexp, ...
+</para>
+
+<para>To have a better integration of the valgrind monitor commands in the GDB
+  command line interface, Valgrind provides python code defining a GDB front end
+  command for each valgrind monitor command.  Similarly, for each tool specific
+  monitor command, the python code provides a matching GDB front end command.
+</para>
+
+<para>Like other GDB commands, the GDB front end Valgrind monitor commands are
+  hierarchically structured starting from 5 "top" GDB commands. Subcommands are
+  defined below these "top" commands.  To ease typing, shorter aliases are also
+  provided.
+
+  <itemizedlist>
+    <listitem>
+      <para><computeroutput>valgrind</computeroutput> (aliased
+      by <computeroutput>vg</computeroutput>
+      and <computeroutput>v</computeroutput>) is the top GDB command providing
+      front end commands to the Valgrind general monitor commands.</para>
+    </listitem>
+    <listitem>
+      <para><computeroutput>memcheck</computeroutput> (aliased
+        by <computeroutput>mc</computeroutput>) is the top GDB command
+        providing the front end commands corresponding to the memcheck specific
+        monitor commands.</para>
+    </listitem>
+    <listitem>
+      <para><computeroutput>callgrind</computeroutput> (aliased
+        by <computeroutput>cg</computeroutput>) is the top GDB command
+        providing the front end commands corresponding to the callgrind specific
+        monitor commands.</para>
+    </listitem>
+    <listitem>
+      <para><computeroutput>massif</computeroutput> (aliased
+        by <computeroutput>ms</computeroutput>) is the top GDB command
+        providing the front end commands corresponding to the massif specific
+        monitor commands.</para>
+    </listitem>
+    <listitem>
+      <para><computeroutput>helgrind</computeroutput> (aliased
+        by <computeroutput>hg</computeroutput>) is the top GDB command
+        providing the front end commands corresponding to the helgrind specific
+        monitor commands.</para>
+    </listitem>
+  </itemizedlist>
+</para>
+
+<para>The usage of a GDB front end command is compatible with a direct usage of
+  the Valgrind monitor command.  The below example shows a direct usage of the
+  Memcheck monitor command <computeroutput>xb</computeroutput> to examine the
+  definedness status of the some_mem array and equivalent usages based on the GDB
+  front end commands.
+
+<programlisting><![CDATA[
+(gdb) list
+1      int main()
+2      {
+3        char some_mem[5];
+4        return 0;
+5      }
+(gdb) p &some_mem
+$2 = (char (*)[5]) 0x1ffefffe5b
+(gdb) p sizeof(some_mem)
+$3 = 5
+(gdb) monitor xb 0x1ffefffe5b 5
+                 ff      ff      ff      ff      ff
+0x1FFEFFFE5B:  0x00    0x00    0x00    0x00    0x00
+(gdb) memcheck xb 0x1ffefffe5b 5
+                 ff      ff      ff      ff      ff
+0x1FFEFFFE5B:  0x00    0x00    0x00    0x00    0x00
+(gdb) mc xb &some_mem sizeof(some_mem)
+                 ff      ff      ff      ff      ff
+0x1FFEFFFE5B:  0x00    0x00    0x00    0x00    0x00
+(gdb) 
+]]></programlisting>
+
+It is worth noting down that the third command uses the
+alias <computeroutput>mc</computeroutput>.  This command also shows a
+significant advantage of using the GDB front end commands: as GDB "understands"
+the structure of these front end commands, where relevant, these front end
+commands will evaluate their arguments. In the case of
+the <computeroutput>xb</computeroutput> command, the
+GDB <computeroutput>xb</computeroutput> command evaluates its second argument
+(which must be an address expression) and its optional second argument (which
+must be an integer expression).
+</para>
+
+<para>GDB will auto-load the python code defining the Valgrind front end
+  commands as soon as GDB detects that the executable being debugged is running
+  under valgrind.  This detection is based on observing that the Valgrind
+  process has loaded a specific Valgrind shared library.  The loading of this
+  library is done by the dynamic loader very early on in the execution of the
+  process.  If GDB is used to connect to a Valgrind process that has not yet
+  started its execution (such as when Valgrind was started with the
+  option <computeroutput>--vgdb-stop-at=startup</computeroutput>
+  or <computeroutput>--vgdb-error=0</computeroutput>), then the GDB front end
+  commands will not yet be auto-loaded.  To have the GDB front end commands
+  auto-loaded, you can put a breakpoint e.g. in main and use the GDB
+  command <computeroutput>continue</computeroutput>. Alternatively, you can add
+  in your .gdbinit a line that loads the python code at GDB startup such as:
+<programlisting><![CDATA[
+source /path/to/valgrind/python/code/valgrind-monitor.py
+]]></programlisting>
+</para>
+<para>
+The exact path to use in the source command depends on your Valgrind
+installation.  The output of the shell command <computeroutput>vgdb
+--help</computeroutput> contains the absolute path name for the python file you
+can source in your .gdbinit to define the GDB valgrind front end monitor
+commands.
+</para>
+</sect2>
+
 <sect2 id="manual-core-adv.gdbserver-threads"
        xreflabel="Valgrind gdbserver thread information">
 <title>Valgrind gdbserver thread information</title>
@@ -1307,10 +1431,25 @@ commands, refer to <xref linkend="mc-manual.monitor-commands"/>,
 
 <para> The monitor commands can be sent either from a shell command line, by using a
 standalone vgdb, or from GDB, by using GDB's "monitor"
-command (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>).
+command (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>) or
+by GDB's "valgrind" front end commands (see
+<xref linkend="manual-core-adv.gdbserver-gdbmonitorfrontend"/>).  
 They can also be launched by the client program, using the VALGRIND_MONITOR_COMMAND
 client request.
 </para>
+<para>Whatever the way the monitor command is launched, it will behave the same
+  way. However, using the GDB's valgrind front end commands allows to benefit
+  from the GDB infrastructure, such as expression evaluation.  When relevant,
+  the description of a monitor command below describes the additional
+  flexibility provided by the GDB valgrind front end command.  To launch a
+  valgrind monitor command via its GDB front end command, instead of prefixing
+  the command with "monitor", you must use the GDB <varname>valgrind</varname>
+  command (or the shorter aliases <varname>vg</varname>
+  or <varname>v</varname>).  In GDB, you can use <varname>help
+  valgrind</varname> to get help about the valgrind front end monitor commands
+  and you can use <varname>apropos valgrind</varname> to get all the commands
+  mentionning the word "valgrind" in their name or on-line help.
+</para>
 
 <itemizedlist>
   <listitem>
@@ -1319,6 +1458,13 @@ client request.
     of the tool. The optional "debug" argument tells to also give help
     for the monitor commands aimed at Valgrind internals debugging.
     </para>
+    <para>Note that this monitor command produces the help information as
+      provided by valgrind gdbserver.  The GDB help given e.g. by <varname>help
+      valgrind</varname> or <varname>help valgrind v.info</varname> provides the
+      help of the GDB front end command for the equivalent valgrind gdbserver
+      monitor command. This "GDB help" describes the additional flexibility
+      provided by the GDB front end command.
+      </para>
   </listitem>
 
   <listitem>
@@ -1345,13 +1491,28 @@ client request.
     detailed information about global or local (stack) variables.
     </para>
 <programlisting><![CDATA[
-(gdb) monitor v.info location 0x8050b20
- Location 0x8050b20 is 0 bytes inside global var "mx"
+(gdb) monitor v.info location 0x1130a0
+ Location 0x1130a0 is 0 bytes inside global var "mx"
  declared at tc19_shadowmem.c:19
+(gdb) mo v.in loc 0x1ffefffe10
+ Location 0x1ffefffe10 is 0 bytes inside info.child,
+ declared at tc19_shadowmem.c:139, in frame #1 of thread 1
+(gdb) 
+]]></programlisting>
 
-(gdb) mo v.in loc 0x582f33c
- Location 0x582f33c is 0 bytes inside local var "info"
- declared at tc19_shadowmem.c:282, in frame #1 of thread 3
+<para>The GDB valgrind front end command <varname>valgrind v.info location ADDR</varname>
+  accepts any address expression for its ADDR argument. In the below examples, mx is
+  a global struct and info is a pointer to a structure. Instead of having to print the
+  addresses of the structure and printing the pointer variable, you can directly use the
+  expressions in the GDB valgrind front end command argument.
+  </para>
+<programlisting><![CDATA[
+(gdb) valgrind v.info location &mx
+ Location 0x1130a0 is 0 bytes inside global var "mx"
+ declared at tc19_shadowmem.c:19
+(gdb) v v.i lo info
+ Location 0x1ffefffe10 is 0 bytes inside info.child,
+ declared at tc19_shadowmem.c:139, in frame #1 of thread 1
 (gdb) 
 ]]></programlisting>
   </listitem>
@@ -1375,16 +1536,28 @@ client request.
     <option>--track-fds=all</option> (to include
     <computeroutput>stdin</computeroutput>,
     <computeroutput>stdout</computeroutput> and
-    <computeroutput>stderr</computeroutput>) was given at Valgrindr
-    startup.</para>
+    <computeroutput>stderr</computeroutput>) was given at Valgrind startup.</para>
   </listitem>
   
   <listitem>
     <para><varname>v.clo &lt;clo_option&gt;...</varname> changes one or more
         dynamic command line options. If no clo_option is given, lists the
         dynamically changeable options. See
-        <xref linkend="manual-core.dynopts"/>.
-      </para>
+      <xref linkend="manual-core.dynopts"/>.
+      The below shows example of changing the value of <varname>--vgdb-error</varname>
+      using directly the valgrind monitor command, using the equivalent GDB valgrind front end command.
+      It also shows how a more flexible setting can be done using the GDB eval command.
+    </para>
+<programlisting><![CDATA[
+(gdb) mo v.clo --vgdb-error=10
+==2808839== Handling new value --vgdb-error=10 for option --vgdb-error
+(gdb) v v.clo --vgdb-error=11
+==2808839== Handling new value --vgdb-error=11 for option --vgdb-error
+(gdb) set var $nnn = 15
+(gdb) eval "v v.clo --vgdb-error=%d", $nnn + 1
+==2808839== Handling new value --vgdb-error=16 for option --vgdb-error
+(gdb)
+]]></programlisting>
   </listitem>
 
   <listitem>
@@ -1417,7 +1590,10 @@ client request.
     "no-op" command to a Valgrind gdbserver so as to continue the
     execution of the guest process.
     </para>
-  </listitem>
+    <para>The GDB valgrind front end command <varname>valgrind v.wait
+      MS</varname> accepts any integer expression for its MS argument, while the
+      monitor command accepts only integer numbers.
+    </para>  </listitem>
 
   <listitem>
     <para><varname>v.kill</varname> requests the gdbserver to kill
@@ -1428,12 +1604,29 @@ client request.
 
   <listitem>
     <para><varname>v.set vgdb-error &lt;errornr&gt;</varname>
+      dynamically changes the value of the 
+      <option>--vgdb-error</option> valgrind command line argument. A
+      typical usage of this is to start with
+      <option>--vgdb-error=0</option> on the
+      command line, then set a few breakpoints, set the vgdb-error value
+      to a huge value and continue execution. Note that you can also change
+      this value using e.g. <varname>v.clo --vgdb-error=12</varname></para>
+    <para>The GDB valgrind front end command <varname>valgrind v.set vgdb-error
+      NUM</varname> accepts any integer expression for its ERRORNR argument, while
+      the monitor command accepts only integer numbers.
+    </para>
+  </listitem>
+
+  <listitem>
+    <para><varname>v.set merge-recursive-frames &lt;num&gt;</varname>
     dynamically changes the value of the 
-    <option>--vgdb-error</option> argument. A
-    typical usage of this is to start with
-    <option>--vgdb-error=0</option> on the
-    command line, then set a few breakpoints, set the vgdb-error value
-    to a huge value and continue execution.</para>
+      <option>--merge-recursive-frames</option> valgrind command line argument.
+     Note that you can also change
+    this value using e.g. <varname>v.clo --merge-recursive-frames=5</varname></para>
+    <para>The GDB valgrind front end command <varname>valgrind v.set merge-recursive-frames
+      NUM</varname> accepts any integer expression for its NUM argument, while
+      the monitor command accepts only integer numbers.
+    </para>
   </listitem>
 
   <listitem>
@@ -1537,6 +1730,11 @@ problems or bugs.</para>
     The default value of &lt;len&gt; is 1, giving the unwind information
     for the instruction at &lt;addr&gt;.
     </para>
+    <para>The GDB valgrind front end command <varname>valgrind v.info unwind
+      ADDR [LEN]</varname> accepts any address expression for its first ADDR
+      argument, such as $pc. The second optional argument is any integer
+      expression. Note that these 2 arguments must be separated by a space.
+    </para>
   </listitem>
 
   <listitem>
@@ -1544,6 +1742,9 @@ problems or bugs.</para>
     Valgrind debug log level to &lt;intvalue&gt;.  This allows to
     dynamically change the log level of Valgrind e.g. when a problem
     is detected.</para>
+    <para>The GDB valgrind front end command <varname>valgrind v.set debuglog
+      LEVEL</varname> accepts any address expression for its LEVEL argument.
+    </para>
   </listitem>
 
   <listitem>
@@ -1556,11 +1757,14 @@ problems or bugs.</para>
 
 <screen><![CDATA[
 (gdb) monitor v.set hostvisibility yes
-(gdb) add-symbol-file /path/to/tool/executable/file/memcheck-x86-linux 0x58000000
-add symbol table from file "/path/to/tool/executable/file/memcheck-x86-linux" at
-       .text_addr = 0x58000000
+Enabled access to Valgrind memory/status by GDB
+If not yet done, tell GDB which valgrind file(s) to use, typically:
+add-symbol-file /home/philippe/valgrind/git/improve/Inst/libexec/valgrind/memcheck-amd64-linux 0x58001000
+(gdb) add-symbol-file /home/philippe/valgrind/git/improve/Inst/libexec/valgrind/memcheck-amd64-linux 0x58001000
+add symbol table from file "/home/philippe/valgrind/git/improve/Inst/libexec/valgrind/memcheck-amd64-linux" at
+       .text_addr = 0x58001000
 (y or n) y
-Reading symbols from /path/to/tool/executable/file/memcheck-x86-linux...done.
+Reading symbols from /home/philippe/valgrind/git/improve/Inst/libexec/valgrind/memcheck-amd64-linux...
 (gdb) 
 ]]></screen>
 
@@ -1600,6 +1804,11 @@ $5 = {iropt_verbosity = 0, iropt_level = 2,
     active for some other reason, for example because there is a breakpoint at
     this address or because gdbserver is in single stepping
     mode.</para>
+    <para>The GDB valgrind front end command <varname>valgrind v.translate ADDR
+      [TRACEFLAG]</varname> accepts any address expression for its first ADDR
+      argument, such as $pc. The second optional argument is any integer
+      expression. Note that these 2 arguments must be separated by a space.
+    </para>
   </listitem>
 
 </itemizedlist>
index 04a56fdef1919b4e61229f2e5ddc38106e8cd8c5..82a7d4c3844c2820f9a884a43798628157a7a790 100755 (executable)
@@ -15,6 +15,10 @@ cat > $PATTERNFILE <<EOF
 #       general way to delete uninteresting and varying lines.
 /filter_gdb BEGIN drop/,/filter_gdb END drop/d
 
+#       delete the messages produced by valgrind python code.
+/Loaded.*valgrind-monitor.py$/d
+/Type "help valgrind" for more info\.$/d
+
 #       initial tty control character sent by gdb 7.0
 s/^\e\[?1034hReading symbols/Reading symbols/
 
index 7082e91f7a9bf97c649abc588bbf1830456c3f19..6ec8caa3f4bd2bcb19f60a9567f00c5be9e9cc0f 100644 (file)
@@ -1385,9 +1385,19 @@ Helgrind:</para>
 
 <sect1 id="hg-manual.monitor-commands" xreflabel="Helgrind Monitor Commands">
 <title>Helgrind Monitor Commands</title>
-<para>The Helgrind tool provides monitor commands handled by Valgrind's
-built-in gdbserver (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>).
-</para>
+<para>The Helgrind tool provides monitor commands handled by Valgrind's built-in
+  gdbserver (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>).
+  Valgrind python code provides GDB front end commands giving an easier usage of
+  the helgrind monitor commands (see
+  <xref linkend="manual-core-adv.gdbserver-gdbmonitorfrontend"/>).  To launch an
+  helgrind monitor command via its GDB front end command, instead of prefixing
+  the command with "monitor", you must use the GDB <varname>helgrind</varname>
+  command (or the shorter aliases <varname>hg</varname>).  Using the helgrind
+  GDB front end command provide a more flexible usage, such as evaluation of
+  address and length arguments by GDB.  In GDB, you can use <varname>help
+  helgrind</varname> to get help about the helgrind front end monitor commands
+  and you can use <varname>apropos helgrind</varname> to get all the commands
+  mentionning the word "helgrind" in their name or on-line help. </para>
 <itemizedlist>
   <listitem>
     <para><varname>info locks [lock_addr]</varname> shows the list of locks
@@ -1431,6 +1441,11 @@ Lock ga 0x8049a20 {
 }
 ]]></programlisting>
 
+    <para>The GDB equivalent helgrind front end command <varname>helgrind info locks
+      [ADDR]</varname> accept any address expression for its first ADDR
+      argument.
+    </para>
+
   </listitem>
 
   <listitem>
@@ -1467,6 +1482,22 @@ write of size 4 at 0x8049D88 by thread #9 tid 2
 ==6319==    by 0x39B924: start_thread (pthread_create.c:297)
 ==6319==    by 0x2F107D: clone (clone.S:130)
 
+]]></programlisting>
+    <para>The GDB equivalent helgrind front end command <varname>helgrind
+      accesshistory ADDR [LEN]</varname> accept any address expression for its
+      first ADDR argument. The second optional argument is any integer
+      expression. Note that these 2 arguments must be separated by a space,
+      like in the following example:
+    </para>
+<programlisting><![CDATA[
+(gdb) hg accesshistory &mx sizeof(mx)
+read of size 4 at 0x1130A8 by thread #2 tid (exited)
+==302== Locks held: none
+==302==    at 0x1094AC: child8 (tc19_shadowmem.c:37)
+==302==    by 0x10A0DF: steer (tc19_shadowmem.c:288)
+==302==    by 0x48448A3: mythread_wrapper (hg_intercepts.c:406)
+==302==    by 0x4879EA6: start_thread (pthread_create.c:477)
+==302==    by 0x4990A2E: clone (clone.S:95)
 ]]></programlisting>
 
   </listitem>
index 2a49781a341cc2454965ddc51fd83c03351a45e0..b589071556f61ede391d7fcc4bbd753c33f27cf0 100644 (file)
@@ -880,6 +880,17 @@ various places online.
 <title>Massif Monitor Commands</title>
 <para>The Massif tool provides monitor commands handled by the Valgrind
 gdbserver (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>).
+Valgrind python code provides GDB front end commands giving an easier usage of
+the massif monitor commands (see
+<xref linkend="manual-core-adv.gdbserver-gdbmonitorfrontend"/>).  To launch a
+massif monitor command via its GDB front end command, instead of prefixing
+the command with "monitor", you must use the GDB <varname>massif</varname>
+command (or the shorter aliases <varname>ms</varname>).  Using the massif GDB
+front end command provide a more flexible usage, such as auto-completion of the
+command by GDB. In GDB, you can use <varname>help massif</varname> to get
+help about the massif front end monitor commands and you can
+use <varname>apropos massif</varname> to get all the commands mentionning the
+word "massif" in their name or on-line help.
 </para>
 
 <itemizedlist>
index 2eb5b12f92bb943438cdf13af8d36c5710c8eba8..e8f48d112d9767e086bb4b84d7ce0da642805668 100644 (file)
@@ -1792,8 +1792,19 @@ is:</para>
 
 <sect1 id="mc-manual.monitor-commands" xreflabel="Memcheck Monitor Commands">
 <title>Memcheck Monitor Commands</title>
-<para>The Memcheck tool provides monitor commands handled by Valgrind's
-built-in gdbserver (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>).
+<para>The Memcheck tool provides monitor commands handled by Valgrind's built-in
+  gdbserver (see <xref linkend="manual-core-adv.gdbserver-commandhandling"/>).
+  Valgrind python code provides GDB front end commands giving an easier usage of
+  the memcheck monitor commands (see
+  <xref linkend="manual-core-adv.gdbserver-gdbmonitorfrontend"/>).  To launch a
+  memcheck monitor command via its GDB front end command, instead of prefixing
+  the command with "monitor", you must use the GDB <varname>memcheck</varname>
+  command (or the shorter aliases <varname>mc</varname>).  Using the memcheck
+  GDB front end command provide a more flexible usage, such as evaluation of
+  address and length arguments by GDB. In GDB, you can use <varname>help
+  memcheck</varname> to get help about the memcheck front end monitor commands
+  and you can use <varname>apropos memcheck</varname> to get all the commands
+  mentionning the word "memcheck" in their name or on-line help.
 </para>
 
 <itemizedlist>
@@ -1834,6 +1845,23 @@ $4 = (char (*)[10]) 0x804a2f0
 0x804A2F8:      0x3f    0x00
 Address 0x804A2F0 len 10 has 1 bytes unaddressable
 (gdb)
+]]></programlisting>
+
+    <para>The GDB memcheck front end command <varname>memcheck xb ADDR
+      [LEN]</varname> accepts any address expression for its first ADDR
+      argument. The second optional argument is any integer expression. Note
+      that these 2 arguments must be separated by a space.
+      The following example shows how to get the definedness of
+      <varname>string10</varname> using the memcheck xb front end command.
+    </para>
+<programlisting><![CDATA[
+(gdb) mc xb &string10 sizeof(string10)
+                  ff      00      ff      00      ff      __      ff      00
+0x804A2F0:      0x3f    0x6e    0x3f    0x65    0x3f    0x??     0x3f    0x65
+                  ff      00
+0x804A2F8:      0x3f    0x00
+Address 0x804A2F0 len 10 has 1 bytes unaddressable
+(gdb)
 ]]></programlisting>
 
     <para> The command xb cannot be used with registers. To get
@@ -1866,15 +1894,19 @@ $10 = 0x0
     with their V bits values.
     </para>
     <para>
-    The following example shows the result of <varname>get_vibts</varname>
-    on the <varname>string10</varname> used in the  <varname>xb</varname>
-    command explanation.
+    The following example shows the result of <varname>get_vbits</varname> on
+    the <varname>string10</varname> used in the <varname>xb</varname> command
+    explanation. The GDB memcheck equivalent front end command <varname>memcheck
+    get_vbits ADDR [LEN]</varname>accepts any ADDR expression and any LEN
+    expression (separated by a space).
     </para>
 <programlisting><![CDATA[
 (gdb) monitor get_vbits 0x804a2f0 10
 ff00ff00 ff__ff00 ff00
 Address 0x804A2F0 len 10 has 1 bytes unaddressable
-(gdb) 
+(gdb) memcheck get_vbits &string10 sizeof(string10)
+ff00ff00 ff__ff00 ff00
+Address 0x804A2F0 len 10 has 1 bytes unaddressable
 ]]></programlisting>
 
   </listitem>
@@ -1895,15 +1927,27 @@ Address 0x804A2F0 len 10 has 1 bytes unaddressable
     that the first letter of <varname>Definedifaddressable</varname>
     is an uppercase D to avoid confusion with <varname>defined</varname>.
     </para>
+    
+    <para>The GDB equivalent memcheck front end commands <varname>memcheck
+      make_memory [noaccess|undefined|defined|Definedifaddressable] ADDR
+      [LEN]</varname> accept any address expression for their first ADDR
+      argument. The second optional argument is any integer expression. Note
+      that these 2 arguments must be separated by a space.
+    </para>
 
     <para>
     In the following example, the first byte of the
-    <varname>string10</varname> is marked as defined:
+    <varname>string10</varname> is marked as defined and then is marked
+    noaccess:
     </para>
 <programlisting><![CDATA[
 (gdb) monitor make_memory defined 0x8049e28  1
 (gdb) monitor get_vbits 0x8049e28 10
 0000ff00 ff00ff00 ff00
+(gdb) memcheck make_memory noaccess &string10[0]
+(gdb) memcheck get_vbits &string10 sizeof(string10)
+__00ff00 ff00ff00 ff00
+Address 0x8049E28 len 10 has 1 bytes unaddressable
 (gdb) 
 ]]></programlisting>
   </listitem>
@@ -1924,6 +1968,13 @@ Address 0x8049E28 len 1 defined
 ==14698==  declared at prog.c:10, in frame #0 of thread 1
 (gdb) 
 ]]></programlisting>
+    <para>The GDB equivalent memcheck front end commands <varname>memcheck
+      check_memory [addressable|defined] ADDR [LEN]</varname> accept any address
+      expression for their first ADDR argument. The second optional argument is
+      any integer expression. Note that these 2 arguments must be separated by a
+      space.
+    </para>
+
   </listitem>
 
   <listitem>
@@ -2044,6 +2095,15 @@ Address 0x8049E28 len 1 defined
     reachable any</computeroutput> (or, using
     abbreviation: <computeroutput>mo l f r a</computeroutput>).
     </para>
+    
+    <para>The GDB equivalent memcheck front end command <varname>memcheck
+        leak_check</varname> auto-completes the user input by providing the full
+      list of keywords still relevant according to what is already typed. For
+      example, if the "summary" keyword has been provided, the following TABs to
+      auto-complete other items will not propose anymore "full" and "xtleak".
+      Note that KIND and HEUR values are not part of auto-completed elements.
+    </para>
+
   </listitem>
 
   <listitem>
@@ -2165,6 +2225,12 @@ Address 0x8049E28 len 1 defined
     are being searched for) will be described.
     </para>
 
+    <para>The GDB equivalent memcheck front end command <varname>memcheck
+      who_points_at ADDR [LEN]</varname> accept any address expression for its
+      first ADDR argument. The second optional argument is any integer
+      expression. Note that these 2 arguments must be separated by a space.
+    </para>
+
     <para>In the below example, the pointers to the 'tree block A' (see example
     in command <varname>block_list</varname>) is shown before the tree was leaked.
     The descriptions are detailed as the option <option>--read-var-info=yes</option>