Re: Learning ASM

Remi Forax <[email protected]> Tue, 2 Oct 2018 15:16:23 +0200 (CEST)
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
This is a multi-part message in MIME format...

------------=_1538486190-8900-10
Content-Type: multipart/alternative; 
	boundary="=_a44eb3ed-a979-4c00-89de-dff9567b8775"

--=_a44eb3ed-a979-4c00-89de-dff9567b8775
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi Paul,=20

> De: "Paul Bell" <[email protected]>
> =C3=80: "asm" <[email protected]>
> Envoy=C3=A9: Mardi 2 Octobre 2018 14:40:18
> Objet: [asm] Learning ASM

> Hello,

> I am just now learning ASM and this is my first post.

> I've cobbled together a working Java agent that uses ASM to modify method=
s in
> the code I want to trace/debug/monitor. Specifically, I modify static met=
hods,
> instance methods, and constructors. These modifications, inserted at meth=
ods'
> entry, call into my tracing program.

> There's an awful lot I don't know about ASM and I would be grateful for h=
elp
> with a few things (for now):

>    * How can ASM be used to "single step" through program execution? By "=
single
>    step" I mean similar to the Eclipse debug breakpoint facility where pr=
essing F5
>     allows you to step into the next instruction.

ASM do bytecode transformation by transforming the bytecode in a series of =
visitor calls, if you put a breakpoint in one of the MethodVisitor.visit*In=
sn you override, you will see the method been called for each bytecode mana=
ged by this method.=20

>    * How can I "hook" INVOKEVIRTUAL calls? I would like to know when a me=
thod calls
>     another method.

override MethodVisitor.visitMethodInsn et check if the opcode is Opcodes.IN=
VOKEVIRTUAL=20

>     * What are "labels" and how are they used?

labels are target of gotos, catch blocks, etc.=20
You can create one with new Label(), insert it in the bytecode flow with vi=
sitLabel() and use it as parameter of any visit* methods.=20

Eric has written a nice guide that explain how to use ASM and how ASM works=
 under the cover,=20
[ https://asm.ow2.io/asm4-guide.pdf | https://asm.ow2.io/asm4-guide.pdf ]=20

> Thanks very much.

> -Paul

R=C3=A9mi=20

--=_a44eb3ed-a979-4c00-89de-dff9567b8775
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<html><body><div style=3D"font-family: arial, helvetica, sans-serif; font-s=
ize: 12pt; color: #000000"><div>Hi Paul,<br></div><div><br></div><hr id=3D"=
zwchr" data-marker=3D"__DIVIDER__"><div data-marker=3D"__HEADERS__"><blockq=
uote style=3D"border-left:2px solid #1010FF;margin-left:5px;padding-left:5p=
x;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font=
-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>De: </b>"Paul Bell" =
&lt;[email protected]&gt;<br><b>=C3=80: </b>"asm" &lt;[email protected]&gt;<br><=
b>Envoy=C3=A9: </b>Mardi 2 Octobre 2018 14:40:18<br><b>Objet: </b>[asm] Lea=
rning ASM<br></blockquote></div><div data-marker=3D"__QUOTED_TEXT__"><block=
quote style=3D"border-left:2px solid #1010FF;margin-left:5px;padding-left:5=
px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;fon=
t-family:Helvetica,Arial,sans-serif;font-size:12pt;"><div dir=3D"ltr"><div =
dir=3D"ltr">Hello,<br></div><br><div>I am just now learning ASM and this is=
 my first post.</div><br><div>I've cobbled together a working Java agent th=
at uses ASM to modify methods in the code I want to trace/debug/monitor. Sp=
ecifically, I modify static methods, instance methods, and constructors. Th=
ese modifications, inserted at methods' entry, call into my tracing program=
.</div><br><div>There's an awful lot I don't know about ASM and I would be =
grateful for help with a few things (for now):</div><div><ul><li>How can AS=
M be used to "single step" through program execution? By "single step" I me=
an similar to the Eclipse debug breakpoint facility where pressing F5 allow=
s you to step into the next instruction.</li></ul></div></div></blockquote>=
<div><br></div><div>ASM do bytecode transformation by transforming the byte=
code in a series of visitor calls, if you put a breakpoint in one of the Me=
thodVisitor.visit*Insn you override, you will see the method been called fo=
r each bytecode managed by this method.&nbsp; <br data-mce-bogus=3D"1"></di=
v><div><br data-mce-bogus=3D"1"></div><blockquote style=3D"border-left:2px =
solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:norma=
l;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-s=
erif;font-size:12pt;"><div dir=3D"ltr"><div><ul><li>How can I "hook" INVOKE=
VIRTUAL calls? I would like to know when a method calls another method.</li=
></ul></div></div></blockquote><div><br></div><div>override MethodVisitor.v=
isitMethodInsn et check if the opcode is Opcodes.INVOKEVIRTUAL<br data-mce-=
bogus=3D"1"></div><div><br data-mce-bogus=3D"1"></div><blockquote style=3D"=
border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;f=
ont-weight:normal;font-style:normal;text-decoration:none;font-family:Helvet=
ica,Arial,sans-serif;font-size:12pt;"><div dir=3D"ltr"><div><ul><li>What ar=
e "labels" and how are they used?</li></ul></div></div></blockquote><div><b=
r></div><div>labels are target of gotos, catch blocks, etc.<br data-mce-bog=
us=3D"1"></div><div>You can create one with new Label(), insert it in the b=
ytecode flow with visitLabel() and use it as parameter of any visit* method=
s.<br data-mce-bogus=3D"1"></div><div><br data-mce-bogus=3D"1"></div><div>E=
ric has written a nice guide that explain how to use ASM and how ASM works =
under the cover,<br data-mce-bogus=3D"1"></div><div><a href=3D"https://asm.=
ow2.io/asm4-guide.pdf">https://asm.ow2.io/asm4-guide.pdf</a><br data-mce-bo=
gus=3D"1"></div><div><br data-mce-bogus=3D"1"></div><div><br data-mce-bogus=
=3D"1"></div><blockquote style=3D"border-left:2px solid #1010FF;margin-left=
:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-=
decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><di=
v dir=3D"ltr"><div>Thanks very much.</div><br><div>-Paul</div></div></block=
quote><div><br></div><div>R=C3=A9mi<br data-mce-bogus=3D"1"></div><div><br =
data-mce-bogus=3D"1"></div>
</div></div></body></html>=

--=_a44eb3ed-a979-4c00-89de-dff9567b8775--

------------=_1538486190-8900-10
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit


-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws

------------=_1538486190-8900-10--