From: Yao Qi <qiyaoltc@gmail.com>
To: "Wiederhake\, Tim" <tim.wiederhake@intel.com>
Cc: Joel Brobecker <brobecker@adacore.com>, "Metzger\,
Markus T" <markus.t.metzger@intel.com>,
"gdb-patches\@sourceware.org" <gdb-patches@sourceware.org>,
"xdje42\@gmail.com" <xdje42@gmail.com>
Subject: Re: GDB 8.0 release/branching 2017-03-20 update
Date: Fri, 07 Apr 2017 15:19:00 -0000 [thread overview]
Message-ID: <8660igjled.fsf@gmail.com> (raw)
In-Reply-To: <9676A094AF46E14E8265E7A3F4CCE9AF3C1342D2@IRSMSX106.ger.corp.intel.com> (Tim Wiederhake's message of "Fri, 7 Apr 2017 11:53:02 +0000")
"Wiederhake, Tim" <tim.wiederhake@intel.com> writes:
> Imagine you have some code like this:
>
> void
> a ()
> {
> /* some code */
> }
>
> void
> b ()
> {
> /* some code */
> a ();
> /* some code */
> }
>
> Then the trace for a call to function "b" would generate three function call
> segments: One for the code in "b" before the call to "a", one for the code in
> "a" and one for the code in "b" after the call to "a" returned.
>
> The "next" attribute in the first function segment points to the third function
> segment and likewise the "prev" attribute in the third function segment points
> to the first function segment. For the second function segment the "up"
> attribute points to the first function segment.
>
> "Segment" is used instead of "Call" throughout the btrace code to avoid the
> impression that one function segment contains the whole recorded data for a
> function call whereas it only contains a part of it. I believe we should
> continue this terminology in Python.
>
OK, "Segment" is fine with me.
>> > The user needs to distinguish between instructions and gaps somehow
>> > anyway, and
>> > this solution would let them do so quite nicely. Example code:
>> >
>> > r = gdb.current_recording()
>> > for insn in r.instruction_history:
>> > try:
>> > print insn.pc, insn.sal
>> > except:
>> > # It's a gap!
>> > print insn.error_message
>> >
>> I don't like using exception for control flow.
>
> The above code with the "error" attribute still in place would look like this:
>
> r = gdb.current_recording()
> for insn in r.instruction_history:
> if not insn.error:
> print insn.pc, insn.sal
> else:
> print insn.error_message
>
> The user has to take care about the rare possibility of a gap occurring in the
> trace. In the latter case, they have to explicitly check that the instruction
> they look at is not a gap, which is easy to forget and will lead to strange
> results as the "pc", "sal", "data", "size" and so on attributes of a gap do not
> contain meaningful data.
>
> In the former example, the exception is raised by accessing "insn.pc", an
> attribute that does not exist for a gap. I expect the usual code for the
> "except" path to just contain a "pass" or "continue" statement. I just printed
> the error_message in the example to showcase how this situation would be handled
> if a user desired so.
>
> If you wanted to write this example without handling exceptions, you could do
> so as well:
>
> r = gdb.current_recording()
> for insn in r.instruction_history:
> print getattr(insn, "pc", "has no address"), getattr(insn, "sal", "has no sal")
>
> And even if the user simply wrote:
>
> r = gdb.current_recording()
> for insn in r.instruction_history:
> print insn.pc, insn.sal
>
> there are two cases: The trace contains no gaps (common), or the trace contains
> gaps (uncommon). If the trace did not contain any gaps, the code works as
> expected. If the trace contained gaps, Python will raise an exception pointing
> in the right direction of the problem.
>
> If instead we continued to offer the "error" attribute and the user forgot to
> check, the code would silently fail and produce wrong results. I believe the
> option where we fail loud and clear is favorable over the silently wrong result.
>
>> If I understand "gap"
>> correctly, it is caused something interrupt the tracing.
>
> There might be other causes as well, such as overflows, decoding errors, etc.
> Again, ideally the trace contains no gaps at all, but rarely it may contain one
> or more gaps interleaved with the regular instructions.
>
Is it possible that gap is not caused by error? As I said in previous
mail, user may want to trace a block of instructions, instructions out
of this range are regarded as gap. My point is that we need to define a
general reason in gap instead of error.
>> I'd like to
>> change the interface like this,
>>
>> gdb.InstructionHistory
>> a list of gdb.RecordInstruction
>> gdb.RecordGap (or gdb.RecordStopReason)
>>
>> It saves a list of instructions and why the record is stopped or
>> interrupted. It can be different reasons, like hardware limitation,
>> or user preference (user only wants to record/trace instructions
>> executed in current function foo, so any function calls in foo will
>> cause a gap in the history. In this way, gdb.RecordGap don't have to be
>> an error).
>>
>> gdb.Record.instruction_history returns a list of gdb.InstructionHistory.
>
> Just to make sure: You propose that gdb.Record.instruction_history returns a
> list of partial lists, and each partial list contains the reason why that
> particular partial list was interrupted / stopped, correct?
Yes.
>
> Generating this list of lists would be quite expensive as we have to go over the
> whole list of instructions (that at least for btrace internally /is/ a list of
> instructions interleaved with gap objects), count the gaps and save their
> position to know the length of this list of lists and the start and end of the
> individual sub lists. With the explanation above how to do this without having
> to care about exceptions, would you agree on keeping the list one-dimensional,
> with instructions and rarely gaps interleaved as-is?
OK, that is fine to me.
--
Yao (齐尧)
next prev parent reply other threads:[~2017-04-07 15:19 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-20 20:16 Joel Brobecker
2017-03-20 20:21 ` Keith Seitz
2017-03-20 22:39 ` Yao Qi
2017-03-20 22:47 ` Yao Qi
2017-03-20 22:52 ` Joel Brobecker
2017-03-20 23:03 ` Yao Qi
2017-03-21 13:28 ` Joel Brobecker
2017-03-21 7:35 ` Wiederhake, Tim
2017-03-21 13:28 ` Joel Brobecker
2017-03-21 13:07 ` Yao Qi
2017-03-21 13:31 ` Joel Brobecker
2017-03-22 13:58 ` Metzger, Markus T
2017-03-22 17:09 ` Yao Qi
2017-03-23 16:01 ` Metzger, Markus T
2017-03-23 17:25 ` Yao Qi
2017-03-23 18:17 ` Metzger, Markus T
2017-03-24 14:41 ` Yao Qi
2017-03-27 10:51 ` Metzger, Markus T
2017-03-27 11:19 ` Yao Qi
2017-03-27 12:46 ` Metzger, Markus T
2017-03-27 16:03 ` Yao Qi
2017-03-28 7:16 ` Metzger, Markus T
2017-03-28 13:25 ` Yao Qi
2017-03-28 15:08 ` Metzger, Markus T
2017-03-28 15:49 ` Yao Qi
2017-03-29 6:08 ` Metzger, Markus T
[not found] ` <861stgo072.fsf@gmail.com>
2017-03-29 14:38 ` Metzger, Markus T
2017-03-30 10:50 ` Yao Qi
2017-03-30 11:58 ` Metzger, Markus T
[not found] ` <86h92a4w86.fsf@gmail.com>
2017-03-30 15:55 ` Metzger, Markus T
2017-03-31 13:55 ` Yao Qi
2017-03-31 15:21 ` Metzger, Markus T
2017-03-31 16:02 ` Joel Brobecker
2017-04-06 14:40 ` Wiederhake, Tim
2017-04-07 8:10 ` Yao Qi
2017-04-07 11:53 ` Wiederhake, Tim
2017-04-07 15:19 ` Yao Qi [this message]
2017-03-21 14:00 ` Yao Qi
2017-03-21 14:03 ` Pedro Alves
2017-03-27 13:35 ` Antoine Tremblay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8660igjled.fsf@gmail.com \
--to=qiyaoltc@gmail.com \
--cc=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=markus.t.metzger@intel.com \
--cc=tim.wiederhake@intel.com \
--cc=xdje42@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox