如何在gdb中获取当前的PHP函数名称?

逆向工程 调试 数据库 php
2021-06-15 10:03:28

我正在按照以下步骤定位当前的 PHP 函数调用,如下所示:

  1. 运行虚拟脚本:

    $ gdb -ex run --args php -r "sleep(10);"
    
  2. 按下Ctrl+C返回gdb运行:

    (gdb) bt full
    #1  0x00007ffff6007dd4 in __sleep (seconds=0) at ../sysdeps/unix/sysv/linux/sleep.c:137
            ts = {tv_sec = 8, tv_nsec = 306649388}
            set = {__val = {65536, 0 <repeats 15 times>}}
            oset = {__val = {0, 4469319, 4294967295, 8081486, 140737319884960, 140737354070488, 15761488, 15454080, 15337134, 
                140737354001040, 0, 7307048, 16048064, 206158430232, 140737488342304, 140737488342096}}
            result = <optimized out>
    #2  0x00000000006156ef in zif_sleep ()
    No symbol table info available.
    #3  0x00000000006ddd7b in dtrace_execute_internal ()
    No symbol table info available.
    #4  0x000000000079dde5 in ?? ()
    No symbol table info available.
    #5  0x0000000000717b18 in execute_ex ()
    No symbol table info available.
    #6  0x00000000006ddc79 in dtrace_execute_ex ()
    No symbol table info available.
    #7  0x00000000006e1b0a in zend_eval_stringl ()
    No symbol table info available.
    #8  0x00000000006e1bf9 in zend_eval_stringl_ex ()
    ...
    (gdb) frame 2
    #2  0x00000000006156ef in zif_sleep ()
    (gdb) print (char *)(executor_globals.function_state_ptr->function)->common.function_name
    Attempt to extract a component of a value that is not a structure.      
    (gdb) print (char *)(executor_globals.function_state_ptr->function)
    Attempt to extract a component of a value that is not a structure.
    (gdb) print (char *)(executor_globals)
    $2 = 0xffffffffffffcf48 <error: Cannot access memory at address 0xffffffffffffcf48>
    

    所以似乎executor_globals符号不可用。是因为二进制文件已经优化了,我在错误的框架中还是别的什么?或者我应该lldb改用?

1个回答

根据此链接,应该可以通过以下步骤找到正在使用的功能:

  1. 将 gdb 附加到当前运行的 PHP 进程: gdb -p <processid>
  2. .gdbinit为您的 PHP 版本加载 PHP文件(可从此处获得
  3. 使用zbacktrace命令显示当前运行的PHP脚本

例如:

gdb -p 4584
(gdb) source PHP_5_5/.gdbinit
(gdb) zbacktrace
[0xec906090] addOne() /tmp/yourscript.php:9