parent
612d5e6d65
commit
cdaab64be2
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@ -80,9 +80,6 @@ jobs:
|
|||||||
make -j
|
make -j
|
||||||
sudo make install
|
sudo make install
|
||||||
cd ../../cpptrace
|
cd ../../cpptrace
|
||||||
file /usr/lib/dyld
|
|
||||||
otool -l /usr/lib/dyld
|
|
||||||
uname -a
|
|
||||||
- name: dependencies
|
- name: dependencies
|
||||||
run: |
|
run: |
|
||||||
pip3 install colorama
|
pip3 install colorama
|
||||||
|
|||||||
@ -110,7 +110,7 @@ def output_matches(raw_output: str, params: Tuple[str]):
|
|||||||
|
|
||||||
return not errored
|
return not errored
|
||||||
|
|
||||||
def run_command(*args: List[str], always_output=False):
|
def run_command(*args: List[str]):
|
||||||
global failed
|
global failed
|
||||||
print(f"{Fore.CYAN}{Style.BRIGHT}Running Command \"{' '.join(args)}\"{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{Style.BRIGHT}Running Command \"{' '.join(args)}\"{Style.RESET_ALL}")
|
||||||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
@ -126,11 +126,6 @@ def run_command(*args: List[str], always_output=False):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
print(f"{Fore.GREEN}{Style.BRIGHT}Command succeeded{Style.RESET_ALL}")
|
print(f"{Fore.GREEN}{Style.BRIGHT}Command succeeded{Style.RESET_ALL}")
|
||||||
if always_output:
|
|
||||||
print("stdout:")
|
|
||||||
print(stdout.decode("utf-8"), end="")
|
|
||||||
print("stderr:")
|
|
||||||
print(stderr.decode("utf-8"), end="")
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run_test(test_binary, params: Tuple[str]):
|
def run_test(test_binary, params: Tuple[str]):
|
||||||
@ -260,8 +255,6 @@ def build_full_or_auto(matrix):
|
|||||||
|
|
||||||
def test(matrix):
|
def test(matrix):
|
||||||
if platform.system() != "Windows":
|
if platform.system() != "Windows":
|
||||||
if platform.system() == "Darwin":
|
|
||||||
run_command("otool", "-l", "./test", always_output=True)
|
|
||||||
return run_test(
|
return run_test(
|
||||||
"./test",
|
"./test",
|
||||||
(matrix["compiler"], matrix["unwind"], matrix["symbols"], matrix["demangle"])
|
(matrix["compiler"], matrix["unwind"], matrix["symbols"], matrix["demangle"])
|
||||||
@ -280,8 +273,6 @@ def test(matrix):
|
|||||||
|
|
||||||
def test_full_or_auto(matrix):
|
def test_full_or_auto(matrix):
|
||||||
if platform.system() != "Windows":
|
if platform.system() != "Windows":
|
||||||
if platform.system() == "Darwin":
|
|
||||||
run_command("otool", "-l", "./test", always_output=True)
|
|
||||||
return run_test(
|
return run_test(
|
||||||
"./test",
|
"./test",
|
||||||
(matrix["compiler"],)
|
(matrix["compiler"],)
|
||||||
|
|||||||
@ -141,7 +141,6 @@ namespace detail {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
mach_o(const std::string& object_path) : object_path(object_path) {
|
mach_o(const std::string& object_path) : object_path(object_path) {
|
||||||
fprintf(stderr, "new mach -------------------------------------- %s\n", object_path.c_str());
|
|
||||||
file = std::fopen(object_path.c_str(), "rb");
|
file = std::fopen(object_path.c_str(), "rb");
|
||||||
if(file == nullptr) {
|
if(file == nullptr) {
|
||||||
throw file_error("Unable to read object file " + object_path);
|
throw file_error("Unable to read object file " + object_path);
|
||||||
@ -167,13 +166,11 @@ namespace detail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::uintptr_t get_text_vmaddr() {
|
std::uintptr_t get_text_vmaddr() {
|
||||||
fprintf(stderr, "get_text_vmaddr------------- %s\n", object_path.c_str());
|
|
||||||
for(const auto& command : load_commands) {
|
for(const auto& command : load_commands) {
|
||||||
if(command.cmd == LC_SEGMENT_64 || command.cmd == LC_SEGMENT) {
|
if(command.cmd == LC_SEGMENT_64 || command.cmd == LC_SEGMENT) {
|
||||||
auto segment = command.cmd == LC_SEGMENT_64
|
auto segment = command.cmd == LC_SEGMENT_64
|
||||||
? load_segment_command<64>(command.file_offset)
|
? load_segment_command<64>(command.file_offset)
|
||||||
: load_segment_command<32>(command.file_offset);
|
: load_segment_command<32>(command.file_offset);
|
||||||
fprintf(stderr, "foo \"%s\", %d\n", segment.segname, std::strcmp(segment.segname, "__TEXT") == 0);
|
|
||||||
if(std::strcmp(segment.segname, "__TEXT") == 0) {
|
if(std::strcmp(segment.segname, "__TEXT") == 0) {
|
||||||
return segment.vmaddr;
|
return segment.vmaddr;
|
||||||
}
|
}
|
||||||
@ -181,6 +178,7 @@ namespace detail {
|
|||||||
}
|
}
|
||||||
// somehow no __TEXT section was found...
|
// somehow no __TEXT section was found...
|
||||||
throw std::runtime_error("Couldn't find __TEXT section while parsing Mach-O object");
|
throw std::runtime_error("Couldn't find __TEXT section while parsing Mach-O object");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t get_fat_index() const {
|
std::size_t get_fat_index() const {
|
||||||
@ -411,7 +409,6 @@ namespace detail {
|
|||||||
flags = header.flags;
|
flags = header.flags;
|
||||||
// handle load commands
|
// handle load commands
|
||||||
std::uint32_t ncmds = header.ncmds;
|
std::uint32_t ncmds = header.ncmds;
|
||||||
fprintf(stderr, "ncmds: %u\n", ncmds);
|
|
||||||
std::uint32_t load_commands_offset = load_base + header_size;
|
std::uint32_t load_commands_offset = load_base + header_size;
|
||||||
// iterate load commands
|
// iterate load commands
|
||||||
std::uint32_t actual_offset = load_commands_offset;
|
std::uint32_t actual_offset = load_commands_offset;
|
||||||
@ -481,7 +478,6 @@ namespace detail {
|
|||||||
std::uint32_t magic = load_bytes<std::uint32_t>(file, mach_header_offset);
|
std::uint32_t magic = load_bytes<std::uint32_t>(file, mach_header_offset);
|
||||||
load_base = mach_header_offset;
|
load_base = mach_header_offset;
|
||||||
fat_index = best - fat_arches.data();
|
fat_index = best - fat_arches.data();
|
||||||
fprintf(stderr, "INDEX: %llu\n", to_ull(fat_index));
|
|
||||||
if(is_magic_64(magic)) {
|
if(is_magic_64(magic)) {
|
||||||
load_mach<64>();
|
load_mach<64>();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -56,9 +56,7 @@ namespace detail {
|
|||||||
if(it == cache.end()) {
|
if(it == cache.end()) {
|
||||||
// arguably it'd be better to release the lock while computing this, but also arguably it's good to not
|
// arguably it'd be better to release the lock while computing this, but also arguably it's good to not
|
||||||
// have two threads try to do the same computation
|
// have two threads try to do the same computation
|
||||||
mach_o obj(object_path);
|
auto base = mach_o(object_path).get_text_vmaddr();
|
||||||
obj.print_segments();
|
|
||||||
auto base = obj.get_text_vmaddr();
|
|
||||||
cache.insert(it, {object_path, base});
|
cache.insert(it, {object_path, base});
|
||||||
return base;
|
return base;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user