Slide 1

Slide 1 text

גࣜձࣾϠϓϦా࣮੣ %#(QΛ࢖ͬͯ 
 1)1ͷσόοΨʔΛͭ͘Ζ͏

Slide 2

Slide 2 text

ࣗݾ঺հ w ా࣮੣!U[N@GSFFEPN w גࣜձࣾϠϓϦͷαʔόʔαΠυΤϯδχΞ w 1)1ྺ͸ʙ೥͘Β͍ w 1)1FS,BJHJͰ͸1)1Ͱ1)1Λ࣮૷ 
 1)1$POGFSFODFͰ͸ಠࣗϑϨʔϜϫʔΫΛվળ

Slide 3

Slide 3 text

1)1FS,BJHJͰ͸ެࣜαΠτͷϝΠϯϏδϡΞϧΛ୲౰

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

μΠΞϞϯυͳεϙϯαʔ΍ͬͯ·͢ʂʂʂ

Slide 6

Slide 6 text

Έͳ͞Μσόοάͯ͠·͔͢ʂʁ

Slide 7

Slide 7 text

͜ͷηογϣϯͰ࿩͢͜ͱ w9EFCVHͱ͸Կ͔ʁ w9EFCVHͷσόοΨͷ࢖͍ํ w9EFCVHͷσόοΨ͸ͲͷΑ͏ʹͯ͠ಈ͍͍ͯΔͷ͔ w9EFCVHͷσόοΨͷ࡞Γํ

Slide 8

Slide 8 text

9EFCVHͱσόοΨʹ͍ͭͯ

Slide 9

Slide 9 text

9EFCVHͱ͸Կ͔ʁ w 1)1ͷ֦ுϞδϡʔϧʢ;FOEFYUFOTJPOʣ w εςοϓσόοάɾΧόϨοδऔಘɾؔ਺ͷτϨʔεɾϓϩϑ ΝΠϦϯά͕Ͱ͖Δ։ൃ༻Ϟδϡʔϧ w $-* NPE@QIQ 'BTU$(*ͳͲͷ4"1*Ͱར༻Մೳ w ओʹεςοϓσόοάɾΧόϨοδऔಘͷจ຺Ͱ࢖ΘΕΔ͜ͱ ͕ଟ͍

Slide 10

Slide 10 text

9EFCVHͷσόοΨͰͰ͖Δ͜ͱ w ΞϓϦέʔγϣϯͷεςοϓ࣮ߦ͕Ͱ͖Δ w ϒϨʔΫϙΠϯτͰ೚ҙͷ৔ॴͰϓϩάϥϜΛࢭΊΒΕΔ w ϩʔΧϧม਺ɾάϩʔόϧม਺ɾఆ਺ͷ஋ΛऔಘͰ͖Δ w 1IQ4UPSNͰσϑΥϧτͰ࢖͑ͨΓɺ7JN΍74$PEFͷϓϥ άΠϯ΋͋Δ

Slide 11

Slide 11 text

1IQ4UPSN$-*ͷ৔߹ w ೚ҙͷεΫϦϓτΛσόοά࣮ߦ͢Δ͚ͩ w ಺෦తʹ͸ҎԼͷίϚϯυΛୟ͍ͯεΫϦϓτΛ࣮ߦ͠ɺ*%& ଆͰσόοΨΛىಈ͍ͯ͠Δ $ /usr/bin/php -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host=127.0.0.1 /path/to/file.php

Slide 12

Slide 12 text

1IQ4UPSN8FCͷ৔߹ w πʔϧόʔ͔ΒσόοΨ઀ଓͷड෇Λ։࢝͢Δ w 8FCαʔόʔଆͷYEFCVHͷઃఆΛ͢Δ w YEFCVHNPEF YEFCVHDMJFOU@QPSU YEFCVHDMJFOU@IPTU YEFCVHTUBSU@XJUI@SFRVFTU ʜ w ର৅ͷϖʔδʹΞΫηε͢Δ

Slide 13

Slide 13 text

1IQ4UPSNϒϨʔΫϙΠϯτͷઃఆ ϒϨʔΫϙΠϯτ

Slide 14

Slide 14 text

1IQ4UPSNσόοά΢Οϯυ΢ εςοϓ࣮ߦ ม਺ ίʔϧελοΫ

Slide 15

Slide 15 text

9EFCVHʹΑΔσόοάͷ࢓૊Έ

Slide 16

Slide 16 text

1)1͔ΒσόοΨʹ઀ଓ YEFCVHDMJFOU@IPTU YEFCVHDMJFOU@QPSU͸ 
 ઀ଓઌͰ͋ΔσόοΨͷϗετɾϙʔτ

