Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 246819 | Differences between
and this patch

Collapse All | Expand All

(-)a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/AST2Bytecode.java (-2 / +9 lines)
 Lines 58-63    Link Here 
58
import java.util.ArrayList;
58
import java.util.ArrayList;
59
import java.util.List;
59
import java.util.List;
60
import java.util.Map;
60
import java.util.Map;
61
import javax.lang.model.element.Element;
62
import javax.lang.model.element.Modifier;
61
import javax.lang.model.element.TypeElement;
63
import javax.lang.model.element.TypeElement;
62
import javax.lang.model.element.TypeParameterElement;
64
import javax.lang.model.element.TypeParameterElement;
63
import javax.lang.model.type.ArrayType;
65
import javax.lang.model.type.ArrayType;
 Lines 150-155    Link Here 
150
                if (from < to) { // We have the method call
152
                if (from < to) { // We have the method call
151
                    TreePath nodePath = trees.getPath(cu, node);
153
                    TreePath nodePath = trees.getPath(cu, node);
152
                    if (nodePath != null && !ci.getTreeUtilities().isSynthetic(nodePath)) {
154
                    if (nodePath != null && !ci.getTreeUtilities().isSynthetic(nodePath)) {
155
                        // Find if 'node' is a native method:
156
                        Element methodElement = ci.getTrees().getElement(nodePath);
157
                        boolean isNativeMethod = (methodElement != null) && methodElement.getModifiers().contains(Modifier.NATIVE);
158
                        //System.err.println("Method "+methodElement+" is native = "+isNativeMethod);
153
                        String methodNameInBytecode = null;
159
                        String methodNameInBytecode = null;
154
                        String methodDescriptorInBytecode = null;
160
                        String methodDescriptorInBytecode = null;
155
                        if (constantPool != null) {
161
                        if (constantPool != null) {
 Lines 358-364    Link Here 
358
                                        methodEndPosition,
364
                                        methodEndPosition,
359
                                        methodName,
365
                                        methodName,
360
                                        methodClassType,
366
                                        methodClassType,
361
                                        from
367
                                        from,
368
                                        isNativeMethod
362
                                );
369
                                );
363
                        try {
370
                        try {
364
                            java.lang.reflect.Field methodDescriptorField = EditorContext.Operation.class.getDeclaredField("methodDescriptor");
371
                            java.lang.reflect.Field methodDescriptorField = EditorContext.Operation.class.getDeclaredField("methodDescriptor");
 Lines 606-612    Link Here 
606
                    EditorContext.Position methodStartPosition,
613
                    EditorContext.Position methodStartPosition,
607
                    EditorContext.Position methodEndPosition,
614
                    EditorContext.Position methodEndPosition,
608
                    String methodName, String methodClassType,
615
                    String methodName, String methodClassType,
609
                    int bytecodeIndex);
616
                    int bytecodeIndex, boolean isNative);
610
            
617
            
611
            EditorContext.Position createPosition(int offset, int line, int column);
618
            EditorContext.Position createPosition(int offset, int line, int column);
612
            
619
            
(-)a/debugger.jpda.projects/src/org/netbeans/modules/debugger/jpda/projects/EditorContextImpl.java (-2 / +3 lines)
 Lines 2969-2975    Link Here 
2969
                 Position methodEndPosition,
2969
                 Position methodEndPosition,
2970
                 String methodName,
2970
                 String methodName,
2971
                 String methodClassType,
2971
                 String methodClassType,
2972
                 int bytecodeIndex) {
2972
                 int bytecodeIndex,
2973
                 boolean isNative) {
2973
             return EditorContextImpl.this.createMethodOperation(
2974
             return EditorContextImpl.this.createMethodOperation(
2974
                     startPosition,
2975
                     startPosition,
2975
                     endPosition,
2976
                     endPosition,
 Lines 2977-2983    Link Here 
2977
                     methodEndPosition,
2978
                     methodEndPosition,
2978
                     methodName,
2979
                     methodName,
2979
                     methodClassType,
2980
                     methodClassType,
2980
                     bytecodeIndex);
2981
                     bytecodeIndex, isNative);
2981
         }
2982
         }
2982
        @Override
2983
        @Override
2983
         public Position createPosition(
2984
         public Position createPosition(
(-)a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/actions/MethodChooserSupport.java (-6 / +11 lines)
 Lines 195-205    Link Here 
195
    public void doStepInto() {
195
    public void doStepInto() {
196
        final int index = chooser.getSelectedIndex();
196
        final int index = chooser.getSelectedIndex();
197
        final String name = operations[index].getMethodName();
197
        final String name = operations[index].getMethodName();
198
        final boolean isNative = operations[index].isNative();
199
        final String methodClassType = operations[index].getMethodClassType();
198
        debugger.getRequestProcessor().post(new Runnable() {
200
        debugger.getRequestProcessor().post(new Runnable() {
199
            @Override
201
            @Override
200
            public void run() {
202
            public void run() {
201
                RunIntoMethodActionProvider.doAction(debugger, name, locations[index],
203
                RunIntoMethodActionProvider.doAction(debugger, name, methodClassType, isNative,
202
                                                     expressionLines, true, MethodEntry.SELECTED);
204
                                                     locations[index], expressionLines, true,
205
                                                     MethodEntry.SELECTED);
203
            }
206
            }
204
        });
207
        });
205
    }
208
    }
 Lines 376-387    Link Here 
376
379
377
        if (operations.length == 1) {
380
        if (operations.length == 1) {
378
            // do not show UI, continue directly using the selection
381
            // do not show UI, continue directly using the selection
379
            String name = operations[selectedIndex].getMethodName();
382
            Operation op = operations[selectedIndex];
383
            String name = op.getMethodName();
380
            if ("<init>".equals(name)) {
384
            if ("<init>".equals(name)) {
381
                name = operations[selectedIndex].getMethodClassType();
385
                name = op.getMethodClassType();
382
            }
386
            }
383
            RunIntoMethodActionProvider.doAction(debugger, name, locations[selectedIndex],
387
            RunIntoMethodActionProvider.doAction(debugger, name, op.getMethodClassType(), op.isNative(),
384
                                                 expr.getInterval(), true, MethodEntry.DIRECT);
388
                                                 locations[selectedIndex], expr.getInterval(),
389
                                                 true, MethodEntry.DIRECT);
385
            return true;
390
            return true;
386
        }
391
        }
387
        return false;
392
        return false;
(-)a/debugger.jpda/src/org/netbeans/modules/debugger/jpda/actions/RunIntoMethodActionProvider.java (-18 / +75 lines)
 Lines 52-57    Link Here 
52
import com.sun.jdi.ThreadReference;
52
import com.sun.jdi.ThreadReference;
53
import com.sun.jdi.VMDisconnectedException;
53
import com.sun.jdi.VMDisconnectedException;
54
import com.sun.jdi.VirtualMachine;
54
import com.sun.jdi.VirtualMachine;
55
import com.sun.jdi.connect.Connector;
55
import com.sun.jdi.event.BreakpointEvent;
56
import com.sun.jdi.event.BreakpointEvent;
56
import com.sun.jdi.event.Event;
57
import com.sun.jdi.event.Event;
57
import com.sun.jdi.request.BreakpointRequest;
58
import com.sun.jdi.request.BreakpointRequest;
 Lines 59-83    Link Here 
59
import java.beans.PropertyChangeEvent;
60
import java.beans.PropertyChangeEvent;
60
import java.beans.PropertyChangeListener;
61
import java.beans.PropertyChangeListener;
61
import java.lang.reflect.InvocationTargetException;
62
import java.lang.reflect.InvocationTargetException;
62
63
import java.util.Collections;
63
import java.util.Collections;
64
import java.util.HashMap;
64
import java.util.List;
65
import java.util.List;
66
import java.util.Map;
65
import java.util.Set;
67
import java.util.Set;
68
import java.util.concurrent.locks.Lock;
66
import java.util.logging.Level;
69
import java.util.logging.Level;
67
import java.util.logging.Logger;
70
import java.util.logging.Logger;
68
import javax.swing.SwingUtilities;
71
import javax.swing.SwingUtilities;
69
import org.netbeans.api.debugger.ActionsManager;
72
import org.netbeans.api.debugger.ActionsManager;
70
import org.netbeans.api.debugger.ActionsManagerListener;
73
import org.netbeans.api.debugger.ActionsManagerListener;
71
import org.netbeans.api.debugger.DebuggerManager;
74
import org.netbeans.api.debugger.DebuggerManager;
72
import org.netbeans.spi.debugger.ContextProvider;
73
import org.netbeans.api.debugger.Session;
75
import org.netbeans.api.debugger.Session;
76
import org.netbeans.api.debugger.SessionBridge;
77
import org.netbeans.api.debugger.jpda.AttachingDICookie;
74
import org.netbeans.api.debugger.jpda.CallStackFrame;
78
import org.netbeans.api.debugger.jpda.CallStackFrame;
75
import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
79
import org.netbeans.api.debugger.jpda.ClassLoadUnloadBreakpoint;
76
import org.netbeans.api.debugger.jpda.JPDADebugger;
80
import org.netbeans.api.debugger.jpda.JPDADebugger;
77
import org.netbeans.api.debugger.jpda.event.JPDABreakpointListener;
78
import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent;
79
import org.netbeans.api.debugger.jpda.JPDAStep;
81
import org.netbeans.api.debugger.jpda.JPDAStep;
80
import org.netbeans.api.debugger.jpda.JPDAThread;
82
import org.netbeans.api.debugger.jpda.JPDAThread;
83
import org.netbeans.api.debugger.jpda.ListeningDICookie;
84
import org.netbeans.api.debugger.jpda.event.JPDABreakpointEvent;
85
import org.netbeans.api.debugger.jpda.event.JPDABreakpointListener;
81
import org.netbeans.modules.debugger.jpda.EditorContextBridge;
86
import org.netbeans.modules.debugger.jpda.EditorContextBridge;
82
import org.netbeans.modules.debugger.jpda.ExpressionPool.Expression;
87
import org.netbeans.modules.debugger.jpda.ExpressionPool.Expression;
83
import org.netbeans.modules.debugger.jpda.ExpressionPool.Interval;
88
import org.netbeans.modules.debugger.jpda.ExpressionPool.Interval;
 Lines 97-114    Link Here 
97
import org.netbeans.modules.debugger.jpda.jdi.VirtualMachineWrapper;
102
import org.netbeans.modules.debugger.jpda.jdi.VirtualMachineWrapper;
98
import org.netbeans.modules.debugger.jpda.jdi.request.EventRequestManagerWrapper;
103
import org.netbeans.modules.debugger.jpda.jdi.request.EventRequestManagerWrapper;
99
import org.netbeans.modules.debugger.jpda.jdi.request.EventRequestWrapper;
104
import org.netbeans.modules.debugger.jpda.jdi.request.EventRequestWrapper;
100
import org.netbeans.spi.debugger.ActionsProviderSupport;
101
import org.openide.DialogDisplayer;
102
import org.openide.NotifyDescriptor;
103
104
import org.netbeans.modules.debugger.jpda.models.CallStackFrameImpl;
105
import org.netbeans.modules.debugger.jpda.models.CallStackFrameImpl;
105
import org.netbeans.modules.debugger.jpda.models.JPDAThreadImpl;
106
import org.netbeans.modules.debugger.jpda.models.JPDAThreadImpl;
106
import org.netbeans.modules.debugger.jpda.util.Executor;
107
import org.netbeans.modules.debugger.jpda.util.Executor;
107
import org.netbeans.spi.debugger.ActionsProvider;
108
import org.netbeans.spi.debugger.ActionsProvider;
109
import org.netbeans.spi.debugger.ActionsProviderSupport;
110
import org.netbeans.spi.debugger.ContextProvider;
108
import org.netbeans.spi.debugger.jpda.EditorContext;
111
import org.netbeans.spi.debugger.jpda.EditorContext;
109
import org.netbeans.spi.debugger.jpda.EditorContext.Operation;
112
import org.netbeans.spi.debugger.jpda.EditorContext.Operation;
113
import org.openide.DialogDisplayer;
110
import org.openide.ErrorManager;
114
import org.openide.ErrorManager;
111
115
import org.openide.NotifyDescriptor;
112
import org.openide.util.Exceptions;
116
import org.openide.util.Exceptions;
113
import org.openide.util.NbBundle;
117
import org.openide.util.NbBundle;
114
118
 Lines 321-326    Link Here 
321
        Expression expr = debugger.getExpressionPool().getExpressionAt(locations.get(0), url);
325
        Expression expr = debugger.getExpressionPool().getExpressionAt(locations.get(0), url);
322
        Location bpLocation = null;
326
        Location bpLocation = null;
323
        Interval expressionLines = null;
327
        Interval expressionLines = null;
328
        String methodClassType = null;
329
        boolean isNative = false;
324
        if (expr != null) {
330
        if (expr != null) {
325
            Operation[] ops = expr.getOperations();
331
            Operation[] ops = expr.getOperations();
326
            for (int i = 0; i < ops.length; i++) {
332
            for (int i = 0; i < ops.length; i++) {
 Lines 329-334    Link Here 
329
                    methodOffset <= op.getMethodEndPosition().getOffset()) {
335
                    methodOffset <= op.getMethodEndPosition().getOffset()) {
330
                    
336
                    
331
                    bpLocation = expr.getLocations()[i];
337
                    bpLocation = expr.getLocations()[i];
338
                    methodClassType = op.getMethodClassType();
339
                    isNative = op.isNative();
332
                    break;
340
                    break;
333
                }
341
                }
334
            }
342
            }
 Lines 337-359    Link Here 
337
        if (bpLocation == null) {
345
        if (bpLocation == null) {
338
            bpLocation = locations.get(0);
346
            bpLocation = locations.get(0);
339
        }
347
        }
340
        doAction(debugger, methodName, bpLocation, expressionLines, false, doResume,
348
        doAction(debugger, methodName, methodClassType, isNative, bpLocation,
341
                 MethodChooserSupport.MethodEntry.SELECTED);
349
                  expressionLines, false, doResume,
350
                  MethodChooserSupport.MethodEntry.SELECTED);
342
    }
351
    }
343
352
344
    static boolean doAction(final JPDADebuggerImpl debugger,
353
    static boolean doAction(final JPDADebuggerImpl debugger,
345
                            final String methodName,
354
                            final String methodName,
355
                            final String methodClassType,
356
                            final boolean isNative,
346
                            Location bpLocation,
357
                            Location bpLocation,
347
                            Interval expressionLines,
358
                            Interval expressionLines,
348
                            // If it's important not to run far from the expression
359
                            // If it's important not to run far from the expression
349
                            boolean setBoundaryStep,
360
                            boolean setBoundaryStep,
350
                            MethodChooserSupport.MethodEntry methodEntry) {
361
                            MethodChooserSupport.MethodEntry methodEntry) {
351
        
362
        
352
        return doAction(debugger, methodName, bpLocation, expressionLines, setBoundaryStep, true, methodEntry);
363
        return doAction(debugger, methodName, methodClassType, isNative, bpLocation, expressionLines, setBoundaryStep, true, methodEntry);
353
    }
364
    }
354
365
355
    private static boolean doAction(final JPDADebuggerImpl debugger,
366
    private static boolean doAction(final JPDADebuggerImpl debugger,
356
                                    final String methodName,
367
                                    final String methodName,
368
                                    final String methodClassType,
369
                                    final boolean isNative,
357
                                    Location bpLocation,
370
                                    Location bpLocation,
358
                                    // If it's important not to run far from the expression
371
                                    // If it's important not to run far from the expression
359
                                    Interval expressionLines,
372
                                    Interval expressionLines,
 Lines 395-402    Link Here 
395
        logger.log(Level.FINE, "doAction() areWeOnTheLocation = {0}, methodName = {1}", new Object[]{areWeOnTheLocation, methodName});
408
        logger.log(Level.FINE, "doAction() areWeOnTheLocation = {0}, methodName = {1}", new Object[]{areWeOnTheLocation, methodName});
396
        if (areWeOnTheLocation) {
409
        if (areWeOnTheLocation) {
397
            // We're on the line from which the method is called
410
            // We're on the line from which the method is called
398
            traceLineForMethod(debugger, ct.getThreadReference(), methodName,
411
            traceLineForMethod(debugger, ct, methodName,
399
                               line, doFinishWhenMethodNotFound, methodEntry);
412
                               methodClassType, isNative, line,
413
                               doFinishWhenMethodNotFound, methodEntry);
400
        } else {
414
        } else {
401
            final JPDAStep[] boundaryStepPtr = new JPDAStep[] { null };
415
            final JPDAStep[] boundaryStepPtr = new JPDAStep[] { null };
402
            // Submit the breakpoint to get to the point from which the method is called
416
            // Submit the breakpoint to get to the point from which the method is called
 Lines 465-472    Link Here 
465
                        } catch (VMDisconnectedExceptionWrapper e) {
479
                        } catch (VMDisconnectedExceptionWrapper e) {
466
                            return false;
480
                            return false;
467
                        }
481
                        }
468
                        traceLineForMethod(debugger, tr, methodName, line,
482
                        traceLineForMethod(debugger, t, methodName, methodClassType,
469
                                           doFinishWhenMethodNotFound, methodEntry);
483
                                           isNative, line, doFinishWhenMethodNotFound,
484
                                           methodEntry);
470
                        return true;
485
                        return true;
471
                    }
486
                    }
472
487
 Lines 545-557    Link Here 
545
    }
560
    }
