btrace | BTrace a safe, dynamic tracing tool for the Java platform

 by   btraceio Java Updated: 12 days ago - v2.2.1 License: No License

Download this library from

Build Applications

kandi X-RAY | btrace REVIEW AND RATINGS

BTrace is a safe, dynamic tracing tool for the Java platform. BTrace can be used to dynamically trace a running Java program (similar to DTrace for OpenSolaris applications and OS). BTrace dynamically instruments the classes of the target application to inject tracing code ("bytecode tracing").

kandi-support
Support

  • btrace has a highly active ecosystem.
  • It has 4923 star(s) with 879 fork(s).
  • There were 1 major release(s) in the last 6 months.
  • On average issues are closed in 51 days.
  • It has a neutral sentiment in the developer community.

quality kandi
Quality

  • btrace has 76 bugs (9 blocker, 2 critical, 24 major, 41 minor) and 2705 code smells.

security
Security

  • btrace has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • btrace code analysis shows 0 unresolved vulnerabilities.
  • There are 43 security hotspots that need review.

license
License

  • btrace does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.

build
Reuse

  • btrace releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • btrace saves you 22320 person hours of effort in developing the same functionality from scratch.
  • It has 43746 lines of code, 3535 functions and 529 files with 0 % test coverage
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
Top functions reviewed by kandi - BETA

kandi has reviewed btrace and discovered the below as its top functions. This is intended to give you an instant insight into btrace implemented functionality, and help decide if they suit your requirements.

  • Returns the instrumentor for the given method invocation .
  • Verify the bytecode of the class .
  • Entry point to btraces .
  • Validates the given arguments .
  • Handle the if recursive expression .
  • create a new consumer
  • Normalize service initialization instructions .
  • Attaches a virtual machine to a process .
  • process the stack frame
  • implements the visitor to check for classes members and constructors .

btrace Key Features

BTrace - a safe, dynamic tracing tool for the Java platform

btrace examples and code snippets

  • Build
  • Deb Repository
  • Getting java.lang.ClassNotFoundException when I try to do spark-submit, referred other similar queries online but couldnt get it to work
  • Errors while trying to build GDB for ARM
  • Segmentation fault after upgrading to openCV 3.4.1 from 3.2
  • btrace with glassfish web container
  • Python RegExp retrieve value from matching string

Build

cd <btrace>
./gradlew build
./gradlew buildDistributions

Deb Repository

echo "deb http://dl.bintray.com/btraceio/deb xenial universe" | sudo tee -a /etc/apt/sources.list

Getting java.lang.ClassNotFoundException when I try to do spark-submit, referred other similar queries online but couldnt get it to work

<project>
  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>4.5.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Errors while trying to build GDB for ARM

./configure ... LD=/path/to/arm-XXX-ld CC=/path/to/arm-XXX-gcc CXX=/path/to/arm-XXX-g++
-----------------------
PATH="$PATH:$HOME/tmp/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/bin"
./configure --host=arm-linux-gnueabi
make
checking for arm-linux-gnueabi-gcc...  found arm-linux-gnueabi-gcc
-----------------------
PATH="$PATH:$HOME/tmp/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/bin"
./configure --host=arm-linux-gnueabi
make
checking for arm-linux-gnueabi-gcc...  found arm-linux-gnueabi-gcc

Segmentation fault after upgrading to openCV 3.4.1 from 3.2

void Txtbin::binarize(){
    src.convertTo(src, CV_32FC1, 1.0 / 255.0);
    cv::Mat res = calc_block_mean_variance(src) * 255;
    imwrite(output, res);
}

btrace with glassfish web container

org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
-----------------------
org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
-----------------------
org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
-----------------------
org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
-----------------------
org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
-----------------------
org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
-----------------------
org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
-----------------------
org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
com.sun.btrace.agent.Client.retransformLoaded
void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff
 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }
  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }
 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...
  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started
  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }

Python RegExp retrieve value from matching string

line = "17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'"
import re
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
# now extract each section
date, time, level, thread, module, message = line_regex.match(line).groups()
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

if 'ClientID' in message:
    client_id = client_id_regex.match(message).group(1)
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

with open('t.log','r') as f:  # use with context manager to auto close the file
    for line in f:  # lets iterate over the lines
        sections = line_regex.match(line)  # make a match object for sections
        if not sections:
            continue  # probably you want to handle this case
        date, time, level, thread, module, message = sections.groups()
        if 'ClientID' in message:  # should we even look here for a client id?
            client_id = client_id_regex.match(message).group(1)
# now do what you wanted to do
-----------------------
line = "17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'"
import re
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
# now extract each section
date, time, level, thread, module, message = line_regex.match(line).groups()
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

if 'ClientID' in message:
    client_id = client_id_regex.match(message).group(1)
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

with open('t.log','r') as f:  # use with context manager to auto close the file
    for line in f:  # lets iterate over the lines
        sections = line_regex.match(line)  # make a match object for sections
        if not sections:
            continue  # probably you want to handle this case
        date, time, level, thread, module, message = sections.groups()
        if 'ClientID' in message:  # should we even look here for a client id?
            client_id = client_id_regex.match(message).group(1)
# now do what you wanted to do
-----------------------
line = "17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'"
import re
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
# now extract each section
date, time, level, thread, module, message = line_regex.match(line).groups()
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

if 'ClientID' in message:
    client_id = client_id_regex.match(message).group(1)
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

with open('t.log','r') as f:  # use with context manager to auto close the file
    for line in f:  # lets iterate over the lines
        sections = line_regex.match(line)  # make a match object for sections
        if not sections:
            continue  # probably you want to handle this case
        date, time, level, thread, module, message = sections.groups()
        if 'ClientID' in message:  # should we even look here for a client id?
            client_id = client_id_regex.match(message).group(1)
# now do what you wanted to do
-----------------------
line = "17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'"
import re
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
# now extract each section
date, time, level, thread, module, message = line_regex.match(line).groups()
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

if 'ClientID' in message:
    client_id = client_id_regex.match(message).group(1)
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

with open('t.log','r') as f:  # use with context manager to auto close the file
    for line in f:  # lets iterate over the lines
        sections = line_regex.match(line)  # make a match object for sections
        if not sections:
            continue  # probably you want to handle this case
        date, time, level, thread, module, message = sections.groups()
        if 'ClientID' in message:  # should we even look here for a client id?
            client_id = client_id_regex.match(message).group(1)
# now do what you wanted to do
-----------------------
import re
s = "17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'"
regex = r"^([\d.]+)\s+([\d.:]+)\s+(TRACE)\s+\[(\d+)] GDS:.*?ClientID:\s*''\s*->\s*'(\d+)'$"
m = re.search(regex, s)
if m:
    print(m.group(1))
    print(m.group(2))
    print(m.group(3))
    print(m.group(4))
    print(m.group(5))