Slide 17

Slide 17 text

%#(QͰ΍ΓऔΓ w εςοϓ࣮ߦ΍ϒϨʔΫϙΠϯτͷઃఆΛϦΫΤετ w ࣮ߦ݁Ռ΍ఀࢭ৔ॴͷ৘ใͳͲ͕Ϩεϙϯεͱͯ͠ฦͬͯ͘Δ

Slide 18

Slide 18 text

%#(Qͱ͸ w ϥϯλΠϜඇґଘͳσόοΨ༻ϓϩτίϧ 
 ʢͱ͸͍͑9EFCVH͔͠࢖ͬͯͳͦ͞͏ w 5$1 w ϦΫΤετ͸ίϚϯυ w Ϩεϙϯε͸9.- w IUUQTYEFCVHPSHEPDTECHQ

Slide 19

Slide 19 text

%#(Qͷϑϩʔ 1)1͔ΒσόοΨʹ5$1઀ଓ 1)1͔ΒJOJUύέοτΛૹ৴ σόοΨ͔ΒίϚϯυΛૹ৴ 1)1͕σόοΨʹϨεϙϯεΛฦ͢ σόοΨ͕ϨεϙϯεΛղऍ ʙͷ܁Γฦ͠

Slide 20

Slide 20 text

1)1͔ΒJOJUύέοτΛૹ৴ …

Slide 21

Slide 21 text

σόοΨ͔ΒίϚϯυΛૹ৴ breakpoint_set -i 2 -t line -f /path/to/file -n 14 w JΦϓγϣϯͰτϥϯβΫγϣϯ*%ʹҰҙͳ਺ࣈΛࢦఆ w Ұҙͳ਺ࣈΛࢦఆ͢Ε͹ྑ͍ͷͰ࿈൪Ͱ0, w Ϩεϙϯεʹ΋τϥϯβΫγϣϯ*%ؚ͕·ΕΔͷͰɺϦΫΤετͱ ඥ෇͚Δ͜ͱ͕Ͱ͖Δ

Slide 22

Slide 22 text

1)1͕σόοΨʹϨεϙϯεΛฦ͢ τϥϯβΫγϣϯ*%

Slide 23

Slide 23 text

1IQ4UPSNͷσόοΨͷ௨৴ ϒϨʔΫϙΠϯτͷઃఆ εΫϦϓτͷ࣮ߦ ίʔϧελοΫͷऔಘ

Slide 24

Slide 24 text

1IQ4UPSNͷσόοΨͷ௨৴ w Ϩεϙϯε͸\9.-ͷαΠζ^laz\9.-^lazͷܗࣜ

Slide 25

Slide 25 text

Ϩεϙϯεͷ಺༰ 9.-ͷαΠζ

Slide 26

Slide 26 text

%#(QͰΑ͘࢖ΘΕΔίϚϯυ CSFBLQPJOU@TFU ϒϨΠΫϙΠϯτΛઃఆ͢Δ TUFQ@PWFS εςοϓΦʔόʔ TUBDL@HFU ݱࡏͷίʔϧελοΫΛऔಘ DPOUFYU@HFU ม਺ɾάϩʔόϧม਺ɾఆ਺Λऔಘ FWBM &YQSFTTJPOͷධՁ

Slide 27

Slide 27 text

1IQ4UPSNϒϨʔΫϙΠϯτ CSFBLQPJOU@TFU

Slide 28

Slide 28 text

1IQ4UPSNσόοά΢Οϯυ΢ TUBDL@HFU DPOUFYU@HFU TUFQ@JOUP TUFQ@PWFS

Slide 29

Slide 29 text

σόοΨΛ࡞Εͦ͏ͳؾ࣋ͪʹͳ͖ͬͯ ·ͨ͠ΑͶʁ

Slide 30

Slide 30 text

%#(QΛ࢖ͬͯ 1)1ͷσόοΨΛͭͬͯ͘Έͨ

Slide 31

Slide 31 text

ࠓճ࡞ͬͨ΋ͷ w HECͷΑ͏ͳίϚϯυϕʔεͷσόοΨ w 1)1੡ w ׬੒ͨ͠΋ͷ͸ͪ͜Βʹˣ w IUUQTHJUIVCDPNU[NGSFFEPNQIEC $ composer global require tzmfreedom/phdb $ phdb

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

%#(Qͷϑϩʔ 1)1͔ΒσόοΨʹ5$1઀ଓ 1)1͔ΒJOJUύέοτΛૹ৴ σόοΨ͔ΒίϚϯυΛૹ৴ 1)1͕σόοΨʹϨεϙϯεΛฦ͢ σόοΨ͕ϨεϙϯεΛղऍ ʙͷ܁Γฦ͠

Slide 34

Slide 34 text

5$1αʔόʔΛ࣮૷ conn, 1024, 0); $command = 'xxx'; stream_socket_sendto($this->conn, "${command}\0"); } } fclose($socket);

