简体   繁体   English

使用C / C ++的ptrace Java程序

[英]ptrace Java program using C/C++

I have problem similar to my previous one presented here . 我遇到的问题与我以前在这里提出的问题类似。

This time I want use program written in c/c++ to track execution of JAVA program. 这次我想使用用c / c ++编写的程序来跟踪JAVA程序的执行。 So as I stated before same code which track stdout printing for c/c++ and register syscall 4 haven't done it for JAVA. 因此,正如我之前说过的,针对c / c ++跟踪stdout打印并注册syscall 4的代码尚未针对JAVA完成。 I assume it's because execlp which I trace is used just to run jvm. 我认为这是因为我跟踪的execlp仅用于运行jvm。 And later on there are created more processes (by inner mechanism of jvm) which I do not track. 后来又创建了更多我不跟踪的进程(通过jvm的内部机制)。 I found this topic which seems to be partial solution. 我发现这个主题似乎是部分解决方案。 If I got it right every child will be traced. 如果我做对了,每个孩子都会被追踪。 But that's is a problem as well I want to track only that process which handles my application and not all others that jvm might create. 但这也是一个问题,我只想跟踪处理我的应用程序的进程,而不跟踪jvm可能创建的所有其他进程。 Is there any chance to get know which jvm thread/process handles my program and track only it? 有没有机会知道哪个jvm线程/进程处理我的程序并仅跟踪它?

For make it a bit easier let's assume my JAVA program is one-thread. 为了使操作更简单,我们假设我的JAVA程序是单线程的。

If you start the binary through your tracer app, all threads will be traced. 如果通过跟踪器应用程序启动二进制文件,则将跟踪所有线程。

But if you attach to a process, then you won't attach to all it's threads. 但是,如果您附加到一个进程,则不会附加到它的所有线程。 You have to attach to all of its threads using the threadids, that you can found listed eg. 您必须使用threadid附加到其所有线程,例如,可以在列表中找到。 in /proc/%d/task/. 在/ proc /%d / task /中。

Also, I suggest reading through strace's source code, I've learnt a lot from it. 另外,我建议阅读strace的源代码,我从中学到了很多。 If you can use strace to successfully follow java threads as you want, you can get the logic from it. 如果可以使用strace成功跟随Java线程,则可以从中获取逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM