--- cnd.debugger.gdb.orig/src/org/netbeans/modules/cnd/debugger/gdb/GdbDebugger.java 2008-04-21 18:42:46.000000000 +0200 +++ cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/GdbDebugger.java 2008-05-22 14:40:45.000000000 +0200 @@ -49,11 +49,14 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Timer; import java.util.TimerTask; import java.util.logging.Logger; @@ -65,6 +68,10 @@ import org.netbeans.api.debugger.Session; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectInformation; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.api.project.SourceGroup; +import org.netbeans.api.project.Sources; +import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.modules.cnd.api.compilers.CompilerSet.CompilerFlavor; import org.netbeans.modules.cnd.api.compilers.CompilerSetManager; import org.netbeans.modules.cnd.api.utils.CppUtils; @@ -94,6 +101,7 @@ import org.openide.DialogDisplayer; import org.openide.ErrorManager; import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.modules.InstalledFileLocator; import org.openide.util.Utilities; @@ -267,6 +275,21 @@ gdb.gdb_set("print repeat", // NOI18N Integer.toString(CppSettings.getDefault().getArrayRepeatThreshold())); if (pae.getID() == DEBUG_ATTACH) { + // publish all source dirs from all opened projects + for(Project p : OpenProjects.getDefault().getOpenProjects()) { + Sources sources = ProjectUtils.getSources(p); + for(SourceGroup sg : sources.getSourceGroups(Sources.TYPE_GENERIC)) { + FileObject root = sg.getRootFolder(); + if (root.getFileObject("src") != null) { + // HACK: if a subfolder named 'src' exists, only add its subdirs + // There is no SG of type GENERIC under project root directory + // (as per Sources.getSourceGroups() API) + root = root.getFileObject("src"); + } + // put all pathes under root + addSourceDirectories(root); + } + } programPID = (Long) lookupProvider.lookupFirst(null, Long.class); CommandBuffer cb = new CommandBuffer(gdb); gdb.target_attach(cb, Long.toString(programPID)); @@ -306,7 +329,8 @@ cb = new CommandBuffer(gdb); gdb.info_files(cb); cb.waitForCompletion(); - if (symbolsReadFromInfoFiles(cb.toString(), path)) { + // don't check debug symbols availability if attached with no real configuration + if ("/ATTACHED".equals(path) || symbolsReadFromInfoFiles(cb.toString(), path)) { setLoading(); } else { final String msg = NbBundle.getMessage(GdbDebugger.class, "ERR_AttachValidationFailure"); // NOI18N @@ -391,7 +416,33 @@ finish(false); } } - + + private static final Set recognizedExt = new HashSet(Arrays.asList(new String[]{"c", "cc", "cpp", "C", "cxx", "mm", "i", "m", "h", "H", "hpp", "hxx", "SUNWCCh", "tcc", "f", "F", "f90", "F90", "f95", "F95, "f03", "F03", "for", "il", "mod", "s", "as", "asm"})); + + // populate GDB sources path recursively + private void addSourceDirectories(FileObject dir) { + boolean empty = true; + for(FileObject sub : dir.getChildren()) { + // ignore hidden dirs + if (sub.getNameExt().startsWith(".")) continue; + // don't walk into SCM dirs + if ("CVS".equals(sub.getNameExt())) continue; + if (sub.isFolder()) { + // recurse + addSourceDirectories(sub); + } + else { + // look for real source files + empty &= recognizedExt.contains(sub.getExt()); + } + } + if (! empty) { + // ok, this dir contains real source files, so add it to GDB sources path + String path = FileUtil.toFile(dir).getAbsolutePath(); + gdb.environment_directory(path); + } + } + private String getCompilerSetPath(ProjectActionEvent pae) { CompilerSet2Configuration cs = ((MakeConfiguration) pae.getConfiguration()).getCompilerSet(); String csname = cs.getOption(); @@ -1727,6 +1778,23 @@ }); } } + else { + // attach without MakeConfiguration avail + MakeConfiguration conf = new MakeConfiguration(FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(), "default", 1); + ProjectActionEvent pae = new ProjectActionEvent( + project, + DEBUG_ATTACH, + pinfo.getDisplayName(), + "/ATTACHED", + conf, + null, + false); + DebuggerEngine[] es = DebuggerManager.getDebuggerManager().startDebugging( + DebuggerInfo.create(SESSION_PROVIDER_ID, new Object[] { pae, Long.valueOf(pid)})); + if (es == null) { + throw new DebuggerStartException(new InternalError()); + } + } } /** --- cnd.debugger.gdb.orig/src/org/netbeans/modules/cnd/debugger/gdb/attach/Bundle.properties 2008-05-22 13:55:23.000000000 +0200 +++ cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/attach/Bundle.properties 2008-05-22 14:34:14.000000000 +0200 @@ -42,6 +42,8 @@ GdbAttachProcessMNEM=A GdbAttachProjectLabel=Project: GdbAttachProjectMNEM=P +GdbAttachAllProcesses=All Processes +GdbAttachAllProcessesMNEM=P # Headers for PTYPE_STD ("ps -o user,pid,ppid,stime,time,args") HDR_USER=User @@ -58,3 +60,8 @@ # Error messages ERR_BadFilterPattern=The pattern was not compilable" ERR_UnexpecedAttachFailure="Gdb was unable to attach to process ID {0}" +GdbAttachPanelAllProcesses=Show All User Processes +GdbAttachProcessesLabel=Show: +GdbAttachTtyProcesses=TTY Processes +GdbAttachUserProcesses=U +GdbAttachTtyProcessesMNEM=T --- cnd.debugger.gdb.orig/src/org/netbeans/modules/cnd/debugger/gdb/attach/GdbAttachPanel.form 2008-04-21 18:42:46.000000000 +0200 +++ cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/attach/GdbAttachPanel.form 2008-05-22 14:34:15.000000000 +0200 @@ -1,6 +1,10 @@
+ + + + @@ -18,18 +22,28 @@ - + - + - + + + + + + + + + + + @@ -42,7 +56,14 @@ - + + + + + + + + @@ -139,5 +160,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- cnd.debugger.gdb.orig/src/org/netbeans/modules/cnd/debugger/gdb/attach/GdbAttachPanel.java 2008-04-21 18:42:46.000000000 +0200 +++ cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/attach/GdbAttachPanel.java 2008-05-22 14:34:15.000000000 +0200 @@ -48,6 +48,7 @@ import java.util.Vector; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import javax.swing.JRadioButton; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import org.netbeans.api.project.Project; @@ -71,8 +72,10 @@ private ProcessList procList; private AttachTableModel processModel; private FilterController filterController; + private JRadioButton[] processesButtons; private static List filterList; private static String selectedFilter; + private static int processesFilter = ProcessList.PROC_TTY; static { filterList = new ArrayList(); @@ -81,7 +84,7 @@ /** Creates new form GdbAttachPanel */ public GdbAttachPanel() { - procList = new ProcessList(this); + procList = new ProcessList(this, processesFilter); filterController = new FilterController(this); initProcessModel(); initComponents(); @@ -89,6 +92,11 @@ } private void postComponentsInit() { + processesButtons = new JRadioButton[3]; + processesButtons[0] = ttyProcesses; + processesButtons[1] = userProcesses; + processesButtons[2] = allProcesses; + processesButtons[processesFilter].setSelected(true); // Initialize the filter filterCB.addItem(""); for (FilterItem item : filterList) { @@ -136,7 +144,13 @@ } // Now get the process list - procList = new ProcessList(this); + for(int k = 0 ; k < processesButtons.length ; k++) { + if (processesButtons[k].isSelected()) { + processesFilter = k; + break; + } + } + procList = new ProcessList(this, processesFilter); } public boolean cancel() { @@ -376,6 +390,7 @@ // //GEN-BEGIN:initComponents private void initComponents() { + buttonGroupProcesses = new javax.swing.ButtonGroup(); jScrollPane1 = new javax.swing.JScrollPane(); processTable = new javax.swing.JTable(); filterLabel = new javax.swing.JLabel(); @@ -384,6 +399,10 @@ procLabel = new javax.swing.JLabel(); projectLabel = new javax.swing.JLabel(); projectCB = new javax.swing.JComboBox(); + processesLabel = new javax.swing.JLabel(); + ttyProcesses = new javax.swing.JRadioButton(); + userProcesses = new javax.swing.JRadioButton(); + allProcesses = new javax.swing.JRadioButton(); processTable.setModel(processModel); processTable.setColumnSelectionAllowed(false); @@ -406,6 +425,35 @@ projectLabel.setLabelFor(projectCB); projectLabel.setText(org.openide.util.NbBundle.getMessage(GdbAttachPanel.class, "GdbAttachProjectLabel")); // NOI18N + processesLabel.setText(org.openide.util.NbBundle.getMessage(GdbAttachPanel.class, "GdbAttachProcessesLabel")); // NOI18N + + buttonGroupProcesses.add(ttyProcesses); + ttyProcesses.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cnd/debugger/gdb/attach/Bundle").getString("GdbAttachTtyProcessesMNEM").charAt(0)); + ttyProcesses.setText(org.openide.util.NbBundle.getMessage(GdbAttachPanel.class, "GdbAttachTtyProcesses")); // NOI18N + ttyProcesses.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + processesActionPerformed(evt); + } + }); + + buttonGroupProcesses.add(userProcesses); + userProcesses.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cnd/debugger/gdb/attach/Bundle").getString("GdbAttachUserProcesses").charAt(0)); + userProcesses.setText(org.openide.util.NbBundle.getMessage(GdbAttachPanel.class, "GdbAttachUserProcesses")); // NOI18N + userProcesses.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + processesActionPerformed(evt); + } + }); + + buttonGroupProcesses.add(allProcesses); + allProcesses.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/cnd/debugger/gdb/attach/Bundle").getString("GdbAttachAllProcessesMNEM").charAt(0)); + allProcesses.setText(org.openide.util.NbBundle.getMessage(GdbAttachPanel.class, "GdbAttachAllProcesses")); // NOI18N + allProcesses.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + processesActionPerformed(evt); + } + }); + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -413,15 +461,24 @@ .add(layout.createSequentialGroup() .add(filterLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(filterCB, 0, 495, Short.MAX_VALUE)) + .add(filterCB, 0, 705, Short.MAX_VALUE)) .add(layout.createSequentialGroup() .add(projectLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(projectCB, 0, 488, Short.MAX_VALUE)) + .add(projectCB, 0, 692, Short.MAX_VALUE)) .add(layout.createSequentialGroup() .add(procLabel) .addContainerGap()) - .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 747, Short.MAX_VALUE) + .add(layout.createSequentialGroup() + .add(processesLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(ttyProcesses) + .add(18, 18, 18) + .add(userProcesses) + .add(18, 18, 18) + .add(allProcesses) + .add(247, 247, 247)) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) @@ -432,22 +489,37 @@ .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(procLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE) + .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE) + .add(6, 6, 6) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(processesLabel) + .add(ttyProcesses) + .add(userProcesses) + .add(allProcesses)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(projectLabel) .add(projectCB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) ); }// //GEN-END:initComponents + + private void processesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processesActionPerformed + updateProcessList(); + }//GEN-LAST:event_processesActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JRadioButton allProcesses; + private javax.swing.ButtonGroup buttonGroupProcesses; private javax.swing.JComboBox filterCB; private javax.swing.JLabel filterLabel; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel procLabel; private javax.swing.JTable processTable; + private javax.swing.JLabel processesLabel; private javax.swing.JComboBox projectCB; private javax.swing.JLabel projectLabel; + private javax.swing.JRadioButton ttyProcesses; + private javax.swing.JRadioButton userProcesses; // End of variables declaration//GEN-END:variables } --- cnd.debugger.gdb.orig/src/org/netbeans/modules/cnd/debugger/gdb/attach/ProcessList.java 2008-04-21 18:42:46.000000000 +0200 +++ cnd.debugger.gdb/src/org/netbeans/modules/cnd/debugger/gdb/attach/ProcessList.java 2008-05-22 14:28:29.000000000 +0200 @@ -44,6 +44,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.netbeans.modules.cnd.api.utils.CppUtils; import org.netbeans.modules.cnd.debugger.gdb.actions.AttachTableColumn; @@ -62,7 +63,11 @@ public final static int PTYPE_UNINITIALIZED = -1; public final static int PTYPE_STD = 0; public final static int PTYPE_CYGWIN = 1; - + + public static final int PROC_TTY = 0; + public static final int PROC_USER = 1; + public static final int PROC_ALL = 2; + private int ptype = PTYPE_UNINITIALIZED; private List args; private List proclist; @@ -70,9 +75,9 @@ private BufferedReader reader; private ProcessListReader plr; - protected ProcessList(ProcessListReader plr) { + protected ProcessList(ProcessListReader plr, int filter) { this.plr = plr; - args = getProcessCommand(); + args = getProcessCommand(filter); pb = new ProcessBuilder(args); pb.redirectErrorStream(true); proclist = new ArrayList(); @@ -143,7 +148,7 @@ return NbBundle.getMessage(ProcessList.class, "HDR_ARGS"); } - private List getProcessCommand() { + private List getProcessCommand(int filter) { List alist = new ArrayList(); if (Utilities.isWindows()) { @@ -161,7 +166,17 @@ } else { if (new File("/bin/ps").exists()) { // NOI18N alist.add("/bin/ps"); // NOI18N - alist.add("-a"); // NOI18N + switch (filter) { + case PROC_ALL: + alist.add("-e"); // NOI18N + break; + case PROC_USER: + alist.add("-u"); // NOI18N + alist.add(System.getProperty("user.name")); // NOI18N + break; + default: + alist.add("-a"); // NOI18N + } alist.add("-o"); // NOI18N if (Utilities.getOperatingSystem() == Utilities.OS_MAC) { alist.add("user,pid,ppid,stime,time,command"); // NOI18N @@ -172,7 +187,17 @@ } else { if (new File("/usr/bin/ps").exists()) { // NOI18N alist.add("/usr/bin/ps"); // NOI18N - alist.add("-a"); // NOI18N + switch (filter) { + case PROC_ALL: + alist.add("-e"); // NOI18N + break; + case PROC_USER: + alist.add("-u"); // NOI18N + alist.add(System.getProperty("user.name")); // NOI18N + break; + default: + alist.add("-a"); // NOI18N + } alist.add("-o"); // NOI18N alist.add("user,pid,ppid,stime,time,args"); // NOI18N ptype = PTYPE_STD;