temp
This commit is contained in:
@@ -67,6 +67,9 @@ make && insmod source/variable_monitor.ko
|
|||||||
# sudo dnf install -y epel-release
|
# sudo dnf install -y epel-release
|
||||||
# sudo dnf makecache
|
# sudo dnf makecache
|
||||||
sudo yum install -y libunwind-devel.x86_64
|
sudo yum install -y libunwind-devel.x86_64
|
||||||
|
yum config-manager --set-enabled powertools
|
||||||
|
sudo dnf makecache
|
||||||
|
yum install -y libdwarf-devel.x86_64
|
||||||
# debian 系
|
# debian 系
|
||||||
sudo apt-get update && apt-get install -y elfutils
|
sudo apt-get update && apt-get install -y elfutils
|
||||||
sudo apt-get update && apt-get install -y libunwind8
|
sudo apt-get update && apt-get install -y libunwind8
|
||||||
@@ -263,4 +266,9 @@ variable monitor 添加/删除
|
|||||||
#define __task_contributes_to_load(task) \
|
#define __task_contributes_to_load(task) \
|
||||||
((READ_ONCE(task->__state) & TASK_UNINTERRUPTIBLE) != 0 && (task->flags & PF_FROZEN) == 0 && \
|
((READ_ONCE(task->__state) & TASK_UNINTERRUPTIBLE) != 0 && (task->flags & PF_FROZEN) == 0 && \
|
||||||
(READ_ONCE(task->__state) & TASK_NOLOAD) == 0)
|
(READ_ONCE(task->__state) & TASK_NOLOAD) == 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
docker build -t userstack-image .
|
||||||
|
docker run --privileged --device=/d/variable_monitor -v /:/host -it userstack-image
|
||||||
```
|
```
|
||||||
@@ -266,6 +266,55 @@ static void get_all_symbols(std::set<symbol> &ss, symbol_sections_ctx *si,
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
bool is_stripped(const char* path) {
|
||||||
|
char command[256];
|
||||||
|
snprintf(command, sizeof(command), "file %s", path);
|
||||||
|
|
||||||
|
FILE* fp = popen(command, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
// handle error
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char output[256];
|
||||||
|
fgets(output, sizeof(output), fp);
|
||||||
|
pclose(fp);
|
||||||
|
|
||||||
|
return strstr(output, "stripped") != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAX_LINE_LENGTH 1024
|
||||||
|
void get_symbol_from_elf_gdb(std::set<symbol> &ss, const char *path) {
|
||||||
|
FILE *fp;
|
||||||
|
char cmd[MAX_LINE_LENGTH];
|
||||||
|
char line[MAX_LINE_LENGTH];
|
||||||
|
// 构建 GDB 命令
|
||||||
|
snprintf(cmd, sizeof(cmd),
|
||||||
|
"gdb -batch -ex \"file %s\" -ex \"info functions\"", path);
|
||||||
|
|
||||||
|
// 执行 GDB 命令并获取输出
|
||||||
|
fp = popen(cmd, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
perror("popen");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取并解析 GDB 的输出
|
||||||
|
while (fgets(line, sizeof(line), fp) != NULL) {
|
||||||
|
unsigned long address;
|
||||||
|
char name[MAX_LINE_LENGTH];
|
||||||
|
|
||||||
|
// 解析函数名和地址
|
||||||
|
if (sscanf(line, "%lx %s", &address, name) == 2) {
|
||||||
|
printf("Name: %s, Address: %lx\n", name, address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭 GDB 进程
|
||||||
|
pclose(fp);
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
bool get_symbol_from_elf(std::set<symbol> &ss, const char *path) {
|
bool get_symbol_from_elf(std::set<symbol> &ss, const char *path) {
|
||||||
static int first_init = 0;
|
static int first_init = 0;
|
||||||
|
|
||||||
@@ -276,6 +325,13 @@ bool get_symbol_from_elf(std::set<symbol> &ss, const char *path) {
|
|||||||
|
|
||||||
int is_reloc = 0;
|
int is_reloc = 0;
|
||||||
elf_version(EV_CURRENT);
|
elf_version(EV_CURRENT);
|
||||||
|
|
||||||
|
// Check if the file attribute contains "stripped"
|
||||||
|
if (is_stripped(path)){
|
||||||
|
get_symbol_from_elf_gdb(ss, path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int fd = open(path, O_RDONLY);
|
int fd = open(path, O_RDONLY);
|
||||||
|
|
||||||
Elf *elf = elf_begin(fd, ELF_C_READ, NULL);
|
Elf *elf = elf_begin(fd, ELF_C_READ, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user