Skip to content

gdb: add -catch-hiperr to the Machine Interface (MI)#180

Open
amd-shahab wants to merge 1 commit into
amd-stagingfrom
users/shvahedi/hip-catch-errs
Open

gdb: add -catch-hiperr to the Machine Interface (MI)#180
amd-shahab wants to merge 1 commit into
amd-stagingfrom
users/shvahedi/hip-catch-errs

Conversation

@amd-shahab

@amd-shahab amd-shahab commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

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.

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.

Running /data/work/src/dev/rocgdb/gdb/testsuite/gdb.rocm/mi-catch-hiperr.exp ...
PASS: gdb.rocm/mi-catch-hiperr.exp: simple catch
PASS: gdb.rocm/mi-catch-hiperr.exp: breakpoint info of simple catch
PASS: gdb.rocm/mi-catch-hiperr.exp: temporary catch
PASS: gdb.rocm/mi-catch-hiperr.exp: breakpoint info of temporary catch
PASS: gdb.rocm/mi-catch-hiperr.exp: conditional catch
PASS: gdb.rocm/mi-catch-hiperr.exp: breakpoint info of conditional catch
PASS: gdb.rocm/mi-catch-hiperr.exp: temporary conditional catch
PASS: gdb.rocm/mi-catch-hiperr.exp: breakpoint info of temporary conditional catch

@lancesix lancesix left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First very quick remarks.

Comment thread gdb/doc/gdb.texinfo
@subsubheading Example

@smallexample
-catch-hiperr -c $_hiperr==hipErrorInvalidDevice -t

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@amd-shahab amd-shahab Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread gdb/testsuite/gdb.rocm/mi-catch-hiperr.exp Outdated
Comment thread gdb/testsuite/gdb.rocm/mi-catch-hiperr.exp Outdated
Comment thread gdb/breakpoint.h
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
@amd-shahab amd-shahab force-pushed the users/shvahedi/hip-catch-errs branch from e06c4b3 to 371adc8 Compare June 22, 2026 19:17
@amd-shahab

Copy link
Copy Markdown
Contributor Author
  • Use -catch-hiperr -c "$_hiperr == hipErrorInvalidDevice -t" -t as temporary conditional test
  • Use mi_gdb_tests instead of gdb_test and gdb_test_multiple
  • get rid of the rocm boiler plates (load_lib rocm.exp, require allow_hip_tests, and the standard_testfile .../prepare_for_testing ...)

@amd-shahab amd-shahab requested a review from lancesix June 22, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants