mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Loader.so+LibELF: Introduce "_LOADER_BREAKPOINT" environment variable
If set, the dynamic loader will perform a software breakpoint after loading all libraries, and just before jumping to the main entry point. This allows a debugger to inspect the loaded libraries before the program starts executing.
This commit is contained in:
parent
bb90d961b8
commit
ca9d6d21b5
Notes:
sideshowbarker
2024-07-19 00:02:32 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/ca9d6d21b5a Pull-request: https://github.com/SerenityOS/serenity/pull/4852 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling
1 changed files with 10 additions and 0 deletions
|
@ -231,6 +231,13 @@ static NonnullRefPtr<DynamicLoader> commit_elf(const String& name)
|
|||
void ELF::DynamicLinker::linker_main(String&& main_program_name, int main_program_fd, int argc, char** argv, char** envp)
|
||||
{
|
||||
g_envp = envp;
|
||||
bool do_breakpoint_trap_before_entry = false;
|
||||
for (char** env = envp; *env; ++env) {
|
||||
if (StringView { *env } == "_LOADER_BREAKPOINT=1") {
|
||||
do_breakpoint_trap_before_entry = true;
|
||||
}
|
||||
}
|
||||
|
||||
map_library(main_program_name, main_program_fd);
|
||||
map_dependencies(main_program_name);
|
||||
|
||||
|
@ -253,6 +260,9 @@ void ELF::DynamicLinker::linker_main(String&& main_program_name, int main_progra
|
|||
|
||||
MainFunction main_function = (MainFunction)(entry_point);
|
||||
VERBOSE("jumping to main program entry point: %p\n", main_function);
|
||||
if (do_breakpoint_trap_before_entry) {
|
||||
asm("int3");
|
||||
}
|
||||
int rc = main_function(argc, argv, envp);
|
||||
VERBOSE("rc: %d\n", rc);
|
||||
if (g_libc_exit != nullptr) {
|
||||
|
|
Loading…
Reference in a new issue