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.
e06c4b3 to
371adc8
Compare
|
371adc8 to
a7a4881
Compare
|
a7a4881 to
8e1c647
Compare
|
8e1c647 to
1e35736
Compare
|
|
Since we're trying to have a clean gdb.rocm testsuite with non-O0 optimization level, please check if this new test behaves well when executed with O1~O3 and -flto. |
1e35736 to
e5db552
Compare
|
e5db552 to
1ef1dd5
Compare
|
1ef1dd5 to
dac995a
Compare
The test fails if any optimization is used. The problems are: - the reference values getting removed. - a failed breakpoint on a comment line at then end of a block. - lack of __device_stub__kernel in call stack. Fix these by: - using volatile qualifier. - adding a volatile NOP assembly instruction at the end of the block. - removing __device_stub__kernel from pattern matching. Rest of the pattern with __hipOnError and hipLaunchKernel is good enough. Change-Id: Iaec647758256300fce37dc759fd31d9a496f41b3
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. Co-authored-by: Pedro Alves <pedro@palves.net> Change-Id: Ib1c2190cc081caeea210d61aec71e6452516525b
dac995a to
b678e33
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
New MI tests are added
hip-catch-errors.exp.Test Result
All the new tests are and "catch hiperr" tests are passing.