Slide 35

Slide 35 text

5$1αʔόʔΛ࣮૷ conn, 1024, 0); $command = 'xxx'; stream_socket_sendto($this->conn, "${command}\0"); } } fclose($socket); 5$1αʔόʔͷ্ཱͪ͛ 5$1઀ଓͷ଴ड 5$1ύέοτड৴ 5$1ύέοτૹ৴

Slide 36

Slide 36 text

// initͷϋϯυϦϯά $this->handleMessages($conn); // breakpoint_setͳͲͷॳظઃఆ while(true) { // ϢʔβೖྗͷಡΈऔΓ $input = readline("=> "); // ίϚϯυͷૹ৴ͱϨεϙϯεͷϋϯυϦϯά if ($this->sendCommand($conn, $input)) { $this->handleMessages($conn); } } 5$1઀ଓޙͷϑϩʔ

Slide 37

Slide 37 text

ϒϨʔΫϙΠϯτͷઃఆ breakpoint_set -i {id} -t line -f /path/to/file -n 14 ϒϨʔΫϙΠϯτ*% छผ ϑΝΠϧ໊ ߦ൪߸

Slide 38

Slide 38 text

ϒϨʔΫϙΠϯτͷछผ MJOF ϑΝΠϧɾߦ൪߸ DBMM ؔ਺ݺͼग़ͨ͠͠ͱ͖ SFUVSO ؔ਺ݺͼग़͔͠Β໭ͬͨͱ͖ FYDFQUJPO &YDFQUJPO͕εϩʔ͞Εͨͱ͖ DPOEJUJPOBM ϑΝΠϧɾߦ൪߸ʴධՁ৚݅

Slide 39

Slide 39 text

ϒϨʔΫϙΠϯτͰࢭΊͨ͋ͱ͸ʜ w ίʔϧελοΫΛ֬ೝ w ม਺Λ֬ೝ w εςοϓ࣮ߦ w FWBM w ͳͲͳͲ

Slide 40

Slide 40 text

ίʔϧελοΫΛ֬ೝ stack_get -i {id} ϑΝΠϧ໊ ߦ൪߸ ελοΫ৘ใ

Slide 41

Slide 41 text

ม਺Λ֬ೝ context_get -i {id} ஋ ม਺໊

Slide 42

Slide 42 text

ม਺Λ֬ೝΦϒδΣΫτͷ৔߹ Πϯελϯεม਺ Ϋϥε໊

Slide 43

Slide 43 text

εςοϓ࣮ߦ step_over -i {id} ݱࡏͷϑΝΠϧ໊ ݱࡏͷߦ൪߸

Slide 44

Slide 44 text

FWBMͰ&YQSFTTJPOΛධՁ eval -i {id} -d 1 -- ZWNobyAkaTs= FYQSFTTJPOͷCBTF ධՁ஋

Slide 45

Slide 45 text

͓·͚

Slide 46

Slide 46 text

ʲ্ڃฤʁʳ9EFCVH͸Ͳ͏΍ͬͯಈ͍͍ͯΔʁ w 1)1͔ΒσόοΨʹ5$1઀ଓͨ͠ΓɺϒϨʔΫϙΠϯτ΍ε ςοϓ࣮ߦͰॲཧΛࢭΊͯσόοΨʹϨεϙϯεΛૹ͍ͬͯΔ w ͜ΕΛ1)1ͰͲ͏΍࣮ͬͯݱ͍ͯ͠Δͷ͔

Slide 47

Slide 47 text

