Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Source Code to analyze the Reading of symbol Table on linux

2025-03-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to use source code analysis to read the symbol table on linux. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Usually when we use jmap,jstack to check stack information, we will not use the-f parameter, but sometimes the system will recommend that you use the parameter-F when the stack information cannot be printed.

The difference between-F parameters and non-F parameters has been described in the previous blog (http://blog.csdn.net/raintungli/article/details/7023092). To put it simply, one is to let the jvm process print the stack information by itself, and the other is to directly access the stack area of jvm to find out the information we need through a fixed structure.

1. Implementation of Linux-F parameters

In linux, you can use the system call of ptrace to access the memory information of running processes. You can refer to the author's blog (http://blog.csdn.net/raintungli/article/details/6563867) for details.

Use dynamic loading method to load jvm's own link sharing library in java. The core link sharing library of jvm is how to load dynamically in libjvm.so,linux (http://www.ibm.com/developerworks/cn/linux/l-dynamic-libraries/#dynamiclinking).

Because it is a dynamic shared library, when you want to find the value of a specific parameter, memory information, you need to calculate the correct parameter or function address.

two。 Symbol offset from address in shared library

Runnable programs, shared libraries use ELF format, when running a program, the kernel will load ELF into user space, which records the address and content of the program's functions and data, the elf file format is not specifically described.

In linux, you can use the structure ELF_EHDR,ELF_PHDR,ELF_SHDR to read program header, section header, section data of elf.

For the specific implementation of the source code in jvm, please refer to / hotspot/agent/os/linux/salibelf.c

Linux itself comes with a tool to read elf format, readelf you can use different parameters to read different content.

Readelf-s libjvm.so

Displays the virtual address, type, and name of the method parameters in the shared library

Readelf-l libjvm.so

Read program headers, in which there are two types of LOAD, * * is the virtual starting address of the program's instructions, and the other is the starting address of the program data.

Through two addresses, we can find the parameters in the shared library, the offset of the function relative to the address.

3. Symbolic address in the process

In the second chapter, we only get the relative address offset, not the symbolic address of the real running process, so how to get the real address is relatively simple in linux.

Cat / proc/$processid/maps

The address assigned by the stack of the process, including the address of the shared library, is recorded in detail in maps, so the starting address is the lowest address assigned by the library.

The minimum address assigned by the process shared library + the offset of the relative address = the real address of the function or variable in the real process

4. Symbol table saved by Java tool

The above is the editor for you to share how to use source code analysis to read the symbol table on linux, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report