diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-05-08 16:28:41 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-05-09 16:50:15 +0100 |
commit | 1ef40c1362fc2411ee45ad7251c4e9cc4c906435 (patch) | |
tree | b97de7cac4f4e58272101a92897538188c7066d6 /gdb | |
parent | 927c4e355e307698d58e6cad17f866bf5515f16e (diff) | |
download | gdb-1ef40c1362fc2411ee45ad7251c4e9cc4c906435.zip gdb-1ef40c1362fc2411ee45ad7251c4e9cc4c906435.tar.gz gdb-1ef40c1362fc2411ee45ad7251c4e9cc4c906435.tar.bz2 |
gdb/py: convert debug logging in py-unwind to use new scheme
Converts the debug print out in python/py-unwind.c to use the new
debug printing scheme. I have also modified what is printed in a few
places, for example, rather than printing frame pointers, I now print
the frame level, this matches what we do in the general 'set debug
frame' tracing, and is usually more helpful (I think).
I also added a couple of ENTER/EXIT scope printers.
gdb/ChangeLog:
* python/py-unwind.c (pyuw_debug): Convert to bool.
(show_pyuw_debug): New function.
(pyuw_debug_printf): Define.
(PYUW_SCOPED_DEBUG_ENTER_EXIT): Define.
(pyuw_this_id): Convert to new debug print macros.
(pyuw_prev_register): Likewise.
(pyuw_sniffer): Likewise.
(pyuw_dealloc_cache): Likewise.
(_initialize_py_unwind): Update now pyuw_debug is a bool, and add
show function when registering.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 13 | ||||
-rw-r--r-- | gdb/python/py-unwind.c | 54 |
2 files changed, 51 insertions, 16 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 23710bc..db21675 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,18 @@ 2021-05-09 Andrew Burgess <andrew.burgess@embecosm.com> + * python/py-unwind.c (pyuw_debug): Convert to bool. + (show_pyuw_debug): New function. + (pyuw_debug_printf): Define. + (PYUW_SCOPED_DEBUG_ENTER_EXIT): Define. + (pyuw_this_id): Convert to new debug print macros. + (pyuw_prev_register): Likewise. + (pyuw_sniffer): Likewise. + (pyuw_dealloc_cache): Likewise. + (_initialize_py_unwind): Update now pyuw_debug is a bool, and add + show function when registering. + +2021-05-09 Andrew Burgess <andrew.burgess@embecosm.com> + * dummy-frame.c (fprint_dummy_frames): Convert use of fprint_frame_id to use frame_id::to_string. * frame.c (fprint_field): Delete. diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c index c82fa3d..7c195eb 100644 --- a/gdb/python/py-unwind.c +++ b/gdb/python/py-unwind.c @@ -28,8 +28,28 @@ #include "regcache.h" #include "valprint.h" -#define TRACE_PY_UNWIND(level, args...) if (pyuw_debug >= level) \ - { fprintf_unfiltered (gdb_stdlog, args); } +/* Debugging of Python unwinders. */ + +static bool pyuw_debug; + +/* Implementation of "show debug py-unwind". */ + +static void +show_pyuw_debug (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("Python unwinder debugging is %s.\n"), value); +} + +/* Print a "py-unwind" debug statement. */ + +#define pyuw_debug_printf(fmt, ...) \ + debug_prefixed_printf_cond (pyuw_debug, "py-unwind", fmt, ##__VA_ARGS__) + +/* Print "py-unwind" enter/exit debug statements. */ + +#define PYUW_SCOPED_DEBUG_ENTER_EXIT \ + scoped_debug_enter_exit (pyuw_debug, "py-unwind") struct pending_frame_object { @@ -96,8 +116,6 @@ extern PyTypeObject pending_frame_object_type extern PyTypeObject unwind_info_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("unwind_info_object"); -static unsigned int pyuw_debug = 0; - static struct gdbarch_data *pyuw_gdbarch_data; /* Convert gdb.Value instance to inferior's pointer. Return 1 on success, @@ -431,9 +449,7 @@ pyuw_this_id (struct frame_info *this_frame, void **cache_ptr, struct frame_id *this_id) { *this_id = ((cached_frame_info *) *cache_ptr)->frame_id; - if (pyuw_debug >= 1) - fprintf_unfiltered (gdb_stdlog, "%s: frame_id: %s\n", __FUNCTION__, - this_id->to_string ().c_str ()); + pyuw_debug_printf ("frame_id: %s", this_id->to_string ().c_str ()); } /* frame_unwind.prev_register. */ @@ -442,12 +458,14 @@ static struct value * pyuw_prev_register (struct frame_info *this_frame, void **cache_ptr, int regnum) { + PYUW_SCOPED_DEBUG_ENTER_EXIT; + cached_frame_info *cached_frame = (cached_frame_info *) *cache_ptr; cached_reg_t *reg_info = cached_frame->reg; cached_reg_t *reg_info_end = reg_info + cached_frame->reg_count; - TRACE_PY_UNWIND (1, "%s (frame=%p,...,reg=%d)\n", __FUNCTION__, this_frame, - regnum); + pyuw_debug_printf ("frame=%d, reg=%d", + frame_relative_level (this_frame), regnum); for (; reg_info < reg_info_end; ++reg_info) { if (regnum == reg_info->num) @@ -463,14 +481,17 @@ static int pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, void **cache_ptr) { + PYUW_SCOPED_DEBUG_ENTER_EXIT; + struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data); cached_frame_info *cached_frame; gdbpy_enter enter_py (gdbarch, current_language); - TRACE_PY_UNWIND (3, "%s (SP=%s, PC=%s)\n", __FUNCTION__, - paddress (gdbarch, get_frame_sp (this_frame)), - paddress (gdbarch, get_frame_pc (this_frame))); + pyuw_debug_printf ("frame=%d, sp=%s, pc=%s", + frame_relative_level (this_frame), + paddress (gdbarch, get_frame_sp (this_frame)), + paddress (gdbarch, get_frame_pc (this_frame))); /* Create PendingFrame instance to pass to sniffers. */ pending_frame_object *pfo = PyObject_New (pending_frame_object, @@ -554,6 +575,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, } *cache_ptr = cached_frame; + pyuw_debug_printf ("frame claimed"); return 1; } @@ -562,7 +584,7 @@ pyuw_sniffer (const struct frame_unwind *self, struct frame_info *this_frame, static void pyuw_dealloc_cache (struct frame_info *this_frame, void *cache) { - TRACE_PY_UNWIND (3, "%s: enter", __FUNCTION__); + PYUW_SCOPED_DEBUG_ENTER_EXIT; cached_frame_info *cached_frame = (cached_frame_info *) cache; for (int i = 0; i < cached_frame->reg_count; i++) @@ -614,13 +636,13 @@ void _initialize_py_unwind (); void _initialize_py_unwind () { - add_setshow_zuinteger_cmd + add_setshow_boolean_cmd ("py-unwind", class_maintenance, &pyuw_debug, _("Set Python unwinder debugging."), _("Show Python unwinder debugging."), - _("When non-zero, Python unwinder debugging is enabled."), - NULL, + _("When on, Python unwinder debugging is enabled."), NULL, + show_pyuw_debug, &setdebuglist, &showdebuglist); pyuw_gdbarch_data = gdbarch_data_register_post_init (pyuw_gdbarch_data_init); |