[RFC] [PATCH] Provide the ability to write the frame unwinder in Python

Alexander Smundak asmundak@google.com
Mon Mar 16 17:25:00 GMT 2015


> How about let's meet somewhat halfway.
>
>   * We rename SnifferInfo to EphemeralFrame.
>
>   * Unwinders return UnwindInfo (better name welcome) on success or
>     None/#f otherwise
>
>     * UnwindInfo takes EphemeralFrame as constructor arg
>
>       - the EphemeralFrame must be valid
>
>       - in practice there is only ever one EphemeralFrame alive because
>         unwinding is not recursive
>
>     * UnwindInfo also takes frame ID as positional constructor args
>
>       - setting frame_id is the only thing an unwinder *must* do, so
>         this makes an invariant "if return value is an UnwindInfo, then
>         it is valid and has all necessary info"
>
>     * UnwindInfo has add_saved_register() API (see discussion with Pedro
>       here: http://article.gmane.org/gmane.comp.gdb.patches/105538)
>
>   * After accepting an UnwindInfo as an unwinder return result,
>     py-unwinders.c / scm-frame-unwinders.c marks the UnwindInfo as
>     frozen so that add_saved_register() etc can't alter the state
>
>   * continuation of unwinder call also checks that the ephemeral frame
>     on the unwindinfo is valid
>
> Example of use:
>
>    def unwind(frame):
>        if we_can_handle(frame):
>            var ret = UnwindInfo(frame, fp, pc)
>            ret.add_saved_register(r0)
>            return ret
>
> I will rework the Guile patch along these lines, and then hopefully I am
> done reworking :)

I'd like to propose one improvement on the Python side: UnwinderInfo
is constructed by a frame method instead of an implicit constructor.
I.e., frame.create_frame_with_id(sp, pc) returns UnwindInfo instance
whose ID is the result of calling GDB's frame_id_build(sp, pc),
frame.create_frame_with_id_wild(sp) returns UnwindInfo instance
whose ID is the results of calling frame_id_build_wild(sp), etc.

The example above would then look as follows:
  def unwind(frame):
    if we_can_handle(frame):
      unwind_info = frame.create_frame_with_id(sp, pc)
      unwind_info.set_previous_frame_register("r0", r0)
      unwind_info.set_previous_frame_register(...)
      return unwind_info
    else
      return None

Would this work for Guile?

As to the class of an object passed to a sniffer, how about calling it
FrameData? Note that it's not very important from the user's point of
view as sniffer code does not ever reference it by name.



More information about the Gdb-patches mailing list