PATCH: Fix MI stack frame output for synthetic frames

Jason Molenda
2002-11-08T22:22:57Z

[-- Attachment #1: Type: text/plain, Size: 3466 bytes --]

Hi all,

We've recently found a little problem with the current gdb in MI
mode with synthesized frames on the stack (a gdb call dummy or a
stack handler). Until last month, print_frame_info_base() would
print information about these frames to stdout via printf_unfiltered;
the reply to -stack-list-frames would have a FRAME tuple for level
0, skip level 1 (assuming that's the synthesized frame), then a
FRAME tuple for level 2 and so on.

With Jeff's change a month ago -
http://sources.redhat.com/ml/gdb-patches/2002-09/msg00777.html

a LEVEL field is being output, but no other parts of the FRAME tuple.
(the FRAME tuple is a named tuple ("frame") with fields ADDR, FUNC,
ARGS, and LINE if those are all available). The output now looks like

~"<signal handler called>\n"
stack=[frame={level="0",addr=...,func=...},level="1",frame={level="2",addr=...},...]

I've attached a patch to emit a TUPLE with a func name of "<signal
handler called>" or "<function called from gdb>" and to include
the ADDR field. I also took the opportunity to remove some code that'd
been #if 0'ed since the original import on to sources.redhat.com in 1999.
It's probably easier to read the new code than the patch -- I'll list the
new code below and attach the patch.

2002-11-08 Jason Molenda (jmolenda@apple.com)

* stack.c (print_frame_info_base): Emit full FRAME tuple for
gdb call dummy and signal handler synthetic stack frames; send
stack frame name through UI instead of stdout.

Jason

PS- Jeff, I saw you doing some tuple/list cleanup recently. The
one place I fixed on the Apple but the FSF doesn't have correct is
the CHILDREN list from -var-list-children; it should be a list,
but it's currently output as a tuple. I'd be willing to submit a
patch to the code and the testsuite if you're interested.

PPS- I should add that this test causes no regressions and doesn't
change the CLI output. I wrote a test file to explicitly cover
these synthesized frames in CLI and MI modes, but it would take a
little reworking to handle the FSF style MI output.

static void
print_frame_info_base (struct frame_info *fi, int level, int source, int args)
{
struct symtab_and_line sal;
int source_print;
int location_print;
struct cleanup *uiout_cleanup;

if (frame_in_dummy (fi) || fi->signal_handler_caller)
{
annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");

/* Do this regardless of SOURCE because we don't have any source
to list for this frame. */
if (level >= 0)
{
ui_out_text (uiout, "#");
ui_out_field_fmt_int (uiout, 2, ui_left, "level", level);
}
if (ui_out_is_mi_like_p (uiout))
{
annotate_frame_address ();
ui_out_field_core_addr (uiout, "addr", fi->pc);
annotate_frame_address_end ();
}
}
if (frame_in_dummy (fi))
{
annotate_function_call ();
ui_out_field_string (uiout, "func", "<function called from gdb>");
ui_out_text (uiout, "\n");
annotate_frame_end ();
do_cleanups (uiout_cleanup);
return;
}
if (fi->signal_handler_caller)
{
annotate_signal_handler_caller ();
ui_out_field_string (uiout, "func", "<signal handler called>");
ui_out_text (uiout, "\n");
annotate_frame_end ();
do_cleanups (uiout_cleanup);
return;
}

[-- Attachment #2: pa.txt --]
[-- Type: text/plain, Size: 3102 bytes --]

2002-11-08 Jason Molenda (jmolenda@apple.com)

* stack.c (print_frame_info_base): Emit full FRAME tuple for
gdb call dummy and signal handler synthetic stack frames; send
stack frame name through UI instead of stdout.

Index: stack.c
===================================================================
RCS file: /cvs/src/src/gdb/stack.c,v
retrieving revision 1.46
diff -u -p -r1.46 stack.c
--- stack.c 3 Oct 2002 22:34:58 -0000 1.46
+++ stack.c 8 Nov 2002 22:02:49 -0000
@@ -332,28 +332,12 @@ print_frame_info_base (struct frame_info
struct symtab_and_line sal;
int source_print;
int location_print;
+ struct cleanup *uiout_cleanup;

-#if 0
- char buf[MAX_REGISTER_RAW_SIZE];
- CORE_ADDR sp;
-
- /* On the 68k, this spends too much time in m68k_find_saved_regs. */
-
- /* Get the value of SP_REGNUM relative to the frame. */
- get_saved_register (buf, (int *) NULL, (CORE_ADDR *) NULL,
- FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *) NULL);
- sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
-
- /* This is not a perfect test, because if a function alloca's some
- memory, puts some code there, and then jumps into it, then the test
- will succeed even though there is no call dummy. Probably best is
- to check for a bp_call_dummy breakpoint. */
- if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
-#else
- if (frame_in_dummy (fi))
-#endif
+ if (frame_in_dummy (fi) || fi->signal_handler_caller)
{
annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
+ uiout_cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "frame");

/* Do this regardless of SOURCE because we don't have any source
to list for this frame. */
@@ -362,25 +346,29 @@ print_frame_info_base (struct frame_info
ui_out_text (uiout, "#");
ui_out_field_fmt_int (uiout, 2, ui_left, "level", level);
}
+ if (ui_out_is_mi_like_p (uiout))
+ {
+ annotate_frame_address ();
+ ui_out_field_core_addr (uiout, "addr", fi->pc);
+ annotate_frame_address_end ();
+ }
+ }
+ if (frame_in_dummy (fi))
+ {
annotate_function_call ();
- printf_filtered ("<function called from gdb>\n");
+ ui_out_field_string (uiout, "func", "<function called from gdb>");
+ ui_out_text (uiout, "\n");
annotate_frame_end ();
+ do_cleanups (uiout_cleanup);
return;
}
if (fi->signal_handler_caller)
{
- annotate_frame_begin (level == -1 ? 0 : level, fi->pc);
-
- /* Do this regardless of SOURCE because we don't have any source
- to list for this frame. */
- if (level >= 0)
- {
- ui_out_text (uiout, "#");
- ui_out_field_fmt_int (uiout, 2, ui_left, "level", level);
- }
annotate_signal_handler_caller ();
- printf_filtered ("<signal handler called>\n");
+ ui_out_field_string (uiout, "func", "<signal handler called>");
+ ui_out_text (uiout, "\n");
annotate_frame_end ();
+ do_cleanups (uiout_cleanup);
return;
}