^([\d.]+)\s+([\d.:]+)\s+(TRACE)\s+\[(\d+)] GDS:.*?ClientID:\s*''\s*->\s*'(\d+)'$
-----------------------
import re
s = "17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'"
regex = r"^([\d.]+)\s+([\d.:]+)\s+(TRACE)\s+\[(\d+)] GDS:.*?ClientID:\s*''\s*->\s*'(\d+)'$"
m = re.search(regex, s)
if m:
    print(m.group(1))
    print(m.group(2))
    print(m.group(3))
    print(m.group(4))
    print(m.group(5))
^([\d.]+)\s+([\d.:]+)\s+(TRACE)\s+\[(\d+)] GDS:.*?ClientID:\s*''\s*->\s*'(\d+)'$

COMMUNITY DISCUSSIONS

Top Trending Discussions on btrace
  • Getting java.lang.ClassNotFoundException when I try to do spark-submit, referred other similar queries online but couldnt get it to work
  • What time units are provided by BTrace when using @Duration annotation? Millis, micros or maybe nanos? Cannot find it in the documentation
  • Errors while trying to build GDB for ARM
  • strange things with btrace and java.lang.NoSuchMethodError
  • Segmentation fault after upgrading to openCV 3.4.1 from 3.2
  • How to trace a java application running on a remote host
  • btrace with glassfish web container
  • Python RegExp retrieve value from matching string
Top Trending Discussions on btrace

QUESTION

Getting java.lang.ClassNotFoundException when I try to do spark-submit, referred other similar queries online but couldnt get it to work

Asked 2021-Jun-14 at 09:36

I am new to Spark and am trying to run on a hadoop cluster a simple spark jar file built through maven in intellij. But I am getting classnotfoundexception in all the ways I tried to submit the application through spark-submit.

My pom.xml:

<?xmlversion="1.0"encoding="UTF-8"?>
<projectxmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>SparkTrans</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<!--https://mvnrepository.com/artifact/org.apache.spark/spark-core-->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.4.3</version>
</dependency>
<!--https://mvnrepository.com/artifact/org.apache.spark/spark-sql-->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.4.3</version>
</dependency>

