Bug 456116 - [launch] Can only use final class fields in GdbLaunchDelegate
Summary: [launch] Can only use final class fields in GdbLaunchDelegate
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 8.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-23 20:37 EST by Marc Khouzam CLA
Modified: 2020-09-04 15:24 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Khouzam CLA 2014-12-23 20:37:12 EST
This bug affects GdbLaunchDelegate and its base class AbstractCLaunchDelegate2, but the problem applies to our legacy launch delegates also and AbstractCLaunchDelegate

Mikhail pointed out in review https://git.eclipse.org/r/#/c/38679/3/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbLaunchDelegate.java :

"There is a problem with storing launch related data in the launch delegate. There is only one instance of a launch delegate is created for an Eclipse session. If two launches start in parallel their data will be mixed up. The only reason we haven't seen this issue yet is because we never start two launchers in parallel."

We could possibly trigger such a bug when using a LaunchGroup which would launch multiple GdbLaunchDelegate at the same time.
Comment 1 Elena Laskavaia CLA 2014-12-23 21:38:42 EST
We may not be able to overcome this easily. Launch delegate API does
not always pass launch object around which makes it extremly difficult to deal with, since GdbLaunchDelegate is probably an API class on its own we may not be able even to change its methods to pass around an additional object...

This situation will be exterimly rare. You need exact same delegate, and launch two diffrent LC at the same time without waiting (And yes you can do it with launch group).
Comment 2 Marc Khouzam CLA 2016-02-19 06:21:02 EST
I've posted a patch that removes the one field in GdbLaunchDelegate.  I wanted to take advantage of CDT 9.0 to clean that up.  It was not trivial, but I believe I got a working solution.

The patch breaks the API as expected but I think it is worth it for the sake of correctness.
Comment 3 Marc Khouzam CLA 2016-02-19 06:54:49 EST
I've realized that we are safe to use final class fields for our launch delegates.  Final fields are specified by the constructor and remain constant for the life of the class, so they are not affected by the issue of parallel launches.

We actually use such a field in AbstractCLaunchDelegate2.requireCProject to allow different overriding launch delegates to behave differently.  Since each of these overriding delegates has its own instance, this field is safe.  I'll make it final for completeness.
Comment 4 Eclipse Genie CLA 2016-02-19 06:59:59 EST
New Gerrit change created: https://git.eclipse.org/r/66921
Comment 7 Martin Oberhuber CLA 2016-03-13 06:51:10 EDT
I really appreciate the efforts cleaning this up, but the change breaks the TCF/TE Launcher for CDT, see https://git.eclipse.org/r/#/c/68276/1

We really need TCF to be compatible with both CDT 9.0 and 8.x from single source.

Could GdbLaunchDelegate offer a cleanupLaunch() method that can be called like in 8.x (for backward compatibility) while still offering the new feature of passing the Launch around ?
Comment 8 Eclipse Genie CLA 2016-03-13 11:16:58 EDT
New Gerrit change created: https://git.eclipse.org/r/68295
Comment 9 Jonah Graham CLA 2016-03-13 11:28:22 EDT
(In reply to Martin Oberhuber from comment #7)
> I really appreciate the efforts cleaning this up, but the change breaks the
> TCF/TE Launcher for CDT, see https://git.eclipse.org/r/#/c/68276/1
> 
> We really need TCF to be compatible with both CDT 9.0 and 8.x from single
> source.
> 
> Could GdbLaunchDelegate offer a cleanupLaunch() method that can be called
> like in 8.x (for backward compatibility) while still offering the new
> feature of passing the Launch around ?

The change in GdbLaunchDelegate needs to be resolved in either CDT side or TCF side. To this end I provide two possible implementations.

1) Add cleanupLaunch() back in to CDT, but deprecated and never called by CDT. This is https://git.eclipse.org/r/68295 
2) Copy cleanupLaunch into TCF, but deprecate it until TCF no longer wants to support CDT < 9.0 at which point it should be removed and replaced with the new API in CDT. This is https://git.eclipse.org/r/68276

Someone needs to decide which one of these options is the best fit going forward.
Comment 10 Jonah Graham CLA 2016-05-20 17:07:33 EDT
> Someone needs to decide which one of these options is the best fit going
> forward.
It was decided a while ago to go with option 2:

> 2) Copy cleanupLaunch into TCF, but deprecate it until TCF no longer wants
> to support CDT < 9.0 at which point it should be removed and replaced with
> the new API in CDT. This is https://git.eclipse.org/r/68276
Comment 11 Jonah Graham CLA 2016-05-25 06:40:38 EDT
I added an additional entry to the API changes in N&N for this change:

# '''GdbLaunchDelegate.getLaunch()''' no longer initializes the launch. Initializing the launch needs to be done in '''launchDebugSession''' if overridden by calling '''launch.initialize()'''.

It is an interesting one because this is a case where API tooling does not tell you anything. But if you override launchDebugSession but not getLaunch the the launch in CDT 8.x was initialized but in CDT 9.x is not initialized.
Comment 12 Marc Khouzam CLA 2016-05-25 13:35:33 EDT
(In reply to Jonah Graham from comment #11)

> It is an interesting one because this is a case where API tooling does not
> tell you anything. But if you override launchDebugSession but not getLaunch
> the the launch in CDT 8.x was initialized but in CDT 9.x is not initialized.

These changes probably happen more often that they should.  They are hard to track as you mention.  They need to be caught in code reviews.

That being said, if we considered code behaviour as API, it would make it very hard to fix some bugs.  I personally have always worried about such changes, but no one has spoken out against them, so I've grown hopeful that extenders do sufficient testing to catch major behavioural changes such as this one.

Thanks for documenting, it will help.