This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Question about printing info to UI (MI -vs- non-MI)


Hello,

I have a question about how we're expected to generate the output
for certain notifications.  In particular, I am working on the
Ada exceptions catchpoint-hit notification for GDB/MI.  By looking
at code such as print_it_catch_exception, I came up with the code
below, but I'm fairly unsatisfied, and also curious about something.

Just for reference, the output in the CLI case is:

    Catchpoint 1, CONSTRAINT_ERROR at [std frame info snipped]

The part that generates the info used to produce the GDB/MI *stopped
notification is nice and compact.  But the rest of the code makes me
wonder whether I might be able to simplify it. For instance, the first
thing I do is:

|  ui_out_text (uiout, (b->disposition == disp_del
|                       ? "\nTemporary catchpoint "
|                       : "\nCatchpoint "));

But this text doesn't get used in the case of GDB/MI.

Immediately following it, I do the same as in print_it_catch_exception,
which is to emit an "int" field, BUT only if we're not in MI mode
(we want that field to be in a special order, I understand). Does it
make a difference to anyone that this info is emitted as an int, and
labeled "bkptno"?

I used to think that there was only the CLI vs GDB/MI, but I'm just
realizing that there might be some solid reasons doing things this
way.  For instance, what about the TUI?

Depending on the answers to these questions, it might be better
for me to write the code:

    if (ui_out_is_mi_like_p (uiout))
      {
        [generate the MI data]
      }
    else
     {
        ui_out_text (uiout, "Catchpoint ");
        ui_out_field_int (uiout, "bkptno", b->number);
        [etc]
     }
}
     
For the record, this is the meat of the code.  Thank you!

|  ui_out_text (uiout, (b->disposition == disp_del
|                       ? "\nTemporary catchpoint "
|                       : "\nCatchpoint "));
|  if (!ui_out_is_mi_like_p (uiout))
|    ui_out_field_int (uiout, "bkptno", b->number);
|  ui_out_text (uiout, ", ");
|
|  switch (ex)
|    {
|      case ex_catch_exception:
|        ui_out_text (uiout, exception_name);
|        break;
|      case ex_catch_exception_unhandled:
|        ui_out_text (uiout, "unhandled ");
|        ui_out_text (uiout, exception_name);
|        break;
|      case ex_catch_assert:
|        ui_out_text (uiout, "failed assertion");
|        break;
|    }
|  ui_out_text (uiout, " at ");
|
|  if (ui_out_is_mi_like_p (uiout))
|    {
|      ui_out_field_string (uiout, "reason",
|                           async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
|      ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition));
|      ui_out_field_int (uiout, "bkptno", b->number);
|      /* Provide the exception name, regardless of what the catchpoint
|         kind is.  This is slightly different from what we do in
|         the non-MI case, where we print "unhandled <exception_name>"
|         for unhandled exceptions, or even replace the exception name
|         in the case of failed assertions.  This makes the semantics
|         of the "exception-name" field simpler, while still providing
|         all the information that any consumer might need to display
|         this event.  */
|      ui_out_field_string (uiout, "exception-name", exception_name);
|    }

-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]