Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 346320 - [tracepoints] Add support for fast tracepoints
Summary: [tracepoints] Add support for fast tracepoints
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 8.0   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: 8.1.0   Edit
Assignee: Marc Khouzam CLA
QA Contact: Marc Khouzam CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 352759
  Show dependency tree
 
Reported: 2011-05-18 15:11 EDT by Marc Khouzam CLA
Modified: 2012-02-23 11:33 EST (History)
3 users (show)

See Also:
nobody: review+


Attachments
Patch for fast tracepoints and JUnit tests (51.21 KB, patch)
2011-06-01 14:56 EDT, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff
Patch for fast tracepoints and JUnit tests 2 (52.41 KB, patch)
2011-06-01 15:00 EDT, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff
Patch for fast tracepoints and multi-thread JUnit tests (56.13 KB, patch)
2011-06-03 09:51 EDT, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff
Patch for fast tracepoints with launch preference and multi-thread JUnit tests (64.06 KB, patch)
2011-06-20 14:36 EDT, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff
Patch for fast tracepoints with launch preference and multi-thread JUnit tests 2 (64.60 KB, patch)
2011-06-20 15:05 EDT, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff
Patch for fast tracepoints with launch preference and multi-thread JUnit tests 3 (108.95 KB, patch)
2011-07-20 09:44 EDT, Marc Khouzam CLA
marc.khouzam: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Khouzam CLA 2011-05-18 15:11:17 EDT
GDB supports the concepts of fast tracepoints.  A fast tracepoint is a tracepoint that does not use a trap to collect the information.  Instead, an instruction of the program is replaced by a jump to a the collect commands.  

The value of fast tracepoints is that they are very efficient and non-intrusive.

The drawbacks of fast tracepoints are:
1- the program needs to be compiled with a special gdb library that supports fast tracepoints.  This library takes care of modifying the program to insert the fast tracepoint jump operation
2- fast tracepoints can only be inserted at location where the opcode is at least 5 bytes to allow for a bug enough jump.

DSF-GDB should make use of fast tracepoints when possible.
Comment 1 Marc Khouzam CLA 2011-05-18 16:14:40 EDT
Here are some thoughts I've had about supporting fast tracepoints.