546
561
547
    private static void traceLineForMethod(final JPDADebuggerImpl debugger,
562
    private static void traceLineForMethod(final JPDADebuggerImpl debugger,
548
                                           final ThreadReference tr,
563
                                           final JPDAThreadImpl jtr,
549
                                           final String method,
564
                                           final String method,
565
                                           final String methodClassType,
566
                                           final boolean isNative,
550
                                           final int methodLine,
567
                                           final int methodLine,
551
                                           final boolean finishWhenNotFound,
568
                                           final boolean finishWhenNotFound,
552
                                           final MethodChooserSupport.MethodEntry methodEntry) {
569
                                           final MethodChooserSupport.MethodEntry methodEntry) {
553
        final JPDAThread jtr = debugger.getThread(tr);
570
        //ThreadReference tr = jtr.getThreadReference();
554
        final int depth = jtr.getStackDepth();
571
        final int depth = jtr.getStackDepth();
572
        //System.err.println("traceLineForMethod: stepping into native method "+methodClassType+"."+method+" = "+isNative);
573
        if (isNative) {
574
            Map<Object, Object> properties = new HashMap<Object, Object>();
575
            properties.put("javaClass", methodClassType);
576
            properties.put("javaMethod", method);
577
            Session session = debugger.getSession();
578
            putConnectionProperties(session, properties);
579
            final Lock writeLock = jtr.accessLock.writeLock();
580
            writeLock.lock();
581
            boolean changed = SessionBridge.getDefault().suggestChange(
582
                    session,
583
                    (String) ActionsManager.ACTION_STEP_INTO,
584
                    properties);
585
            if (changed) {
586
                writeLock.unlock();
587
                jtr.resume();
588
                return ;
589
            } else {
590
                writeLock.unlock();
591
            }
592
        }
555
        final JPDAStep step = debugger.createJPDAStep(JPDAStep.STEP_LINE, JPDAStep.STEP_INTO);
593
        final JPDAStep step = debugger.createJPDAStep(JPDAStep.STEP_LINE, JPDAStep.STEP_INTO);
556
        step.setHidden(true);
594
        step.setHidden(true);
557
        logger.log(Level.FINE, "Will traceLineForMethod({0}, {1}, {2})",
595
        logger.log(Level.FINE, "Will traceLineForMethod({0}, {1}, {2})",
 Lines 628-633    Link Here 
628
        });
666
        });
