Skip to content

Commit

Permalink
Fixed twolevel nested debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
jindrapetrik committed Aug 5, 2024
1 parent 3f9e66c commit d505eee
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

private static var s:Socket;
private static var q = [];
private static var first:Boolean = true;
private static var inited:Boolean = false;
private static var name:String;
private static var failed:Boolean = false;
Expand All @@ -34,12 +33,16 @@
public static const MSG_DUMP_BYTEARRAY = 3;
public static const MSG_REQUEST_BYTEARRAY = 4;
public static const MSG_LOADER_URL_INFO = 5;
public static const MSG_LOADER_MODIFY_BYTES = 6;
public static const MSG_LOADER_MODIFY_BYTES = 6;

private static var connected:Boolean = false;

public static const SHOW_TRACE = false;

private static function sendQueue(){
if (SHOW_TRACE) trace("debugswf: client " + name + " sending queue");
var qo = q;
q = [];
sendHeader();
for each(var m in qo){
writeMsg(m.data,m.type);
}
Expand Down Expand Up @@ -103,25 +106,30 @@
if(inited){
return;
}
if (SHOW_TRACE) trace("debugswf: initing client " + sname);
name = sname;
inited = true;
try {
s = new Socket();
s = new Socket();
s.addEventListener(Event.CONNECT, onSocketConnect);
s.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
var port:int = 0;
port = 123456;
port = 123456;
if (SHOW_TRACE) trace("debugswf: connecting client " + sname + " to localhost:" + port) ;
s.connect("localhost",port);

inited = true;
} catch (e:SecurityError) {
trace("Debugger helper failed to connect to localhost");
if (SHOW_TRACE) trace("Debugger helper failed to connect to localhost");
failed = true;
}
}

private static function onSocketConnect(event:Event):void {
sendQueue();
if (SHOW_TRACE) trace("debugswf: client " + name + " connected");
sendHeader();
connected = true;
sendQueue();
}


Expand Down Expand Up @@ -150,8 +158,10 @@
} else {
ba.position = pos;
}
if (SHOW_TRACE) trace("debugswf: client " + name + " received bytearray of " + ba.length + " bytes");
var onComplete = fillByteArraysEvents.pop();
if (onComplete != null) {
if (SHOW_TRACE) trace("debugswf: client " + name + " calling onComplete");
onComplete.call(onComplete);
}
}
Expand Down Expand Up @@ -200,33 +210,31 @@
}

private static function sendHeader() {
if (!first) {
return;
}
if (!s.connected) {
return;
}
writeStringNull("debug.version.major="+DEBUG_VERSION_MAJOR+";debug.version.minor="+DEBUG_VERSION_MINOR);
writeString(name);
first = false;
}