<!--https://mvnrepository.com/artifact/org.apache.spark/spark-hive-->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.11</artifactId>
<version>2.4.3</version>
<scope>compile</scope>
</dependency>
<!--https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.8</version>
<scope>test</scope>
</dependency>
<!--https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8</version>
</dependency>
<!--https://mvnrepository.com/artifact/com.typesafe/config-->
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>shade-libs</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>resources/*</exclude>
</excludes>
</filter>
</filters>
<shadedClassifierName>fat</shadedClassifierName>
<shadedArtifactAttached>true</shadedArtifactAttached>
<relocations>
<relocation>
<pattern>org.apache.http.client</pattern>
<shadedPattern>shaded.org.apache.http.client</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>

My main scala object (SparkTrans.scala):

import common.InputConfig
import org.apache.spark.sql.{DataFrame,SparkSession}
importorg.slf4j.LoggerFactory

object SparkTrans{

private val logger=LoggerFactory.getLogger(getClass.getName)

def main(args:Array[String]):Unit={
try{
logger.info("main method started")
logger.warn("This is a warning")

val arg_length=args.length

if(arg_length==0){
logger.warn("No Argument passed")
System.exit(1)
}

val inputConfig:InputConfig=InputConfig(env=args(0),targetDB=args(1))
println("The first argument passed is" + inputConfig.env)
println("The second argument passed is" + inputConfig.targetDB)

val spark=SparkSession
.builder()
.appName("SparkPOCinside")
.config("spark.master","yarn")
.enableHiveSupport()
.getOrCreate()

println("Created Spark Session")

val sampleSeq=Seq((1,"Spark"),(2,"BigData"))

val df1=spark.createDataFrame(sampleSeq).toDF("courseid","coursename")
df1.show()


logger.warn("sql_test_a method started")
val courseDF=spark.sql("select * from MYINSTANCE.sql_test_a")
logger.warn("sql_test_a method ended")
courseDF.show()


}
catch{
case e:Exception=>
logger.error("An error has occurred in the main method" + e.printStackTrace())
}


}

}

I tried the below commands to spark-submit, but all of them give classnotfoundexception. I tried to switch the arguments around where I mention the --class right after --deploy-mode but in vain:

spark-submit --master yarn --deploy-mode cluster --queue ABCD --conf spark.yarn.security.tokens.hive.enabled=false --files hdfs://nameservice1/user/XMLs/hive-site.xml --keytab hdfs://nameservice1/user/MYINSTANCE/landing/workflow/wf_data/lib/MYKEY.keytab --num-executors 1 --executor-cores 1 --executor-memory 2g --conf spark.yarn.executor.memoryOverhead=3072 --class org.example.SparkTrans hdfs://nameservice1/user/MYINSTANCE/landing/workflow/wf_data/SparkTrans-1.0-SNAPSHOT-fat.jar dev somedb


spark-submit --master yarn --deploy-mode cluster --queue ABCD --conf spark.yarn.security.tokens.hive.enabled=false --files hdfs://nameservice1/user/XMLs/hive-site.xml --keytab hdfs://nameservice1/user/MYINSTANCE/landing/workflow/wf_data/lib/MYKEY.keytab --num-executors 1 --executor-cores 1 --executor-memory 2g --conf spark.yarn.executor.memoryOverhead=3072 --class org.example.SparkTrans --name org.example.SparkTrans hdfs://nameservice1/user/MYINSTANCE/landing/workflow/wf_data/SparkTrans-1.0-SNAPSHOT-fat.jar dev somedb


spark-submit --master yarn --deploy-mode cluster --queue ABCD --conf spark.yarn.security.tokens.hive.enabled=false --files hdfs://nameservice1/user/XMLs/hive-site.xml --keytab hdfs://nameservice1/user/MYINSTANCE/landing/workflow/wf_data/lib/MYKEY.keytab --num-executors 1 --executor-cores 1 --executor-memory 2g --conf spark.yarn.executor.memoryOverhead=3072 --class SparkTrans hdfs://nameservice1/user/MYINSTANCE/landing/workflow/wf_data/SparkTrans-1.0-SNAPSHOT-fat.jar dev somedb

Exact error I am getting:

btrace WARNING: No output stream. DataCommand output is ignored.
[main] INFO ResourceCollector - Unravel Sensor 4.6.1.8rc0013/2.0.3 initializing.
21/06/11 10:09:27 INFO yarn.ApplicationMaster: Registered signal handlers for [TERM, HUP, INT]
21/06/11 10:09:28 INFO yarn.ApplicationMaster: ApplicationAttemptId: appattempt_1614625006458_6646161_000001
21/06/11 10:09:30 INFO spark.SecurityManager: Changing view acls to: MYKEY
21/06/11 10:09:30 INFO spark.SecurityManager: Changing modify acls to: MYKEY
21/06/11 10:09:30 INFO spark.SecurityManager: Changing view acls groups to: 
21/06/11 10:09:30 INFO spark.SecurityManager: Changing modify acls groups to: 
21/06/11 10:09:30 INFO spark.SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(MYKEY); groups with view permissions: Set(); users  with modify permissions: Set(MYKEY); groups with modify permissions: Set()
21/06/11 10:09:30 INFO yarn.ApplicationMaster: Starting the user application in a separate Thread
21/06/11 10:09:30 ERROR yarn.ApplicationMaster: Uncaught exception: 
java.lang.ClassNotFoundException: SparkTrans
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.spark.deploy.yarn.ApplicationMaster.startUserApplication(ApplicationMaster.scala:561)
    at org.apache.spark.deploy.yarn.ApplicationMaster.runDriver(ApplicationMaster.scala:347)
    at org.apache.spark.deploy.yarn.ApplicationMaster.run(ApplicationMaster.scala:197)
    at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$main$1.apply$mcV$sp(ApplicationMaster.scala:695)
    at org.apache.spark.deploy.SparkHadoopUtil$$anon$1.run(SparkHadoopUtil.scala:69)
    at org.apache.spark.deploy.SparkHadoopUtil$$anon$1.run(SparkHadoopUtil.scala:68)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1924)
    at org.apache.spark.deploy.SparkHadoopUtil.runAsSparkUser(SparkHadoopUtil.scala:68)
    at org.apache.spark.deploy.yarn.ApplicationMaster$.main(ApplicationMaster.scala:693)
    at org.apache.spark.deploy.yarn.ApplicationMaster.main(ApplicationMaster.scala)
21/06/11 10:09:30 INFO yarn.ApplicationMaster: Final app status: FAILED, exitCode: 10, (reason: Uncaught exception: java.lang.ClassNotFoundException: SparkTrans)
21/06/11 10:09:30 INFO util.ShutdownHookManager: Shutdown hook called

Can any of you let me know what I am doing wrong? I have checked and see the hive-site.xml and my jar are in the correct locations in hdfs as mentioned in my commands.

ANSWER

Answered 2021-Jun-14 at 09:36

You need to add scala-compiler configuration to your pom.xml. The problem is without that there is nothing to compile your SparkTrans.scala file into java classes.

Add:

<project>
  <build>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>scala-maven-plugin</artifactId>
        <version>4.5.2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>testCompile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

to your pom.xml and ensure your scala file is in src/main/scala

Then it should be compiled and added to your jar. Here's the documentation for the scala plugin.

You can check what's in your jar with jar tf jar-file, see guide here.

Source https://stackoverflow.com/questions/67934425

QUESTION

What time units are provided by BTrace when using @Duration annotation? Millis, micros or maybe nanos? Cannot find it in the documentation

Asked 2019-Feb-08 at 08:22

Look at method 'methodExit'. What units of time are held in parameter "@Duration long time"?

package com.sun.btrace.samples;

import com.sun.btrace.Profiler;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
import java.awt.EventQueue;
import java.awt.AWTEvent;
import java.awt.event.FocusEvent;

@BTrace
public class AllMethods {

    @OnMethod(
        clazz="java.awt.EventQueue",
        method="dispatchEvent",
        location=@Location(Kind.RETURN))
    public static void methodExit(@Duration long time, @ProbeMethodName String pmn) {
        println(pmn + " " + (time / 1000000));
    }
}

ANSWER

Answered 2017-Feb-17 at 09:13

The duration is measured in nanoseconds.

The javadoc is missing this information - I have filed an issue for that. If you want to dig in the sources this place is a good start.

Source https://stackoverflow.com/questions/42133516

QUESTION

Errors while trying to build GDB for ARM

Asked 2018-Oct-08 at 12:32

I'm trying to build GDB (version 8.0) for an arm on my Ubuntu 16.04 machine. I'm planning to debug it directly on the arm machine (currently without a server).

I have executed these instructions (as it was explained here)

./configure --target=arm-linux-gnueabi --host=arm-linux-gnueabi --build=x86_64_unknown-linux-gnu 
make

During the linkage the system threw me this error:

g++ -std=gnu++11 -g -O2   -static-libstdc++ -static-libgcc    \
    -o gdb gdb.o arm.o arm-linux.o arm-get-next-pcs.o arm-tdep.o arm-linux-tdep.o glibc-tdep.o solib-svr4.o symfile-mem.o linux-tdep.o linux-record.o ser-base.o ser-unix.o ser-pipe.o ser-tcp.o inf-ptrace.o fork-child.o arm-linux-nat.o aarch32-linux-nat.o proc-service.o linux-thread-db.o linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o linux-waitpid.o linux-personality.o linux-namespaces.o ax-gdb.o ax-general.o ctf.o dcache.o remote.o remote-fileio.o remote-notif.o tracefile.o tracefile-tfile.o tracepoint.o  cli-cmds.o cli-decode.o cli-dump.o cli-interp.o cli-logging.o cli-script.o cli-setshow.o cli-utils.o mi-cmd-break.o mi-cmd-catch.o mi-cmd-disas.o mi-cmd-env.o mi-cmd-file.o mi-cmd-info.o mi-cmd-stack.o mi-cmd-target.o mi-cmd-var.o mi-cmds.o mi-console.o mi-getopt.o mi-interp.o mi-main.o mi-out.o mi-parse.o mi-symbol-cmds.o stub-termcap.o python.o guile.o elfread.o stap-probe.o dtrace-probe.o posix-hdep.o posix-strerror.o ada-exp.o c-exp.o cp-name-parser.o d-exp.o f-exp.o go-exp.o m2-exp.o p-exp.o rust-exp.o ada-lang.o ada-tasks.o ada-typeprint.o ada-valprint.o ada-varobj.o addrmap.o agent.o annotate.o arch-utils.o auto-load.o auxv.o bcache.o bfd-target.o block.o blockframe.o break-catch-sig.o break-catch-syscall.o break-catch-throw.o breakpoint.o btrace.o btrace-common.o buffer.o build-id.o buildsym.o c-lang.o c-typeprint.o c-valprint.o c-varobj.o charset.o cleanups.o cli-out.o coff-pe-read.o coffread.o common-agent.o common-debug.o common-exceptions.o common-regcache.o common-utils.o complaints.o completer.o continuations.o copying.o corefile.o corelow.o cp-abi.o cp-namespace.o cp-support.o cp-valprint.o d-lang.o d-namespace.o d-valprint.o dbxread.o debug.o demangle.o dfp.o dictionary.o disasm.o disasm-selftests.o doublest.o dummy-frame.o dwarf2-frame.o dwarf2-frame-tailcall.o dwarf2expr.o dwarf2loc.o dwarf2read.o environ.o errors.o eval.o event-loop.o event-top.o exceptions.o exec.o expprint.o extension.o f-lang.o f-typeprint.o f-valprint.o fileio.o filestuff.o filesystem.o findcmd.o findvar.o format.o frame.o frame-base.o frame-unwind.o gcore.o gdb_bfd.o gdb-dlfcn.o gdb_obstack.o gdb_usleep.o gdb_vecs.o gdbarch.o gdbtypes.o gnu-v2-abi.o gnu-v3-abi.o go-lang.o go-typeprint.o go-valprint.o inf-child.o inf-loop.o infcall.o infcmd.o inferior.o infrun.o inline-frame.o interps.o jit.o language.o linespec.o location.o m2-lang.o m2-typeprint.o m2-valprint.o macrocmd.o macroexp.o macroscope.o macrotab.o main.o maint.o mdebugread.o mem-break.o memattr.o memory-map.o memrange.o mi-common.o minidebug.o minsyms.o mipsread.o namespace.o new-op.o objc-lang.o objfiles.o observer.o opencl-lang.o osabi.o osdata.o p-lang.o p-typeprint.o p-valprint.o parse.o print-utils.o printcmd.o probe.o progspace.o prologue-value.o psymtab.o ptid.o record.o record-btrace.o record-full.o regcache.o reggroups.o registry.o reverse.o rsp-low.o run-time-clock.o rust-lang.o selftest.o selftest-arch.o sentinel-frame.o ser-event.o serial.o signals.o signals-state-save-restore.o skip.o solib.o solib-target.o source.o stabsread.o stack.o std-regs.o symfile.o symfile-debug.o symmisc.o symtab.o target.o target-dcache.o target-descriptions.o target-memory.o thread.o thread-fsm.o tid-parse.o top.o trad-frame.o tramp-frame.o typeprint.o ui-file.o ui-out.o user-regs.o utils.o utils-selftests.o valarith.o valops.o valprint.o value.o varobj.o vec.o version.o waitstatus.o xml-builtin.o xml-support.o xml-syscall.o xml-tdesc.o xml-utils.o compile.o compile-c-support.o compile-c-symbols.o compile-c-types.o compile-loc2c.o compile-object-load.o compile-object-run.o inflow.o    init.o \
       ../readline/libreadline.a ../opcodes/libopcodes.a ../bfd/libbfd.a -L./../zlib -lz  ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a    -ldl -ldl -lm -ldl     ../libiberty/libiberty.a  build-gnulib/import/libgnu.a  -ldl -Wl,--dynamic-list=./proc-service.list
/usr/bin/ld: ../readline/libreadline.a(readline.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: ../readline/libreadline.a(readline.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: ../readline/libreadline.a(readline.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: ../readline/libreadline.a(readline.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: ../readline/libreadline.a(readline.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: ../readline/libreadline.a(readline.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: ../readline/libreadline.a(readline.o): Relocations in generic ELF (EM: 40)
../readline/libreadline.a: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
Makefile:2215: recipe for target 'gdb' failed
make[2]: *** [gdb] Error 1
make[2]: Leaving directory '/home/user/gdb-8.0/gdb'
Makefile:9126: recipe for target 'all-gdb' failed
make[1]: *** [all-gdb] Error 2
make[1]: Leaving directory '/home/user/gdb-8.0'
Makefile:849: recipe for target 'all' failed
make: *** [all] Error 2

I have tried to download a new readline library and replace it with the one that comes with the gdb, but it didn't solve my problem.

Does anybody have a clue?

Thanks!

ANSWER

Answered 2017-Dec-15 at 16:01

./configure --target=arm-linux-gnueabi ...

You are trying to build an ARM binary on an x86 machine. You need a cross-compiler targeting ARM for that, but you appear to be using your native compiler (which produces x86 objects).

As fei han said, you need:

./configure ... LD=/path/to/arm-XXX-ld CC=/path/to/arm-XXX-gcc CXX=/path/to/arm-XXX-g++

Source https://stackoverflow.com/questions/47807718

QUESTION

strange things with btrace and java.lang.NoSuchMethodError

Asked 2018-Sep-12 at 09:25

the main class:

package com.xxx.yyy;

public class Hello{
    public static void main(String[] args){
        A a = new A();
        while(true){
            try {
                a.execute(1000);
                Thread.sleep(1000);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}

class A:

package com.xxx.yyy;

public class A{
    public void execute(int sleepTime) throws Exception {
        System.out.println("sleep time is "+sleepTime); 
    }
}

btrace script:

import static com.sun.btrace.BTraceUtils.println;  
import static com.sun.btrace.BTraceUtils.str;  
import static com.sun.btrace.BTraceUtils.strcat;  
import static com.sun.btrace.BTraceUtils.timeMillis;  

import com.sun.btrace.annotations.BTrace;  
import com.sun.btrace.annotations.Kind;  
import com.sun.btrace.annotations.Location;  
import com.sun.btrace.annotations.OnMethod;  
import com.sun.btrace.annotations.ProbeClassName;  
import com.sun.btrace.annotations.ProbeMethodName;  
import com.sun.btrace.annotations.TLS;
@BTrace
public class BtraceTest{

    @OnMethod(clazz="com.xxx.yyy.A",method="execute",location=@Location(Kind.RETURN))
    public static void traceExecute(@ProbeClassName String name,@ProbeMethodName String method,int sleepTime){
        println(strcat("the class name=>", name));  
        println(strcat("the class method=>", method));  
        println(strcat("the class method params=>", str(sleepTime)));
    }
}

everything is right. BUT: when I move the line Thread.sleep(1000) to class A's execute function, like this:

package com.xxx.yyy;

public class A{
    public void execute(int sleepTime) throws Exception {
        System.out.println("sleep time is "+sleepTime); 
        Thread.sleep(1000);
    }
}

the NoSuchMethodError is thrown by Hello.

Exception in thread "main" java.lang.NoSuchMethodError: com.xxx.yyy.A.$btrace$BtraceTest$traceExecute(Ljava/lang/String;Ljava/lang/String;I)V
    at com.xxx.yyy.A.execute(Unknown Source)
    at com.xxx.yyy.Hello.main(Hello.java:8)

my environment is

java version "1.8.0_121"
BTrace v.1.3.9 (20170111)

anyone can explain why?thanks!

ANSWER

Answered 2017-Nov-13 at 04:54

I think your class should implements Runnable or extends Thread. Then only you can use start, sleepand such similar methods in your program. Have a look at here to know how to implement thread methods.

Source https://stackoverflow.com/questions/47256932

QUESTION

Segmentation fault after upgrading to openCV 3.4.1 from 3.2

Asked 2018-Jun-25 at 00:09

After upgrading from openCV 3.2 to openCV 3.4.1 I get Segmentation fault when running my program

Full source code below (I'm not a C expert)

running the program ./txtbin input.png output.png

Hope someone would be helpful :)

error

> Error: signal 11:
> #1 ./txtbin(_Z6bTracei+0x1c) [0x5596628d8e68]
> #2 /lib/x86_64-linux-gnu/libc.so.6(+0x33060) [0x7fa1b8481060]
> #3 /usr/local/lib/libopencv_world.so.3.4(+0xa3f7da) [0x7fa1b9ac97da]
> #4 /usr/local/lib/libopencv_world.so.3.4(+0xa2782d) [0x7fa1b9ab182d]
> #5 /usr/local/lib/libopencv_world.so.3.4(_ZN2cv7imwriteERKNS_6StringERKNS_11_InputArrayERKSt6vectorIiSaIiEE+0x8e) [0x7fa1b9ab4a4e]
> #6 ./txtbin(_ZN6Txtbin8binarizeEv+0x12d) [0x5596628d67c3]
> #7 ./txtbin(_ZN6Txtbin3runEv+0x698) [0x5596628d8c10]
> #8 ./txtbin(main+0x3fa) [0x5596628d92db]
> #9 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1) [0x7fa1b846e2e1]

input.png

enter image description here

txtbin.cpp

/*
 *  Compile
 *  # g++ -rdynamic -std=c++11 txtbin.cpp -o txtbin `pkg-config opencv --cflags --libs`
 *
 *  Get opencv version
 *  # pkg-config --modversion opencv
*/

