Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger implementation #159

Merged
merged 100 commits into from
Jun 24, 2017
Merged

Debugger implementation #159

merged 100 commits into from
Jun 24, 2017

Conversation

dkimitsa
Copy link
Contributor

it seems to be more-less stable, to extend the audience let make it a part of snapshot.
changes:

  • JDWP server/hooks side implementation itself.
  • it requires modified soot. Modification were done to fetch local variable debug data. Modified version of soot is located here https://github.com/dkimitsa/soot
  • LLMV code was extended with one to receive dwarf debug information for local variables. compiled library included in this PR
  • ClassCompiler was modified to include debug information into binary during the build

Optional:
there is an issue with moe sim launcher https://github.com/multi-os-engine/moe-ios-simulator-launcher/issues/1 and workaround https://github.com/dkimitsa/moe-ios-simulator-launcher/tree/fix_for_pipe_hangs_on_long_msg

dkimitsa and others added 30 commits March 2, 2017 14:20
Added launch plugin with arguments
Integrated to idea
…ome cases it crashes with message "Block was not compiled using a compiler that inserts type information about arguments"
* origin/master:
  Removed unused old simulator binaries.
  Exclude some Entitlement keys (MobiVM#144)
  Update README.md
  Update README.md
  Fix issue MobiVM#140 (MobiVM#142)
  Add the "framework" compiler target (issue MobiVM#132) (MobiVM#141)
  Added the ability to select one of several USB-connected physical devices with the robovm.device.udid parameter in the Gradle plugin. (MobiVM#139)
  Update poms to next development version
…s in tar, otherwise on each launch idea will rebuild all classes in case of snapshot builds
* origin/master:
  Ios10.3 bindings (MobiVM#152)
  IDEA -- fixed resource unpack to maintain the timestamp same as it was in tar, otherwise on each launch idea will rebuild all classes in case of snapshot builds (MobiVM#149)
  Remove leftovers of old simulator handling, bringing to foreground.
  Remove old commercial license manager eclipse ui elements and gradle tasks
  Android studio/Idea fixes (MobiVM#148)
  blocks implementation -- added signature generation to blocks as in some cases it crashes with message "Block was not compiled using a compiler that inserts type information about arguments" (MobiVM#147)
@florianf florianf self-requested a review June 12, 2017 19:44
@florianf
Copy link
Collaborator

florianf commented Jun 12, 2017

That looks awesome!

Regarding LLVM: did you patch the lib? I think we should fork the robovm llvm repo with your patches applied @too, so that we can rebuild it? Same goes for moe-ios-simulator launcher.

So that would add up to the following new repos:

  • Soot from your fork
  • LLVM from original RoboVM?
  • moe-ios-simulator launcher from moe with your pr applied

@dkimitsa
Copy link
Contributor Author

hi,
there is no LLVM changes itself, but robovm llvm library was changed, there was code for dwarf support (dylib already included in PR). But it would be good idea to fork LLVM as well as it is being picked up currently from RoboVM AB account (but this is not required).

mod-sim-simulator launcher -- there is dirty workaround that works for me. I just recommend to use it as on big log outputs applications will hang.

@florianf
Copy link
Collaborator

florianf commented Jun 13, 2017

Allright, thanks for the info.

We started forking all necessary repos under the MobiVM organisation, see: https://github.com/MobiVM
We'll move all other repos to this organisation in the future, so the fork isn't tied to @MobiDevelop's personal account anymore.

How should we proceed further? Releasing a SOOT version in the com.mobidevelop namespace?

@dkimitsa
Copy link
Contributor Author

yep, after SOOT under mobidev is only missing dependency.
regarding LLVM: I'd built only MAC dylib so Linux ones are old. I don't know the status of RoboVM for linux, probably these libs could be removed for now at all to reduce package size

@florianf
Copy link
Collaborator

Okay. @Tom-Ski could you release the forked SOOT on Maven?

Regarding Linux: I would like to keep it, since my primary platform in use is Linux. I can recompile the .so for linux, so that's not a problem.

@Tom-Ski
Copy link
Member

Tom-Ski commented Jun 17, 2017

I've pushed 2.5.0-4-SNAPSHOT of soot, if you could give that a whirl and let me know how it goes i can push a release to work from on stable.

@florianf
Copy link
Collaborator

florianf commented Jun 17, 2017

Perfect, thanks! @dkimitsa can you take a look at this? I would merge this after your okay.

@dkimitsa
Copy link
Contributor Author

@florianf built with, no issues so far

@florianf
Copy link
Collaborator

Okay, than we're good to merge?

@florianf
Copy link
Collaborator

florianf commented Jun 20, 2017

Got the debugger to work in Eclipse, very cool! Currently I'm encountering an exception when trying to set a breakpoint:

Exception in thread "org.eclipse.jdt.debug: JDI Event Dispatcher" com.sun.jdi.InternalException: Invalid ReferenceTypeID tag encountered:76
	at org.eclipse.jdi.internal.ReferenceTypeImpl.readWithTypeTag(ReferenceTypeImpl.java:1350)
	at org.eclipse.jdi.internal.MethodImpl.readWithReferenceTypeWithTag(MethodImpl.java:697)
	at org.eclipse.jdi.internal.LocationImpl.read(LocationImpl.java:175)
	at org.eclipse.jdi.internal.event.LocatableEventImpl.readThreadAndLocation(LocatableEventImpl.java:48)
	at org.eclipse.jdi.internal.event.BreakpointEventImpl.read(BreakpointEventImpl.java:55)
	at org.eclipse.jdi.internal.event.EventImpl.read(EventImpl.java:124)
	at org.eclipse.jdi.internal.event.EventSetImpl.read(EventSetImpl.java:167)
	at org.eclipse.jdi.internal.event.EventQueueImpl.remove(EventQueueImpl.java:71)
	at org.eclipse.jdt.internal.debug.core.EventDispatcher.run(EventDispatcher.java:240)
	at java.lang.Thread.run(Thread.java:745)

This happens here in the Eclipse JDT tools:
https://github.com/eclipse/eclipse.jdt.debug/blob/master/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/ReferenceTypeImpl.java#L1342

Any idea what this might cause, since 76 seems to be the ReferenceID for an object type? Im running the debugger in client mode for eclipse (opposed to server mode for IDEA).

EDIT:
The Type Tag constants are defined as follows:

	public static final byte TYPE_TAG_CLASS = 1; // ReferenceType is a class.
	public static final byte TYPE_TAG_INTERFACE = 2; // ReferenceType is an
														// interface.
	public static final byte TYPE_TAG_ARRAY = 3; // ReferenceType is an array.

so in the method

	public static ReferenceTypeImpl readWithTypeTag(MirrorImpl target,
			DataInputStream in) throws IOException {
		byte typeTag = target.readByte("type tag", JdwpID.typeTagMap(), in); //$NON-NLS-1$
		switch (typeTag) {
		case 0:
			return null;
		case ArrayTypeImpl.typeTag:
			return ArrayTypeImpl.read(target, in);
		case ClassTypeImpl.typeTag:
			return ClassTypeImpl.read(target, in);
		case InterfaceTypeImpl.typeTag:
			return InterfaceTypeImpl.read(target, in);
		}
		throw new InternalException(
				JDIMessages.ReferenceTypeImpl_Invalid_ReferenceTypeID_tag_encountered___8
						+ typeTag);
	}

there shouldn't be a type 76, because it's not a reference type.
Reading through the eclipse source, it should be 1 for a class reference here.

The stack leading to it:

ReferenceTypeImpl.readWithTypeTag(MirrorImpl, DataInputStream) line: 1350	
MethodImpl.readWithReferenceTypeWithTag(MirrorImpl, DataInputStream) line: 697	
LocationImpl.read(MirrorImpl, DataInputStream) line: 175	
BreakpointEventImpl(LocatableEventImpl).readThreadAndLocation(MirrorImpl, DataInputStream) line: 48	
BreakpointEventImpl.read(MirrorImpl, RequestID, DataInputStream) line: 55	
EventImpl.read(MirrorImpl, DataInputStream) line: 124	
EventSetImpl.read(MirrorImpl, DataInputStream) line: 167	
EventQueueImpl.remove(long) line: 71	
EventDispatcher.run() line: 240	

@dkimitsa
Copy link
Contributor Author

fixed, btw idea also uses client mode

@florianf
Copy link
Collaborator

florianf commented Jun 20, 2017

I meant server mode. I need to pass clientmode=false when launchin, since eclipse seems to be expecting a running jdwp server.

I'll test your fixes, thanks!

@florianf
Copy link
Collaborator

Oh yes, it works now! Currently I'm having problems with the source lookup in eclipse, but breakpoints, stackvars and the like work. Nice work.

@florianf
Copy link
Collaborator

Hey @dkimitsa, spent some time trying to get the eclipse source lookup to work. I encountered the following: I'm creating a simple ConsoleProject with the following simple main method:

    public static void main(String[] args) throws Exception, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, NoSuchFieldException {	
		System.out.println("Entering sleep ...");
		for (int i=0;i<10;i++) {
			Thread.currentThread().sleep(1000);
		}
		
		System.out.println("okk");
    }

For some reason I need some time before setting a breakpoint works. If I do this, setting the breakpoint works but than the Thread HooksChannel crashes. Following log:

22:27:32.236 INFORMATION: JdwpDebugServer: handling req: Method(6).LineTable(1)
22:27:32.236 INFORMATION: JdwpDebugServer: handling req: Method(6).LineTable(1)
22:27:32.236 INFORMATION: JdwpDebugServer: handling req: Method(6).LineTable(1)
22:27:32.236 INFORMATION: JdwpDebugServer: handling req: Method(6).LineTable(1)
22:27:32.237 INFORMATION: JdwpDebugServer: handling req: EventRequest(15).Set(1)
22:27:32.237 INFORMATION: JdwpEventCenterDelegate: jdwpSetEventRequest: JdwpEventRequest{requestId=113, eventKind=BREAKPOINT, suspendPolicy=EVENT_THREAD, predicates=[Location{classId=5735, methodId=1057, index=56} ]}
22:27:32.237 INFORMATION: JdwpDebugServer: handling req: ReferenceType(2).Signature(1)
22:27:39.537 INFORMATION: JdwpDebugServer: handling req: ThreadReference(11).Resume(3)
22:27:39.537 INFORMATION: JdwpEventCenterDelegate: THREAD_RESUMED: thread (33, main, main)
22:27:39.538 INFORMATION: JdwpEventCenterDelegate: THREAD_DETTACHED: thread (33, main, main)
22:27:39.539 SCHWERWIEGEND: Debugger: Thread HooksChannel socket thread crashed
org.robovm.debugger.DebuggerException: java.nio.BufferOverflowException
	at org.robovm.debugger.hooks.HooksChannel.doSocketWork(HooksChannel.java:152)
	at org.robovm.debugger.hooks.HooksChannel.lambda$0(HooksChannel.java:65)
	at java.lang.Thread.run(Thread.java:745)
	at org.robovm.debugger.utils.DebuggerThread.run(DebuggerThread.java:42)
Caused by: java.nio.BufferOverflowException
	at org.robovm.debugger.utils.bytebuffer.ByteBufferPacket.fillFromInputStream(ByteBufferPacket.java:187)
	at org.robovm.debugger.hooks.HooksChannel.doSocketWork(HooksChannel.java:120)
	... 3 more
22:27:40.042 SCHWERWIEGEND: Debugger: Thread JDWP server socket thread crashed
org.robovm.debugger.DebuggerException: java.net.SocketException: Socket closed
	at org.robovm.debugger.jdwp.JdwpDebugServer.doSocketWork(JdwpDebugServer.java:211)
	at org.robovm.debugger.jdwp.JdwpDebugServer.lambda$0(JdwpDebugServer.java:129)
	at java.lang.Thread.run(Thread.java:745)
	at org.robovm.debugger.utils.DebuggerThread.run(DebuggerThread.java:42)
Caused by: java.net.SocketException: Socket closed
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
	at java.net.SocketInputStream.read(SocketInputStream.java:170)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at org.robovm.debugger.utils.bytebuffer.ByteBufferPacket.fillFromInputStream(ByteBufferPacket.java:185)
	at org.robovm.debugger.jdwp.protocol.JdwpRequestHeader.readFromStream(JdwpRequestHeader.java:36)
	at org.robovm.debugger.jdwp.JdwpDebugServer.doSocketWork(JdwpDebugServer.java:182)
	... 3 more

Any idea what's going wrong?

@dkimitsa
Copy link
Contributor Author

dkimitsa commented Jun 23, 2017

can you please add following parameters.getArguments().add("-rvm:log=debug"); to see at device side ?
also I can see that your application lives only 10 sec

  • there is known limitation of application that run without system debugger attached -- they shall complete DidFinishLaunching in 20 seconds. so if you keep main on breakpoint -- system will terminate you in 20 sec

@florianf
Copy link
Collaborator

Hey @dkimitsa, thanks for your help! I'm gonna merge this as it is, since I can't get the eclipse debugging to work right now. I'm going to open a seperate issue for this, but in the meantime we can bring this amazing stuff to the people, and maybe someone steps up helping with eclipse.

@florianf florianf merged commit 557af56 into MobiVM:master Jun 24, 2017
@dkimitsa dkimitsa deleted the debugger branch July 19, 2017 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants