1 # This file is part of Valgrind, a dynamic binary instrumentation
4 # Copyright (C) 2022-2022 Philippe Waroquiers
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http://www.gnu.org/licenses/>.
19 # The GNU General Public License is contained in the file COPYING.
22 This file defines a series of gdb commands and subcommands to help interfacing
23 gdb with the Valgrind gdbserver.
25 !!! This only works with GDB version >= 9.1, as some command names contains
26 a dot character only allowed from this version onwards.
28 Type "help valgrind" to get help about the top of the command hierarchy.
31 from typing
import Callable
35 class _Debug_Valgrind_Execute_Monitor(gdb
.Parameter
):
36 """Set valgrind monitor command execution debugging.
37 Usage: set debug valgrind-execute-monitor [on|off]"""
39 super().__init
__("debug valgrind-execute-monitor",
40 gdb
.COMMAND_MAINTENANCE
,
43 Debug_Valgrind_Execute_Monitor
= _Debug_Valgrind_Execute_Monitor()
45 def gdb_execute_monitor(monitor_command
: str, from_tty
: bool) -> None:
46 """Execute the given monitor command."""
47 cmd
= "monitor " + monitor_command
48 if Debug_Valgrind_Execute_Monitor
.value
:
49 print('[valgrind-execute-monitor] sending "' + cmd
+ '" to valgrind')
51 gdb
.execute (cmd
, from_tty
)
52 except Exception as inst
:
53 if monitor_command
== "v.kill" and str(inst
).find('Remote connection closed') >= 0:
54 print('Remote connection closed')
56 print('Error sending "' + monitor_command
+ '" to valgrind: '+ str(inst
))
58 class Valgrind_Command(gdb
.Command
):
59 """Parent class for all Valgrind commands."""
60 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
61 """Generic Valgrind Command invoke method to override if needed."""
62 # print("generic invoke", self.mname)
64 gdb_execute_monitor (self
.mname
+ " " + arg_str
, from_tty
)
66 gdb_execute_monitor (self
.mname
, from_tty
)
68 def Vinit(toolname
: str,
71 completer_class
: Enum
,
72 prefix
: bool) -> Callable
[[Valgrind_Command
],
74 """Class decorator to initialise and register a Valgrind_Command class.
75 MNAME is the Valgrind monitor name string for this command.
76 The gdb command is the concatenation of TOOLNAME and MNAME.
77 TOOLNAME is valgrind for the general valgrind commands."""
78 def instantiate(GDB_Command
: Valgrind_Command
) -> Valgrind_Command
:
79 def adhoc_init (self
):
80 # print("initializing", GDB_Command)
82 super(GDB_Command
, self
).__init
__(name
= toolname
+ " " + mname
,
83 command_class
= command_class
,
84 completer_class
= completer_class
,
87 super(GDB_Command
, self
).__init
__(name
= toolname
+ " " + mname
,
88 command_class
= command_class
,
90 self
.toolname
=toolname
92 GDB_Command
.__init
__ = adhoc_init
93 GDB_Command() # register the command
97 def build_name(command
: Valgrind_Command
) -> str:
98 """Returns the GDB full name for the given COMMAND."""
100 return command
.toolname
+ ' ' + command
.mname
102 return command
.toolname
104 def build_help(command
: Valgrind_Command
) -> str:
105 """Returns a string to ask help for the given COMMAND."""
106 return "help " + build_name(command
)
108 def build_type_help(command
: Valgrind_Command
) -> str:
109 """Returns a string giving what to type to get helps about the given command"""
110 return 'Type "' + build_help(command
) + '"'
112 class Valgrind_Prefix_Command(Valgrind_Command
):
113 """Parent class for all Valgrind prefix commands."""
114 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
115 """Generic Valgrind prefix Command invoke method to override if needed."""
116 # print("generic prefix invoke", self.mname)
118 # If it is not a recognised sub-command, raise an error.
119 raise gdb
.GdbError(('Undefined ' + build_name (self
)
120 + ' command: "' + arg_str
+ '".\n'
121 + build_type_help(self
)))
123 gdb
.execute (build_help(self
), from_tty
)
125 class Valgrind_Prefix_Exec_Command(Valgrind_Prefix_Command
):
126 """Parent class for all Valgrind prefix commands that can be executed without subcommands."""
127 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
128 """Invoke for a prefix command that can be executed."""
130 super().invoke(arg_str
, from_tty
)
132 gdb_execute_monitor (self
.mname
, from_tty
)
134 def eval_execute(command
: Valgrind_Command
,
136 arg_opt
: bool, arg_descr
: str, format_fn
,
137 from_tty
: bool) -> None:
138 """Evaluates ARG_STR, format the result with FORMAT_FN and
139 executes the monitor command COMMAND.mname + FORMAT_FN(evaluated ARG_STR).
140 ARG_OPT True indicates the argument is optional.
141 ARG_DESCR is used in error messages."""
143 eval_arg_str
= gdb
.parse_and_eval (arg_str
)
144 gdb_execute_monitor (command
.mname
+ " " + format_fn(eval_arg_str
), from_tty
)
146 gdb_execute_monitor (command
.mname
, from_tty
)
148 raise gdb
.GdbError(('Argument "' + arg_descr
+ '" required.\n'
149 + build_type_help(command
)))
151 def eval_execute_2(command
: Valgrind_Command
,
153 arg1_opt
: bool, arg1_descr
: str, format_fn1
,
154 arg2_opt
: bool, arg2_descr
: str, format_fn2
,
155 from_tty
: bool) -> None:
156 """Like eval_execute but allowing 2 arguments to be extracted from ARG_STR).
157 The second argument starts after the first space in ARG_STR."""
158 if arg1_opt
and not arg2_opt
:
159 raise gdb
.GdbError(('Cannot have arg1_opt True and arg2_opt False'
160 + ' in definition of '
161 + build_name(command
)))
163 arg_str_v
= arg_str
.split(' ', 1);
164 eval_arg1_str
= gdb
.parse_and_eval (arg_str_v
[0])
165 if len(arg_str_v
) <= 1:
167 gdb_execute_monitor (command
.mname
+ " " + format_fn1(eval_arg1_str
), from_tty
)
169 raise gdb
.GdbError(('Argument 2 "' + arg2_descr
+ '" required.\n'
170 + build_type_help(command
)))
172 eval_arg2_str
= gdb
.parse_and_eval (arg_str_v
[1])
173 gdb_execute_monitor (command
.mname
174 + " " + format_fn1(eval_arg1_str
)
175 + " " + format_fn1(eval_arg2_str
),
177 elif arg1_opt
and arg2_opt
:
178 gdb_execute_monitor (command
.mname
, from_tty
)
180 raise gdb
.GdbError(('Argument 1 "' + arg1_descr
+ '" required.\n'
182 else 'Argument 2 "' + arg2_descr
+ '" required.\n')
183 + build_type_help(command
)))
185 def def_alias(alias
: str, command_name
: str) -> None:
186 """Defines an alias ALIAS = COMMAND_NAME.
187 Traps the error if ALIAS is already defined (so as to be able to source
189 d
= "alias " + alias
+ ' = ' + command_name
192 except Exception as inst
:
193 print('"' + d
+ '" : '+ str(inst
))
195 class Valgrind_ADDR(Valgrind_Command
):
196 """Common class for Valgrind commands taking ADDR arg."""
197 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
198 eval_execute(self
, arg_str
,
199 False, "ADDR (address expression)", hex,
202 class Valgrind_ADDR_opt(Valgrind_Command
):
203 """Common class for Valgrind commands taking [ADDR] arg."""
204 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
205 eval_execute(self
, arg_str
,
206 True, "ADDR (address expression)", hex,
209 class Valgrind_ADDR_LEN_opt(Valgrind_Command
):
210 """Common class for Valgrind commands taking ADDR and [LEN] args.
211 For compatibility reason with the Valgrind gdbserver monitor command,
212 we detect and accept usages such as 0x1234ABCD[10]."""
213 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
214 if re
.fullmatch(r
"^0x[0123456789ABCDEFabcdef]+\[[^\[\]]+\]$", arg_str
):
215 arg_str
= arg_str
.replace("[", " ")
216 arg_str
= arg_str
.replace("]", " ")
217 eval_execute_2(self
, arg_str
,
218 False, "ADDR (address expression)", hex,
219 True, "LEN (integer length expression)", str,
222 ############# The rest of this file defines first the valgrind general commands
223 # then the tool specific commands.
224 # The commands are defined in the same order as produced by
225 # (gdb) monitor help debug
227 ############# valgrind general commands.
229 ###### Top of the hierarchy of the valgrind general commands.
230 @Vinit("valgrind", "", gdb
.COMMAND_SUPPORT
, gdb
.COMPLETE_COMMAND
, True)
231 class Valgrind_Monitor_Command(Valgrind_Prefix_Command
):
232 """Front end GDB command for Valgrind gdbserver monitor commands.
233 Usage: valgrind VALGRIND_MONITOR_COMMAND [ARG...]
234 VALGRIND_MONITOR_COMMAND is a valgrind subcommand, matching a
235 gdbserver Valgrind monitor command.
236 ARG... are optional arguments. They depend on the VALGRIND_MONITOR_COMMAND.)
238 Type "help memcheck" or "help mc" for memcheck specific commands.
239 Type "help helgrind" or "help hg" for helgrind specific commands.
240 Type "help callgrind" or "help cg" for callgrind specific commands.
241 Type "help massif" or "help ms" for massif specific commands.
244 def_alias("vg", "valgrind")
245 def_alias("v", "valgrind") # To avoid 'v' reported as ambiguous for 'vg' and 'valgrind' !
247 @Vinit("valgrind", "help", gdb
.COMMAND_SUPPORT
, gdb
.COMPLETE_COMMAND
, True)
248 class Valgrind_Help_Command(Valgrind_Prefix_Exec_Command
):
249 """Ask Valgrind gdbserver to output the help for its monitor commands.
251 This shows the help string reported by the Valgrind gdbserver.
252 Type "help valgrind" to get help about the GDB front end commands interfacing
253 to the Valgrind gdbserver monitor commands.
255 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
256 """Invoke for a prefix command that can be executed."""
258 super().invoke(arg_str
, from_tty
)
260 gdb_execute_monitor (self
.mname
, from_tty
)
262 @Vinit("valgrind", "help debug", gdb
.COMMAND_SUPPORT
, gdb
.COMPLETE_NONE
, False)
263 class Valgrind_Help_Debug_Command(Valgrind_Command
):
264 """Ask Valgrind gdbserver to output the help for its monitor commands (including debugging commands).
265 Usage: valgrind help debug
266 This shows the help string reported by the Valgrind gdbserver.
267 Type "help valgrind" to get help about the GDB front end commands interfacing
268 to the Valgrind gdbserver monitor commands.
271 @Vinit("valgrind", "v.wait", gdb
.COMMAND_OBSCURE
, gdb
.COMPLETE_EXPRESSION
, False)
272 class Valgrind_Wait_Command(Valgrind_Command
):
273 """Have Valgrind gdbserver sleeping for MS (default 0) milliseconds.
274 Usage: valgrind v.wait [MS]
275 MS is an integer expression evaluated by GDB.
277 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
278 eval_execute(self
, arg_str
,
279 True, "MS (integer expression in milliseconds)", str,
282 @Vinit("valgrind", "v.info", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_COMMAND
, True)
283 class Valgrind_Info_Command(Valgrind_Prefix_Command
):
284 """Get various information about Valgrind gdbserver.
285 Usage: valgrind v.info WHAT [ARG...]
286 WHAT is the v.info subcommand, specifying the type of information requested.
287 ARG are optional arguments, depending on the WHAT subcommand.
290 @Vinit("valgrind", "v.info all_errors", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, True)
291 class Valgrind_Info_All_Errors_Command(Valgrind_Command
):
292 """Show all errors found so far by Valgrind.
293 Usage: valgrind v.info all_errors
296 @Vinit("valgrind", "v.info all_errors also_suppressed", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, False)
297 class Valgrind_Info_All_Errors_Also_Suppressed_Command(Valgrind_Command
):
298 """Show all errors found so far by Valgrind, including the suppressed errors.
299 Usage: valgrind v.info all_errors also_suppressed
302 @Vinit("valgrind", "v.info last_error", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, False)
303 class Valgrind_Info_Last_Error_Command(Valgrind_Command
):
304 """Show last error found by Valgrind.
305 Usage: valgrind v.info last_error
308 @Vinit("valgrind", "v.info location", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
309 class Valgrind_Info_Location_Command(Valgrind_ADDR
):
310 """Show information known by Valgrind about location ADDR.
311 Usage: valgrind v.info location ADDR
312 ADDR is an address expression evaluated by GDB.
315 @Vinit("valgrind", "v.info n_errs_found", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, False)
316 class Valgrind_Info_N_Errs_Found_Command(Valgrind_Command
):
317 """Show the nr of errors found so far by Valgrind and the given MSG.
318 Usage: valgrind v.info n_errs_found [MSG]
319 The optional MSG is made of all what follows n_errs_found and is not evaluated.
322 @Vinit("valgrind", "v.info open_fds", gdb
.COMMAND_DATA
, gdb
.COMPLETE_NONE
, False)
323 class Valgrind_Info_Open_Fds_Command(Valgrind_Command
):
324 """Show open file descriptors tracked by Valgrind (only if --track-fds=yes).
325 Usage: valgrind v.info open_fds
328 @Vinit("valgrind", "v.kill", gdb
.COMMAND_RUNNING
, gdb
.COMPLETE_NONE
, False)
329 class Valgrind_Kill_Command(Valgrind_Command
):
330 """Instruct valgrind gdbserver to kill the valgrind process.
331 Usage: valgrind v.kill
334 @Vinit("valgrind", "v.clo", gdb
.COMMAND_RUNNING
, gdb
.COMPLETE_NONE
, False)
335 class Valgrind_Clo_Command(Valgrind_Command
):
336 """Change one or more Valgrind dynamic command line options.
337 Usage: valgrind v.clo [VALGRIND_OPTION]...
338 VALGRIND_OPTION is the command line option to change.
339 Example: (gdb) valgrind v.clo --stats=yes --show-below-main=yes
341 Without VALGRIND_OPTION, shows the dynamically changeable options.
344 @Vinit("valgrind", "v.set", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_COMMAND
, True)
345 class Valgrind_Set_Command(Valgrind_Prefix_Command
):
346 """Modify various setting of Valgrind gdbserver.
347 Usage: valgrind v.set WHAT [ARG]...
348 WHAT is the v.set subcommand, specifying the setting to change.
349 ARG are optional arguments, depending on the WHAT subcommand.
352 @Vinit("valgrind", "v.set gdb_output", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, False)
353 class Valgrind_Set_Gdb_Output_Command(Valgrind_Command
):
354 """Set Valgrind output to gdb.
355 Usage: valgrind v.set gdb_output
358 @Vinit("valgrind", "v.set log_output", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, False)
359 class Valgrind_Set_Log_Output_Command(Valgrind_Command
):
360 """Set Valgrind output to Valgrind log.
361 Usage: valgrind v.set log_output
364 @Vinit("valgrind", "v.set mixed_output", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, False)
365 class Valgrind_Set_Mixed_Output_Command(Valgrind_Command
):
366 """Set Valgrind output to Valgrind log, interactive output to gdb.
367 Usage: valgrind v.set mixed_output
370 @Vinit("valgrind", "v.set merge-recursive-frames", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_EXPRESSION
, False)
371 class Valgrind_Set_Merge_Recursive_Frames_Command(Valgrind_Command
):
372 """Set the number of frames for recursive calls merging in Valgrind stacktraces.
373 Usage: valgrind v.set merge-recursive-frames NUM
374 NUM is an integer expression evaluated by GDB.
376 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
377 eval_execute(self
, arg_str
,
378 False, "NUM (number of frames for recursive calls merging)",
382 @Vinit("valgrind", "v.set vgdb-error", gdb
.COMMAND_RUNNING
, gdb
.COMPLETE_EXPRESSION
, False)
383 class Valgrind_Set_Vgdb_Error_Command(Valgrind_Command
):
384 """Set the number of errors at which Valgrind gdbserver gives control to gdb.
385 Usage: valgrind v.set vgdb-error NUM
386 NUM is an integer expression evaluated by GDB.
388 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
389 eval_execute(self
, arg_str
,
390 False, "NUM (number of errors)",
394 @Vinit("valgrind", "v.do", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_COMMAND
, True)
395 class Valgrind_Do_Command(Valgrind_Prefix_Command
):
396 """Ask Valgrind gdbserver to do an internal/maintenance action.
397 Usage: valgrind v.do WHAT
398 WHAT is the valgrind v.do subcommand, specifying the type of action requested.
401 @Vinit("valgrind", "v.do expensive_sanity_check_general", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
402 class Valgrind_Do_Expensive_Sanity_Check_General_Command(Valgrind_Command
):
403 """Do an expensive Valgrind sanity check now.
404 Usage: valgrind v.do expensive_sanity_check_general
407 @Vinit("valgrind", "v.info gdbserver_status", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
408 class Valgrind_Info_Gdbserver_Status_Command(Valgrind_Command
):
409 """Show gdbserver status.
410 Usage: valgrind v.info gdbserver_status
413 @Vinit("valgrind", "v.info memory", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_COMMAND
, True)
414 class Valgrind_Info_Memory_Status_Command(Valgrind_Prefix_Exec_Command
):
415 """Show valgrind heap memory stats.
416 Usage: valgrind v.info memory
419 @Vinit("valgrind", "v.info memory aspacemgr", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
420 class Valgrind_Info_Memory_Aspacemgr_Command(Valgrind_Command
):
421 """Show Valgrind heap memory stats and show Valgrind segments on log output.
422 Usage: valgrind v.info memory aspacemgr
425 @Vinit("valgrind", "v.info exectxt", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
426 class Valgrind_Info_Exectxt_Command(Valgrind_Command
):
427 """Show stacktraces and stats of all execontexts record by Valgrind.
428 Usage: valgrind v.info exectxt
431 @Vinit("valgrind", "v.info scheduler", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
432 class Valgrind_Info_Scheduler_Command(Valgrind_Command
):
433 """Show Valgrind thread state and stacktrace.
434 Usage: valgrind v.info scheduler
437 @Vinit("valgrind", "v.info stats", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
438 class Valgrind_Info_Stats_Command(Valgrind_Command
):
439 """Show various Valgrind and tool stats.
440 Usage: valgrind v.info stats
443 @Vinit("valgrind", "v.info unwind", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_EXPRESSION
, False)
444 class Valgrind_Info_Unwind_Command(Valgrind_ADDR_LEN_opt
):
445 """Show unwind debug info for ADDR .. ADDR+LEN.
446 Usage: valgrind v.info unwind ADDR [LEN]
447 ADDR is an address expression evaluated by GDB.
448 LEN is an integer expression evaluated by GDB.
451 @Vinit("valgrind", "v.set debuglog", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_EXPRESSION
, False)
452 class Valgrind_Set_Debuglog_Command(Valgrind_Command
):
453 """Set Valgrind debug log level to LEVEL.
454 Usage: valgrind v.set LEVEL
455 LEVEL is an integer expression evaluated by GDB.
457 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
458 eval_execute(self
, arg_str
,
459 False, "LEVEL (valgrind debug log level)",
462 @Vinit("valgrind", "v.set hostvisibility", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_COMMAND
, True)
463 class Valgrind_Set_Hostvisibility_Command(Valgrind_Prefix_Exec_Command
):
464 """Set visibility of the internal Valgrind 'host' state.
465 Without arguments, enables the host visibility.
466 Host visibility allows to examine with GDB the internal status and memory
468 Usage: valgrind v.set hostvisibility
471 @Vinit("valgrind", "v.set hostvisibility yes", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
472 class Valgrind_Set_Hostvisibility_Yes_Command(Valgrind_Command
):
473 """Enable visibility of the internal Valgrind 'host' state.
474 Usage: valgrind v.set hostvisibility yes
475 See "help v.set hostvisibility".
478 @Vinit("valgrind", "v.set hostvisibility no", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_NONE
, False)
479 class Valgrind_Set_Hostvisibility_No_Command(Valgrind_Command
):
480 """Disable visibility of the internal Valgrind 'host' state.
481 Usage: valgrind v.set hostvisibility no
482 See "help v.set hostvisibility".
485 def base2(value
: int) -> str:
486 """Image of value in base 2 prefixed with 0b."""
487 "0b" + "{0:b}".format(value
)
489 @Vinit("valgrind", "v.translate", gdb
.COMMAND_MAINTENANCE
, gdb
.COMPLETE_EXPRESSION
, False)
490 class Valgrind_Translate_Command(Valgrind_Command
):
491 """Show the translation of instructions at ADDR with TRACEFLAGS.
492 Usage: valgrind v.translate ADDR [TRACEFLAG]
493 For TRACEFLAG values, type in shell "valgrind --help-debug".
494 An additional flag 0b100000000 allows one to show gdbserver instrumentation.
495 ADDR is an address expression evaluated by GDB.
496 TRACEFLAG is an integer expression (used as a bitmask) evaluated by GDB.
498 def invoke(self
, arg_str
: str, from_tty
: bool) -> None:
499 eval_execute_2(self
, arg_str
,
500 False, "ADDR (address expression)", hex,
501 True, "TRACEFLAGS (bit mask expression)", base2
,
504 ############# memcheck commands.
506 ###### Top of the hierarchy of the memcheck commands.
507 @Vinit("memcheck", "", gdb
.COMMAND_SUPPORT
, gdb
.COMPLETE_COMMAND
, True)
508 class Memcheck_Command(Valgrind_Prefix_Command
):
509 """Front end GDB command for Valgrind memcheck gdbserver monitor commands.
510 Usage: memcheck MEMCHECK_MONITOR_COMMAND [ARG...]
511 MEMCHECK_MONITOR_COMMAND is a memcheck subcommand, matching
512 a gdbserver Valgrind memcheck monitor command.
513 ARG... are optional arguments. They depend on the MEMCHECK_MONITOR_COMMAND.
516 def_alias("mc", "memcheck")
518 @Vinit("memcheck", "xtmemory", gdb
.COMMAND_DATA
, gdb
.COMPLETE_FILENAME
, False)
519 class Memcheck_Xtmemory_Command(Valgrind_Command
):
520 """Dump xtree memory profile in FILENAME (default xtmemory.kcg.%p.%n).
521 Usage: memcheck xtmemory [FILENAME]
523 Example: (gdb) memcheck xtmemory my_program_xtree.kcg
526 @Vinit("memcheck", "xb", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
527 class Memcheck_Xb_Command(Valgrind_ADDR_LEN_opt
):
528 """Print validity bits for LEN (default 1) bytes at ADDR.
529 bit values 0 = valid, 1 = invalid, __ = unaddressable byte
530 Prints the bytes values below the corresponding validity bits
531 in a layout similar to the gdb command 'x /LENxb ADDR
532 Usage: memcheck xb ADDR [LEN]
533 ADDR is an address expression evaluated by GDB.
534 LEN is an integer expression evaluated by GDB.
536 Example: (gdb) memcheck xb &p sizeof(p)
539 @Vinit("memcheck", "get_vbits", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
540 class Memcheck_Get_Vbits_Command(Valgrind_ADDR_LEN_opt
):
541 """Print validity bits for LEN (default 1) bytes at ADDR.
542 bit values 0 = valid, 1 = invalid, __ = unaddressable byte
543 Usage: memcheck get_vbits ADDR [LEN]
544 ADDR is an address expression evaluated by GDB.
545 LEN is an integer expression evaluated by GDB.
547 Example: (gdb) memcheck get_vbits &p sizeof(p)
549 Note: the command 'memcheck xb ADDR [LEN]' prints the value
550 and validity bits of ADDR [LEN] bytes in an easier to read format.
553 @Vinit("memcheck", "make_memory", gdb
.COMMAND_DATA
, gdb
.COMPLETE_COMMAND
, True)
554 class Memcheck_Make_Memory_Command(Valgrind_Prefix_Command
):
555 """Prefix command to change memory accessibility."""
557 @Vinit("memcheck", "make_memory noaccess", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
558 class Memcheck_Make_Memory_Noaccess_Command(Valgrind_ADDR_LEN_opt
):
559 """Mark LEN (default 1) bytes at ADDR as noaccess.
560 Usage: memcheck make_memory noaccess ADDR [LEN]
561 ADDR is an address expression evaluated by GDB.
562 LEN is an integer expression evaluated by GDB.
564 Example: (gdb) memcheck make_memory noaccess &p sizeof(p)
567 @Vinit("memcheck", "make_memory undefined", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
568 class Memcheck_Make_Memory_Undefined_Command(Valgrind_ADDR_LEN_opt
):
569 """Mark LEN (default 1) bytes at ADDR as undefined.
570 Usage: memcheck make_memory undefined ADDR [LEN]
571 ADDR is an address expression evaluated by GDB.
572 LEN is an integer expression evaluated by GDB.
574 Example: (gdb) memcheck make_memory undefined &p sizeof(p)
577 @Vinit("memcheck", "make_memory defined", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
578 class Memcheck_Make_Memory_Defined_Command(Valgrind_ADDR_LEN_opt
):
579 """Mark LEN (default 1) bytes at ADDR as defined.
580 Usage: memcheck make_memory defined ADDR [LEN]
581 ADDR is an address expression evaluated by GDB.
582 LEN is an integer expression evaluated by GDB.
584 Example: (gdb) memcheck make_memory defined &p sizeof(p)
587 @Vinit("memcheck", "make_memory Definedifaddressable", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
588 class Memcheck_Make_Memory_Definedifaddressable_Command(Valgrind_ADDR_LEN_opt
):
589 """Mark LEN (default 1) bytes at ADDR as Definedifaddressable.
590 Usage: memcheck make_memory Definedifaddressable ADDR [LEN]
591 ADDR is an address expression evaluated by GDB.
592 LEN is an integer expression evaluated by GDB.
594 Example: (gdb) memcheck make_memory Definedifaddressable &p sizeof(p)
597 @Vinit("memcheck", "check_memory", gdb
.COMMAND_DATA
, gdb
.COMPLETE_COMMAND
, True)
598 class Memcheck_Check_Memory_Command(Valgrind_Prefix_Command
):
599 """Command to check memory accessibility."""
601 @Vinit("memcheck", "check_memory addressable", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
602 class Memcheck_Check_Memory_Addressable_Command(Valgrind_ADDR_LEN_opt
):
603 """Check that LEN (default 1) bytes at ADDR are addressable.
604 Usage: memcheck check_memory addressable ADDR [LEN]
605 ADDR is an address expression evaluated by GDB.
606 LEN is an integer expression evaluated by GDB.
608 Example: (gdb) memcheck check_memory addressable &p sizeof(p)
611 @Vinit("memcheck", "check_memory defined", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
612 class Memcheck_Check_Memory_Defined_Command(Valgrind_ADDR_LEN_opt
):
613 """Check that LEN (default 1) bytes at ADDR are defined.
614 Usage: memcheck check_memory defined ADDR [LEN]
615 ADDR is an address expression evaluated by GDB.
616 LEN is an integer expression evaluated by GDB.
618 Example: (gdb) memcheck check_memory defined &p sizeof(p)
621 @Vinit("memcheck", "leak_check", gdb
.COMMAND_DATA
, gdb
.COMPLETE_NONE
, False)
622 class Memcheck_Leak_Check_Command(Valgrind_Command
):
623 """Execute a memcheck leak search.
624 Usage: leak_check [full*|summary|xtleak]
625 [kinds KIND1,KIND2,...|reachable|possibleleak*|definiteleak]
626 [heuristics HEUR1,HEUR2,...]
627 [new|increased*|changed|any]
628 [unlimited*|limited MAX_LOSS_RECORDS_OUTPUT]
631 full: outputs stacktraces of all leaks followed by a summary.
632 summary: outputs only the leak summary.
633 xtleak: produce an xtree full leak result in xtleak.kcg.%p.%n
635 KIND indicates which kind of leaks to report, and is one of:
636 definite indirect possible reachable all none
638 HEUR indicates an heuristic to activate when doing leak search and is one of:
639 stdstring length64 newarray multipleinheritance all none*
641 new: only outputs the new leak loss records since last leak search.
642 increased: only outputs the leak loss records with an increase since
644 changed: also outputs the leak loss records with a decrease.
645 any: also outputs the leak loss records that did not change.
647 unlimited: outputs all matching loss records.
648 limited: outputs only the first matching MAX_LOSS_RECORDS_OUTPUT.
650 This command auto-completes the user input by providing the full list of
651 keywords still relevant according to what is already typed. For example, if the
652 "summary" keyword has been provided, the following TABs to auto-complete other
653 items will not propose anymore "full" and "xtleak". Note that KIND and HEUR
654 values are not part of auto-completed elements.
656 Examples: (gdb) memcheck leak_check
657 (gdb) memcheck leak_check summary any
658 (gdb) memcheck leak_check full kinds indirect,possible
659 (gdb) memcheck leak_check full reachable any limited 100
663 def complete(self
, text
, word
):
664 # print('/' + text + ' ' + word + '/\n')
665 leak_check_mode
= ["full", "summary", "xtleak"]
666 leak_kind
= ["kinds", "reachable", "possibleleak", "definiteleak"]
667 leak_heuristic
= ["heuristics"]
668 leak_check_delta_mode
= ["new", "increased", "changed", "any"]
669 leak_check_loss_record_limit
= ["unlimited", "limited"]
670 kwd_lists
= [leak_check_mode
, leak_kind
, leak_heuristic
,
671 leak_check_delta_mode
, leak_check_loss_record_limit
]
672 # Build the list of still allowed keywords.
673 # We append all the keywords of a list unless we find already one
674 # existing word in text that starts with the first letter of a keyword
675 # of the list. Checking the first letter is ok (currently!)
676 # as all keywords of leak_check monitor command starts with a different
679 command_words
= text
.split()
680 for kwd_list
in kwd_lists
:
682 # print('list:/' + str(kwd_list) + '/')
684 for command_word
in command_words
:
685 # print('word:/' + command_word + '/' + kwd)
686 if kwd
[0] == command_word
[0]:
687 # print("setting to false")
689 if (kwd
.startswith(word
) and
691 and kwd
not in command_words
693 # print('/' + word + '/' + kwd + '/')
699 for keyword
in keywords
:
700 if keyword
.startswith(word
):
701 result
.append(keyword
)
704 @Vinit("memcheck", "block_list", gdb
.COMMAND_DATA
, gdb
.COMPLETE_NONE
, False)
705 class Memcheck_Block_List_Command(Valgrind_Command
):
706 """Show the list of blocks for a leak search loss record.
707 Usage: memcheck block_list LOSS_RECORD_NR|LOSS_RECORD_NR_FROM..LOSS_RECORD_NR_TO
708 unlimited*|limited MAX_BLOCKS
709 [heuristics HEUR1,HEUR2,...]
712 After a leak search, use block_list to show the list of blocks matching a loss
713 record or matching a range of loss records.
715 unlimited: outputs all blocks matching the selected loss records.
716 limited: outputs only the first matching MAX_BLOCKS.
718 Use heuristics to only output the blocks found via one of the given heuristics,
719 where HEUR is one of:
720 stdstring length64 newarray multipleinheritance all none*
723 @Vinit("memcheck", "who_points_at", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
724 class Memcheck_Who_Points_At_Command(Valgrind_ADDR_LEN_opt
):
725 """Show places pointing inside LEN (default 1) bytes at ADDR.
726 Usage: memcheck who_points_at ADDR [LEN]
727 With LEN 1, only shows "start pointers" pointing exactly to ADDR.
728 With LEN > 1, will also show "interior pointers"
729 ADDR is an address expression evaluated by GDB.
730 LEN is an integer expression evaluated by GDB.
733 ############# helgrind commands.
735 ###### Top of the hierarchy of the helgrind commands.
736 @Vinit("helgrind", "", gdb
.COMMAND_SUPPORT
, gdb
.COMPLETE_COMMAND
, True)
737 class Helgrind_Command(Valgrind_Prefix_Command
):
738 """Front end GDB command for Valgrind helgrind gdbserver monitor commands.
739 Usage: helgrind HELGRIND_MONITOR_COMMAND [ARG...]
740 HELGRIND_MONITOR_COMMAND is a helgrind subcommand, matching
741 a gdbserver Valgrind helgrind monitor command.
742 ARG... are optional arguments. They depend on the HELGRIND_MONITOR_COMMAND.
745 def_alias("hg", "helgrind")
747 @Vinit("helgrind", "info", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_COMMAND
, True)
748 class Helgrind_Info_Command(Valgrind_Prefix_Command
):
749 """Get various information about helgrind tool status.
750 Usage: helgrind info WHAT
751 WHAT is the helgrind info subcommand, specifying the type of information requested.
754 @Vinit("helgrind", "info locks", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
755 class Helgrind_Info_Locks_Command(Valgrind_ADDR_opt
):
756 """Show the status of one or all locks recorded by helgrind.
757 Usage: helgrind info locks [ADDR]
758 ADDR is an address expression evaluated by GDB.
759 When ADDR is provided, shows the status of the lock located at ADDR,
760 otherwise shows the status of all locks.
763 @Vinit("helgrind", "accesshistory", gdb
.COMMAND_DATA
, gdb
.COMPLETE_EXPRESSION
, False)
764 class Helgrind_Accesshistory_Command(Valgrind_ADDR_LEN_opt
):
765 """Show access history recorded for LEN (default 1) bytes at ADDR.
766 Usage: helgrind accesshistory ADDR [LEN]
767 ADDR is an address expression evaluated by GDB.
768 LEN is an integer expression evaluated by GDB.
770 Example: (gdb) helgrind accesshistory &p sizeof(p)
773 @Vinit("helgrind", "xtmemory", gdb
.COMMAND_DATA
, gdb
.COMPLETE_FILENAME
, False)
774 class Helgrind_Xtmemory_Command(Valgrind_Command
):
775 """Dump xtree memory profile in FILENAME (default xtmemory.kcg.%p.%n).
776 Usage: helgrind xtmemory [FILENAME]
778 Example: (gdb) helgrind xtmemory my_program_xtree.kcg
781 ############# callgrind commands.
783 ###### Top of the hierarchy of the callgrind commands.
784 @Vinit("callgrind", "", gdb
.COMMAND_SUPPORT
, gdb
.COMPLETE_COMMAND
, True)
785 class Callgrind_Command(Valgrind_Prefix_Command
):
786 """Front end GDB command for Valgrind callgrind gdbserver monitor commands.
787 Usage: callgrind CALLGRIND_MONITOR_COMMAND [ARG...]
788 CALLGRIND_MONITOR_COMMAND is a callgrind subcommand, matching
789 a gdbserver Valgrind callgrind monitor command.
790 ARG... are optional arguments. They depend on the CALLGRIND_MONITOR_COMMAND.
793 def_alias("cg", "callgrind")
795 @Vinit("callgrind", "dump", gdb
.COMMAND_DATA
, gdb
.COMPLETE_COMMAND
, False)
796 class Callgrind_Dump_Command(Valgrind_Command
):
797 """Dump the callgrind counters.
798 Usage: callgrind dump [DUMP_HINT]
799 DUMP_HINT is a message stored in the resulting callgrind dump file.
802 @Vinit("callgrind", "zero", gdb
.COMMAND_DATA
, gdb
.COMPLETE_COMMAND
, False)
803 class Callgrind_Zero_Command(Valgrind_Command
):
804 """Set the callgrind counters to zero.
805 Usage: callgrind zero
808 @Vinit("callgrind", "status", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_NONE
, False)
809 class Callgrind_Status_Command(Valgrind_Command
):
810 """Show the status of callgrind.
811 Usage: callgrind status
814 @Vinit("callgrind", "instrumentation", gdb
.COMMAND_STATUS
, gdb
.COMPLETE_COMMAND
, False)
815 class Callgrind_Instrumentation_Command(Valgrind_Command
):
816 """Get or set the callgrind instrumentation state.
817 Usage: callgrind instrumentation [on|off]
818 Without argument, shows the current state of instrumentation,
819 otherwise changes the instrumentation state to the given argument.
822 ############# massif commands.
824 ###### Top of the hierarchy of the massif commands.
825 @Vinit("massif", "", gdb
.COMMAND_SUPPORT
, gdb
.COMPLETE_COMMAND
, True)
826 class Massif_Command(Valgrind_Prefix_Command
):
827 """Front end GDB command for Valgrind massif gdbserver monitor commands.
828 Usage: massif MASSIF_MONITOR_COMMAND [ARG...]
829 MASSIF_MONITOR_COMMAND is a massif subcommand, matching
830 a gdbserver Valgrind massif monitor command.
831 ARG... are optional arguments. They depend on the MASSIF_MONITOR_COMMAND.
834 def_alias("ms", "massif")
836 @Vinit("massif", "snapshot", gdb
.COMMAND_DATA
, gdb
.COMPLETE_FILENAME
, False)
837 class Massif_Dump_Command(Valgrind_Command
):
838 """Take a massif snapshot in FILENAME (default massif.vgdb.out).
839 Usage: massif snapshot [FILENAME]
842 @Vinit("massif", "detailed_snapshot", gdb
.COMMAND_DATA
, gdb
.COMPLETE_FILENAME
, False)
843 class Massif_Dump_Command(Valgrind_Command
):
844 """Take a massif detailed snapshot in FILENAME (default massif.vgdb.out).
845 Usage: massif detailed_snapshot [FILENAME]
848 @Vinit("massif", "all_snapshots", gdb
.COMMAND_DATA
, gdb
.COMPLETE_FILENAME
, False)
849 class Massif_Dump_Command(Valgrind_Command
):
850 """Save all snapshot(s) taken so far in FILENAME (default massif.vgdb.out).
851 Usage: massif all_snapshots [FILENAME]
854 @Vinit("massif", "xtmemory", gdb
.COMMAND_DATA
, gdb
.COMPLETE_FILENAME
, False)
855 class Massic_Xtmemory_Command(Valgrind_Command
):
856 """Dump xtree memory profile in FILENAME (default xtmemory.kcg.%p.%n).
857 Usage: massif xtmemory [FILENAME]
859 Example: (gdb) massif xtmemory my_program_xtree.kcg