#include <signal.h>
#include "../backtrace/backtrace.h"
#include "txtbin.hpp"

Backtrace b;
void bTrace(int sig){
    b.trace(sig);
}

void usage(const std::string VERSION){
    std::cout << "txtbin: " << VERSION << "\nOpenCV: " << CV_VERSION << "\n\nUsage: txtbin input [options] output\n"
        "Options:\n"
        "\t-w <number>          -- Set max width (keeps aspect ratio)\n"
        "\t-h <number>          -- Set max height (keeps aspect ratio)\n"
        "\t-c                   -- Crop text contours\n"
        "\t-r                   -- Rotate contents (deskew)\n"
        "\t-m <number>          -- Set margins (%)\n"
        "\t-b <number>          -- Set blockside (pixel)\n"
        "\t                        Default: 9 pixel\n"
        "\t-t <number>          -- Set threshold (%)\n"
        "\t                        Default: 85 %\n"
        "\t-v                   -- Verbose\n" << std::endl;
}

int main(int argc, char* argv[]){
    signal(SIGSEGV, &bTrace);

    Txtbin a;

    try{
        //  Parse arguments
        for(int i = 1; i < argc; i++){
            std::string arg = std::string(argv[i]);

            if(i == 1){
                a.set_input(arg);
            }
            else if(arg == "-w"){
                a.set_width(atoi(argv[++i]));
            }
            else if(arg == "-h"){
                a.set_height(atoi(argv[++i]));
            }
            else if(arg == "-c"){
                a.set_crop(true);
            }
            else if(arg == "-r"){
                a.set_rotate(true);
            }
            else if(arg == "-m"){
                a.set_margin(atoi(argv[++i]));
            }
            else if(arg == "-b"){
                a.set_blockside(atoi(argv[++i]));
            }
            else if(arg == "-t"){
                a.set_threshold(atoi(argv[++i]));
            }
            else if(arg == "-v"){
                a.set_verbose(true);
            }
            else if(i == argc - 1){
                a.set_output(arg);
            }
            else{
                throw std::runtime_error("Argument '"+arg+"' is invalid");
            }
        }

        a.run();
    }
    catch(std::exception& e){
        std::cerr << "Error: " << e.what() << "\n" << std::endl;
        usage(a.VERSION);
        return 1;
    }

    return 0;
}