629
        step.addStep(jtr);
667
        step.addStep(jtr);
630
    } 
668
    } 
669
    
670
    private static void putConnectionProperties(Session session, Map properties) {
671
        ListeningDICookie lc = session.lookupFirst(null, ListeningDICookie.class);
672
        Map<String, ? extends Connector.Argument> args = null;
673
        if (lc != null) {
674
            args = lc.getArgs();
675
            properties.put("conn_port", lc.getPortNumber());
676
            properties.put("conn_shmem", lc.getSharedMemoryName());
677
        } else {
678
            AttachingDICookie ac = session.lookupFirst(null, AttachingDICookie.class);
679
            if (ac != null) {
680
                args = ac.getArgs();
681
                properties.put("conn_host", ac.getHostName());
682
                properties.put("conn_port", ac.getPortNumber());
683
                properties.put("conn_shmem", ac.getSharedMemoryName());
684
                properties.put("conn_pid", ac.getProcessID());
685
            }
686
        }
687
    }
631
688
632
    @Override
689
    @Override
633
    public void actionPerformed(Object action) {
690
    public void actionPerformed(Object action) {
(-)a/cnd.debugger.common2/src/org/netbeans/modules/cnd/debugger/common2/debugger/breakpoints/NativeBreakpoint.java (+17 lines)
 Lines 88-93    Link Here 
88
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.props.ActionProperty;
88
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.props.ActionProperty;
89
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.props.ContextProperty;
89
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.props.ContextProperty;
90
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.props.CountLimitProperty;
90
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.props.CountLimitProperty;
91
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.types.FunctionBreakpoint;
92
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.types.FunctionBreakpointType;
91
93
92
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.types.LineBreakpoint;
94
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.types.LineBreakpoint;
93
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.types.LineBreakpointType;
95
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.types.LineBreakpointType;
 Lines 3062-3067    Link Here 
3062
    }
3064
    }
