PageRenderTime 1306ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/cnd.debugger.common2/src/org/netbeans/modules/cnd/debugger/common2/debugger/breakpoints/SystemInfo.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 230 lines | 144 code | 28 blank | 58 comment | 27 complexity | 6f1fcc40d993ba5cd8ead8788de0b9b9 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 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. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.cnd.debugger.common2.debugger.breakpoints;
  45. import java.util.*;
  46. import java.io.*;
  47. import javax.swing.JComboBox;
  48. import javax.swing.SwingUtilities;
  49. import javax.swing.DefaultComboBoxModel;
  50. import org.openide.util.RequestProcessor;
  51. public abstract class SystemInfo {
  52. protected Vector<String> items;
  53. protected String cmd;
  54. protected String ignore;
  55. private static final RequestProcessor RP = new RequestProcessor("SystemInfo", 1); // NOI18N
  56. protected SystemInfo(Vector<String> items, String cmd, String ignore) {
  57. this.items = items;
  58. this.cmd = cmd;
  59. this.ignore = ignore;
  60. }
  61. public abstract String all();
  62. public void stuffIntoAsync(final JComboBox combo) {
  63. RP.post(new Runnable () {
  64. public void run () {
  65. stuffInto(combo);
  66. }
  67. }, 100);
  68. }
  69. public void stuffInto(final JComboBox combo) {
  70. fill();
  71. if (items.isEmpty())
  72. return;
  73. final DefaultComboBoxModel model;
  74. model = new DefaultComboBoxModel(new Vector<String>(items));
  75. SwingUtilities.invokeLater(new Runnable () {
  76. public void run () {
  77. combo.setModel(model);
  78. }
  79. });
  80. }
  81. /**
  82. * Run a command to find a set of items to add to a Vector, skipping
  83. * a given string match
  84. */
  85. public void fill() {
  86. Runtime rt = Runtime.getRuntime();
  87. try {
  88. String [] args = new String[3];
  89. args[0] = "/bin/sh"; // NOI18N
  90. args[1] = "-c"; // NOI18N
  91. args[2] = cmd;
  92. Process proc = rt.exec(args);
  93. InputStream procIn = proc.getInputStream();
  94. BufferedReader br = new BufferedReader(new InputStreamReader(
  95. procIn));
  96. while (true) {
  97. String moreoutput = br.readLine();
  98. if (moreoutput == null) {
  99. break;
  100. } else {
  101. if (moreoutput.endsWith("_H")) { // NOI18N
  102. // Known to not be a signal, fault, syscall, etc. but
  103. // sometimes erroneously included by the headerfile
  104. // greps
  105. continue;
  106. }
  107. if (moreoutput.startsWith("reserved_")) { // NOI18N
  108. // Known to not be a syscall but is listed in the
  109. // syscall headerfile, exclude these.
  110. continue;
  111. }
  112. if ((ignore == null) || !(ignore.equals(moreoutput))) {
  113. items.add(moreoutput);
  114. }
  115. }
  116. }
  117. br.close();
  118. proc.waitFor();
  119. } catch (Exception e) {
  120. // e.printStackTrace();
  121. }
  122. }
  123. public static class Signals extends SystemInfo {
  124. public Signals(Vector<String> items) {
  125. super(items, null, null);
  126. if (new File("/usr/include/sys/iso/signal_iso.h").exists()) { // NOI18N
  127. cmd =
  128. "LC_ALL=C /usr/bin/grep \"#define\tSIG.*[0-9].*/\" /usr/include/sys/iso/signal_iso.h | /usr/bin/nawk '{print $2}'"; // NOI18N
  129. } else if (new File("/usr/include/asm/signal.h").exists()) { // NOI18N
  130. // Linux
  131. cmd =
  132. "LC_ALL=C /bin/grep \"#define SIG.*[0-9]\" /usr/include/asm/signal.h | /bin/awk '{print $2}'"; // NOI18N
  133. } else {
  134. cmd =
  135. "LC_ALL=C /usr/bin/grep \"#define\tSIG.*[0-9].*/\" /usr/include/sys/signal.h | /usr/bin/nawk '{print $2}'"; // NOI18N
  136. }
  137. //System.out.println("cmd = " + cmd);
  138. }
  139. public String all() {
  140. return Catalog.get("Signal_AllCodes"); // NOI18N
  141. }
  142. }
  143. public static class Subcodes extends SystemInfo {
  144. public Subcodes(Vector<String> items) {
  145. super(items, null, null);
  146. items.add(all());
  147. if (new File("/usr/include/bits/siginfo.h").exists()) { // NOI18N
  148. // Linux
  149. cmd =
  150. "LC_ALL=C /bin/grep \"# define.*\" /usr/include/bits/siginfo.h | /bin/awk '{print $3}'"; // NOI18N
  151. } else {
  152. cmd =
  153. "LC_ALL=C /usr/bin/grep \"#define.*/\" /usr/include/sys/machsig.h | /usr/bin/nawk '{print $2}'"; // NOI18N
  154. }
  155. //System.out.println("cmd = " + cmd);
  156. }
  157. // override super
  158. public String all() {
  159. return Catalog.get("Signal_AllCodes"); // NOI18N
  160. }
  161. public Vector<String> subcodesFor(String sig) {
  162. if (sig == null)
  163. return null;
  164. sig = sig.trim();
  165. if (sig.length() == 0)
  166. return null;
  167. if (items == null || items.size() == 0)
  168. return null;
  169. sig += "_"; // NOI18N
  170. if (sig.startsWith("SIG")) // NOI18N
  171. sig = sig.substring(3); // everything following SIG
  172. Vector<String> actual = new Vector<String>(10);
  173. actual.add(all());
  174. for (int scx = 0; scx < items.size(); scx++) {
  175. if (items.get(scx).toString().startsWith(sig))
  176. actual.add(items.get(scx));
  177. }
  178. return actual;
  179. }
  180. }
  181. public static class Faults extends SystemInfo {
  182. public Faults(Vector<String> items) {
  183. super(items, null, "_SYS_FAULT_H"); // NOI18N
  184. cmd =
  185. "LC_ALL=C /usr/bin/grep \"#define\" /usr/include/sys/fault.h | /usr/bin/nawk '{print $2}'"; // NOI18N
  186. }
  187. public String all() {
  188. return ""; // NOI18N
  189. }
  190. }
  191. public static class Syscalls extends SystemInfo {
  192. public Syscalls(Vector<String> items) {
  193. super(items, null, "syscall"); // NOI18N
  194. items.add(all());
  195. cmd =
  196. "LC_ALL=C /usr/bin/grep \"#define\" /usr/include/sys/syscall.h | /usr/bin/nawk '{print $2}' | /usr/bin/cut -c 5-"; // NOI18N
  197. }
  198. public String all() {
  199. return Catalog.get("SysCall_All"); // NOI18N
  200. }
  201. }
  202. }