txtbin.h

struct textblock{
    int left = 0;
    int top = 0;
    int right = 0;
    int bottom = 0;
};

class Txtbin{
    private:
        std::string input               = "";
        std::string output              = "output.png";
        int max_width                   = 0;
        int max_height                  = 0;
        bool is_crop                    = false;
        bool is_rotate                  = false;
        float margin                    = 0;
        int blockside                   = 9;            //  set greater for larger fonts in image and vice versa
        bool is_verbose                 = false;
        float contrast                  = 0.01;         //  set smaller for lower contrast image
        float thresholding              = 0.85;
        void binarize                   ();
        cv::Mat src;
        cv::Mat calc_block_mean_variance(cv::Mat& img);
        textblock detect_text_block     (bool test_output);
        void downsize                   ();
        void crop                       (textblock coords);
        void error                      (const std::string& s);

    public:
        Txtbin();
        const std::string VERSION   = "0.3.6";
        void set_input              (const std::string& s);
        void set_output             (const std::string& s);
        void set_height             (int h);
        void set_width              (int w);
        void set_crop               (bool c);
        void set_rotate             (bool r);
        void set_margin             (float m);
        void set_blockside          (int b);
        void set_threshold          (int t);
        void set_verbose            (bool v);
        void run                    ();
};

txtbin.hpp

#include <iostream>
#include <fstream>
#include <chrono>
#include <boost/algorithm/string.hpp>
#include "/usr/local/include/opencv2/opencv.hpp"
#include "txtbin.h"

Txtbin::Txtbin(){}

void Txtbin::set_input(const std::string& s){
    input = s;
}

void Txtbin::set_output(const std::string& s){
    output = s;
}

void Txtbin::set_height(int h){
    max_height = h;
}

void Txtbin::set_width(int w){
    max_width = w;
}

void Txtbin::set_crop(bool c){
    is_crop = c;
}

void Txtbin::set_rotate(bool r){
    is_rotate = r;
}

void Txtbin::set_margin(float m){
    margin = m;
}

void Txtbin::set_blockside(int b){
    blockside = b;
}

void Txtbin::set_threshold(int t){
    thresholding = t / 100;
}

void Txtbin::set_verbose(bool v){
    is_verbose = v;
}

void Txtbin::error(const std::string& s){
    throw std::runtime_error(s);
}

void Txtbin::binarize(){
    src.convertTo(src, CV_32FC1, 1.0 / 255.0);
    cv::Mat res = calc_block_mean_variance(src);
    imwrite(output, res * 255);
}

void Txtbin::crop(textblock coords){
    if(coords.left < coords.right && coords.top < coords.bottom){
        if(coords.left < 0){
            coords.left = 0;
        }

        int crop_width = coords.right - coords.left;
        int trim_width = coords.left + crop_width - src.cols;
        if(trim_width > 0){
            crop_width -= trim_width;
        }

        if(coords.top < 0){
            coords.top = 0;
        }

        int crop_height = coords.bottom - coords.top;
        int trim_height = coords.top + crop_height - src.rows;
        if(trim_height > 0){
            crop_height -= trim_height;
        }

        cv::Rect cut_rect = cv::Rect(coords.left, coords.top, crop_width, crop_height);
        src = src(cut_rect);
    }
    else{
        std::cout << "Warning: Invalid text block coordinates. Cropping is omitted!" << std::endl;
    }
}

void Txtbin::downsize(){
    float
        width = src.cols,
        height = src.rows,
        scale = 0;

    bool resized = false;

    if(max_width > 0 && width > max_width){
        scale = width / max_width;
        width /= scale;
        height /= scale;
        resized = true;
    }

    if(max_height > 0 && height > max_height){
        scale = height / max_height;
        width /= scale;
        height /= scale;
        resized = true;
    }

    if(resized){
        resize(src, src, cv::Size(round(width), round(height)));
    }
}

