gdb: add -catch-hiperr to the Machine Interface (MI)#180
Conversation
lancesix
left a comment
There was a problem hiding this comment.
First very quick remarks.
| @subsubheading Example | ||
|
|
||
| @smallexample | ||
| -catch-hiperr -c $_hiperr==hipErrorInvalidDevice -t |
There was a problem hiding this comment.
usual parsing question… How do you differentiate -t as a flag after the condition v.s. -t being the unari - operator, i.e. hipErrorInvalidDevice - t?
There was a problem hiding this comment.
Debugging the code around the option parsing [1], reveals that the valid ways of passing arguments to options (in this example, condition to -c) is to not use any spaces in the argument or have them double-quoted. For instance, see the two alternatives below and how they end up setting the parameters:
# alt.1: no spaces
interpreter-exec mi '-catch-hiperr -c $_hiperr=hipErrorInvalidDevice-t -t'
mi_cmd_catch_hiperr (..., const char *const argv, int argc)
argc: 3
argv[0]: "-c"
argv[1]: "$_hiperr==hipErrorInvalidDevice-t"
argv[2]: "-t"
.
.
.
condition = "$_hiperr==hipErrorInvalidDevice-t"
temp = true
---------------------------------------------------
# alt.2: double-quoted
interpreter-exec mi '-catch-hiperr -c "$_hiperr == hipErrorInvalidDevice - t" -t'
mi_cmd_catch_hiperr (..., const char *const argv, int argc)
argc: 3
argv[0]: "-c"
argv[1]: "$_hiperr == hipErrorInvalidDevice - t"
argv[2]: "-t"
.
.
.
condition = "$_hiperr == hipErrorInvalidDevice - t"
temp = true
Any deviation from this and we'll end up with the wrong argc/argv to begin with:
interpreter-exec mi '-catch-hiperr -c $_hiperr == hipErrorInvalidDevice - t -t'
mi_cmd_catch_hiperr (..., const char *const argv, int argc)
argc: 7
argv[0]: "-c"
argv[1]: "$_hiperr"
argv[2]: "=="
argv[3]: "hipErrorInvalidDevice"
argv[4]: "-"
argv[5]: "t"
argv[6]: "-t"
.
.
.
condition = "$_hiperr"
then "opt" in the for-loop [1] becomes negative and the loop is broken
and we'll end up with a conditional catchpoint with $_hiperr as its condition.
[1] gdb/mi/mi-cmd-catch.c
void mi_cmd_catch_hiperr (const char *cmd, const char *const *argv, int argc)
{
...
for (;;)
{
int opt = mi_getopt (cmd, argc, argv, opts, &oind, &oarg);
if (opt < 0)
break;
switch ((enum opt) opt)
{
case OPT_CONDITION:
condition = oarg;
break;
case OPT_TEMP:
temp = true;
break;
}
}
...
}For the record, I've added -catch-hiperr -c "$_hiperr == hipErrorInvalidDevice -t" -t as a test now.
Introduce a new MI command to catch HIP runtime errors that takes the form of: -catch-hiperr [ -c <condition>] [ -t ] Along with it the documentation is updated and new tests are added. Change-Id: Ib1c2190cc081caeea210d61aec71e6452516525b
e06c4b3 to
371adc8
Compare
|
Introduce a new MI command to catch HIP runtime errors that takes the form of:
Along with it the documentation is updated and new tests are added.
Motivation
Add Machine Interface for "catch hiperr".
Technical Details
Machine Interface allows other tools control GDB by sending it commands and reading its feedback. This was missing for the "catch hiperr" support that we added earlier.
Test Plan
A new test with 4 different scenarios are added (see gdb.rocm/mi-catch-hiperr.exp).
Test Result
All the new tests are and "catch hiperr" tests are passing.