gdb/dummy-frame.c - gdb
Global variables defined
Data types defined
Functions defined
Source code
- #include "defs.h"
- #include "dummy-frame.h"
- #include "regcache.h"
- #include "frame.h"
- #include "inferior.h"
- #include "frame-unwind.h"
- #include "command.h"
- #include "gdbcmd.h"
- #include "observer.h"
- #include "gdbthread.h"
- struct dummy_frame_id
- {
-
- struct frame_id id;
-
- ptid_t ptid;
- };
- static int
- dummy_frame_id_eq (struct dummy_frame_id *id1,
- struct dummy_frame_id *id2)
- {
- return frame_id_eq (id1->id, id2->id) && ptid_equal (id1->ptid, id2->ptid);
- }
- struct dummy_frame
- {
- struct dummy_frame *next;
-
- struct dummy_frame_id id;
-
- struct infcall_suspend_state *caller_state;
-
- void (*dtor) (void *data);
-
- void *dtor_data;
- };
- static struct dummy_frame *dummy_frame_stack = NULL;
- void
- dummy_frame_push (struct infcall_suspend_state *caller_state,
- const struct frame_id *dummy_id, ptid_t ptid)
- {
- struct dummy_frame *dummy_frame;
- dummy_frame = XCNEW (struct dummy_frame);
- dummy_frame->caller_state = caller_state;
- dummy_frame->id.id = (*dummy_id);
- dummy_frame->id.ptid = ptid;
- dummy_frame->next = dummy_frame_stack;
- dummy_frame_stack = dummy_frame;
- }
- static void
- remove_dummy_frame (struct dummy_frame **dummy_ptr)
- {
- struct dummy_frame *dummy = *dummy_ptr;
- *dummy_ptr = dummy->next;
- discard_infcall_suspend_state (dummy->caller_state);
- xfree (dummy);
- }
- static int
- pop_dummy_frame_bpt (struct breakpoint *b, void *dummy_voidp)
- {
- struct dummy_frame *dummy = dummy_voidp;
- if (b->thread == pid_to_thread_id (dummy->id.ptid)
- && b->disposition == disp_del && frame_id_eq (b->frame_id, dummy->id.id))
- {
- while (b->related_breakpoint != b)
- delete_breakpoint (b->related_breakpoint);
- delete_breakpoint (b);
-
- return 1;
- }
-
- return 0;
- }
- static void
- pop_dummy_frame (struct dummy_frame **dummy_ptr)
- {
- struct dummy_frame *dummy = *dummy_ptr;
- gdb_assert (ptid_equal (dummy->id.ptid, inferior_ptid));
- if (dummy->dtor != NULL)
- dummy->dtor (dummy->dtor_data);
- restore_infcall_suspend_state (dummy->caller_state);
- iterate_over_breakpoints (pop_dummy_frame_bpt, dummy);
-
- *dummy_ptr = dummy->next;
- xfree (dummy);
-
- reinit_frame_cache ();
- }
- static struct dummy_frame **
- lookup_dummy_frame (struct dummy_frame_id *dummy_id)
- {
- struct dummy_frame **dp;
- for (dp = &dummy_frame_stack; *dp != NULL; dp = &(*dp)->next)
- {
- if (dummy_frame_id_eq (&(*dp)->id, dummy_id))
- return dp;
- }
- return NULL;
- }
- void
- dummy_frame_pop (struct frame_id dummy_id, ptid_t ptid)
- {
- struct dummy_frame **dp;
- struct dummy_frame_id id = { dummy_id, ptid };
- dp = lookup_dummy_frame (&id);
- gdb_assert (dp != NULL);
- pop_dummy_frame (dp);
- }
- void
- dummy_frame_discard (struct frame_id dummy_id, ptid_t ptid)
- {
- struct dummy_frame **dp;
- struct dummy_frame_id id = { dummy_id, ptid };
- dp = lookup_dummy_frame (&id);
- if (dp)
- remove_dummy_frame (dp);
- }
- void
- register_dummy_frame_dtor (struct frame_id dummy_id, ptid_t ptid,
- dummy_frame_dtor_ftype *dtor, void *dtor_data)
- {
- struct dummy_frame_id id = { dummy_id, ptid };
- struct dummy_frame **dp, *d;
- dp = lookup_dummy_frame (&id);
- gdb_assert (dp != NULL);
- d = *dp;
- gdb_assert (d->dtor == NULL);
- d->dtor = dtor;
- d->dtor_data = dtor_data;
- }
- int
- find_dummy_frame_dtor (dummy_frame_dtor_ftype *dtor, void *dtor_data)
- {
- struct dummy_frame *d;
- for (d = dummy_frame_stack; d != NULL; d = d->next)
- if (d->dtor == dtor && d->dtor_data == dtor_data)
- return 1;
- return 0;
- }
- static void
- cleanup_dummy_frames (struct target_ops *target, int from_tty)
- {
- while (dummy_frame_stack != NULL)
- remove_dummy_frame (&dummy_frame_stack);
- }
- struct dummy_frame_cache
- {
- struct frame_id this_id;
- struct regcache *prev_regcache;
- };
- static int
- dummy_frame_sniffer (const struct frame_unwind *self,
- struct frame_info *this_frame,
- void **this_prologue_cache)
- {
-
-
- if (dummy_frame_stack != NULL)
- {
- struct dummy_frame *dummyframe;
-
- struct frame_id this_id
- = gdbarch_dummy_id (get_frame_arch (this_frame), this_frame);
- struct dummy_frame_id dummy_id = { this_id, inferior_ptid };
-
- for (dummyframe = dummy_frame_stack;
- dummyframe != NULL;
- dummyframe = dummyframe->next)
- {
- if (dummy_frame_id_eq (&dummyframe->id, &dummy_id))
- {
- struct dummy_frame_cache *cache;
- cache = FRAME_OBSTACK_ZALLOC (struct dummy_frame_cache);
- cache->prev_regcache = get_infcall_suspend_state_regcache
- (dummyframe->caller_state);
- cache->this_id = this_id;
- (*this_prologue_cache) = cache;
- return 1;
- }
- }
- }
- return 0;
- }
- static struct value *
- dummy_frame_prev_register (struct frame_info *this_frame,
- void **this_prologue_cache,
- int regnum)
- {
- struct dummy_frame_cache *cache = (*this_prologue_cache);
- struct gdbarch *gdbarch = get_frame_arch (this_frame);
- struct value *reg_val;
-
- gdb_assert (cache != NULL);
-
- reg_val = value_zero (register_type (gdbarch, regnum), not_lval);
-
- regcache_cooked_read (cache->prev_regcache, regnum,
- value_contents_writeable (reg_val));
- return reg_val;
- }
- static void
- dummy_frame_this_id (struct frame_info *this_frame,
- void **this_prologue_cache,
- struct frame_id *this_id)
- {
-
- struct dummy_frame_cache *cache = (*this_prologue_cache);
- gdb_assert (cache != NULL);
- (*this_id) = cache->this_id;
- }
- const struct frame_unwind dummy_frame_unwind =
- {
- DUMMY_FRAME,
- default_frame_unwind_stop_reason,
- dummy_frame_this_id,
- dummy_frame_prev_register,
- NULL,
- dummy_frame_sniffer,
- };
- static void
- fprint_dummy_frames (struct ui_file *file)
- {
- struct dummy_frame *s;
- for (s = dummy_frame_stack; s != NULL; s = s->next)
- {
- gdb_print_host_address (s, file);
- fprintf_unfiltered (file, ":");
- fprintf_unfiltered (file, " id=");
- fprint_frame_id (file, s->id.id);
- fprintf_unfiltered (file, ", ptid=%s",
- target_pid_to_str (s->id.ptid));
- fprintf_unfiltered (file, "\n");
- }
- }
- static void
- maintenance_print_dummy_frames (char *args, int from_tty)
- {
- if (args == NULL)
- fprint_dummy_frames (gdb_stdout);
- else
- {
- struct cleanup *cleanups;
- struct ui_file *file = gdb_fopen (args, "w");
- if (file == NULL)
- perror_with_name (_("maintenance print dummy-frames"));
- cleanups = make_cleanup_ui_file_delete (file);
- fprint_dummy_frames (file);
- do_cleanups (cleanups);
- }
- }
- extern void _initialize_dummy_frame (void);
- void
- _initialize_dummy_frame (void)
- {
- add_cmd ("dummy-frames", class_maintenance, maintenance_print_dummy_frames,
- _("Print the contents of the internal dummy-frame stack."),
- &maintenanceprintlist);
- observer_attach_inferior_created (cleanup_dummy_frames);
- }