Я подготовил небольшую демонстрацию:
Код: Выделить всё
// test.cpp
int add(int a, int b) {
return a + b;
}
// main.cpp
extern int add(int, int);
int main() {
int a = 3, b = 4;
int result = ::add(a, b);
return 0;
}
Код: Выделить всё
g++ -c -g -gsplit-dwarf main.cpp -o main.o
g++ -c -g -gsplit-dwarf test.cpp -o test.o
g++ main.o test.o -o test
readelf -wi test | grep dwo
DW_AT_dwo_name : (indirect string, offset: 0x19): main.dwo
DW_AT_dwo_name : (indirect string, offset: 0x22): test.dwo
strace -o log gdb --batch-silent --eval-command=quit test
grep dwo log
newfstatat(AT_FDCWD, "/home/ubuntu/learn/dwarf/main.dwo", {st_mode=S_IFREG|0664, st_size=1376, ...}, 0) = 0
openat(AT_FDCWD, "/home/ubuntu/learn/dwarf/main.dwo", O_RDONLY|O_CLOEXEC) = 12
readlink("/home/ubuntu/learn/dwarf/main.dwo", 0x7ffee97a3c10, 1023) = -1 EINVAL (Invalid argument)
newfstatat(AT_FDCWD, "/home/ubuntu/learn/dwarf/test.dwo", {st_mode=S_IFREG|0664, st_size=1280, ...}, 0) = 0
openat(AT_FDCWD, "/home/ubuntu/learn/dwarf/test.dwo", O_RDONLY|O_CLOEXEC) = 13
readlink("/home/ubuntu/learn/dwarf/test.dwo", 0x7ffee97a3c10, 1023) = -1 EINVAL (Invalid argument)
Код: Выделить всё
EINVAL bufsiz is not positive.
EINVAL The named file (i.e., the final filename component of pathname) is not a symbolic link.
Код: Выделить всё
#include
int main() {
char buffer[1024];
ssize_t ret = readlink("/home/ubuntu/learn/dwarf/main.dwo", buffer, 1023);
if (ret < 0) {
perror("readlink");
return -1;
}
return 0;
}
Код: Выделить всё
./read_link
readlink: Invalid argument
Код: Выделить всё
mv main.dwo main.dwo.tmp
ln -s main.dwo.tmp main.dwo
mv test.dwo test.dwo.tmp
ln -s test.dwo.tmp test.dwo
# let's try...
./read_link
echo $?
0
# try again with gdb
strace -o log gdb --batch-silent --eval-command=quit test
grep dwo log
newfstatat(AT_FDCWD, "/home/ubuntu/learn/dwarf/main.dwo", {st_mode=S_IFREG|0664, st_size=1376, ...}, 0) = 0
openat(AT_FDCWD, "/home/ubuntu/learn/dwarf/main.dwo", O_RDONLY|O_CLOEXEC) = 12
readlink("/home/ubuntu/learn/dwarf/main.dwo", "main.dwo.tmp", 1023) = 12
readlink("/home/ubuntu/learn/dwarf/main.dwo.tmp", 0x7fff26037280, 1023) = -1 EINVAL (Invalid argument)
newfstatat(AT_FDCWD, "/home/ubuntu/learn/dwarf/test.dwo", {st_mode=S_IFREG|0664, st_size=1280, ...}, 0) = 0
openat(AT_FDCWD, "/home/ubuntu/learn/dwarf/test.dwo", O_RDONLY|O_CLOEXEC) = 13
readlink("/home/ubuntu/learn/dwarf/test.dwo", "test.dwo.tmp", 1023) = 12
readlink("/home/ubuntu/learn/dwarf/test.dwo.tmp", 0x7fff26037280, 1023) = -1 EINVAL (Invalid argument)
Подробнее здесь: https://stackoverflow.com/questions/791 ... s-with-gdb
Мобильная версия