textblock Txtbin::detect_text_block(bool test_output){
    cv::Mat img = src.clone();

    // downsample image and use it for processing
    int multiplier = 2;
    pyrDown(img, img);

    textblock block;

    block.left = img.cols;
    block.top = img.rows;

    int
        rect_bottom,
        rect_right;

    // morphological gradient
    cv::Mat grad;
    cv::Mat morphKernel = getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(3, 3));
    morphologyEx(img, grad, cv::MORPH_GRADIENT, morphKernel);
    // binarize
    cv::Mat bw;
    threshold(grad, bw, 0.0, 255.0, cv::THRESH_BINARY | cv::THRESH_OTSU);
    // connect horizontally oriented regions
    cv::Mat connected;
    morphKernel = getStructuringElement(cv::MORPH_RECT, cv::Size(9, 1));
    morphologyEx(bw, connected, cv::MORPH_CLOSE, morphKernel);
    // find contours
    cv::Mat mask = cv::Mat::zeros(bw.size(), CV_8UC1);
    std::vector<std::vector<cv::Point> > contours;
    std::vector<cv::Vec4i> hierarchy;
    findContours(connected, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));

    cv::Scalar color = cv::Scalar(0, 255, 0);
    cv::Scalar color2 = cv::Scalar(0, 0, 255);
    int thickness = 2;

    if(test_output){
        cv::cvtColor(img, img, CV_GRAY2BGR);
    }

    // filter contours
    if(!hierarchy.empty()){
        for(int idx = 0; idx >= 0; idx = hierarchy[idx][0]){
            cv::Rect rect = boundingRect(contours[idx]);
            cv::Mat maskROI(mask, rect);
            maskROI = cv::Scalar(0, 0, 0);
            // fill the contour
            drawContours(mask, contours, idx, cv::Scalar(255, 255, 255), CV_FILLED);
            // ratio of non-zero pixels in the filled region
            double r = (double)countNonZero(maskROI) / (rect.width * rect.height);
            // assume at least 25% of the area is filled if it contains text
            if (r > 0.25 && 
            (rect.height > 8 && rect.width > 8) // constraints on region size
            // these two conditions alone are not very robust. better to use something 
            //like the number of significant peaks in a horizontal projection as a third condition
            ){
                if(test_output){
                    rectangle(img, rect, color, thickness);
                }
                //rectangle(src, cv::Rect(rect.x * multiplier, rect.y * multiplier, rect.width * multiplier, rect.height * multiplier), color, thickness);

                if(rect.y < block.top){
                    block.top = rect.y;
                }
                rect_bottom = rect.y + rect.height;
                if(rect_bottom > block.bottom){
                    block.bottom = rect_bottom;
                }
                if(rect.x < block.left){
                    block.left = rect.x;
                }
                rect_right = rect.x + rect.width;
                if(rect_right > block.right){
                    block.right = rect_right;
                }
            }
        }
    }

    if(test_output){
        rectangle(img, cv::Point(block.left, block.top), cv::Point(block.right, block.bottom), color2, thickness);
        imwrite("test_text_contours.jpg", img);
    }
    //rectangle(src, cv::Point(block.left * multiplier, block.top * multiplier), cv::Point(block.right * multiplier, block.bottom * multiplier), color2, thickness);

    block.left *= multiplier;
    block.top *= multiplier;
    block.right *= multiplier;
    block.bottom *= multiplier;

    return block;
}

cv::Mat Txtbin::calc_block_mean_variance(cv::Mat& img){
    cv::Mat res;
    cv::Mat I;
    img.convertTo(I, CV_32FC1);
    res = cv::Mat::zeros(img.rows / blockside, img.cols / blockside, CV_32FC1);
    cv::Mat inpaintmask;
    cv::Mat patch;
    cv::Mat small_img;
    cv::Scalar m, s;
    for(int i = 0; i < img.rows - blockside; i += blockside){
        for(int j = 0; j < img.cols - blockside; j += blockside){
            patch = I(cv::Range(i, i + blockside + 1), cv::Range(j, j + blockside + 1));
            meanStdDev(patch, m, s);

            if(s[0] > contrast){
                res.at<float>(i / blockside, j / blockside) = m[0];
            }
            else{
                res.at<float>(i / blockside, j / blockside) = 0;
            }
        }
    }
    resize(I, small_img, res.size());
    threshold(res, inpaintmask, 0.02, 1.0, cv::THRESH_BINARY);
    cv::Mat inpainted;
    small_img.convertTo(small_img, CV_8UC1, 255);
    inpaintmask.convertTo(inpaintmask, CV_8UC1);
    inpaint(small_img, inpaintmask, inpainted, 5, cv::INPAINT_TELEA);
    resize(inpainted, res, img.size());
    res.convertTo(res, CV_32FC1, 1.0 / 255.0);
    res = 1.0 - res;
    res = img + res;
    threshold(res, res, thresholding, 1, cv::THRESH_BINARY);

    return res;
}

void Txtbin::run(){
    //  Return error if input file is not defined
    if(input == ""){
        error("Input file not defined");
    }
    //  Return error if input file is not found
    else{
        std::ifstream stream(input.c_str());
        if(!stream.good()){
            error("Input file not found");
        }
    }

    //  Return error if output file is not defined
    if(output == ""){
        error("Output file not defined");
    }
    //  Return error if output file is not PNG
    else{
        std::string output_lc = output;
        boost::to_lower(output_lc);
        if(output_lc.substr(output_lc.find_last_of(".") + 1) != "png"){
            error("Output file must be PNG");
        }
    }

    bool test_output = false;

    auto start = std::chrono::high_resolution_clock::now();

    src = cv::imread(input, CV_LOAD_IMAGE_GRAYSCALE);

    if(is_crop || is_verbose){
        textblock coords = detect_text_block(test_output);

        if(is_verbose){
            std::cout << "Image dimensions: " << src.cols << " x " << src.rows << std::endl;
            std::cout << "Text block coordinates: Left|Top " << coords.left << "," << coords.top << " Right|Bottom " << coords.right << "," << coords.bottom << std::endl;
        }

        if(is_crop){
            crop(coords);
        }
    }

    if(margin){
        int border = src.cols * margin / 100;
        copyMakeBorder(src, src, border, border, border, border, cv::BORDER_CONSTANT, cv::Scalar(255, 255, 255));
    }

    downsize();

    binarize();

    auto elapsed = std::chrono::high_resolution_clock::now() - start;
    if(is_verbose){
        std::cout << "Execution time: " << (std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count() / 1000) << " ms" << std::endl;
    }
}

backtrace.h

#include <stdio.h>
#include <execinfo.h>
#include <stdlib.h>

class Backtrace {
    public:
        Backtrace();
        void trace(int sig);
};

Backtrace::Backtrace(){}

void Backtrace::trace(int sig){
    void *trace[10];
    char **messages = (char **)NULL;
    int i, trace_size = 0;

    trace_size = backtrace(trace, 10);
    messages = backtrace_symbols(trace, trace_size);

    fprintf(stderr, "Error: signal %d:\n", sig);
    for(i=1; i<trace_size; ++i){
        fprintf(stderr, "#%d %s\n", i, messages[i]);
    }

    exit(1);
}

ANSWER

Answered 2018-Jun-25 at 00:09

The segfault does not occur with the following implementation of Txtbin::binarize.

void Txtbin::binarize(){
    src.convertTo(src, CV_32FC1, 1.0 / 255.0);
    cv::Mat res = calc_block_mean_variance(src) * 255;
    imwrite(output, res);
}

