日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
教你如何使用gdb調(diào)試php!

本文給大家介紹關(guān)于如何使用gdb調(diào)試php(gdb 是c語言的代碼調(diào)試工具,可以用來調(diào)試php、python、mysql等),希望對需要的朋友有所幫助!

調(diào)試主要有4種形式

gdb:啟動之后用attach pid 追蹤程序
gdb [options] [executable-file [core-file or process-id]]
gdb [options] --args executable-file [inferior-arguments ...]
gdb [options] [--python|-P] script-file [script-arguments ...]

常用調(diào)試命令

attach pid

例:如果向跟蹤調(diào)試mysql代碼
1.先找到mysql進行ID:10111

2.再attach 10111追蹤mysql

layout

顯示源碼/匯編指令

Layout names are:
   src      : Displays source and command windows. 顯示源碼
   asm      : Displays disassembly    and command windows. 顯示匯編指令
   split : Displays source, disassembly    and command windows. 顯示源碼和匯編指令
   regs     : Displays register window. If    existing layout
              is source/command or    assembly/command, the 
              register window is displayed. If the
              source/assembly/command (split) is displayed, 
              the register    window is displayed with 
              the window that has current logical focus

break

  • b 增加斷點
  • info b 顯示斷點信息
  • delete num 刪除指定斷點

continue [num]

  • c num 執(zhí)行到num個斷點,num可以不填默認=1

next [num]

  • n num 執(zhí)行到下num行,num可以不填默認=1,不進入函數(shù)內(nèi)部

step [num]

  • s num 執(zhí)行到下num行,num可以不填默認=1,不進入函數(shù)內(nèi)部

backtrace

  • bt 查看當(dāng)前調(diào)用棧

print [value]

  • p value 打印變量信息

help

  • help layout 查看命令如何使用

調(diào)試php代碼

1. 新增一個php文件


2.查看php-fpm work進程PID

我這里通過修改php-fpm配置只啟動一個work進程方便追蹤

pm = static
pm.max_children = 1
[root@test ~]# ps aux|grep php-fpm
www        1127  0.0  0.1 279352  2816 ?        S    5月12   0:00 php-fpm: pool www
root      12224  0.0  0.0 112736   976 pts/0    S+   17:37   0:00 grep --color=auto php-fpm

3.追蹤PID

[root@test ~]# gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
.
(gdb) attach 1127
Attaching to process 1127
Reading symbols from /usr/local/php/sbin/php-fpm...done.
Reading symbols from /usr/lib64/libcrypt.so.1...Reading symbols 
from /usr/lib/debug/usr/lib64/libcrypt-2.17.so.debug...done.
done.

4.打斷點,這里在timelib_update_tsdo_years方法打了一個斷點,這里需要你看下php源碼,看你需要在哪里調(diào)試代碼

(gdb) b timelib_update_ts
Breakpoint 1 at 0x48ba90: file /opt/lnmp1.6/src/php-7.3.11/ext/date/lib/tm2unixtime.c, line 499.
(gdb) b do_years
`Breakpoint 3 at 0x48bb95: file /opt/lnmp1.6/src/php-7.3.11/ext/date/lib/tm2unixtime.c, line 381.`

5.請求測試文件

請求之后發(fā)現(xiàn)沒有立刻看到返回結(jié)果,被阻塞在了這里,說明執(zhí)行到了斷點的地方

[root@test ~]# curl localhost/3.php

6.查看調(diào)試信息

通過p *time可以看到變量time里面的內(nèi)容

(gdb) c
Continuing.

Breakpoint 1, timelib_update_ts (time=time@entry=0x7fc63ec02000, tzi=tzi@entry=0x7fc63ec75000) 
at /opt/lnmp1.6/src/php-7.3.11/ext/date/lib/tm2unixtime.c:499
499    {
(gdb) c
Continuing.

Breakpoint 3, timelib_update_ts (time=time@entry=0x7fc63ec02000, tzi=tzi@entry=0x7fc63ec75000) 
at /opt/lnmp1.6/src/php-7.3.11/ext/date/lib/tm2unixtime.c:505
505        res += do_years(time->y);
(gdb) s
do_years (year=2020) at /opt/lnmp1.6/src/php-7.3.11/ext/date/lib/tm2unixtime.c:381
381        eras = (year - 1970) / 40000;
(gdb) s
timelib_update_ts (time=time@entry=0x7fc63ec02000, tzi=tzi@entry=0x7fc63ec75000) 
at /opt/lnmp1.6/src/php-7.3.11/ext/date/lib/tm2unixtime.c:504
504        do_adjust_special(time);
(gdb) p *time
$1 = {y = 2020, m = 7, d = 31, h = 0, i = 0, s = 0, us = 0, z = 28800, tz_abbr = 0x7fc63ec71018 "CST", 
tz_info = 0x7fc63ec75000, dst = 0, relative = {y = 0, m = 2, 
    d = 0, h = 0, i = 0, s = 0, us = 0, weekday = 0, weekday_behavior = 0, first_last_day_of = 2, invert = 0, 
    days = -99999, special = {type = 0, amount = 0}, 
    have_weekday_relative = 0, have_special_relative = 0}, sse = 0, have_time = 0, have_date = 0, have_zone = 0, 
    have_relative = 1, have_weeknr_day = 0, 
  sse_uptodate = 0, tim_uptodate = 0, is_localtime = 1, zone_type = 3}
(gdb)

下面是do_years方法的代碼

static timelib_sll do_years(timelib_sll year)
{
    timelib_sll i;
    timelib_sll res = 0;
    timelib_sll eras;

    eras = (year - 1970) / 40000;
    if (eras != 0) {
        year = year - (eras * 40000);
        res += (SECS_PER_ERA * eras * 100);
    }
    
    if (year >= 1970) {
        for (i = year - 1; i >= 1970; i--) {
            //判斷是否是閏年,閏年366天,平年365天
            if (timelib_is_leap(i)) {
                res += (DAYS_PER_LYEAR * SECS_PER_DAY);
            } else {
                res += (DAYS_PER_YEAR * SECS_PER_DAY);
            }
        }
    } else {
        for (i = 1969; i >= year; i--) {
            if (timelib_is_leap(i)) {
                res -= (DAYS_PER_LYEAR * SECS_PER_DAY);
            } else {
                res -= (DAYS_PER_YEAR * SECS_PER_DAY);
            }
        }
    }
    return res;
}

總結(jié)

= 1970; $i--) {
        if (is_leap($i)) {
            $res += YEARLEEP * 86400;
        } else {
            $res += YEAR * 86400;
        }
    }
    //上海是東八區(qū)要減8小時
    $res -= 8 * 3600;
    return $res;
}

echo getStime('2020');

分享文章:教你如何使用gdb調(diào)試php!
分享網(wǎng)址:http://www.dlmjj.cn/article/cdjedeh.html