3063
    
3065
    
3064
    /**
3066
    /**
3067
     * Quick and easy way to create a function bpt.
3068
     *  Used for toggling.
3069
     */
3070
    public static NativeBreakpoint newFunctionBreakpoint(String functionName) {
3071
        NativeBreakpoint bpt =
3072
                newBreakpointOfType(FunctionBreakpointType.class);
3073
        if (bpt == null) {
3074
            return null;
3075
        }
3076
        FunctionBreakpoint fb = (FunctionBreakpoint) bpt;
3077
        fb.setFunction(functionName);
3078
        return fb;
3079
    }
3080
    
3081
    /**
3065
     * Returns a list of changed properties (with the new values)
3082
     * Returns a list of changed properties (with the new values)
3066
     * @param oldBpt
3083
     * @param oldBpt
3067
     * @param newBpt
3084
     * @param newBpt
(-)a/cnd.debugger.common2/src/org/netbeans/modules/cnd/debugger/common2/debugger/mixed/SessionChangerImpl.java (+146 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.cnd.debugger.common2.debugger.mixed;
44
45
import java.util.Collections;
46
import java.util.HashMap;
47
import java.util.Map;
48
import java.util.Set;
49
import java.util.Vector;
50
import java.util.regex.Pattern;
51
import org.netbeans.api.debugger.ActionsManager;
52
import org.netbeans.api.debugger.DebuggerManager;
53
import org.netbeans.api.debugger.DebuggerManagerAdapter;
54
import org.netbeans.api.debugger.Session;
55
import org.netbeans.api.debugger.SessionBridge;
56
import org.netbeans.modules.cnd.debugger.common2.debugger.NativeDebugger;
57
import org.netbeans.modules.cnd.debugger.common2.debugger.NativeDebuggerManager;
58
import org.netbeans.modules.cnd.debugger.common2.debugger.RoutingToken;
59
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.Handler;
60
import org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints.NativeBreakpoint;
61
import org.netbeans.modules.cnd.debugger.common2.debugger.debugtarget.DebugTarget;
62
import org.netbeans.modules.cnd.debugger.common2.debugger.remote.Host;
63
import org.netbeans.modules.cnd.debugger.common2.utils.PsProvider;
64
import org.netbeans.spi.debugger.DebuggerServiceRegistration;
65
import org.openide.util.NbBundle;
66
67
/**
68
 *
69
 * @author Nikolay Koldunov
70
 */