With the prior definition of Txtbin::binarize, cv::imwrite sees the type as _InputArray::EXPR rather than as _InputArray::MAT, and passes an uninitialized value of img_vec to cv::imwrite_. The segfault results from an attempt to dereference that uninitialized value. The _InputArray::EXPR value comes from the return value of MatExpr operator * (a cv::MatExpr) being passed to _InputArray::_InputArray.

With the modified definition of Txtbin::binarize the return value of MatExpr operator * is passed to MatExpr::operator Mat() const, which passes it to MatOp_AddEx::assign, and the value passed to _InputArray::_InputArray is a cv::Mat rather than a cv::MatExpr. In short, it seems the assignment of the return value of MatExpr operator * prevents an incorrect type conversion (cv::imwrite expects a cv::InputArray, not a cv:Mat, for its second parameter).

It appears that newer versions of opencv are not susceptible to this crash. Prior to this commit, cv::imwrite called the getMat method, and this commit restored that call as the default behavior (the else clause), as a replacement for an overly specific conditional. I confirmed that recompiling opencv with that change to cv::imwrite prevents the crash even with the prior version of Txtbin::binarize (the one in the question), and that the return value of MatExpr operator * is passed to MatExpr::operator Mat() const, as in the modified definition of Txtbin::binarize due to the assignment.

In short, you can work around issue 15545, or you can install its fix.

Source https://stackoverflow.com/questions/50967266

QUESTION

How to trace a java application running on a remote host

Asked 2018-Apr-03 at 05:43

I know the tool btrace that allows you to print the method calls as they are executed. But it doesn't seem to work for a java app running on a remote host.

I don't need a thread dump. I what to see what classes and methods are affected when a particular use case is executed. They should be printed as soon as they are called. How to achieve it?

ANSWER

Answered 2018-Mar-31 at 18:35

U should use logger for this. You can trace each method call by using debug and info logs with logger.

Source https://stackoverflow.com/questions/49590473

QUESTION

btrace with glassfish web container

Asked 2018-Feb-02 at 14:21

Recently I use BTrace to check exceptions that are thrown inside glassfish VM. I use script:

@BTrace public class OnThrow {    
    // store current exception in a thread local
    // variable (@TLS annotation). Note that we can't
    // store it in a global variable!
    @TLS static Throwable currentException;

    // introduce probe into every constructor of java.lang.Throwable
    // class and store "this" in the thread local variable.
    @OnMethod(
        clazz="java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow(@Self Throwable self) {
        currentException = self;
    }

    @OnMethod(
        clazz="java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow1(@Self Throwable self, String s) {
        currentException = self;
    }

    @OnMethod(
        clazz="java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow1(@Self Throwable self, String s, Throwable cause) {
        currentException = self;
    }

    @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }

    // when any constructor of java.lang.Throwable returns
    // print the currentException's stack trace.
    @OnMethod(
        clazz="java.lang.Throwable",
        method="<init>",
        location=@Location(Kind.RETURN)
    )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }
}

When I attach to GF 4.1.1 (build 1) with BTrace v.1.3.10.2 (20180129) using '-v' flag the following stracktrace is generated by GF and I see no console output thrown by BTrace:

btrace DEBUG: parsed command line arguments]]  
btrace DEBUG: Bootstrap ClassPath: .]]
btrace DEBUG: ignoring boot classpath element '.' - only jar files allowed]]
btrace DEBUG: System ClassPath: /usr/lib/jvm/java-8-oracle/jre/../lib/tools.jar]]
btrace DEBUG: debugMode is true]]
btrace DEBUG: probe descriptor path is .]]
btrace DEBUG: stdout is false]]
btrace DEBUG: starting agent thread]]
btrace DEBUG: Agent init took: 10482105ns]]
btrace DEBUG: starting server at 2020]]
btrace DEBUG: waiting for clients]]
btrace DEBUG: client accepted    Socket[addr=/127.0.0.1,port=43496,localport=2020]]]
btrace DEBUG: got instrument command]]
btrace DEBUG: loading BTrace class]]
btrace DEBUG: verifying BTrace class ...]]
btrace DEBUG: BTrace class com.sun.btrace.samples.OnThrow  verified]]
btrace DEBUG: preprocessing BTrace class com.sun.btrace.samples.OnThrow ...]]
btrace DEBUG: ... preprocessed]]  
btrace DEBUG: loaded 'com.sun.btrace.samples.OnThrow' successfully]]
btrace DEBUG: creating BTraceRuntime instance for com.sun.btrace.samples.OnThrow]]
btrace DEBUG: created BTraceRuntime instance for com.sun.btrace.samples.OnThrow]]
btrace DEBUG: sending Okay command]]
btrace DEBUG: client com.sun.btrace.samples.OnThrow: got com.sun.btrace.comm.OkayCommand@26cab401]]
btrace DEBUG: about to defineClass com/sun/btrace/samples/OnThrow]]
btrace DEBUG: defineClass succeeded for com.sun.btrace.samples.OnThrow]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/agent/RemoteClient$1]]
btrace DEBUG: starting client command handler thread]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/agent/Main$3]]
btrace DEBUG: new Client created com.sun.btrace.agent.RemoteClient@44c6c5b2]]
btrace DEBUG: retransforming loaded classes]]
btrace DEBUG: filtering loaded classes]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/runtime/ClassCache$Singleton]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/runtime/ClassInfo$ClassName]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/runtime/ClassInfo$JavaClassName]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/runtime/ClassInfo$BaseClassName]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/runtime/ClassInfo$InternalClassName]]
btrace DEBUG: skipping transform for BTrace class com/sun/btrace/runtime/BTraceClassReader$BailoutExceptio]]
btrace DEBUG: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: This web container has not yet been started]]

java.util.concurrent.ExecutionException: java.lang.IllegalStateException:    This web container has not yet been started
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at com.sun.btrace.agent.Main.startServer(Main.java:674)
at com.sun.btrace.agent.Main.access$000(Main.java:60)
at com.sun.btrace.agent.Main$2.run(Main.java:125)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: This web container has not yet been started
at org.glassfish.web.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2827)
at org.glassfish.web.loader.WebappClassLoader.findResource(WebappClassLoader.java:1320)
at org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)
at com.sun.btrace.agent.Main$3.run(Main.java:693)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

btrace DEBUG: waiting for clients]]
btrace DEBUG: skipping transform for BTrace class sun/security/ssl/ServerNameExtension]]
btrace DEBUG: skipping transform for BTrace class sun/security/ssl/UnknownExtension]]  
btrace DEBUG: skipping transform for BTrace class sun/security/provider/PolicyFile$6]]

The thing I am confused about is the glassfish exception. When btrace is being attached there is already an application deployed on GF that serves HTTP requests.

If there is a webapp (CDI/REST/JPA) deployed that uses web container why 'the container has not been started' is raised?

ANSWER

Answered 2018-Feb-02 at 14:21

I finally found out whats going on - looking again on this Ex:

org.glassfish.web.loader.WebappClassLoader.getResourceAsStream(WebappClassLoader.java:1528)
at com.sun.btrace.runtime.ClassInfo.loadExternalClass(ClassInfo.java:262)
at com.sun.btrace.runtime.ClassInfo.<init>(ClassInfo.java:215)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:70)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:62)
at com.sun.btrace.runtime.ClassCache.get(ClassCache.java:51)
at com.sun.btrace.agent.Client.retransformLoaded(Client.java:451)