ʲ্ڃฤʁʳ9EFCVH͸Ͳ͏΍ͬͯಈ͍͍ͯΔʁ w 1)1͔ΒσόοΨʹ5$1઀ଓͨ͠ΓɺϒϨʔΫϙΠϯτ΍ε ςοϓ࣮ߦͰॲཧΛࢭΊͯσόοΨʹϨεϙϯεΛૹ͍ͬͯΔ w ͜ΕΛ1)1ͰͲ͏΍࣮ͬͯݱ͍ͯ͠Δͷ͔ w [FOE@FYFDVUF@FYͷࠩ͠ସ͑ w TUBUFNFOU@IBOEMFSʹΑΔϑοΫ

Slide 48

Slide 48 text

[FOE@FYFDVUF@FY w εΫϦϓτ࣮ߦ࣌ʹݺ͹ΕΔؔ਺ϙΠϯλ w σϑΥϧτͷؔ਺ϙΠϯλ͔Βࠩ͠ସ͑Δͱɺؔ਺ݺͼग़͠ͷͨͼʹݺ͹ ΕΔΑ͏ʹͳΔ w ࠷ॳͷ5$1઀ଓͱJOJUύέοτͷૹ৴ w εΫϦϓτ࣮ߦ࣌ʹݺ͹ΕΔ[FOE@FYFDVUF@FYͰ࣮ߦ w ίʔϧελοΫͷ؅ཧ w ؔ਺ݺͼग़͠ͷ[FOE@FYFDVUF@FYͷલޙͰελοΫʹϓογϡϙοϓ

Slide 49

Slide 49 text

[FOE@FYFDVUF@FYͷࠩ͠ସ͑ void xdebug_base_minit(INIT_FUNC_ARGS) { // ... xdebug_old_execute_ex = zend_execute_ex; zend_execute_ex = xdebug_execute_ex; xdebug_old_execute_internal = zend_execute_internal; zend_execute_internal = xdebug_execute_internal; // ... } ݩͷ[FOE@FYFDVUF@FYΛPMEʹ଴ආ YEFCVH@FYFDVUF@FYͰؔ਺ϙΠϯλΛ্ॻ͖

Slide 50

Slide 50 text

ݩͷ[FOE@FYFDVUF@FYલޙʹॲཧΛೖΕΔ static void xdebug_execute_ex(zend_execute_data *execute_data) { // ... fse = xdebug_add_stack_frame(edata, op_array, XDEBUG_USER_DEFINED); // ... xdebug_old_execute_ex(execute_data); // ... if (XG_BASE(stack)) { xdebug_vector_pop(XG_BASE(stack)); } } ίʔϧελοΫʹϓογϡ ίʔϧελοΫ͔Βϙοϓ ݩͷ[FOE@FYFDVUF@FYΛݺͼग़͠

Slide 51

Slide 51 text

TUBUFNFOU@IBOEMFS w ;FOE֦ுͰ͸εςʔτϝϯτ࣮ߦ͝ͱʹϑοΫ͢Δؔ਺ΛࢦఆͰ͖Δ w 9EFCVHͰ͸εςοϓ࣮ߦ΍ϒϨʔΫϙΠϯτͰॲཧΛࢭΊΔͱ͖ʹ ར༻ ZEND_DLEXPORT zend_extension zend_extension_entry = { … xdebug_statement_call, /* statement_handler_func_t */ … };

Slide 52

Slide 52 text

CSFBLQPJOUͰݺ͹ΕΔؔ਺ int xdebug_dbgp_breakpoint() { // ... response = xdebug_xml_node_init("response"); xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); // ... send_message(context, response); // ... xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BAIL); // ... 9.-ͷϨεϙϯεΛ࡞੒ ϝοηʔδΛૹ৴ ίϚϯυϧʔϓ

Slide 53

Slide 53 text

·ͱΊ w%#(QͱσόοΨͷ࡞ΓํΛ঺հ͠·ͨ͠ w%#(Q͸5$1ͳϓϩτίϧ 
 ϖΠϩʔυ͸ίϚϯυʴ9.- w%#(QΛ࢖ͬͨσόοΨ͸ൺֱత؆୯ʹ࡞ΕΔͷͰ 
 օ͞Μ࠷ڧͷσόοΨΛ࡞͍͖ͬͯ·͠ΐ͏💪

Slide 54

Slide 54 text

σόοΨͱ஥ྑ͘ͳͬͯ ര଎։ൃ͍͖ͯ͠·͠ΐ͏👍

Slide 55

Slide 55 text

͓·͚ඪ४ग़ྗɾΤϥʔग़ྗ΋੍ޚͰ͖Δ stdout -i {id} -c 1 ແޮ ίϐʔ ϦμΠϨΫτ w ΞϓϦέʔγϣϯͷඪ४ग़ྗɾΤϥʔग़ྗΛ 
 σόοΨʹίϐʔ͢Δ͔ϦμΠϨΫτͤ͞Δ͜ͱ͕Մೳ w ಺༰͸9.-Ͱฦͬͯ͘Δ

Slide 56

Slide 56 text

ඪ४ग़ྗͷ9.- ...Base64 Data... w lSFTQPOTFͰ͸ͳ͘lTUSFBNzͰฦͬͯ͘Δ w ίϚϯυϨεϙϯεͷΑ͏ʹҰରʹͳ͓ͬͯΒͣෳ਺ฦͬ ͯ͘ΔͷͰ஫ҙ͕ඞཁ