This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC] [PATCH] Provide the ability to write the frame unwinder in Python
- From: Alexander Smundak <asmundak at google dot com>
- To: Andy Wingo <wingo at igalia dot com>
- Cc: Doug Evans <dje at google dot com>, gdb-patches <gdb-patches at sourceware dot org>
- Date: Mon, 16 Mar 2015 10:25:13 -0700
- Subject: Re: [RFC] [PATCH] Provide the ability to write the frame unwinder in Python
- Authentication-results: sourceware.org; auth=none
- References: <CAHQ51u7NUoQ8w9c5mc-Eiz05b1Nub6zqj_Ne7vfgWb5EP9_X8w at mail dot gmail dot com> <21714 dot 40641 dot 510825 dot 30998 at ruffy2 dot mtv dot corp dot google dot com> <CAHQ51u5_ViLaEmv9e43R-wzuWw8dwNkb-2XgCRy5ELQq5FUAWg at mail dot gmail dot com> <54E71694 dot 1080304 at redhat dot com> <CAHQ51u75+9HYAVJXYNQa0gTnQtYKEgmSkyAhAPYp-y4HGtXssg at mail dot gmail dot com> <CAHQ51u6UZ7A47rpGgX0QGeYSTCz1eo_3jWHc=q2ZX3YhqcJ6iQ at mail dot gmail dot com> <87ioei31uj dot fsf at igalia dot com> <CAHQ51u4f+Vx7qXPm-KAAENOceaVogMbDMw6==N_nY+GrLr4Pgg at mail dot gmail dot com> <87d24p19tt dot fsf at igalia dot com> <54FD7DAA dot 7010603 at redhat dot com> <CAHQ51u7sUkGhkmvTaaO_Jo6Jn+kojfiMWHmc2=7OWHThAq6EKw at mail dot gmail dot com> <87twxrncld dot fsf at igalia dot com> <CAHQ51u60nHp1a2DXZ4srvRefyTtge1BUw7-=JuYqChHN_wUGyQ at mail dot gmail dot com> <87ioe1dvu2 dot fsf at igalia dot com>
> 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.