One of the methods I analyzed in BTrace code is:

com.sun.btrace.agent.Client.retransformLoaded

which looks like:

void retransformLoaded() throws UnmodifiableClassException {
        if (runtime != null) {
            if (probe.isTransforming() && settings.isRetransformStartup()) {
                ArrayList<Class> list = new ArrayList<>();
                debugPrint("retransforming loaded classes");
                debugPrint("filtering loaded classes");
                ClassCache cc = ClassCache.getInstance();
                for (Class c : inst.getAllLoadedClasses()) {
                    if (c != null) {                                
451                     cc.get(c);
                        }
                        if (inst.isModifiableClass(c) &&  isCandidate(c)) 
                            debugPrint("candidate " + c + " added");
                            list.add(c);
                        }
...other stuff

cc.get(c) throws this Exception. It uses method from ClassCache:

 ClassInfo get(ClassLoader cl, ClassName className) {
        Map<ClassName, ClassInfo> infos = getInfos(cl);

        ClassInfo ci = infos.get(className);
        if (ci == null) {
70          ci = new ClassInfo(this, cl, className);
            infos.put(className, ci);
        }
        return ci;
    }

And the constructor of ClassInfo:

  ClassInfo(ClassCache cache, ClassLoader cl, ClassName cName) {
        this.cache = cache;
        cLoaderId = (cl != null ? cl.toString() : "<null>");
        classId = cName;
215     loadExternalClass(cl, cName);
    }

and finally constructor's loadExternalClass method:

 private void loadExternalClass(final ClassLoader cl, final ClassName className) {
        String resourcePath = className.getResourcePath();

262 InputStream typeIs = cl == null ? SYS_CL.getResourceAsStream(resourcePath) : cl.getResourceAsStream(resourcePath);
        if (typeIs != null) {
            try {
            BTraceClassReader cr = new BTraceClassReader(cl, typeIs);
            ...

SYS_CL is taken using ClassLoader.getSystemClassLoader(). This is actually WebappClassLoader which is the main actor in the exception. I noticed that exception is thrown by CDI/JPA classes (after catching and printing classes that throw the EX):

  btrace DEBUG: Class class some.package.EntityManagerWrapper -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.AsyncAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.OperationAuditFacade -> EX thrown: This web container has not yet been started]]
  btrace DEBUG: Class class some.package.FacadeConfigFactory -> EX thrown: This web container has not yet been started

Can somone can tell me why only these classes throw EX when instrumenting them?

My BTrace script is taken from samples and looks like:

  @TLS static Throwable currentException;
  @OnMethod(
        clazz="+java.lang.Throwable",
        method="<init>"
    )
    public static void onthrow2(@Self Throwable self, Throwable cause) {
        currentException = self;
    }
      @OnMethod(
            clazz="java.lang.Throwable",
            method="<init>",
            location=@Location(Kind.RETURN)
        )
    public static void onthrowreturn() {
        if (currentException != null) {
            Threads.jstack(currentException);
            println("=====================");
            currentException = null;
        }
    }

To solve this and get output from BTrace I can just wrap line 451 in com.sun.btrace.agent.Client.retransformLoaded with try-catch block and everything is working fine and output is generated.

I wonder just why this exception is thrown? SYS_CL is a default classloader (CL) and I've read that in Glassfish every webapp has its own newly created CL. These CDI/JPA classes are loaded with WebappClassLoader (cl variable is not null - 262 in ClassInfo.class and I truly checked that cl='WebappClassLoader (delegate=true)') so why they are not willling to be instrumented ?

The moral is U just cannot use BTrace with every script U want coz enviroment frameworks can interfere the probing.

Source https://stackoverflow.com/questions/48540484

QUESTION

Python RegExp retrieve value from matching string

Asked 2017-Feb-13 at 13:57

Deal all

I faced some not trivial problem for me to parse log.

I need to go through a file and check if the line matches the patter : if YES then get ClientID specified in this line.

The line looks like :

17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'

So I need to get 99071901.

I tried to construct regexp search pattern, but it is not complete..stuck at 'TRACE':

regex = '(^[(\d\.)]+) ([(\d\:)]+) ([\bTRACE\b]+) ([(\d)]+) ([\bGDS\b:)]+) ([\ClientID\b])'

Script code is :

log=open('t.log','r')
for i in log:
    key=re.search(regex,i)
    print(key.group()) #print string matching 
    for g in key:
        client_id=re.seach(????,g) # find ClientIt    
log.close()

Appreciate if you give me a hint how to solve this challenge.

Thank you.

ANSWER

Answered 2017-Feb-13 at 13:57

You don't need to be too specific. You can just capture the sections and parse them individually.

Lets start with just your one line for example:

line = "17.02.09 10:42:31.242 TRACE [1245] GDS:     someText(SomeText).ClientID: '' -> '99071901'"

And then lets add our first regex that gets all the sections:

import re
line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
# now extract each section
date, time, level, thread, module, message = line_regex.match(line).groups()

Now, if we look at the different sections they will have all the information we need to make more decisions, or further parse them. Now lets get the client ID when the right kind of message shows up.

client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

if 'ClientID' in message:
    client_id = client_id_regex.match(message).group(1)

And now we have the client_id.


Just work that logic into your loop and you are all set.

line_regex = re.compile(r'(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+):\s+(.+)')
client_id_regex = re.compile(r".*ClientID: '' -> '(\d+)'")

with open('t.log','r') as f:  # use with context manager to auto close the file
    for line in f:  # lets iterate over the lines
        sections = line_regex.match(line)  # make a match object for sections
        if not sections:
            continue  # probably you want to handle this case
        date, time, level, thread, module, message = sections.groups()
        if 'ClientID' in message:  # should we even look here for a client id?
            client_id = client_id_regex.match(message).group(1)
# now do what you wanted to do

Source https://stackoverflow.com/questions/42202382

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

VULNERABILITIES

No vulnerabilities reported

INSTALL btrace

You will need the following applications installed. In order to ease the pre-build config the config_build.sh script is provided. You should run it first as source config_build.sh to automatically download all required JDKs and set up the corresponding JAVA_*_HOME env variables.
Git
JDKs - JDK 8, Java 9 and Java 11 are required to be available
(optionally, the default launcher is the bundled gradlew wrapper) Gradle
Download a distribution file from the release page. Explode the binary distribution file (either *.tar.gz or *.zip) to a directory of your choice. You may set the system environment variable BTRACE_HOME to point to the directory containing the exploded distribution. You may enhance the system environment variable PATH with $BTRACE_HOME/bin for your convenience. Or, alternatively, you may install one of the *.rpm or *.deb packages.

SUPPORT

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Implement btrace faster with kandi.

  • Use the support, quality, security, license, reuse scores and reviewed functions to confirm the fit for your project.
  • Use the, Q & A, Installation and Support guides to implement faster.

Discover Millions of Libraries and
Pre-built Use Cases on kandi