71
72
@DebuggerServiceRegistration(types = SessionBridge.SessionChanger.class)
73
public class SessionChangerImpl implements SessionBridge.SessionChanger{
74
    private static final Map<String, Session> sessions = new HashMap<String, Session>();
75
76
    @Override
77
    public Set<String> getActions() {
78
        return Collections.singleton((String) ActionsManager.ACTION_STEP_INTO);
79
    }
80
81
    @Override
82
    public Session changeSuggested(Session origin, String action, Map<Object, Object> properties) {
83
        final Vector<Vector<String>> processes = PsProvider.getDefault(Host.getLocal()).getData(false).processes(
84
                Pattern.compile(".*java.+:" + properties.get("conn_port") + ".*")
85
        );
86
        if (processes.size() != 1) {
87
            NativeDebuggerManager.warning(NbBundle.getMessage(this.getClass(), "MSG_ProcessDetectionError"));
88
            return null;
89
        }
90
        final String funcName = MethodMapper.getNativeName(
91
                "" + properties.get("javaClass") + "." + properties.get("javaMethod"));
92
        final String pid = processes.firstElement().get(1);
93
        Session ret = sessions.get(pid);
94
        if (ret == null) {
95
            final long longPid = Long.parseLong(pid);
96
            final DebugTarget target = new DebugTarget();
97
            target.setPid(longPid);
98
            target.setHostName("localhost");
99
   
100
            insertBreakpoint(null, funcName);
101
            NativeDebuggerManager.get().attach(target);
102
 
103
            ret = NativeDebuggerManager.get().currentDebugger().session().coreSession();
104
            sessions.put(pid, ret);
105
        } else {
106
            insertBreakpoint(NativeDebuggerManager.get().currentDebugger(), funcName);
107
        }
108
        
109
        // FIXME maybe sometimes we should return origin instead
110
        return ret;
111
    }
112
    
113
    private static void insertBreakpoint(NativeDebugger debugger, String functionName) {
114
        NativeBreakpoint bpt = NativeBreakpoint.newFunctionBreakpoint(functionName);
115
        if (bpt != null) {
116
            int routingToken = RoutingToken.BREAKPOINTS.getUniqueRoutingTokenInt();
117
            bpt.setTemp(true);
118
            Handler.postNewHandler(debugger, bpt, routingToken);
119
        }
120
    }
121
122
    private static final class MethodMapper {
123
        /*package*/ static String getNativeName(String javaName) {
124
            return "Java_".concat(javaName.replaceAll("[.]", "_"));
125
        }
126
    }
127
128
//    /*package*/ String resolveSymbol(CharSequence funcName) {
129
//        Project[] projects = OpenProjects.getDefault().getOpenProjects();
130
//        for (Project prj : projects) {
131
//            NativeProject nativeProject = prj.getLookup().lookup(NativeProject.class);
132
//            if (nativeProject != null) {
133
//                Collection<CsmOffsetable> candidates = CsmSymbolResolver.resolveSymbol(nativeProject, funcName);
134
//                if (!candidates.isEmpty()) {
135
//                    CsmOffsetable candidate = candidates.iterator().next();
136
////                    CsmUtilities.openSource(candidate);
137
//                    if (CsmKindUtilities.isFunction(candidate)) {
138
//                        return ((CsmFunction) candidate).getQualifiedName().toString();
139
//                    }
140
//                    break;
141
//                }
142
//            }
143
//        }
144
//        return null;
145
//    }
146
}

Return to bug 246819
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo