Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 7925 Details for
Bug 47023
debug breaks on caught exception on jdk 1.4.2
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
simple jdi code to show and solve the problem
TestUncaughtBehindNative.java (text/plain), 5.80 KB, created by
quartz quartz
on 2004-02-14 15:21:40 EST
(
hide
)
Description:
simple jdi code to show and solve the problem
Filename:
MIME Type:
Creator:
quartz quartz
Created:
2004-02-14 15:21:40 EST
Size:
5.80 KB
patch
obsolete
>package testjdi; > >import java.io.InputStream; >import java.io.InterruptedIOException; >import java.io.OutputStream; >import java.util.*; >import com.sun.jdi.*; >import com.sun.jdi.connect.*; >import com.sun.jdi.event.*; >import com.sun.jdi.request.*; > > > >public class TestUncaughtBehindNative { > > static void out(Object obj) { > System.out.println("TestUncaughtBehindNative: "+obj); > } > > public static void main(String[] args) throws Exception { > > VirtualMachineManager vmmgr = Bootstrap.virtualMachineManager(); > LaunchingConnector lc = vmmgr.defaultConnector(); > Map def = lc.defaultArguments(); > Connector.StringArgument vmargs = (Connector.StringArgument)def.get("options"); > Connector.StringArgument mainargs = (Connector.StringArgument)def.get("main"); > > JDIHandler handler = new JDIHandler(); > handler.setupArguments(vmargs, mainargs); > > out("Starting: vmargs (options) = "+vmargs.value()); > out("Starting: mainargs ( main ) = "+mainargs.value()); > out("======================================================================="); > > VirtualMachine vm = lc.launch(def); > > Process proc = vm.process(); > StreamPump pump_out = new StreamPump("proc output pump", proc.getInputStream(), System.out); > StreamPump pump_err = new StreamPump("proc error pump", proc.getErrorStream(), System.err); > pump_out.setDaemon(true); > pump_err.setDaemon(true); > pump_out.start(); > pump_err.start(); > > //vm.setDebugTraceMode(VirtualMachine.TRACE_EVENTS); > EventQueue queue = vm.eventQueue(); > EventRequestManager erm = vm.eventRequestManager(); > > handler.setupTracing(erm); > > boolean done = false; > while(!done) { > EventSet eset = queue.remove(10000); > if(eset==null) > break; > > EventIterator it = eset.eventIterator(); > while(it.hasNext()) { > Event ev = it.nextEvent(); > done |= handler.handleEvent(ev); > } > } > > try { > vm.dispose(); > vm.exit(1); > } catch(Exception e) { > out(e); > } > > Thread.sleep(2000); > pump_out.kill(); > pump_err.kill(); > Thread.sleep(2000); > } >} > > >class jdk142exc { > public static void main(String[] args) throws Exception { > > System.err.println("jdk142exc: 1"); > try { > throw new Exception("my-caught-exception"); > } catch(Exception e) { > System.err.println("jdk142exc: "+e); > } > > System.err.println("jdk142exc: 2"); > TimeZone tz = TimeZone.getTimeZone("UTC"); //this causes the natively-caught exception > System.err.println("jdk142exc"+tz); > > System.err.println("jdk142exc: 3"); > //throw new Exception("my-uncaught-exception"); > } >} > > >class JDIHandler { > > static final String CLAZZ = jdk142exc.class.getName(); > static final boolean NOTIFY_CAUGHT = true; > static final boolean NOTIFY_UNCAUGHT = true; > > private static void out(Object obj) { > System.out.println("~jdi handler: "+obj); > } > private static void err(Object obj) { > System.err.println("~jdi handler: "+obj); > } > > > public void setupArguments(Connector.StringArgument vmargs, Connector.StringArgument mainargs) { > //make sure you have a correct classpath... > vmargs.setValue("-cp .\\output"); > > mainargs.setValue(CLAZZ+" arg1 \"long arg2 with space\" arg3"); > } > > public void setupTracing(EventRequestManager erm) { > List l = erm.virtualMachine().classesByName("java.lang.Throwable"); > out(l); > ReferenceType tt = (ReferenceType)l.get(0); > ExceptionRequest er = erm.createExceptionRequest(tt, NOTIFY_CAUGHT, NOTIFY_UNCAUGHT); > er.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); > er.enable(); > } > > public boolean handleEvent(Event ev) { > out(ev); > > if(ev instanceof VMStartEvent) { > out("calling vm.resume()..."); > ev.virtualMachine().resume(); > } else if(ev instanceof VMDisconnectEvent) { > return true; > } else if(ev instanceof VMDeathEvent) { > return true; > } else if(ev instanceof ExceptionEvent) { > ExceptionEvent exev = (ExceptionEvent)ev; > ThreadReference tr = exev.thread(); > Location cl = exev.catchLocation(); > > if(cl!=null) { > out("********** CAUGHT EXCEPTION : thread="+tr+", caught at "+cl); > } else { > List frames = null; > try { > frames = tr.frames(); > } catch(IncompatibleThreadStateException e) { > e.printStackTrace(); > } > > if(frames==null) { > err("********** UNAUGHT EXCEPTION: thread="+tr+", (no stackframes)"); > } else { > boolean behindNative = false; > for(Iterator it = frames.iterator(); it.hasNext();) { > StackFrame sf = (StackFrame)it.next(); > if(sf.location().method().isNative()) { > behindNative = true; > break; > } > } > > err("********** UNAUGHT EXCEPTION "+(behindNative?"(behind native)":"")+": thread="+tr); > > //if(behindNative) > // tr.resume(); > } > } > > if(tr.isSuspended()) > tr.resume(); > > } > return false; > } >} > > > >class StreamPump extends Thread { > InputStream is; > OutputStream os; > boolean stopped = false; > > StreamPump(String name, InputStream is, OutputStream os) { > super(name); > this.is = is; > this.os = os; > } > > public synchronized void kill() throws Exception { > stopped = true; > interrupt(); > } > > void out(Object obj) { > System.out.println(getName()+": "+obj); > } > > public void run() { > byte[] buff = new byte[1024]; > int n=0; > try { > while(true) { > n = is.available(); > if(n>0) { > n = is.read(buff, 0, Math.min(n, buff.length)); > if(n<0) > break; > os.write(buff, 0, n); > } else { > n = is.read(); > if(n<0) > break; > os.write(n); > } > } > } catch(InterruptedIOException e) { > out(e); > } catch(Exception e) { > out(e); > } finally { > } > > synchronized(this) { > if(!stopped) { > try { > this.wait(); > } catch(InterruptedException e){ > out(e); > } > } > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 47023
:
6885
| 7925