public static function writeMsg(msg,msgType=0){
if (failed) {
return;
}
if(!inited) {
initClient("");
var max:int = 100000;
var randomInt:int = Math.floor(Math.random() * (max + 1));
initClient("rand" + randomInt);
}
if ((msg is ByteArray) && msgType == MSG_DUMP_BYTEARRAY) {
var ba2:ByteArray = new ByteArray();
ba2.writeBytes(msg);
msg = ba2;
}

if(s.connected){
sendHeader();
s.writeByte(msgType);
if(connected) {
if (SHOW_TRACE) trace("debugswf: client " + name +" sending msg " + msgType);
s.writeByte(msgType);
switch(msgType){
case MSG_STRING:
writeString(msg);
Expand All @@ -242,6 +250,7 @@
break;
case MSG_REQUEST_BYTEARRAY:
fillByteArrays.push(msg);
fillByteArraysEvents.push(null);
break;
case MSG_LOADER_MODIFY_BYTES:
writeString(msg["url"]);
Expand All @@ -251,7 +260,9 @@
break;
}
s.flush();
if (SHOW_TRACE) trace("debugswf: client " + name +" msg " + msgType + " sent");
}else{
if (SHOW_TRACE) trace("debugswf: client " + name +" pushing msg " + msgType + " to queue");
q.push({type:msgType,data:msg});
}
}
Expand Down
Binary file modified libsrc/ffdec_lib/testdata/debug_inner/inner.swf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'04.08.2024'</value>
<value>'05.08.2024'</value>
</define>
<define append="true">
<name>CONFIG::air</name>
Expand All @@ -32,12 +32,12 @@
</define>
<verbose-stacktraces>true</verbose-stacktraces>
<source-path append="true">
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner\src</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner\src</path-element>
<path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
</source-path>
</compiler>
<file-specs>
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner\src\InnerMain.as</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner\src\InnerMain.as</path-element>
</file-specs>
<default-background-color>#FFFFFF</default-background-color>
<default-frame-rate>30</default-frame-rate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'04.08.2024'</value>
<value>'05.08.2024'</value>
</define>
<define append="true">
<name>CONFIG::air</name>
Expand All @@ -32,12 +32,12 @@
</define>
<verbose-stacktraces>true</verbose-stacktraces>
<source-path append="true">
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner\src</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner\src</path-element>
<path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
</source-path>
</compiler>
<file-specs>
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner\src\InnerMain.as</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner\src\InnerMain.as</path-element>
</file-specs>
<default-background-color>#FFFFFF</default-background-color>
<default-frame-rate>30</default-frame-rate>
Expand Down
20 changes: 18 additions & 2 deletions libsrc/ffdec_lib/testdata/debug_inner/inner/src/InnerMain.as
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;

public class InnerMain extends Sprite
{
Expand All @@ -13,10 +15,24 @@ package
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point

var textField:TextField = new TextField();

textField.text = "Main inner1.";

var textFormat:TextFormat = new TextFormat();
textFormat.size = 24;
textFormat.color = 0x000000;
textField.setTextFormat(textFormat);
textField.width = 200;

addChild(textField);

textField.x = 50;
textField.y = 125;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ package
var byteArray:ByteArray = new binaryData2Class() as ByteArray;
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
//trace("loading innerSwf 2");
loader.loadBytes(byteArray);
}

private function onLoaderComplete(event:Event):void {
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
var className:String = "MyInnerClass2";
//trace("getting definition of " + className);
var LoadedClass:Class = loaderInfo.applicationDomain.getDefinition(className) as Class;
var instance:* = new LoadedClass();
//trace("calling innerSwf 2 instance");
instance.run(root);
}

Expand Down
Binary file modified libsrc/ffdec_lib/testdata/debug_inner/inner2.swf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<output>
<movie outputType="Application" />
<movie input="" />
<movie path="../inner2.swf" />
<movie path="..\inner2.swf" />
<movie fps="30" />
<movie width="800" />
<movie height="600" />
Expand Down Expand Up @@ -72,7 +72,7 @@
</library>
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
<compile path="src\Main.as" />
<compile path="src\InnerMain2.as" />
</compileTargets>
<!-- Paths to exclude from the Project Explorer tree -->
<hiddenPaths>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'04.08.2024'</value>
<value>'05.08.2024'</value>
</define>
<define append="true">
<name>CONFIG::air</name>
Expand All @@ -32,12 +32,12 @@
</define>
<verbose-stacktraces>true</verbose-stacktraces>
<source-path append="true">
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner2\src</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner2\src</path-element>
<path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
</source-path>
</compiler>
<file-specs>
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner2\src\Main.as</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner2\src\InnerMain2.as</path-element>
</file-specs>
<default-background-color>#FFFFFF</default-background-color>
<default-frame-rate>30</default-frame-rate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'04.08.2024'</value>
<value>'05.08.2024'</value>
</define>
<define append="true">
<name>CONFIG::air</name>
Expand All @@ -32,12 +32,12 @@
</define>
<verbose-stacktraces>true</verbose-stacktraces>
<source-path append="true">
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner2\src</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner2\src</path-element>
<path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
</source-path>
</compiler>
<file-specs>
<path-element>C:\FlashRelated\test_debugger\inner_debug\inner2\src\Main.as</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\inner2\src\InnerMain2.as</path-element>
</file-specs>
<default-background-color>#FFFFFF</default-background-color>
<default-frame-rate>30</default-frame-rate>
Expand Down
40 changes: 40 additions & 0 deletions libsrc/ffdec_lib/testdata/debug_inner/inner2/src/InnerMain2.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFormat;

public class InnerMain2 extends Sprite
{
MyInnerClass2;

public function InnerMain2()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);

var textField:TextField = new TextField();

textField.text = "Main inner2.";

var textFormat:TextFormat = new TextFormat();
textFormat.size = 24;
textFormat.color = 0x000000;
textField.setTextFormat(textFormat);
textField.width = 200;

addChild(textField);

textField.x = 50;
textField.y = 100;
}

}

}
24 changes: 0 additions & 24 deletions libsrc/ffdec_lib/testdata/debug_inner/inner2/src/Main.as

This file was deleted.

Binary file modified libsrc/ffdec_lib/testdata/debug_inner/outer.swf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</define>
<define append="true">
<name>CONFIG::timeStamp</name>
<value>'04.08.2024'</value>
<value>'05.08.2024'</value>
</define>
<define append="true">
<name>CONFIG::air</name>
Expand All @@ -32,12 +32,12 @@
</define>
<verbose-stacktraces>true</verbose-stacktraces>
<source-path append="true">
<path-element>C:\FlashRelated\test_debugger\inner_debug\outer\src</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\outer\src</path-element>
<path-element>C:\Program Files (x86)\FlashDevelop\Library\AS3\classes</path-element>
</source-path>
</compiler>
<file-specs>
<path-element>C:\FlashRelated\test_debugger\inner_debug\outer\src\Main.as</path-element>
<path-element>C:\Dropbox\Programovani\JavaSE\FFDec\libsrc\ffdec_lib\testdata\debug_inner\outer\src\Main.as</path-element>
</file-specs>
<default-background-color>#FFFFFF</default-background-color>
<default-frame-rate>30</default-frame-rate>
Expand Down
Loading

0 comments on commit d505eee

Please sign in to comment.