Things to consider are:
1- gdbserver 7.2 supports fast tracepoints
2- some other remote targets may not support fast tracepoints
3- some remote targets may only allow fast tracepoints (e.g., when GDB's observer mode is enabled)
4- fast tracepoints will fail for certain locations (opcode < 5 bytes)
5- with gdbserver fast tracepoints will not be supported if the the program was not compiled with the in-process library

Option 1: 

Always attempt to set a fast tracepoint.  If it fails, then try a normal tracepoint

Option 2: 

Have some UI to allow the user to choose between:
- set a fast tracepoint only
- set a normal tracepoint only
- set a fast tracepoint and if it fails, set a normal tracepoint (option 1)

Option 3:

Have some UI to allow the user to choose between:
- set a fast tracepoint only
- set a fast tracepoint and if it fails, set a normal tracepoint (option 1)

This could be through a preference "Create normal tracepoint when fast tracepoints
cannot be set".

Other aspects besides ability to set fast tracepoints:
1- special decorator showing that a tracepoints has been installed as a fast tracepoint
2- indication in editor/disassemblyView to show which lines of code support fast tracepoint
Comment 2 Marc Khouzam CLA 2011-06-01 14:56:51 EDT
Created attachment 197146 [details]
Patch for fast tracepoints and JUnit tests

This patch always attempt to set a fast tracepoint and if it fails, then tries a normal (slow) tracepoint.  

The patch codes the service to allow for different settings: "fast then slow", "fast only", "slow only".  I'm not sure we will want to present the user with such choices yet, so I'm only putting the logic in the service and defaulting it to "fast then slow".
Comment 3 Marc Khouzam CLA 2011-06-01 14:58:10 EDT
The patch I just attach also contains the fix to Bug 347196 and the one for Bug 346215
Comment 4 Marc Khouzam CLA 2011-06-01 15:00:08 EDT
Created attachment 197147 [details]
Patch for fast tracepoints and JUnit tests 2

I noticed I had an unsaved file when I generated the previous patch.  This one is correct.
Comment 5 Marc Khouzam CLA 2011-06-03 09:51:33 EDT
Created attachment 197301 [details]
Patch for fast tracepoints and multi-thread JUnit tests

I updated the JUnit tests to be multi-threaded
Comment 6 Marc Khouzam CLA 2011-06-20 14:36:10 EDT
Created attachment 198277 [details]
Patch for fast tracepoints with launch preference and multi-thread JUnit tests

The behavior of GDB with fast tracepoints is not what I originally thought.  It turns out that creating a fast tp may succeed, but when starting the tracing experiment, installation will fail.  This can happen for example:
1- if the inferior was not compiled with in-process trace library
or
2- if the option 'set may-insert-fast-tracepoints' is off

on the other hand, if a fast tracepoint does not fit at the chosen location, GDB will report that failure immediately:

080,054 [MI]  19-break-insert --thread-group i1 -h -a -f TracepointTestApp.cc:109
080,058 [MI]  19^error,msg="May not have a fast tracepoint at 0x0x80486c4; instruction is only 4 bytes long, need at least 5 bytes for the jump"

This means that the use of a fast vs slow tracepoint depends on the support of the target, which we cannot know in advance.

Therefore, I think we need to let the user choose if the launch should use fast/slow/automatic.  With such a scheme, the user can create tracepoints and use them on different targets, by simply telling the launch if the tracepoints should be created fast or not on that particular target.

This patch does this by adding a launch configuration combo box to the Debugger tab.  As before, the patch also contains the fix to Bug 347196 and the one for Bug 346215.

The patch is in git format.
Comment 7 Marc Khouzam CLA 2011-06-20 15:05:26 EDT
Created attachment 198281 [details]
Patch for fast tracepoints with launch preference and multi-thread JUnit tests 2

A small change missing for the JUnit tests to work.  As before, the patch also contains the fix to Bug 347196 and the one for Bug 346215.
Comment 8 Marc Khouzam CLA 2011-07-20 09:44:32 EDT
Created attachment 200000 [details]
Patch for fast tracepoints with launch preference and multi-thread JUnit tests 3

Now that Bug 347196 and Bug 346215 have been committed, I updated the fast tracepoint patch for the latest master.
Comment 9 Marc Khouzam CLA 2011-07-25 15:49:18 EDT
(In reply to comment #8)
> Created attachment 200000 [details]
> Patch for fast tracepoints with launch preference and multi-thread JUnit tests
> 3
> 
> Now that Bug 347196 and Bug 346215 have been committed, I updated the fast
> tracepoint patch for the latest master.

I still don't have a way to hide the launch UI for tracepoints based on the actionSet.  I will commit this patch because I would like to have it available, but I'll open a new bug for hiding the UI.

So, committed to master.
Comment 10 Marc Khouzam CLA 2011-07-25 15:53:53 EDT
Mikhail, if/when you are ever interested in looking at how GDB handles fast tracepoints, then maybe you can review this fix?

Note that the biggest part of the patch are JUnit tests.  The actual logic is pretty small, and simply lets the user choose in the launch if they want:
1- always use fast tp
2- always use slow tp
3- try fast tp and if it fails automatically try slow tp

After that, to set a fast tp, we simply add the -h flag to -break-insert for tracepoints, and let gdb do the rest.
Comment 11 Marc Khouzam CLA 2011-07-25 16:02:59 EDT
I've opened Bug 353040 about hiding the new "fast vs slow tracepoint" launch option
Comment 12 CDT Genie CLA 2011-07-25 16:18:50 EDT
*** cdt git genie on behalf of 346320 ***

    Bug 346320: Add support for fast tracepoints

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=d592d691aaa79832843e991734a3ef2c1a819c40
Comment 13 Nobody - feel free to take it CLA 2011-07-25 17:34:31 EDT
The patch seems to be OK. My only concern is that I don't see the error message in the gdb console when setting a fast tracepoint fails. It looks like a GDB problem though.
Comment 14 Marc Khouzam CLA 2011-07-28 10:16:33 EDT
(In reply to comment #13)
> The patch seems to be OK. My only concern is that I don't see the error message
> in the gdb console when setting a fast tracepoint fails. It looks like a GDB
> problem though.

Should there be an error in the console?  I created a normal breakpoint with an invalid condition, and there was no error in the console.  I also tried CDI and set a breakpoint in a file not part of the debug session, and again no error in the console.

I never actually thought about what should be shown as errors in the console or should not.
Comment 15 Nobody - feel free to take it CLA 2011-07-28 10:39:39 EDT
(In reply to comment #14)
> Should there be an error in the console?  I created a normal breakpoint with an
> invalid condition, and there was no error in the console.  I also tried CDI and
> set a breakpoint in a file not part of the debug session, and again no error in
> the console.
> 
> I never actually thought about what should be shown as errors in the console or
> should not.

We don't write anything to the console, GDB does. In this case it looks like a GDB issue - nothing is written to the log stream and as a result doesn't appear in the GDB console.
Re your example with invalid condition, I thought something would appear in the console when the breakpoint hit. If not it's a bug in GDB.
Comment 16 Marc Khouzam CLA 2011-07-28 10:59:41 EDT
(In reply to comment #15)

> We don't write anything to the console, GDB does. In this case it looks like a
> GDB issue - nothing is written to the log stream and as a result doesn't appear
> in the GDB console.
> Re your example with invalid condition, I thought something would appear in the
> console when the breakpoint hit. If not it's a bug in GDB.

Right, so in both my attempts (invalid condition and invalid breakpoint file), GDB wrote nothing to the log stream.  I thought that was normal...
Comment 17 Nobody - feel free to take it CLA 2011-07-28 11:04:24 EDT
(In reply to comment #16)
> Right, so in both my attempts (invalid condition and invalid breakpoint file),
> GDB wrote nothing to the log stream.  I thought that was normal...
I just compared the MI output for setting an invalid breakpoint and tracepoint. In case of breakpoint GDB writes the error message to the log, but it doesn't write it in case of tracepoint.
Comment 18 Marc Khouzam CLA 2011-07-28 11:17:39 EDT
(In reply to comment #17)
> (In reply to comment #16)
> > Right, so in both my attempts (invalid condition and invalid breakpoint file),
> > GDB wrote nothing to the log stream.  I thought that was normal...
> I just compared the MI output for setting an invalid breakpoint and tracepoint.
> In case of breakpoint GDB writes the error message to the log, but it doesn't
> write it in case of tracepoint.

Just curious, what is the command you gave to see the error for breakpoints?
Comment 19 Nobody - feel free to take it CLA 2011-07-28 11:22:45 EDT
(In reply to comment #18)
> Just curious, what is the command you gave to see the error for breakpoints?
I just had a breakpoint in my workspace set on a file that wasn't in my project. In this case GDB sets a pending breakpoint and reports an error.
Comment 20 Marc Khouzam CLA 2011-07-28 12:24:41 EDT
(In reply to comment #19)
> (In reply to comment #18)
> > Just curious, what is the command you gave to see the error for breakpoints?
> I just had a breakpoint in my workspace set on a file that wasn't in my
> project. In this case GDB sets a pending breakpoint and reports an error.

You are right.
Strangely, if we turn off pending breakpoints, then GDB does not write to the log for bad breakpoints:

246,497 [MI]  36-break-insert --thread-group i1 /home/lmckhou/runtime-TestDSF/Producer/src/Producer.cpp:175
246,506 [MI]  36^error,msg="No source file named /home/lmckhou/runtime-TestDSF/Producer/src/Producer.cpp."

It may be that printing an error to the log for pending breakpoints is the bug.
Comment 21 Nobody - feel free to take it CLA 2011-07-28 12:28:21 EDT
(In reply to comment #20)
> Strangely, if we turn off pending breakpoints, then GDB does not write to the
> log for bad breakpoints:
> 
> 246,497 [MI]  36-break-insert --thread-group i1
> /home/lmckhou/runtime-TestDSF/Producer/src/Producer.cpp:175
> 246,506 [MI]  36^error,msg="No source file named
> /home/lmckhou/runtime-TestDSF/Producer/src/Producer.cpp."
> 
> It may be that printing an error to the log for pending breakpoints is the bug.

This is strange. I remember this message appearing in the console long before the pending breakpoints were introduced.
Comment 22 Marc Khouzam CLA 2011-07-28 13:38:04 EDT
(In reply to comment #21)

> This is strange. I remember this message appearing in the console long before
> the pending breakpoints were introduced.

You're right, it happens with GDB 6.8, but no longer starting with GDB 7.0.  I guess they removed it.
Comment 23 Nobody - feel free to take it CLA 2011-07-28 13:44:39 EDT
(In reply to comment #22)
> You're right, it happens with GDB 6.8, but no longer starting with GDB 7.0.  I
> guess they removed it.

It is even stranger. Why they didn't remove it for pending breakpoints?
Anyway, I think we should address the error handling of breakpoints (and tracepoints?) in the new UI for target breakpoints.
Comment 24 Marc Khouzam CLA 2011-07-28 13:45:38 EDT
(In reply to comment #23)
> (In reply to comment #22)
> > You're right, it happens with GDB 6.8, but no longer starting with GDB 7.0.  I
> > guess they removed it.
> 
> It is even stranger. Why they didn't remove it for pending breakpoints?

Probably forgot :-)

> Anyway, I think we should address the error handling of breakpoints (and
> tracepoints?) in the new UI for target breakpoints.

Sounds good.