question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simple Dynamic attach not found

See original GitHub issue

Hi Rafael,

I have the same 3 classes last https://github.com/raphw/byte-buddy/issues/643 very simple, but this time, I use the agentmain due to the jframe already in full execution.

I am using jdk 8, with the tools.jar in the classpath

public static void agentmain(final String args, Instrumentation inst) {
        System.out.print("agent main");
        new AgentBuilder.Default()
                .ignore(ElementMatchers.none())
                .disableClassFormatChanges()
                .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
                .with(AgentBuilder.Listener.StreamWriting.toSystemOut())
                .type((ElementMatchers.nameContains("Usuario")))
                .transform((builder, typeDescription, classLoader, module) ->
                        builder.visit(Advice.to(MoreLifeAdvice.class)
                                .on(ElementMatchers.isConstructor()))
                )
                .installOn(inst);
    }

MoreLifeAdvice

public class MoreLifeAdvice {

    @Advice.OnMethodExit
    static void giveMeMoreLife(@Advice.FieldValue(value = "life", readOnly = false) int life)
    throws Exception {
        System.out.println("New life set to 1000");
        life = 1000;
    }

}

Launcher

public static void main( String[] args ) {

        final Path path = getFile(null,JFileChooser.FILES_ONLY);

        ByteBuddyAgent.attach(path.toFile(),"pid");
    }

No exception is thrown And the field x is not modified

image

Yesterday I was able to verify that the Advice is not executed

Thanks for the help provided.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rucko24commented, Jul 9, 2019

My lord, how class of bytebuddy API , helps me?

I’m going crazy now. Damn lmao.

I should be use bytebuddy API right?

2reactions
raphwcommented, Jun 27, 2019

You would need to check when your constructor is called and when your agent is attached. If the latter happens before the former, the field value will mot have changed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixing Bugs in Running Java Code with Dynamic Attach
Using Java agents and the dynamic attach and instrumentation APIs it is possible to fix bugs in running Java programs.
Read more >
Dynamically attaching a Java agent not working - Stack Overflow
Just inspect the output directory, and you will see it. Simply add the missing class file to the JAR and be happy: runCommand("jar...
Read more >
Using JConsole - Java SE Monitoring and Management Guide
Applications which support dynamic attach do not require the management agent to be started by specifying the com.sun.management.jmxremote or ...
Read more >
Attach a Database - SQL Server - Microsoft Learn
Learn how to attach a database in SQL Server by using SQL Server Management Studio or Transact-SQL. Use this feature to copy, move, ......
Read more >
Unknown thread dumps found in mule_ee.log
If we see thread dumps in mule_ee.log while no one purposely triggers it, it might be the dynamic attach is failing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found